From 4668ded6d6ea4299d998abbb57543f37519812e2 Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Tue, 8 Sep 2020 14:36:31 -0400 Subject: validation: Move ~CMainCleanup logic to ~BlockManager ~CMainCleanup: 1. Is vestigial 2. References the g_chainman global (we should minimize g_chainman refs) 3. Only acts on g_chainman.m_blockman 4. Does the same thing as BlockManager::Unload --- src/validation.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/validation.h') diff --git a/src/validation.h b/src/validation.h index 53c2dd65e5..12d1d4c91f 100644 --- a/src/validation.h +++ b/src/validation.h @@ -416,6 +416,10 @@ public: BlockValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main); + + ~BlockManager() { + Unload(); + } }; /** -- cgit v1.2.3 From 74f73c783d46b012f375d819e2cd09c792820cd5 Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Tue, 25 Aug 2020 15:23:57 -0400 Subject: validation: Pass in chainman to UnloadBlockIndex --- src/validation.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/validation.h') diff --git a/src/validation.h b/src/validation.h index 12d1d4c91f..2d9d2cb918 100644 --- a/src/validation.h +++ b/src/validation.h @@ -159,7 +159,7 @@ void LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFi /** Ensures we have a genesis block in the block tree, possibly writing one to disk. */ bool LoadGenesisBlock(const CChainParams& chainparams); /** Unload database information */ -void UnloadBlockIndex(CTxMemPool* mempool); +void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman); /** Run an instance of the script checking thread */ void ThreadScriptCheck(int worker_num); /** -- cgit v1.2.3 From f8d4975ab3fcd3553843cf0862251289c88c106b Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Tue, 25 Aug 2020 19:05:50 -0400 Subject: validation: Move PruneOneBlockFile to BlockManager [META] This is a pure refactor commit. Move PruneBlockFile to BlockManager because: 1. PruneOneBlockFile only acts on BlockManager 2. Eliminates the need for callers (FindFilesToPrune{,Manual}) to have a reference to the larger ChainstateManager, just a reference to BlockManager is enough. See following commits. --- src/validation.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/validation.h') diff --git a/src/validation.h b/src/validation.h index 2d9d2cb918..40611fa61f 100644 --- a/src/validation.h +++ b/src/validation.h @@ -407,6 +407,9 @@ public: /** Create a new block index entry for a given block hash */ CBlockIndex* InsertBlockIndex(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main); + //! 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. @@ -903,9 +906,6 @@ public: */ bool ProcessNewBlockHeaders(const std::vector& block, BlockValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex = nullptr) LOCKS_EXCLUDED(cs_main); - //! Mark one block file as pruned (modify associated database entries) - void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main); - //! Load the block tree and coins database from disk, initializing state if we're running with -reindex bool LoadBlockIndex(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main); -- cgit v1.2.3 From 3f5b5f3f6db0e5716911b3fba1460ce327e8a845 Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Tue, 25 Aug 2020 19:38:23 -0400 Subject: validation: Move FindFilesToPrune{,Manual} to BlockManager [META] No behaviour change is intended in this commit. [META] This commit should be followed up by removing the comments and assertions meant only to show that the change is correct. Also stop FindFilesToPrune{,Manual} from unnecessary reaching for ::ChainActive() by passing in the necessary information. --- src/validation.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/validation.h') diff --git a/src/validation.h b/src/validation.h index 40611fa61f..94bf16968a 100644 --- a/src/validation.h +++ b/src/validation.h @@ -356,7 +356,15 @@ struct CBlockIndexWorkComparator * This data is used mostly in `CChainState` - information about, e.g., * candidate tips is not maintained here. */ -class BlockManager { +class BlockManager +{ + friend CChainState; + +private: + // See definition for documentation + void FindFilesToPruneManual(std::set& setFilesToPrune, int nManualPruneHeight, int chain_tip_height); + void FindFilesToPrune(std::set& setFilesToPrune, uint64_t nPruneAfterHeight, int chain_tip_height, bool is_ibd); + public: BlockMap m_block_index GUARDED_BY(cs_main); -- cgit v1.2.3 From 3756853b15902d63f4b5a3129e8b5d82e84e125b Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Mon, 14 Sep 2020 10:19:12 -0400 Subject: docs: Move FindFilesToPrune{,Manual} doxygen comment [META] This is a pure comment commit. They belong in the member declarations in the header file. --- src/validation.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/validation.h') diff --git a/src/validation.h b/src/validation.h index 94bf16968a..9114b24c94 100644 --- a/src/validation.h +++ b/src/validation.h @@ -361,8 +361,24 @@ class BlockManager friend CChainState; private: - // See definition for documentation + /* Calculate the block/rev files to delete based on height specified by user with RPC command pruneblockchain */ void FindFilesToPruneManual(std::set& setFilesToPrune, int nManualPruneHeight, int chain_tip_height); + + /** + * Prune block and undo files (blk???.dat and undo???.dat) so that the disk space used is less than a user-defined target. + * The user sets the target (in MB) on the command line or in config file. This will be run on startup and whenever new + * space is allocated in a block or undo file, staying below the target. Changing back to unpruned requires a reindex + * (which in this case means the blockchain must be re-downloaded.) + * + * Pruning functions are called from FlushStateToDisk when the global fCheckForPruning flag has been set. + * Block and undo files are deleted in lock-step (when blk00003.dat is deleted, so is rev00003.dat.) + * Pruning cannot take place until the longest chain is at least a certain length (100000 on mainnet, 1000 on testnet, 1000 on regtest). + * Pruning will never delete a block within a defined distance (currently 288) from the active chain's tip. + * The block index is updated by unsetting HAVE_DATA and HAVE_UNDO for any blocks that were stored in the deleted files. + * A db flag records the fact that at least some block files have been pruned. + * + * @param[out] setFilesToPrune The set of file indices that can be unlinked will be returned + */ void FindFilesToPrune(std::set& setFilesToPrune, uint64_t nPruneAfterHeight, int chain_tip_height, bool is_ibd); public: -- cgit v1.2.3