From 413a175b531910d45bec0dfe6332494c452ddf37 Mon Sep 17 00:00:00 2001 From: James Dorfman Date: Mon, 23 Sep 2024 21:22:11 +0000 Subject: [PATCH] Fixes for Elements PR #1270 --- src/node/blockstorage.cpp | 10 +++++----- src/node/blockstorage.h | 4 ++-- src/validation.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) mode change 100644 => 100755 src/node/blockstorage.h diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index 3245f9927e..c4906711c4 100755 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -257,7 +257,7 @@ CBlockIndex* BlockManager::InsertBlockIndex(const uint256& hash) return pindex; } -bool BlockManager::LoadBlockIndex(const Consensus::Params& consensus_params) +bool BlockManager::LoadBlockIndex(ChainstateManager& chainman, const Consensus::Params& consensus_params) { int trim_below_height = 0; if (fTrimHeaders) { @@ -302,8 +302,8 @@ bool BlockManager::LoadBlockIndex(const Consensus::Params& consensus_params) } } - if (pindexBestHeader) { - ForceUntrimHeader(pindexBestHeader); + if (chainman.m_best_header) { + ForceUntrimHeader(chainman.m_best_header); } return true; } @@ -329,9 +329,9 @@ bool BlockManager::WriteBlockIndexDB() return true; } -bool BlockManager::LoadBlockIndexDB(const Consensus::Params& consensus_params) +bool BlockManager::LoadBlockIndexDB(ChainstateManager& chainman, const Consensus::Params& consensus_params) { - if (!LoadBlockIndex(consensus_params)) { + if (!LoadBlockIndex(chainman, consensus_params)) { return false; } diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h old mode 100644 new mode 100755 index 31c9711690..3da17fd905 --- a/src/node/blockstorage.h +++ b/src/node/blockstorage.h @@ -97,7 +97,7 @@ private: * per index entry (nStatus, nChainWork, nTimeMax, etc.) as well as peripheral * collections like m_dirty_blockindex. */ - bool LoadBlockIndex(const Consensus::Params& consensus_params) + bool LoadBlockIndex(ChainstateManager& chainman, const Consensus::Params& consensus_params) EXCLUSIVE_LOCKS_REQUIRED(cs_main); void FlushBlockFile(bool fFinalize = false, bool finalize_undo = false); void FlushUndoFile(int block_file, bool finalize = false); @@ -161,7 +161,7 @@ public: std::unique_ptr m_block_tree_db GUARDED_BY(::cs_main); bool WriteBlockIndexDB() EXCLUSIVE_LOCKS_REQUIRED(::cs_main); - bool LoadBlockIndexDB(const Consensus::Params& consensus_params) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); + bool LoadBlockIndexDB(ChainstateManager& chainman, const Consensus::Params& consensus_params) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); CBlockIndex* AddToBlockIndex(const CBlockHeader& block, CBlockIndex*& best_header) EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** Create a new block index entry for a given block hash */ diff --git a/src/validation.cpp b/src/validation.cpp index c35f7c618d..53cf2cc0c2 100755 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2650,8 +2650,8 @@ bool CChainState::FlushStateToDisk( } int trim_height = 0; - if (pindexBestHeader && (uint64_t)pindexBestHeader->nHeight > node::nMustKeepFullHeaders) { // check first, to prevent underflow - trim_height = pindexBestHeader->nHeight - node::nMustKeepFullHeaders; + if (m_chainman.m_best_header && (uint64_t)m_chainman.m_best_header->nHeight > node::nMustKeepFullHeaders) { // check first, to prevent underflow + trim_height = m_chainman.m_best_header->nHeight - node::nMustKeepFullHeaders; } if (node::fTrimHeaders && trim_height > 0 && !ShutdownRequested()) { static int nMinTrimHeight{0}; @@ -2662,7 +2662,7 @@ bool CChainState::FlushStateToDisk( (*it)->trim(); } } - CBlockIndex* min_index = pindexBestHeader->GetAncestor(trim_height-1); + CBlockIndex* min_index = m_chainman.m_best_header->GetAncestor(trim_height-1); // Handle any remaining untrimmed blocks that were too recent for trimming last time we flushed. if (min_index) { int nMaxTrimHeightRound = std::max(nMinTrimHeight, min_index->nHeight + 1); @@ -4610,7 +4610,7 @@ bool ChainstateManager::LoadBlockIndex() // Load block index from databases bool needs_init = fReindex; if (!fReindex) { - bool ret = m_blockman.LoadBlockIndexDB(GetConsensus()); + bool ret = m_blockman.LoadBlockIndexDB(*this, GetConsensus()); if (!ret) return false; std::vector vSortedByHeight{m_blockman.GetAllBlockIndices()};