qa: timelock coinbase transactions created in fuzz targets

This commit is contained in:
Antoine Poinsot 2025-04-21 14:47:39 -04:00
parent 9c94069d8b
commit c76dbe9b8b
3 changed files with 8 additions and 2 deletions

View file

@ -589,9 +589,9 @@ public:
{ {
// For use by fuzz target src/test/fuzz/utxo_snapshot.cpp // For use by fuzz target src/test/fuzz/utxo_snapshot.cpp
.height = 200, .height = 200,
.hash_serialized = AssumeutxoHash{uint256{"7e3b7780fbd2fa479a01f66950dc8f728dc1b11f03d06d5bf223168520df3a48"}}, .hash_serialized = AssumeutxoHash{uint256{"17dcc016d188d16068907cdeb38b75691a118d43053b8cd6a25969419381d13a"}},
.m_chain_tx_count = 201, .m_chain_tx_count = 201,
.blockhash = consteval_ctor(uint256{"5e93653318f294fb5aa339d00bbf8cf1c3515488ad99412c37608b139ea63b27"}), .blockhash = consteval_ctor(uint256{"385901ccbd69dff6bbd00065d01fb8a9e464dede7cfe0372443884f9b1dcf6b9"}),
}, },
{ {
// For use by test/functional/feature_assumeutxo.py // For use by test/functional/feature_assumeutxo.py

View file

@ -52,6 +52,7 @@ FUZZ_TARGET(utxo_total_supply)
// Replace OP_FALSE with OP_TRUE // Replace OP_FALSE with OP_TRUE
{ {
CMutableTransaction tx{*block->vtx.back()}; CMutableTransaction tx{*block->vtx.back()};
tx.nLockTime = 0; // Use the same nLockTime for all as we want to duplicate one of them.
tx.vout.at(0).scriptPubKey = CScript{} << OP_TRUE; tx.vout.at(0).scriptPubKey = CScript{} << OP_TRUE;
block->vtx.back() = MakeTransactionRef(tx); block->vtx.back() = MakeTransactionRef(tx);
} }

View file

@ -17,6 +17,8 @@
#include <validationinterface.h> #include <validationinterface.h>
#include <versionbits.h> #include <versionbits.h>
#include <algorithm>
using node::BlockAssembler; using node::BlockAssembler;
using node::NodeContext; using node::NodeContext;
@ -34,12 +36,15 @@ std::vector<std::shared_ptr<CBlock>> CreateBlockChain(size_t total_height, const
{ {
std::vector<std::shared_ptr<CBlock>> ret{total_height}; std::vector<std::shared_ptr<CBlock>> ret{total_height};
auto time{params.GenesisBlock().nTime}; auto time{params.GenesisBlock().nTime};
// NOTE: here `height` does not correspond to the block height but the block height - 1.
for (size_t height{0}; height < total_height; ++height) { for (size_t height{0}; height < total_height; ++height) {
CBlock& block{*(ret.at(height) = std::make_shared<CBlock>())}; CBlock& block{*(ret.at(height) = std::make_shared<CBlock>())};
CMutableTransaction coinbase_tx; CMutableTransaction coinbase_tx;
coinbase_tx.nLockTime = static_cast<uint32_t>(height);
coinbase_tx.vin.resize(1); coinbase_tx.vin.resize(1);
coinbase_tx.vin[0].prevout.SetNull(); coinbase_tx.vin[0].prevout.SetNull();
coinbase_tx.vin[0].nSequence = CTxIn::MAX_SEQUENCE_NONFINAL; // Make sure timelock is enforced.
coinbase_tx.vout.resize(1); coinbase_tx.vout.resize(1);
coinbase_tx.vout[0].scriptPubKey = P2WSH_OP_TRUE; coinbase_tx.vout[0].scriptPubKey = P2WSH_OP_TRUE;
coinbase_tx.vout[0].nValue = GetBlockSubsidy(height + 1, params.GetConsensus()); coinbase_tx.vout[0].nValue = GetBlockSubsidy(height + 1, params.GetConsensus());