mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 02:33:24 -03:00
validation: add ChainstateRole
This commit is contained in:
parent
9f2318c76c
commit
c6af23c517
4 changed files with 48 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <chain.h>
|
#include <chain.h>
|
||||||
#include <interfaces/chain.h>
|
#include <interfaces/chain.h>
|
||||||
|
#include <kernel/chain.h>
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
|
|
||||||
|
@ -25,3 +26,13 @@ interfaces::BlockInfo MakeBlockInfo(const CBlockIndex* index, const CBlock* data
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
} // namespace kernel
|
} // namespace kernel
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const ChainstateRole& role) {
|
||||||
|
switch(role) {
|
||||||
|
case ChainstateRole::NORMAL: os << "normal"; break;
|
||||||
|
case ChainstateRole::ASSUMEDVALID: os << "assumedvalid"; break;
|
||||||
|
case ChainstateRole::BACKGROUND: os << "background"; break;
|
||||||
|
default: os.setstate(std::ios_base::failbit);
|
||||||
|
}
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#ifndef BITCOIN_KERNEL_CHAIN_H
|
#ifndef BITCOIN_KERNEL_CHAIN_H
|
||||||
#define BITCOIN_KERNEL_CHAIN_H
|
#define BITCOIN_KERNEL_CHAIN_H
|
||||||
|
|
||||||
|
#include<iostream>
|
||||||
|
|
||||||
class CBlock;
|
class CBlock;
|
||||||
class CBlockIndex;
|
class CBlockIndex;
|
||||||
namespace interfaces {
|
namespace interfaces {
|
||||||
|
@ -14,6 +16,24 @@ struct BlockInfo;
|
||||||
namespace kernel {
|
namespace kernel {
|
||||||
//! Return data from block index.
|
//! Return data from block index.
|
||||||
interfaces::BlockInfo MakeBlockInfo(const CBlockIndex* block_index, const CBlock* data = nullptr);
|
interfaces::BlockInfo MakeBlockInfo(const CBlockIndex* block_index, const CBlock* data = nullptr);
|
||||||
|
|
||||||
} // namespace kernel
|
} // namespace kernel
|
||||||
|
|
||||||
|
//! This enum describes the various roles a specific Chainstate instance can take.
|
||||||
|
//! Other parts of the system sometimes need to vary in behavior depending on the
|
||||||
|
//! existence of a background validation chainstate, e.g. when building indexes.
|
||||||
|
enum class ChainstateRole {
|
||||||
|
// Single chainstate in use, "normal" IBD mode.
|
||||||
|
NORMAL,
|
||||||
|
|
||||||
|
// Doing IBD-style validation in the background. Implies use of an assumed-valid
|
||||||
|
// chainstate.
|
||||||
|
BACKGROUND,
|
||||||
|
|
||||||
|
// Active assumed-valid chainstate. Implies use of a background IBD chainstate.
|
||||||
|
ASSUMEDVALID,
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const ChainstateRole& role);
|
||||||
|
|
||||||
#endif // BITCOIN_KERNEL_CHAIN_H
|
#endif // BITCOIN_KERNEL_CHAIN_H
|
||||||
|
|
|
@ -5813,6 +5813,16 @@ bool ChainstateManager::DeleteSnapshotChainstate()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ChainstateRole Chainstate::GetRole() const
|
||||||
|
{
|
||||||
|
if (m_chainman.GetAll().size() <= 1) {
|
||||||
|
return ChainstateRole::NORMAL;
|
||||||
|
}
|
||||||
|
return (this != &m_chainman.ActiveChainstate()) ?
|
||||||
|
ChainstateRole::BACKGROUND :
|
||||||
|
ChainstateRole::ASSUMEDVALID;
|
||||||
|
}
|
||||||
|
|
||||||
const CBlockIndex* ChainstateManager::GetSnapshotBaseBlock() const
|
const CBlockIndex* ChainstateManager::GetSnapshotBaseBlock() const
|
||||||
{
|
{
|
||||||
return m_active_chainstate ? m_active_chainstate->SnapshotBase() : nullptr;
|
return m_active_chainstate ? m_active_chainstate->SnapshotBase() : nullptr;
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <arith_uint256.h>
|
#include <arith_uint256.h>
|
||||||
#include <attributes.h>
|
#include <attributes.h>
|
||||||
#include <chain.h>
|
#include <chain.h>
|
||||||
|
#include <kernel/chain.h>
|
||||||
#include <consensus/amount.h>
|
#include <consensus/amount.h>
|
||||||
#include <deploymentstatus.h>
|
#include <deploymentstatus.h>
|
||||||
#include <kernel/chainparams.h>
|
#include <kernel/chainparams.h>
|
||||||
|
@ -511,6 +512,12 @@ public:
|
||||||
ChainstateManager& chainman,
|
ChainstateManager& chainman,
|
||||||
std::optional<uint256> from_snapshot_blockhash = std::nullopt);
|
std::optional<uint256> from_snapshot_blockhash = std::nullopt);
|
||||||
|
|
||||||
|
//! Return the current role of the chainstate. See `ChainstateManager`
|
||||||
|
//! documentation for a description of the different types of chainstates.
|
||||||
|
//!
|
||||||
|
//! @sa ChainstateRole
|
||||||
|
ChainstateRole GetRole() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the CoinsViews UTXO set database management data structures. The in-memory
|
* Initialize the CoinsViews UTXO set database management data structures. The in-memory
|
||||||
* cache is initialized separately.
|
* cache is initialized separately.
|
||||||
|
|
Loading…
Add table
Reference in a new issue