Skip to content

Commit

Permalink
scripted-diff: Rename nChainTx to m_chain_tx_count
Browse files Browse the repository at this point in the history
-BEGIN VERIFY SCRIPT-
sed -i 's/nChainTx/m_chain_tx_count/g'
-END VERIFY SCRIPT-
  • Loading branch information
fjahr committed Mar 18, 2024
1 parent 2677a24 commit 2011c2d
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 43 deletions.
8 changes: 4 additions & 4 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ enum BlockStatus : uint32_t {
/**
* Only first tx is coinbase, 2 <= coinbase input script length <= 100, transactions valid, no duplicate txids,
* sigops, size, merkle root. Implies all parents are at least TREE but not necessarily TRANSACTIONS. When all
* parent blocks also have TRANSACTIONS, CBlockIndex::nChainTx will be set.
* parent blocks also have TRANSACTIONS, CBlockIndex::m_chain_tx_count will be set.
*/
BLOCK_VALID_TRANSACTIONS = 3,

Expand Down Expand Up @@ -187,7 +187,7 @@ class CBlockIndex
//! have the underlying block data available during snapshot load.
//! @sa AssumeutxoData
//! @sa ActivateSnapshot
uint64_t nChainTx{0};
uint64_t m_chain_tx_count{0};

//! Verification status of this block. See enum BlockStatus
//!
Expand Down Expand Up @@ -268,10 +268,10 @@ class CBlockIndex
* Does not imply the transactions are still stored on disk. (IsBlockPruned might return true)
*
* Note that this will be true for the snapshot base block, if one is loaded (and
* all subsequent assumed-valid blocks) since its nChainTx value will have been set
* all subsequent assumed-valid blocks) since its m_chain_tx_count value will have been set
* manually based on the related AssumeutxoData entry.
*/
bool HaveNumChainTxs() const { return nChainTx != 0; }
bool HaveNumChainTxs() const { return m_chain_tx_count != 0; }

NodeSeconds Time() const
{
Expand Down
8 changes: 4 additions & 4 deletions src/kernel/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class CTestNetParams : public CChainParams {
{
.height = 2'500'000,
.hash_serialized = AssumeutxoHash{uint256S("0xf841584909f68e47897952345234e37fcd9128cd818f41ee6c3ca68db8071be7")},
.nChainTx = 66484552,
.m_chain_tx_count = 66484552,
.blockhash = uint256S("0x0000000000000093bcb68c03a9a168ae252572d348a2eaeba2cdf9231d73206f")
}
};
Expand Down Expand Up @@ -379,7 +379,7 @@ class SigNetParams : public CChainParams {
{
.height = 160'000,
.hash_serialized = AssumeutxoHash{uint256S("0xfe0a44309b74d6b5883d246cb419c6221bcccf0b308c9b59b7d70783dbdf928a")},
.nChainTx = 2289496,
.m_chain_tx_count = 2289496,
.blockhash = uint256S("0x0000003ca3c99aff040f2563c2ad8f8ec88bd0fd6b8f0895cfaf1ef90353a62c")
}
};
Expand Down Expand Up @@ -495,14 +495,14 @@ class CRegTestParams : public CChainParams
{
.height = 110,
.hash_serialized = AssumeutxoHash{uint256S("0x6657b736d4fe4db0cbc796789e812d5dba7f5c143764b1b6905612f1830609d1")},
.nChainTx = 111,
.m_chain_tx_count = 111,
.blockhash = uint256S("0x696e92821f65549c7ee134edceeeeaaa4105647a3c4fd9f298c0aec0ab50425c")
},
{
// For use by test/functional/feature_assumeutxo.py
.height = 299,
.hash_serialized = AssumeutxoHash{uint256S("0xa4bf3407ccb2cc0145c49ebba8fa91199f8a3903daf0883875941497d2493c27")},
.nChainTx = 334,
.m_chain_tx_count = 334,
.blockhash = uint256S("0x3bb7ce5eba0be48939b7a521ac1ba9316afee2c7bada3a0cca24188e6d7d96c0")
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ struct AssumeutxoData {
//! The expected hash of the deserialized UTXO set.
AssumeutxoHash hash_serialized;

//! Used to populate the nChainTx value, which is used during BlockManager::LoadBlockIndex().
//! Used to populate the m_chain_tx_count value, which is used during BlockManager::LoadBlockIndex().
//!
//! We need to hardcode the value here because this is computed cumulatively using block data,
//! which we do not necessarily have at the time of snapshot load.
uint64_t nChainTx;
uint64_t m_chain_tx_count;

//! The hash of the base block for this snapshot. Used to refer to assumeutxo data
//! prior to having a loaded blockindex.
Expand Down
16 changes: 8 additions & 8 deletions src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,11 @@ bool BlockManager::LoadBlockIndex(const std::optional<uint256>& snapshot_blockha
m_snapshot_height = au_data.height;
CBlockIndex* base{LookupBlockIndex(*snapshot_blockhash)};

// Since nChainTx (responsible for estimated progress) isn't persisted
// Since m_chain_tx_count (responsible for estimated progress) isn't persisted
// to disk, we must bootstrap the value for assumedvalid chainstates
// from the hardcoded assumeutxo chainparams.
base->nChainTx = au_data.nChainTx;
LogPrintf("[snapshot] set nChainTx=%d for %s\n", au_data.nChainTx, snapshot_blockhash->ToString());
base->m_chain_tx_count = au_data.m_chain_tx_count;
LogPrintf("[snapshot] set m_chain_tx_count=%d for %s\n", au_data.m_chain_tx_count, snapshot_blockhash->ToString());
} else {
// If this isn't called with a snapshot blockhash, make sure the cached snapshot height
// is null. This is relevant during snapshot completion, when the blockman may be loaded
Expand Down Expand Up @@ -450,15 +450,15 @@ bool BlockManager::LoadBlockIndex(const std::optional<uint256>& snapshot_blockha
if (m_snapshot_height && pindex->nHeight == *m_snapshot_height &&
pindex->GetBlockHash() == *snapshot_blockhash) {
// Should have been set above; don't disturb it with code below.
Assert(pindex->nChainTx > 0);
} else if (pindex->pprev->nChainTx > 0) {
pindex->nChainTx = pindex->pprev->nChainTx + pindex->nTx;
Assert(pindex->m_chain_tx_count > 0);
} else if (pindex->pprev->m_chain_tx_count > 0) {
pindex->m_chain_tx_count = pindex->pprev->m_chain_tx_count + pindex->nTx;
} else {
pindex->nChainTx = 0;
pindex->m_chain_tx_count = 0;
m_blocks_unlinked.insert(std::make_pair(pindex->pprev, pindex));
}
} else {
pindex->nChainTx = pindex->nTx;
pindex->m_chain_tx_count = pindex->nTx;
}
}
if (!(pindex->nStatus & BLOCK_FAILED_MASK) && pindex->pprev && (pindex->pprev->nStatus & BLOCK_FAILED_MASK)) {
Expand Down
6 changes: 3 additions & 3 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1680,11 +1680,11 @@ static RPCHelpMan getchaintxstats()

const CBlockIndex& past_block{*CHECK_NONFATAL(pindex->GetAncestor(pindex->nHeight - blockcount))};
const int64_t nTimeDiff{pindex->GetMedianTimePast() - past_block.GetMedianTimePast()};
const uint64_t nTxDiff = pindex->nChainTx - past_block.nChainTx;
const uint64_t nTxDiff = pindex->m_chain_tx_count - past_block.m_chain_tx_count;

UniValue ret(UniValue::VOBJ);
ret.pushKV("time", (int64_t)pindex->nTime);
ret.pushKV("txcount", pindex->nChainTx);
ret.pushKV("txcount", pindex->m_chain_tx_count);
ret.pushKV("window_final_block_hash", pindex->GetBlockHash().GetHex());
ret.pushKV("window_final_block_height", pindex->nHeight);
ret.pushKV("window_block_count", blockcount);
Expand Down Expand Up @@ -2716,7 +2716,7 @@ UniValue CreateUTXOSnapshot(
result.pushKV("base_height", tip->nHeight);
result.pushKV("path", path.utf8string());
result.pushKV("txoutset_hash", maybe_stats->hashSerialized.ToString());
result.pushKV("nchaintx", tip->nChainTx);
result.pushKV("nchaintx", tip->m_chain_tx_count);
return result;
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/blockchain_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ BOOST_AUTO_TEST_CASE(get_difficulty_for_very_high_target)
BOOST_AUTO_TEST_CASE(num_chain_tx_max)
{
std::unique_ptr<CBlockIndex> block_index{CreateBlockIndexWithNbits(0x1f111111)};
block_index->nChainTx = std::numeric_limits<uint64_t>::max();
BOOST_CHECK_EQUAL(block_index->nChainTx, std::numeric_limits<uint64_t>::max());
block_index->m_chain_tx_count = std::numeric_limits<uint64_t>::max();
BOOST_CHECK_EQUAL(block_index->m_chain_tx_count, std::numeric_limits<uint64_t>::max());
}

BOOST_AUTO_TEST_SUITE_END()
2 changes: 1 addition & 1 deletion src/test/fuzz/utxo_snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ FUZZ_TARGET(utxo_snapshot, .init = initialize_chain)
chain_tx += num_tx;
}
Assert(g_chain->size() == coinscache.GetCacheSize());
Assert(chain_tx == chainman.ActiveTip()->nChainTx);
Assert(chain_tx == chainman.ActiveTip()->m_chain_tx_count);
} else {
Assert(!chainman.SnapshotBlockhash());
Assert(!chainman.ActiveChainstate().m_from_snapshot_blockhash);
Expand Down
2 changes: 1 addition & 1 deletion src/test/validation_chainstatemanager_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ struct SnapshotTestSetup : TestChain100Setup {
const auto& au_data = ::Params().AssumeutxoForHeight(snapshot_height);
const CBlockIndex* tip = WITH_LOCK(chainman.GetMutex(), return chainman.ActiveTip());

BOOST_CHECK_EQUAL(tip->nChainTx, au_data->nChainTx);
BOOST_CHECK_EQUAL(tip->m_chain_tx_count, au_data->m_chain_tx_count);

// To be checked against later when we try loading a subsequent snapshot.
uint256 loaded_snapshot_blockhash{*chainman.SnapshotBlockhash()};
Expand Down
4 changes: 2 additions & 2 deletions src/test/validation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ BOOST_AUTO_TEST_CASE(test_assumeutxo)

const auto out110 = *params->AssumeutxoForHeight(110);
BOOST_CHECK_EQUAL(out110.hash_serialized.ToString(), "6657b736d4fe4db0cbc796789e812d5dba7f5c143764b1b6905612f1830609d1");
BOOST_CHECK_EQUAL(out110.nChainTx, 111U);
BOOST_CHECK_EQUAL(out110.m_chain_tx_count, 111U);

const auto out110_2 = *params->AssumeutxoForBlockhash(uint256S("0x696e92821f65549c7ee134edceeeeaaa4105647a3c4fd9f298c0aec0ab50425c"));
BOOST_CHECK_EQUAL(out110_2.hash_serialized.ToString(), "6657b736d4fe4db0cbc796789e812d5dba7f5c143764b1b6905612f1830609d1");
BOOST_CHECK_EQUAL(out110_2.nChainTx, 111U);
BOOST_CHECK_EQUAL(out110_2.m_chain_tx_count, 111U);
}

BOOST_AUTO_TEST_CASE(block_malleation)
Expand Down
32 changes: 16 additions & 16 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2777,7 +2777,7 @@ static void UpdateTipLog(
LogPrintf("%s%s: new best=%s height=%d version=0x%08x log2_work=%f tx=%lu date='%s' progress=%f cache=%.1fMiB(%utxo)%s\n",
prefix, func_name,
tip->GetBlockHash().ToString(), tip->nHeight, tip->nVersion,
log(tip->nChainWork.getdouble()) / log(2.0), tip->nChainTx,
log(tip->nChainWork.getdouble()) / log(2.0), tip->m_chain_tx_count,
FormatISO8601DateTime(tip->GetBlockTime()),
GuessVerificationProgress(params.TxData(), tip),
coins_tip.DynamicMemoryUsage() * (1.0 / (1 << 20)),
Expand Down Expand Up @@ -3660,7 +3660,7 @@ void ChainstateManager::ReceivedBlockTransactions(const CBlock& block, CBlockInd
{
AssertLockHeld(cs_main);
pindexNew->nTx = block.vtx.size();
pindexNew->nChainTx = 0;
pindexNew->m_chain_tx_count = 0;
pindexNew->nFile = pos.nFile;
pindexNew->nDataPos = pos.nPos;
pindexNew->nUndoPos = 0;
Expand All @@ -3680,7 +3680,7 @@ void ChainstateManager::ReceivedBlockTransactions(const CBlock& block, CBlockInd
while (!queue.empty()) {
CBlockIndex *pindex = queue.front();
queue.pop_front();
pindex->nChainTx = (pindex->pprev ? pindex->pprev->nChainTx : 0) + pindex->nTx;
pindex->m_chain_tx_count = (pindex->pprev ? pindex->pprev->m_chain_tx_count : 0) + pindex->nTx;
pindex->nSequenceId = nBlockSequenceId++;
for (Chainstate *c : GetAll()) {
c->TryAddBlockIndexCandidate(pindex);
Expand Down Expand Up @@ -5114,13 +5114,13 @@ void ChainstateManager::CheckBlockIndex()
// Checks for not-invalid blocks.
assert((pindex->nStatus & BLOCK_FAILED_MASK) == 0); // The failed mask cannot be set for blocks without invalid parents.
}
// Make sure nChainTx sum is correctly computed.
uint64_t prev_chain_tx = pindex->pprev ? pindex->pprev->nChainTx : 0;
assert((pindex->nChainTx == pindex->nTx + prev_chain_tx)
// Make sure m_chain_tx_count sum is correctly computed.
uint64_t prev_chain_tx = pindex->pprev ? pindex->pprev->m_chain_tx_count : 0;
assert((pindex->m_chain_tx_count == pindex->nTx + prev_chain_tx)
// Transaction may be completely unset - happens if only the header was accepted but the block hasn't been processed.
|| (pindex->nChainTx == 0 && pindex->nTx == 0)
// nChainTx may be unset, but nTx set (if a block has been accepted, but one of its predecessors hasn't been processed yet)
|| (pindex->nChainTx == 0 && prev_chain_tx == 0 && pindex->pprev)
|| (pindex->m_chain_tx_count == 0 && pindex->nTx == 0)
// m_chain_tx_count may be unset, but nTx set (if a block has been accepted, but one of its predecessors hasn't been processed yet)
|| (pindex->m_chain_tx_count == 0 && prev_chain_tx == 0 && pindex->pprev)
// Transaction counts prior to snapshot are unknown.
|| pindex->IsAssumedValid());
// Chainstate-specific checks on setBlockIndexCandidates
Expand Down Expand Up @@ -5281,7 +5281,7 @@ bool Chainstate::ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
}

//! Guess how far we are in the verification process at the given block index
//! require cs_main if pindex has not been validated yet (because nChainTx might be unset)
//! require cs_main if pindex has not been validated yet (because m_chain_tx_count might be unset)
double GuessVerificationProgress(const ChainTxData& data, const CBlockIndex *pindex) {
if (pindex == nullptr)
return 0.0;
Expand All @@ -5290,13 +5290,13 @@ double GuessVerificationProgress(const ChainTxData& data, const CBlockIndex *pin

double fTxTotal;

if (pindex->nChainTx <= data.nTxCount) {
if (pindex->m_chain_tx_count <= data.nTxCount) {
fTxTotal = data.nTxCount + (nNow - data.nTime) * data.dTxRate;
} else {
fTxTotal = pindex->nChainTx + (nNow - pindex->GetBlockTime()) * data.dTxRate;
fTxTotal = pindex->m_chain_tx_count + (nNow - pindex->GetBlockTime()) * data.dTxRate;
}

return std::min<double>(pindex->nChainTx / fTxTotal, 1.0);
return std::min<double>(pindex->m_chain_tx_count / fTxTotal, 1.0);
}

std::optional<uint256> ChainstateManager::SnapshotBlockhash() const
Expand Down Expand Up @@ -5706,8 +5706,8 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
if (!index->nTx) {
index->nTx = 1;
}
// Fake nChainTx so that GuessVerificationProgress reports accurately
index->nChainTx = index->pprev->nChainTx + index->nTx;
// Fake m_chain_tx_count so that GuessVerificationProgress reports accurately
index->m_chain_tx_count = index->pprev->m_chain_tx_count + index->nTx;

// Mark unvalidated block index entries beneath the snapshot base block as assumed-valid.
if (!index->IsValid(BLOCK_VALID_SCRIPTS)) {
Expand All @@ -5731,7 +5731,7 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
}

assert(index);
index->nChainTx = au_data.nChainTx;
index->m_chain_tx_count = au_data.m_chain_tx_count;
snapshot_chainstate.setBlockIndexCandidates.insert(snapshot_start_block);

LogPrintf("[snapshot] validated snapshot (%.2f MB)\n",
Expand Down

0 comments on commit 2011c2d

Please sign in to comment.