From 110a0f405cd696ebfd6edce07c1b347723e84a0f Mon Sep 17 00:00:00 2001 From: pablomartin4btc Date: Sun, 10 Aug 2025 15:11:12 -0300 Subject: [PATCH 1/2] interfaces, chain, refactor: Remove unused getTipLocator Also removed CChain::GetLocator() and replaced its call with GetLocator() which uses LocatorEntries instead. Co-authored-by: ryanofsky Co-authored-by: l0rinc --- src/chain.cpp | 5 ----- src/chain.h | 3 --- src/interfaces/chain.h | 3 --- src/node/interfaces.cpp | 5 ----- src/validation.cpp | 2 +- 5 files changed, 1 insertion(+), 17 deletions(-) diff --git a/src/chain.cpp b/src/chain.cpp index 82007a8a1e7..4e2d1bf0ac8 100644 --- a/src/chain.cpp +++ b/src/chain.cpp @@ -52,11 +52,6 @@ CBlockLocator GetLocator(const CBlockIndex* index) return CBlockLocator{LocatorEntries(index)}; } -CBlockLocator CChain::GetLocator() const -{ - return ::GetLocator(Tip()); -} - const CBlockIndex *CChain::FindFork(const CBlockIndex *pindex) const { if (pindex == nullptr) { return nullptr; diff --git a/src/chain.h b/src/chain.h index f5bfdb2fb4b..68aa612bfc4 100644 --- a/src/chain.h +++ b/src/chain.h @@ -467,9 +467,6 @@ public: /** Set/initialize a chain with a given tip. */ void SetTip(CBlockIndex& block); - /** Return a CBlockLocator that refers to the tip in of this chain. */ - CBlockLocator GetLocator() const; - /** Find the last common block between this chain and a block index entry. */ const CBlockIndex* FindFork(const CBlockIndex* pindex) const; diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index 56716ec673f..f45cb8e5987 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -143,9 +143,6 @@ public: //! pruned), and contains transactions. virtual bool haveBlockOnDisk(int height) = 0; - //! Get locator for the current chain tip. - virtual CBlockLocator getTipLocator() = 0; - //! Return a locator that refers to a block in the active chain. //! If specified block is not in the active chain, return locator for the latest ancestor that is in the chain. virtual CBlockLocator getActiveChainLocator(const uint256& block_hash) = 0; diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 62172930dca..d7ada5ae75b 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -559,11 +559,6 @@ public: const CBlockIndex* block{chainman().ActiveChain()[height]}; return block && ((block->nStatus & BLOCK_HAVE_DATA) != 0) && block->nTx > 0; } - CBlockLocator getTipLocator() override - { - LOCK(::cs_main); - return chainman().ActiveChain().GetLocator(); - } CBlockLocator getActiveChainLocator(const uint256& block_hash) override { LOCK(::cs_main); diff --git a/src/validation.cpp b/src/validation.cpp index 61dec1314b3..fbc1b03c578 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2919,7 +2919,7 @@ bool Chainstate::FlushStateToDisk( } if (full_flush_completed && m_chainman.m_options.signals) { // Update best block in wallet (so we can detect restored wallets). - m_chainman.m_options.signals->ChainStateFlushed(this->GetRole(), m_chain.GetLocator()); + m_chainman.m_options.signals->ChainStateFlushed(this->GetRole(), GetLocator(m_chain.Tip())); } } catch (const std::runtime_error& e) { return FatalError(m_chainman.GetNotifications(), state, strprintf(_("System error while flushing: %s"), e.what())); From 2b00030af84efd50cfc60125db4ae49da6b7aa9a Mon Sep 17 00:00:00 2001 From: pablomartin4btc Date: Sun, 10 Aug 2025 15:24:49 -0300 Subject: [PATCH 2/2] interfaces, chain, refactor: Remove inaccurate getActiveChainLocator The getActiveChainLocator method name was misleading, and its functionality duplicated `Chain::findBlock`. This commit removes the method and replaces all its usages with direct `Chain::findBlock` calls. Additionally, the comment of getActiveChainLocator has been outdated since commit ed47094 from #25717. Finally, in CWallet::ScanForWalletTransactions, the findBlock calls are now unified into a single call at the start of the function. Co-authored-by: Ryan Ofsky Co-authored-by: Matias Furszyfer --- src/interfaces/chain.h | 4 ---- src/node/interfaces.cpp | 6 ------ src/wallet/wallet.cpp | 20 ++++++++++---------- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index f45cb8e5987..82e626e35de 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -143,10 +143,6 @@ public: //! pruned), and contains transactions. virtual bool haveBlockOnDisk(int height) = 0; - //! Return a locator that refers to a block in the active chain. - //! If specified block is not in the active chain, return locator for the latest ancestor that is in the chain. - virtual CBlockLocator getActiveChainLocator(const uint256& block_hash) = 0; - //! Return height of the highest block on chain in common with the locator, //! which will either be the original block used to create the locator, //! or one of its ancestors. diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index d7ada5ae75b..106c961173d 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -559,12 +559,6 @@ public: const CBlockIndex* block{chainman().ActiveChain()[height]}; return block && ((block->nStatus & BLOCK_HAVE_DATA) != 0) && block->nTx > 0; } - CBlockLocator getActiveChainLocator(const uint256& block_hash) override - { - LOCK(::cs_main); - const CBlockIndex* index = chainman().m_blockman.LookupBlockIndex(block_hash); - return GetLocator(index); - } std::optional findLocatorFork(const CBlockLocator& locator) override { LOCK(::cs_main); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index f86a28c52e4..6985f2cf6dd 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1837,9 +1837,13 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc chain().findBlock(block_hash, FoundBlock().inActiveChain(block_still_active).nextBlock(FoundBlock().inActiveChain(next_block).hash(next_block_hash))); if (fetch_block) { - // Read block data + // Read block data and locator if needed (the locator is usually null unless we need to save progress) CBlock block; - chain().findBlock(block_hash, FoundBlock().data(block)); + CBlockLocator loc; + // Find block + FoundBlock found_block{FoundBlock().data(block)}; + if (save_progress && next_interval) found_block.locator(loc); + chain().findBlock(block_hash, found_block); if (!block.IsNull()) { LOCK(cs_wallet); @@ -1857,14 +1861,10 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc result.last_scanned_block = block_hash; result.last_scanned_height = block_height; - if (save_progress && next_interval) { - CBlockLocator loc = m_chain->getActiveChainLocator(block_hash); - - if (!loc.IsNull()) { - WalletLogPrintf("Saving scan progress %d.\n", block_height); - WalletBatch batch(GetDatabase()); - batch.WriteBestBlock(loc); - } + if (!loc.IsNull()) { + WalletLogPrintf("Saving scan progress %d.\n", block_height); + WalletBatch batch(GetDatabase()); + batch.WriteBestBlock(loc); } } else { // could not scan block, keep scanning but record this block as the most recent failure