2020-04-26 19:29:03 +00:00
|
|
|
// Copyright (c) 2020 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <policy/rbf.h>
|
|
|
|
#include <primitives/transaction.h>
|
|
|
|
#include <sync.h>
|
|
|
|
#include <test/fuzz/FuzzedDataProvider.h>
|
|
|
|
#include <test/fuzz/fuzz.h>
|
|
|
|
#include <test/fuzz/util.h>
|
|
|
|
#include <txmempool.h>
|
|
|
|
|
|
|
|
#include <cstdint>
|
2020-05-10 18:35:55 +00:00
|
|
|
#include <optional>
|
2020-04-26 19:29:03 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-12-03 16:42:49 +01:00
|
|
|
FUZZ_TARGET(rbf)
|
2020-04-26 19:29:03 +00:00
|
|
|
{
|
|
|
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
2020-11-19 21:25:14 +00:00
|
|
|
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
2020-05-10 18:35:55 +00:00
|
|
|
std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
2020-04-26 19:29:03 +00:00
|
|
|
if (!mtx) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CTxMemPool pool;
|
2021-10-25 19:48:22 +00:00
|
|
|
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
|
2020-05-10 18:35:55 +00:00
|
|
|
const std::optional<CMutableTransaction> another_mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
2020-04-26 19:29:03 +00:00
|
|
|
if (!another_mtx) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const CTransaction another_tx{*another_mtx};
|
|
|
|
if (fuzzed_data_provider.ConsumeBool() && !mtx->vin.empty()) {
|
|
|
|
mtx->vin[0].prevout = COutPoint{another_tx.GetHash(), 0};
|
|
|
|
}
|
|
|
|
LOCK2(cs_main, pool.cs);
|
|
|
|
pool.addUnchecked(ConsumeTxMemPoolEntry(fuzzed_data_provider, another_tx));
|
|
|
|
}
|
|
|
|
const CTransaction tx{*mtx};
|
|
|
|
if (fuzzed_data_provider.ConsumeBool()) {
|
|
|
|
LOCK2(cs_main, pool.cs);
|
|
|
|
pool.addUnchecked(ConsumeTxMemPoolEntry(fuzzed_data_provider, tx));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
LOCK(pool.cs);
|
|
|
|
(void)IsRBFOptIn(tx, pool);
|
|
|
|
}
|
|
|
|
}
|