interfaces, chain, refactor: Remove inaccurate getActiveChainLocator
What changed, and why it matters
This is a routine internal code cleanup in Bitcoin Core. It removes a redundant method called getActiveChainLocator and replaces its uses with an existing equivalent method, findBlock. There is no security fix here and no indication this change addresses any vulnerability.
No security action required. Treat as normal refactoring during code review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors the Chain interface by removing getActiveChainLocator, whose behavior duplicated Chain::findBlock with FoundBlock().locator(). The implementation in src/node/interfaces.cpp is deleted, and the wallet’s rescan logic in CWallet::ScanForWalletTransactions is updated to obtain the block locator through a single findBlock call instead of a separate getActiveChainLocator call. The change is purely structural and consolidates two lookups into one.
Changed components
src/interfaces/chain.hsrc/node/interfaces.cppsrc/wallet/wallet.cppInspect captured patch +10 / −20
diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h
index f45cb8e5..82e626e3 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 d7ada5ae..106c9611 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<int> findLocatorFork(const CBlockLocator& locator) override
{
LOCK(::cs_main);
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index f86a28c5..6985f2cf 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
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.