Skip to content

Commit 8405fdb

Browse files
committed
Merge bitcoin/bitcoin#33169: interfaces, chain, refactor: Remove unused getTipLocator and incaccurate getActiveChainLocator
2b00030 interfaces, chain, refactor: Remove inaccurate getActiveChainLocator (pablomartin4btc) 110a0f4 interfaces, chain, refactor: Remove unused getTipLocator (pablomartin4btc) Pull request description: Remove `Chain::getTipLocator`, `Chain::GetLocator()`, and `Chain::getActiveChainLocator`: - `Chain::getTipLocator` is no longer used. - `Chain::GetLocator`, replaced its call by `GetLocator()`, which uses `LocatorEntries`, avoiding direct access to the chain itself (change suggested by l0rinc while reviewing this PR to maintain consistency with the overall refactoring). - `Chain::getActiveChainLocator`, whose name was misleading, has functionality redundant with Chain::findBlock. - Additionally, the comment for getActiveChainLocator became inaccurate following changes in commit bitcoin/bitcoin@ed47094 (from PR #25717). This is a [follow-up](bitcoin/bitcoin#29652 (comment)) to #29652. ACKs for top commit: achow101: ACK 2b00030 furszy: ACK 2b00030 stickies-v: ACK 2b00030 w0xlt: ACK bitcoin/bitcoin@2b00030 Tree-SHA512: b12ba6a15feeaeec692d69204a6e155e3af43edfac25597dabf14cacca1e4a2152574816e58dc544f39043c5721f5e707acf544f4541d3b9c0f8c0c40069215e
2 parents e17b5da + 2b00030 commit 8405fdb

File tree

6 files changed

+11
-37
lines changed

6 files changed

+11
-37
lines changed

src/chain.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ CBlockLocator GetLocator(const CBlockIndex* index)
5252
return CBlockLocator{LocatorEntries(index)};
5353
}
5454

55-
CBlockLocator CChain::GetLocator() const
56-
{
57-
return ::GetLocator(Tip());
58-
}
59-
6055
const CBlockIndex *CChain::FindFork(const CBlockIndex *pindex) const {
6156
if (pindex == nullptr) {
6257
return nullptr;

src/chain.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,6 @@ class CChain
467467
/** Set/initialize a chain with a given tip. */
468468
void SetTip(CBlockIndex& block);
469469

470-
/** Return a CBlockLocator that refers to the tip in of this chain. */
471-
CBlockLocator GetLocator() const;
472-
473470
/** Find the last common block between this chain and a block index entry. */
474471
const CBlockIndex* FindFork(const CBlockIndex* pindex) const;
475472

src/interfaces/chain.h

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

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

src/node/interfaces.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -559,17 +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 getTipLocator() override
563-
{
564-
LOCK(::cs_main);
565-
return chainman().ActiveChain().GetLocator();
566-
}
567-
CBlockLocator getActiveChainLocator(const uint256& block_hash) override
568-
{
569-
LOCK(::cs_main);
570-
const CBlockIndex* index = chainman().m_blockman.LookupBlockIndex(block_hash);
571-
return GetLocator(index);
572-
}
573562
std::optional<int> findLocatorFork(const CBlockLocator& locator) override
574563
{
575564
LOCK(::cs_main);

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2897,7 +2897,7 @@ bool Chainstate::FlushStateToDisk(
28972897
}
28982898
if (full_flush_completed && m_chainman.m_options.signals) {
28992899
// Update best block in wallet (so we can detect restored wallets).
2900-
m_chainman.m_options.signals->ChainStateFlushed(this->GetRole(), m_chain.GetLocator());
2900+
m_chainman.m_options.signals->ChainStateFlushed(this->GetRole(), GetLocator(m_chain.Tip()));
29012901
}
29022902
} catch (const std::runtime_error& e) {
29032903
return FatalError(m_chainman.GetNotifications(), state, strprintf(_("System error while flushing: %s"), e.what()));

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)