aboutsummaryrefslogtreecommitdiff
path: root/src/validation.h
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-12-16 15:13:18 +0100
committerMarcoFalke <falke.marco@gmail.com>2021-12-16 15:13:31 +0100
commit8c0bd871fcf6c5ff5851ccb18a7bc7554a0484b0 (patch)
treeef3d170cffde96584676bcfd5ef1327dddb1171b /src/validation.h
parent6b212cbbb9d7a564fc47c390e4bb20989ce26f5a (diff)
parentfab6d6b2d154893ab422dda87f3535d42c3e06f4 (diff)
downloadbitcoin-8c0bd871fcf6c5ff5851ccb18a7bc7554a0484b0.tar.xz
Merge bitcoin/bitcoin#23785: refactor: Move stuff to ChainstateManager
fab6d6b2d154893ab422dda87f3535d42c3e06f4 Move pindexBestInvalid to ChainstateManager (MarcoFalke) facd2137eceacb95e1f71c87ddc704d752b37272 Move m_failed_blocks to ChainstateManager (MarcoFalke) fa47b5c100f81c65c15b5a6afaf6c91bc0861264 Move AcceptBlockHeader to ChainstateManager (MarcoFalke) fa3d62cf7b3501a056b34c5458c14d2fe6a55bd7 Move FindForkInGlobalIndex from BlockManager to CChainState (MarcoFalke) Pull request description: Move globals or members of the wrong class to the right class. ACKs for top commit: naumenkogs: ACK fab6d6b2d154893ab422dda87f3535d42c3e06f4 Sjors: ACK fab6d6b2d154893ab422dda87f3535d42c3e06f4 shaavan: ACK fab6d6b2d154893ab422dda87f3535d42c3e06f4 Tree-SHA512: 926cbdfa22838517497bacb79ed5f521f64117c2aacf96a0176f62831b4713314a32abc0213df5ee067edf63e4a4300f752a26006d36e5aab415bb91209a271f
Diffstat (limited to 'src/validation.h')
-rw-r--r--src/validation.h71
1 files changed, 38 insertions, 33 deletions
diff --git a/src/validation.h b/src/validation.h
index ddfc8df939..160fffd048 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -421,26 +421,6 @@ private:
public:
BlockMap m_block_index GUARDED_BY(cs_main);
- /** In order to efficiently track invalidity of headers, we keep the set of
- * blocks which we tried to connect and found to be invalid here (ie which
- * were set to BLOCK_FAILED_VALID since the last restart). We can then
- * walk this set and check if a new header is a descendant of something in
- * this set, preventing us from having to walk m_block_index when we try
- * to connect a bad block and fail.
- *
- * While this is more complicated than marking everything which descends
- * from an invalid block as invalid at the time we discover it to be
- * invalid, doing so would require walking all of m_block_index to find all
- * descendants. Since this case should be very rare, keeping track of all
- * BLOCK_FAILED_VALID blocks in a set should be just fine and work just as
- * well.
- *
- * Because we already walk m_block_index in height-order at startup, we go
- * ahead and mark descendants of invalid blocks as FAILED_CHILD at that time,
- * instead of putting things in this set.
- */
- std::set<CBlockIndex*> m_failed_blocks;
-
/**
* All pairs A->B, where A (or one of its ancestors) misses transactions, but B has transactions.
* Pruned nodes may have entries where B is missing data.
@@ -470,21 +450,8 @@ public:
//! Mark one block file as pruned (modify associated database entries)
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
- /**
- * If a block header hasn't already been seen, call CheckBlockHeader on it, ensure
- * that it doesn't descend from an invalid block, and then add it to m_block_index.
- */
- bool AcceptBlockHeader(
- const CBlockHeader& block,
- BlockValidationState& state,
- const CChainParams& chainparams,
- CBlockIndex** ppindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
-
CBlockIndex* LookupBlockIndex(const uint256& hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
- /** Find the last common block between the parameter chain and a locator. */
- CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
-
//! Returns last CBlockIndex* that is a checkpoint
CBlockIndex* GetLastCheckpoint(const CCheckpointData& data) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
@@ -772,6 +739,9 @@ public:
/** Check whether we are doing an initial block download (synchronizing from disk or network) */
bool IsInitialBlockDownload() const;
+ /** Find the last common block of this chain and a locator. */
+ CBlockIndex* FindForkInGlobalIndex(const CBlockLocator& locator) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
+
/**
* Make various assertions about the state of the block index.
*
@@ -912,18 +882,53 @@ private:
//! by the background validation chainstate.
bool m_snapshot_validated{false};
+ CBlockIndex* m_best_invalid;
+ friend bool BlockManager::LoadBlockIndex(const Consensus::Params&, ChainstateManager&);
+
//! Internal helper for ActivateSnapshot().
[[nodiscard]] bool PopulateAndValidateSnapshot(
CChainState& snapshot_chainstate,
CAutoFile& coins_file,
const SnapshotMetadata& metadata);
+ /**
+ * If a block header hasn't already been seen, call CheckBlockHeader on it, ensure
+ * that it doesn't descend from an invalid block, and then add it to m_block_index.
+ */
+ bool AcceptBlockHeader(
+ const CBlockHeader& block,
+ BlockValidationState& state,
+ const CChainParams& chainparams,
+ CBlockIndex** ppindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
+ friend CChainState;
+
public:
std::thread m_load_block;
//! A single BlockManager instance is shared across each constructed
//! chainstate to avoid duplicating block metadata.
BlockManager m_blockman GUARDED_BY(::cs_main);
+ /**
+ * In order to efficiently track invalidity of headers, we keep the set of
+ * blocks which we tried to connect and found to be invalid here (ie which
+ * were set to BLOCK_FAILED_VALID since the last restart). We can then
+ * walk this set and check if a new header is a descendant of something in
+ * this set, preventing us from having to walk m_block_index when we try
+ * to connect a bad block and fail.
+ *
+ * While this is more complicated than marking everything which descends
+ * from an invalid block as invalid at the time we discover it to be
+ * invalid, doing so would require walking all of m_block_index to find all
+ * descendants. Since this case should be very rare, keeping track of all
+ * BLOCK_FAILED_VALID blocks in a set should be just fine and work just as
+ * well.
+ *
+ * Because we already walk m_block_index in height-order at startup, we go
+ * ahead and mark descendants of invalid blocks as FAILED_CHILD at that time,
+ * instead of putting things in this set.
+ */
+ std::set<CBlockIndex*> m_failed_blocks;
+
//! The total number of bytes available for us to use across all in-memory
//! coins caches. This will be split somehow across chainstates.
int64_t m_total_coinstip_cache{0};