scripted-diff: Modernize naming of nChainTx and nTxCount

-BEGIN VERIFY SCRIPT-
sed -i 's/nChainTx/m_chain_tx_count/g' $(git grep -l 'nChainTx' ./src)
sed -i 's/nTxCount/tx_count/g' $(git grep -l 'nTxCount' ./src)
-END VERIFY SCRIPT-
This commit is contained in:
Fabian Jahr 2024-03-18 23:28:10 +01:00
parent 72e5d1be1f
commit bf0efb4fc7
No known key found for this signature in database
GPG key ID: F13D1E9D890798CD
12 changed files with 70 additions and 70 deletions

View file

@ -102,7 +102,7 @@ enum BlockStatus : uint32_t {
*
* If a block's validity is at least VALID_TRANSACTIONS, CBlockIndex::nTx will be set. If a block and all previous
* blocks back to the genesis block or an assumeutxo snapshot block are at least VALID_TRANSACTIONS,
* CBlockIndex::nChainTx will be set.
* CBlockIndex::m_chain_tx_count will be set.
*/
BLOCK_VALID_TRANSACTIONS = 3,
@ -173,7 +173,7 @@ public:
//! This value will be non-zero if this block and all previous blocks back
//! to the genesis block or an assumeutxo snapshot block have reached the
//! VALID_TRANSACTIONS level.
uint64_t nChainTx{0};
uint64_t m_chain_tx_count{0};
//! Verification status of this block. See enum BlockStatus
//!
@ -253,10 +253,10 @@ public:
* Does not imply the transactions are consensus-valid (ConnectTip might fail)
* 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, since its nChainTx value will have
* Note that this will be true for the snapshot base block, if one is loaded, 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
{

View file

@ -180,7 +180,7 @@ public:
chainTxData = ChainTxData{
// Data from RPC: getchaintxstats 4096 000000000000000000026811d149d4d261995ec5b3f64f439a0a10e1a464af9a
.nTime = 1704194835,
.nTxCount = 946728933,
.tx_count = 946728933,
.dTxRate = 6.569290261471664,
};
}
@ -272,7 +272,7 @@ public:
{
.height = 2'500'000,
.hash_serialized = AssumeutxoHash{uint256S("0xf841584909f68e47897952345234e37fcd9128cd818f41ee6c3ca68db8071be7")},
.nChainTx = 66484552,
.m_chain_tx_count = 66484552,
.blockhash = uint256S("0x0000000000000093bcb68c03a9a168ae252572d348a2eaeba2cdf9231d73206f")
}
};
@ -280,7 +280,7 @@ public:
chainTxData = ChainTxData{
// Data from RPC: getchaintxstats 4096 000000000001323071f38f21ea5aae529ece491eadaccce506a59bcc2d968917
.nTime = 1703579240,
.nTxCount = 67845391,
.tx_count = 67845391,
.dTxRate = 1.464436832560951,
};
}
@ -312,7 +312,7 @@ public:
chainTxData = ChainTxData{
// Data from RPC: getchaintxstats 4096 0000000870f15246ba23c16e370a7ffb1fc8a3dcf8cb4492882ed4b0e3d4cd26
.nTime = 1706331472,
.nTxCount = 2425380,
.tx_count = 2425380,
.dTxRate = 0.008277759863833788,
};
} else {
@ -382,7 +382,7 @@ public:
{
.height = 160'000,
.hash_serialized = AssumeutxoHash{uint256S("0xfe0a44309b74d6b5883d246cb419c6221bcccf0b308c9b59b7d70783dbdf928a")},
.nChainTx = 2289496,
.m_chain_tx_count = 2289496,
.blockhash = uint256S("0x0000003ca3c99aff040f2563c2ad8f8ec88bd0fd6b8f0895cfaf1ef90353a62c")
}
};
@ -498,21 +498,21 @@ public:
{ // For use by unit tests
.height = 110,
.hash_serialized = AssumeutxoHash{uint256S("0x6657b736d4fe4db0cbc796789e812d5dba7f5c143764b1b6905612f1830609d1")},
.nChainTx = 111,
.m_chain_tx_count = 111,
.blockhash = uint256S("0x696e92821f65549c7ee134edceeeeaaa4105647a3c4fd9f298c0aec0ab50425c")
},
{
// For use by fuzz target src/test/fuzz/utxo_snapshot.cpp
.height = 200,
.hash_serialized = AssumeutxoHash{uint256S("0x4f34d431c3e482f6b0d67b64609ece3964dc8d7976d02ac68dd7c9c1421738f2")},
.nChainTx = 201,
.m_chain_tx_count = 201,
.blockhash = uint256S("0x5e93653318f294fb5aa339d00bbf8cf1c3515488ad99412c37608b139ea63b27"),
},
{
// 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")
},
};

View file

@ -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.
@ -69,7 +69,7 @@ struct AssumeutxoData {
*/
struct ChainTxData {
int64_t nTime; //!< UNIX timestamp of last known number of transactions
uint64_t nTxCount; //!< total number of transactions between genesis and that timestamp
uint64_t tx_count; //!< total number of transactions between genesis and that timestamp
double dTxRate; //!< estimated number of transactions per second after that timestamp
};

View file

@ -410,11 +410,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
@ -449,15 +449,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)) {

View file

@ -1725,16 +1725,16 @@ static RPCHelpMan getchaintxstats()
UniValue ret(UniValue::VOBJ);
ret.pushKV("time", (int64_t)pindex->nTime);
if (pindex->nChainTx) {
ret.pushKV("txcount", pindex->nChainTx);
if (pindex->m_chain_tx_count) {
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);
if (blockcount > 0) {
ret.pushKV("window_interval", nTimeDiff);
if (pindex->nChainTx != 0 && past_block.nChainTx != 0) {
const auto window_tx_count = pindex->nChainTx - past_block.nChainTx;
if (pindex->m_chain_tx_count != 0 && past_block.m_chain_tx_count != 0) {
const auto window_tx_count = pindex->m_chain_tx_count - past_block.m_chain_tx_count;
ret.pushKV("window_tx_count", window_tx_count);
if (nTimeDiff > 0) {
ret.pushKV("txrate", double(window_tx_count) / nTimeDiff);
@ -2799,7 +2799,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;
}

View file

@ -113,8 +113,8 @@ BOOST_FIXTURE_TEST_CASE(get_prune_height, TestChain100Setup)
BOOST_AUTO_TEST_CASE(num_chain_tx_max)
{
CBlockIndex block_index{};
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()

View file

@ -113,9 +113,9 @@ FUZZ_TARGET(utxo_snapshot, .init = initialize_chain)
if (index->nHeight == chainman.GetSnapshotBaseHeight()) {
auto params{chainman.GetParams().AssumeutxoForHeight(index->nHeight)};
Assert(params.has_value());
Assert(params.value().nChainTx == index->nChainTx);
Assert(params.value().m_chain_tx_count == index->m_chain_tx_count);
} else {
Assert(index->nChainTx == 0);
Assert(index->m_chain_tx_count == 0);
}
}
Assert(g_chain->size() == coinscache.GetCacheSize());

View file

@ -29,10 +29,10 @@ BOOST_FIXTURE_TEST_SUITE(pmt_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(pmt_test1)
{
static const unsigned int nTxCounts[] = {1, 4, 7, 17, 56, 100, 127, 256, 312, 513, 1000, 4095};
static const unsigned int tx_counts[] = {1, 4, 7, 17, 56, 100, 127, 256, 312, 513, 1000, 4095};
for (int i = 0; i < 12; i++) {
unsigned int nTx = nTxCounts[i];
unsigned int nTx = tx_counts[i];
// build a block with some dummy transactions
CBlock block;

View file

@ -99,7 +99,7 @@ CreateAndActivateUTXOSnapshot(
assert(pindex->IsValid(BlockStatus::BLOCK_VALID_TREE));
pindex->nStatus = BlockStatus::BLOCK_VALID_TREE;
pindex->nTx = 0;
pindex->nChainTx = 0;
pindex->m_chain_tx_count = 0;
pindex->nSequenceId = 0;
pindex = pindex->pprev;
}

View file

@ -285,7 +285,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()};
@ -465,7 +465,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_loadblockindex, TestChain100Setup)
if (i < last_assumed_valid_idx && i >= assumed_valid_start_idx) {
index->nStatus = BlockStatus::BLOCK_VALID_TREE;
index->nTx = 0;
index->nChainTx = 0;
index->m_chain_tx_count = 0;
}
++num_indexes;

View file

@ -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)

View file

@ -2956,7 +2956,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)),
@ -3846,17 +3846,17 @@ void ChainstateManager::ReceivedBlockTransactions(const CBlock& block, CBlockInd
{
AssertLockHeld(cs_main);
pindexNew->nTx = block.vtx.size();
// Typically nChainTx will be 0 at this point, but it can be nonzero if this
// Typically m_chain_tx_count will be 0 at this point, but it can be nonzero if this
// is a pruned block which is being downloaded again, or if this is an
// assumeutxo snapshot block which has a hardcoded nChainTx value from the
// assumeutxo snapshot block which has a hardcoded m_chain_tx_count value from the
// snapshot metadata. If the pindex is not the snapshot block and the
// nChainTx value is not zero, assert that value is actually correct.
auto prev_tx_sum = [](CBlockIndex& block) { return block.nTx + (block.pprev ? block.pprev->nChainTx : 0); };
if (!Assume(pindexNew->nChainTx == 0 || pindexNew->nChainTx == prev_tx_sum(*pindexNew) ||
// m_chain_tx_count value is not zero, assert that value is actually correct.
auto prev_tx_sum = [](CBlockIndex& block) { return block.nTx + (block.pprev ? block.pprev->m_chain_tx_count : 0); };
if (!Assume(pindexNew->m_chain_tx_count == 0 || pindexNew->m_chain_tx_count == prev_tx_sum(*pindexNew) ||
pindexNew == GetSnapshotBaseBlock())) {
LogWarning("Internal bug detected: block %d has unexpected nChainTx %i that should be %i (%s %s). Please report this issue here: %s\n",
pindexNew->nHeight, pindexNew->nChainTx, prev_tx_sum(*pindexNew), PACKAGE_NAME, FormatFullVersion(), PACKAGE_BUGREPORT);
pindexNew->nChainTx = 0;
LogWarning("Internal bug detected: block %d has unexpected m_chain_tx_count %i that should be %i (%s %s). Please report this issue here: %s\n",
pindexNew->nHeight, pindexNew->m_chain_tx_count, prev_tx_sum(*pindexNew), PACKAGE_NAME, FormatFullVersion(), PACKAGE_BUGREPORT);
pindexNew->m_chain_tx_count = 0;
}
pindexNew->nFile = pos.nFile;
pindexNew->nDataPos = pos.nPos;
@ -3877,15 +3877,15 @@ void ChainstateManager::ReceivedBlockTransactions(const CBlock& block, CBlockInd
while (!queue.empty()) {
CBlockIndex *pindex = queue.front();
queue.pop_front();
// Before setting nChainTx, assert that it is 0 or already set to
// Before setting m_chain_tx_count, assert that it is 0 or already set to
// the correct value. This assert will fail after receiving the
// assumeutxo snapshot block if assumeutxo snapshot metadata has an
// incorrect hardcoded AssumeutxoData::nChainTx value.
if (!Assume(pindex->nChainTx == 0 || pindex->nChainTx == prev_tx_sum(*pindex))) {
LogWarning("Internal bug detected: block %d has unexpected nChainTx %i that should be %i (%s %s). Please report this issue here: %s\n",
pindex->nHeight, pindex->nChainTx, prev_tx_sum(*pindex), PACKAGE_NAME, FormatFullVersion(), PACKAGE_BUGREPORT);
// incorrect hardcoded AssumeutxoData::m_chain_tx_count value.
if (!Assume(pindex->m_chain_tx_count == 0 || pindex->m_chain_tx_count == prev_tx_sum(*pindex))) {
LogWarning("Internal bug detected: block %d has unexpected m_chain_tx_count %i that should be %i (%s %s). Please report this issue here: %s\n",
pindex->nHeight, pindex->m_chain_tx_count, prev_tx_sum(*pindex), PACKAGE_NAME, FormatFullVersion(), PACKAGE_BUGREPORT);
}
pindex->nChainTx = prev_tx_sum(*pindex);
pindex->m_chain_tx_count = prev_tx_sum(*pindex);
pindex->nSequenceId = nBlockSequenceId++;
for (Chainstate *c : GetAll()) {
c->TryAddBlockIndexCandidate(pindex);
@ -5333,17 +5333,17 @@ 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.
// Make sure m_chain_tx_count sum is correctly computed.
if (!pindex->pprev) {
// If no previous block, nTx and nChainTx must be the same.
assert(pindex->nChainTx == pindex->nTx);
} else if (pindex->pprev->nChainTx > 0 && pindex->nTx > 0) {
// If previous nChainTx is set and number of transactions in block is known, sum must be set.
assert(pindex->nChainTx == pindex->nTx + pindex->pprev->nChainTx);
// If no previous block, nTx and m_chain_tx_count must be the same.
assert(pindex->m_chain_tx_count == pindex->nTx);
} else if (pindex->pprev->m_chain_tx_count > 0 && pindex->nTx > 0) {
// If previous m_chain_tx_count is set and number of transactions in block is known, sum must be set.
assert(pindex->m_chain_tx_count == pindex->nTx + pindex->pprev->m_chain_tx_count);
} else {
// Otherwise nChainTx should only be set if this is a snapshot
// Otherwise m_chain_tx_count should only be set if this is a snapshot
// block, and must be set if it is.
assert((pindex->nChainTx != 0) == (pindex == snap_base));
assert((pindex->m_chain_tx_count != 0) == (pindex == snap_base));
}
// Chainstate-specific checks on setBlockIndexCandidates
@ -5548,13 +5548,13 @@ 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;
if (!Assume(pindex->nChainTx > 0)) {
LogWarning("Internal bug detected: block %d has unset nChainTx (%s %s). Please report this issue here: %s\n",
if (!Assume(pindex->m_chain_tx_count > 0)) {
LogWarning("Internal bug detected: block %d has unset m_chain_tx_count (%s %s). Please report this issue here: %s\n",
pindex->nHeight, PACKAGE_NAME, FormatFullVersion(), PACKAGE_BUGREPORT);
return 0.0;
}
@ -5563,13 +5563,13 @@ double GuessVerificationProgress(const ChainTxData& data, const CBlockIndex *pin
double fTxTotal;
if (pindex->nChainTx <= data.nTxCount) {
fTxTotal = data.nTxCount + (nNow - data.nTime) * data.dTxRate;
if (pindex->m_chain_tx_count <= data.tx_count) {
fTxTotal = data.tx_count + (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
@ -6026,7 +6026,7 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
assert(index);
assert(index == snapshot_start_block);
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",