mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
fuzz: Limit mocktime to MTP in tx_pool targets
This is needed for the next commit to generate blocks. Also, apply the same mocking strategies to both targets.
This commit is contained in:
parent
fab646b8ea
commit
fa61ce5cf5
1 changed files with 33 additions and 3 deletions
|
@ -77,13 +77,21 @@ void SetMempoolConstraints(ArgsManager& args, FuzzedDataProvider& fuzzed_data_pr
|
|||
ToString(fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 999)));
|
||||
}
|
||||
|
||||
void MockTime(FuzzedDataProvider& fuzzed_data_provider, const CChainState& chainstate)
|
||||
{
|
||||
const auto time = ConsumeTime(fuzzed_data_provider,
|
||||
chainstate.m_chain.Tip()->GetMedianTimePast() + 1,
|
||||
std::numeric_limits<decltype(chainstate.m_chain.Tip()->nTime)>::max());
|
||||
SetMockTime(time);
|
||||
}
|
||||
|
||||
FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
const auto& node = g_setup->m_node;
|
||||
auto& chainstate = node.chainman->ActiveChainstate();
|
||||
|
||||
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
||||
MockTime(fuzzed_data_provider, chainstate);
|
||||
SetMempoolConstraints(*node.args, fuzzed_data_provider);
|
||||
|
||||
// All RBF-spendable outpoints
|
||||
|
@ -163,7 +171,7 @@ FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
|
|||
}();
|
||||
|
||||
if (fuzzed_data_provider.ConsumeBool()) {
|
||||
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
||||
MockTime(fuzzed_data_provider, chainstate);
|
||||
}
|
||||
if (fuzzed_data_provider.ConsumeBool()) {
|
||||
SetMempoolConstraints(*node.args, fuzzed_data_provider);
|
||||
|
@ -254,6 +262,10 @@ FUZZ_TARGET_INIT(tx_pool, initialize_tx_pool)
|
|||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
const auto& node = g_setup->m_node;
|
||||
auto& chainstate = node.chainman->ActiveChainstate();
|
||||
|
||||
MockTime(fuzzed_data_provider, chainstate);
|
||||
SetMempoolConstraints(*node.args, fuzzed_data_provider);
|
||||
|
||||
std::vector<uint256> txids;
|
||||
for (const auto& outpoint : g_outpoints_coinbase_init_mature) {
|
||||
|
@ -265,11 +277,29 @@ FUZZ_TARGET_INIT(tx_pool, initialize_tx_pool)
|
|||
txids.push_back(ConsumeUInt256(fuzzed_data_provider));
|
||||
}
|
||||
|
||||
CTxMemPool tx_pool{/* estimator */ nullptr, /* check_ratio */ 1};
|
||||
CTxMemPool tx_pool_{/* estimator */ nullptr, /* check_ratio */ 1};
|
||||
MockedTxPool& tx_pool = *static_cast<MockedTxPool*>(&tx_pool_);
|
||||
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
const auto mut_tx = ConsumeTransaction(fuzzed_data_provider, txids);
|
||||
|
||||
if (fuzzed_data_provider.ConsumeBool()) {
|
||||
MockTime(fuzzed_data_provider, chainstate);
|
||||
}
|
||||
if (fuzzed_data_provider.ConsumeBool()) {
|
||||
SetMempoolConstraints(*node.args, fuzzed_data_provider);
|
||||
}
|
||||
if (fuzzed_data_provider.ConsumeBool()) {
|
||||
tx_pool.RollingFeeUpdate();
|
||||
}
|
||||
if (fuzzed_data_provider.ConsumeBool()) {
|
||||
const auto& txid = fuzzed_data_provider.ConsumeBool() ?
|
||||
mut_tx.GetHash() :
|
||||
PickValue(fuzzed_data_provider, txids);
|
||||
const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
|
||||
tx_pool.PrioritiseTransaction(txid, delta);
|
||||
}
|
||||
|
||||
const auto tx = MakeTransactionRef(mut_tx);
|
||||
const bool bypass_limits = fuzzed_data_provider.ConsumeBool();
|
||||
::fRequireStandard = fuzzed_data_provider.ConsumeBool();
|
||||
|
|
Loading…
Add table
Reference in a new issue