Skip to content

Commit a482f86

Browse files
fjahrMarcoFalke
andcommitted
chain: Rename HaveTxsDownloaded to HaveNumChainTxs
Co-authored-by: MarcoFalke <falke.marco@gmail.com>
1 parent 82e48d2 commit a482f86

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

src/chain.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,8 @@ class CBlockIndex
280280
* Note that this will be true for the snapshot base block, if one is loaded (and
281281
* all subsequent assumed-valid blocks) since its nChainTx value will have been set
282282
* manually based on the related AssumeutxoData entry.
283-
*
284-
* TODO: potentially change the name of this based on the fact above.
285283
*/
286-
bool HaveTxsDownloaded() const { return nChainTx != 0; }
284+
bool HaveNumChainTxs() const { return nChainTx != 0; }
287285

288286
NodeSeconds Time() const
289287
{

src/net_processing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ void PeerManagerImpl::FindNextBlocks(std::vector<const CBlockIndex*>& vBlocks, c
14481448
return;
14491449
}
14501450
if (pindex->nStatus & BLOCK_HAVE_DATA || (activeChain && activeChain->Contains(pindex))) {
1451-
if (activeChain && pindex->HaveTxsDownloaded())
1451+
if (activeChain && pindex->HaveNumChainTxs())
14521452
state->pindexLastCommonBlock = pindex;
14531453
} else if (!IsBlockRequested(pindex->GetBlockHash())) {
14541454
// The block is not already downloaded, and not yet in flight.
@@ -2233,7 +2233,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
22332233
LOCK(cs_main);
22342234
const CBlockIndex* pindex = m_chainman.m_blockman.LookupBlockIndex(inv.hash);
22352235
if (pindex) {
2236-
if (pindex->HaveTxsDownloaded() && !pindex->IsValid(BLOCK_VALID_SCRIPTS) &&
2236+
if (pindex->HaveNumChainTxs() && !pindex->IsValid(BLOCK_VALID_SCRIPTS) &&
22372237
pindex->IsValid(BLOCK_VALID_TREE)) {
22382238
// If we have the block and all of its parents, but have not yet validated it,
22392239
// we might be in the middle of connecting it (ie in the unlock of cs_main

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ static RPCHelpMan getchaintips()
14551455
} else if (block->nStatus & BLOCK_FAILED_MASK) {
14561456
// This block or one of its ancestors is invalid.
14571457
status = "invalid";
1458-
} else if (!block->HaveTxsDownloaded()) {
1458+
} else if (!block->HaveNumChainTxs()) {
14591459
// This block cannot be connected because full block data for it or one of its parents is missing.
14601460
status = "headers-only";
14611461
} else if (block->IsValid(BLOCK_VALID_SCRIPTS)) {

src/test/fuzz/chain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ FUZZ_TARGET(chain)
2929
(void)disk_block_index->GetBlockTimeMax();
3030
(void)disk_block_index->GetMedianTimePast();
3131
(void)disk_block_index->GetUndoPos();
32-
(void)disk_block_index->HaveTxsDownloaded();
32+
(void)disk_block_index->HaveNumChainTxs();
3333
(void)disk_block_index->IsValid();
3434
}
3535

src/validation.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2996,7 +2996,7 @@ CBlockIndex* Chainstate::FindMostWorkChain()
29962996
CBlockIndex *pindexTest = pindexNew;
29972997
bool fInvalidAncestor = false;
29982998
while (pindexTest && !m_chain.Contains(pindexTest)) {
2999-
assert(pindexTest->HaveTxsDownloaded() || pindexTest->nHeight == 0);
2999+
assert(pindexTest->HaveNumChainTxs() || pindexTest->nHeight == 0);
30003000

30013001
// Pruned nodes may have entries in setBlockIndexCandidates for
30023002
// which block files have been deleted. Remove those as candidates
@@ -3351,7 +3351,7 @@ bool Chainstate::PreciousBlock(BlockValidationState& state, CBlockIndex* pindex)
33513351
// call preciousblock 2**31-1 times on the same set of tips...
33523352
m_chainman.nBlockReverseSequenceId--;
33533353
}
3354-
if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS) && pindex->HaveTxsDownloaded()) {
3354+
if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS) && pindex->HaveNumChainTxs()) {
33553355
setBlockIndexCandidates.insert(pindex);
33563356
PruneBlockIndexCandidates();
33573357
}
@@ -3399,7 +3399,7 @@ bool Chainstate::InvalidateBlock(BlockValidationState& state, CBlockIndex* pinde
33993399
if (!m_chain.Contains(candidate) &&
34003400
!CBlockIndexWorkComparator()(candidate, pindex->pprev) &&
34013401
candidate->IsValid(BLOCK_VALID_TRANSACTIONS) &&
3402-
candidate->HaveTxsDownloaded()) {
3402+
candidate->HaveNumChainTxs()) {
34033403
candidate_blocks_by_work.insert(std::make_pair(candidate->nChainWork, candidate));
34043404
}
34053405
}
@@ -3488,7 +3488,7 @@ bool Chainstate::InvalidateBlock(BlockValidationState& state, CBlockIndex* pinde
34883488
// Loop back over all block index entries and add any missing entries
34893489
// to setBlockIndexCandidates.
34903490
for (auto& [_, block_index] : m_blockman.m_block_index) {
3491-
if (block_index.IsValid(BLOCK_VALID_TRANSACTIONS) && block_index.HaveTxsDownloaded() && !setBlockIndexCandidates.value_comp()(&block_index, m_chain.Tip())) {
3491+
if (block_index.IsValid(BLOCK_VALID_TRANSACTIONS) && block_index.HaveNumChainTxs() && !setBlockIndexCandidates.value_comp()(&block_index, m_chain.Tip())) {
34923492
setBlockIndexCandidates.insert(&block_index);
34933493
}
34943494
}
@@ -3520,7 +3520,7 @@ void Chainstate::ResetBlockFailureFlags(CBlockIndex *pindex) {
35203520
if (!block_index.IsValid() && block_index.GetAncestor(nHeight) == pindex) {
35213521
block_index.nStatus &= ~BLOCK_FAILED_MASK;
35223522
m_blockman.m_dirty_blockindex.insert(&block_index);
3523-
if (block_index.IsValid(BLOCK_VALID_TRANSACTIONS) && block_index.HaveTxsDownloaded() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), &block_index)) {
3523+
if (block_index.IsValid(BLOCK_VALID_TRANSACTIONS) && block_index.HaveNumChainTxs() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), &block_index)) {
35243524
setBlockIndexCandidates.insert(&block_index);
35253525
}
35263526
if (&block_index == m_chainman.m_best_invalid) {
@@ -3583,7 +3583,7 @@ void ChainstateManager::ReceivedBlockTransactions(const CBlock& block, CBlockInd
35833583
pindexNew->RaiseValidity(BLOCK_VALID_TRANSACTIONS);
35843584
m_blockman.m_dirty_blockindex.insert(pindexNew);
35853585

3586-
if (pindexNew->pprev == nullptr || pindexNew->pprev->HaveTxsDownloaded()) {
3586+
if (pindexNew->pprev == nullptr || pindexNew->pprev->HaveNumChainTxs()) {
35873587
// If pindexNew is the genesis block or all parents are BLOCK_VALID_TRANSACTIONS.
35883588
std::deque<CBlockIndex*> queue;
35893589
queue.push_back(pindexNew);
@@ -4566,7 +4566,7 @@ bool ChainstateManager::LoadBlockIndex()
45664566
// here.
45674567
if (pindex == GetSnapshotBaseBlock() ||
45684568
(pindex->IsValid(BLOCK_VALID_TRANSACTIONS) &&
4569-
(pindex->HaveTxsDownloaded() || pindex->pprev == nullptr))) {
4569+
(pindex->HaveNumChainTxs() || pindex->pprev == nullptr))) {
45704570

45714571
for (Chainstate* chainstate : GetAll()) {
45724572
chainstate->TryAddBlockIndexCandidate(pindex);
@@ -4890,7 +4890,7 @@ void ChainstateManager::CheckBlockIndex()
48904890
}
48914891
}
48924892
}
4893-
if (!pindex->HaveTxsDownloaded()) assert(pindex->nSequenceId <= 0); // nSequenceId can't be set positive for blocks that aren't linked (negative is used for preciousblock)
4893+
if (!pindex->HaveNumChainTxs()) assert(pindex->nSequenceId <= 0); // nSequenceId can't be set positive for blocks that aren't linked (negative is used for preciousblock)
48944894
// VALID_TRANSACTIONS is equivalent to nTx > 0 for all nodes (whether or not pruning has occurred).
48954895
// HAVE_DATA is only equivalent to nTx > 0 (or VALID_TRANSACTIONS) if no pruning has occurred.
48964896
// Unless these indexes are assumed valid and pending block download on a
@@ -4920,9 +4920,9 @@ void ChainstateManager::CheckBlockIndex()
49204920
// actually seen a block's transactions.
49214921
assert(((pindex->nStatus & BLOCK_VALID_MASK) >= BLOCK_VALID_TRANSACTIONS) == (pindex->nTx > 0)); // This is pruning-independent.
49224922
}
4923-
// All parents having had data (at some point) is equivalent to all parents being VALID_TRANSACTIONS, which is equivalent to HaveTxsDownloaded().
4924-
assert((pindexFirstNeverProcessed == nullptr) == pindex->HaveTxsDownloaded());
4925-
assert((pindexFirstNotTransactionsValid == nullptr) == pindex->HaveTxsDownloaded());
4923+
// All parents having had data (at some point) is equivalent to all parents being VALID_TRANSACTIONS, which is equivalent to HaveNumChainTxs().
4924+
assert((pindexFirstNeverProcessed == nullptr) == pindex->HaveNumChainTxs());
4925+
assert((pindexFirstNotTransactionsValid == nullptr) == pindex->HaveNumChainTxs());
49264926
assert(pindex->nHeight == nHeight); // nHeight must be consistent.
49274927
assert(pindex->pprev == nullptr || pindex->nChainWork >= pindex->pprev->nChainWork); // For every block except the genesis block, the chainwork must be larger than the parent's.
49284928
assert(nHeight < 2 || (pindex->pskip && (pindex->pskip->nHeight < nHeight))); // The pskip pointer must point back for all but the first 2 blocks.

0 commit comments

Comments
 (0)