mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-21 14:34:49 +01:00
validation, test: Improve and document nChainTx check for testability
Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
This commit is contained in:
parent
2c9354facb
commit
73700fb554
3 changed files with 11 additions and 7 deletions
|
@ -495,7 +495,7 @@ public:
|
|||
{
|
||||
.height = 110,
|
||||
.hash_serialized = AssumeutxoHash{uint256S("0x1ebbf5850204c0bdb15bf030f47c7fe91d45c44c712697e4509ba67adb01c618")},
|
||||
.nChainTx = 110,
|
||||
.nChainTx = 111,
|
||||
.blockhash = uint256S("0x696e92821f65549c7ee134edceeeeaaa4105647a3c4fd9f298c0aec0ab50425c")
|
||||
},
|
||||
{
|
||||
|
|
|
@ -138,11 +138,11 @@ BOOST_AUTO_TEST_CASE(test_assumeutxo)
|
|||
|
||||
const auto out110 = *params->AssumeutxoForHeight(110);
|
||||
BOOST_CHECK_EQUAL(out110.hash_serialized.ToString(), "1ebbf5850204c0bdb15bf030f47c7fe91d45c44c712697e4509ba67adb01c618");
|
||||
BOOST_CHECK_EQUAL(out110.nChainTx, 110U);
|
||||
BOOST_CHECK_EQUAL(out110.nChainTx, 111U);
|
||||
|
||||
const auto out110_2 = *params->AssumeutxoForBlockhash(uint256S("0x696e92821f65549c7ee134edceeeeaaa4105647a3c4fd9f298c0aec0ab50425c"));
|
||||
BOOST_CHECK_EQUAL(out110_2.hash_serialized.ToString(), "1ebbf5850204c0bdb15bf030f47c7fe91d45c44c712697e4509ba67adb01c618");
|
||||
BOOST_CHECK_EQUAL(out110_2.nChainTx, 110U);
|
||||
BOOST_CHECK_EQUAL(out110_2.nChainTx, 111U);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
|
|
@ -4844,10 +4844,14 @@ void ChainstateManager::CheckBlockIndex()
|
|||
CBlockIndex* pindexFirstAssumeValid = nullptr; // Oldest ancestor of pindex which has BLOCK_ASSUMED_VALID
|
||||
while (pindex != nullptr) {
|
||||
nNodes++;
|
||||
if (pindex->pprev && pindex->nTx > 0) {
|
||||
// nChainTx should increase monotonically
|
||||
assert(pindex->pprev->nChainTx <= pindex->nChainTx);
|
||||
}
|
||||
// Make sure nChainTx sum is correctly computed.
|
||||
unsigned int prev_chain_tx = pindex->pprev ? pindex->pprev->nChainTx : 0;
|
||||
assert((pindex->nChainTx == pindex->nTx + prev_chain_tx)
|
||||
// For testing, allow transaction counts to be completely unset.
|
||||
|| (pindex->nChainTx == 0 && pindex->nTx == 0)
|
||||
// For testing, allow this nChainTx to be unset if previous is also unset.
|
||||
|| (pindex->nChainTx == 0 && prev_chain_tx == 0 && pindex->pprev));
|
||||
|
||||
if (pindexFirstAssumeValid == nullptr && pindex->nStatus & BLOCK_ASSUMED_VALID) pindexFirstAssumeValid = pindex;
|
||||
if (pindexFirstInvalid == nullptr && pindex->nStatus & BLOCK_FAILED_VALID) pindexFirstInvalid = pindex;
|
||||
if (pindexFirstMissing == nullptr && !(pindex->nStatus & BLOCK_HAVE_DATA)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue