Merge bitcoin/bitcoin#31910: qa: fix an off-by-one in utxo snapshot fuzz target and sanity check its snapshot data

63b534f97e fuzz: sanity check hardcoded snapshot in utxo_snapshot target (Antoine Poinsot)
3b85eba83a test util: split up ConnectBlock from MineBlock (Antoine Poinsot)
d1527f6b88 qa: correct off-by-one in utxo snapshot fuzz target (Antoine Poinsot)

Pull request description:

  The assumeutxo data for the fuzz target could change and invalidate the hash silently, preventing the fuzz target from reaching some code paths. Fix this by introducing a unit test which would break if the snapshot data the fuzz target relies on were to change.

  In implementing this i noticed the height used for coins in the fuzz target is actually off-by-one (as if the first block in the created chain was the genesis but it's block `1`), so fix that too.

ACKs for top commit:
  mzumsande:
    Code Review ACK 63b534f97e
  fjahr:
    tACK 63b534f97e

Tree-SHA512: 2399b6e74db9b78aab8efba67c57a405d2d7d880ae3b7d8518a1c96cc6266f61f5e77722cd999adeac5d3e03e73d84cf9ae7bdbcc0afae198cc87049dde4012f
This commit is contained in:
merge-script
2025-03-21 16:46:54 +08:00
4 changed files with 42 additions and 3 deletions

View File

@@ -92,6 +92,11 @@ COutPoint MineBlock(const NodeContext& node, std::shared_ptr<CBlock>& block)
assert(block->nNonce);
}
return ProcessBlock(node, block);
}
COutPoint ProcessBlock(const NodeContext& node, const std::shared_ptr<CBlock>& block)
{
auto& chainman{*Assert(node.chainman)};
const auto old_height = WITH_LOCK(chainman.GetMutex(), return chainman.ActiveHeight());
bool new_block;

View File

@@ -32,6 +32,11 @@ COutPoint MineBlock(const node::NodeContext&,
**/
COutPoint MineBlock(const node::NodeContext&, std::shared_ptr<CBlock>& block);
/**
* Returns the generated coin (or Null if the block was invalid).
*/
COutPoint ProcessBlock(const node::NodeContext&, const std::shared_ptr<CBlock>& block);
/** Prepare a block to be mined */
std::shared_ptr<CBlock> PrepareBlock(const node::NodeContext&);
std::shared_ptr<CBlock> PrepareBlock(const node::NodeContext& node,