Skip to content

Commit 2b00030

Browse files
pablomartin4btcryanofskyfurszy
committed
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 <[email protected]> Co-authored-by: Matias Furszyfer <[email protected]>
1 parent 110a0f4 commit 2b00030

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

src/interfaces/chain.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,6 @@ class Chain
143143
//! pruned), and contains transactions.
144144
virtual bool haveBlockOnDisk(int height) = 0;
145145

146-
//! Return a locator that refers to a block in the active chain.
147-
//! If specified block is not in the active chain, return locator for the latest ancestor that is in the chain.
148-
virtual CBlockLocator getActiveChainLocator(const uint256& block_hash) = 0;
149-
150146
//! Return height of the highest block on chain in common with the locator,
151147
//! which will either be the original block used to create the locator,
152148
//! or one of its ancestors.

src/node/interfaces.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -559,12 +559,6 @@ class ChainImpl : public Chain
559559
const CBlockIndex* block{chainman().ActiveChain()[height]};
560560
return block && ((block->nStatus & BLOCK_HAVE_DATA) != 0) && block->nTx > 0;
561561
}
562-
CBlockLocator getActiveChainLocator(const uint256& block_hash) override
563-
{
564-
LOCK(::cs_main);
565-
const CBlockIndex* index = chainman().m_blockman.LookupBlockIndex(block_hash);
566-
return GetLocator(index);
567-
}
568562
std::optional<int> findLocatorFork(const CBlockLocator& locator) override
569563
{
570564
LOCK(::cs_main);

src/wallet/wallet.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,9 +1837,13 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
18371837
chain().findBlock(block_hash, FoundBlock().inActiveChain(block_still_active).nextBlock(FoundBlock().inActiveChain(next_block).hash(next_block_hash)));
18381838

18391839
if (fetch_block) {
1840-
// Read block data
1840+
// Read block data and locator if needed (the locator is usually null unless we need to save progress)
18411841
CBlock block;
1842-
chain().findBlock(block_hash, FoundBlock().data(block));
1842+
CBlockLocator loc;
1843+
// Find block
1844+
FoundBlock found_block{FoundBlock().data(block)};
1845+
if (save_progress && next_interval) found_block.locator(loc);
1846+
chain().findBlock(block_hash, found_block);
18431847

18441848
if (!block.IsNull()) {
18451849
LOCK(cs_wallet);
@@ -1857,14 +1861,10 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
18571861
result.last_scanned_block = block_hash;
18581862
result.last_scanned_height = block_height;
18591863

1860-
if (save_progress && next_interval) {
1861-
CBlockLocator loc = m_chain->getActiveChainLocator(block_hash);
1862-
1863-
if (!loc.IsNull()) {
1864-
WalletLogPrintf("Saving scan progress %d.\n", block_height);
1865-
WalletBatch batch(GetDatabase());
1866-
batch.WriteBestBlock(loc);
1867-
}
1864+
if (!loc.IsNull()) {
1865+
WalletLogPrintf("Saving scan progress %d.\n", block_height);
1866+
WalletBatch batch(GetDatabase());
1867+
batch.WriteBestBlock(loc);
18681868
}
18691869
} else {
18701870
// could not scan block, keep scanning but record this block as the most recent failure

0 commit comments

Comments
 (0)