26 std::vector<COutPoint> g_outpoints_coinbase_init_mature;
27 std::vector<COutPoint> g_outpoints_coinbase_init_immature;
33 lastRollingFeeUpdate =
GetTime();
34 blockSinceLastRollingFeeBump =
true;
38 void initialize_tx_pool()
40 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
41 g_setup = testing_setup.get();
47 g_outpoints_coinbase_init_mature :
48 g_outpoints_coinbase_init_immature;
49 outpoints.push_back(in.
prevout);
55 std::set<CTransactionRef>& m_removed;
56 std::set<CTransactionRef>& m_added;
58 explicit TransactionsDelta(std::set<CTransactionRef>& r, std::set<CTransactionRef>& a)
59 : m_removed{r}, m_added{a} {}
61 void TransactionAddedToMempool(
const CTransactionRef& tx, uint64_t )
override 63 Assert(m_added.insert(tx).second);
68 Assert(m_removed.insert(tx).second);
92 BlockAssembler::Options options;
96 auto block_template = assembler.CreateNewBlock(
CScript{} <<
OP_TRUE);
97 Assert(block_template->block.vtx.size() >= 1);
99 const auto info_all = tx_pool.infoAll();
100 if (!info_all.empty()) {
101 const auto& tx_to_remove = *
PickValue(fuzzed_data_provider, info_all).tx;
103 std::vector<uint256> all_txids;
104 tx_pool.queryHashes(all_txids);
105 assert(all_txids.size() < info_all.size());
113 const auto time =
ConsumeTime(fuzzed_data_provider,
115 std::numeric_limits<decltype(chainstate.
m_chain.
Tip()->
nTime)>::max());
126 mempool_opts.check_ratio = 1;
127 mempool_opts.require_standard = fuzzed_data_provider.
ConsumeBool();
136 const auto&
node = g_setup->m_node;
139 MockTime(fuzzed_data_provider, chainstate);
142 std::set<COutPoint> outpoints_rbf;
144 std::set<COutPoint> outpoints_supply;
145 for (
const auto& outpoint : g_outpoints_coinbase_init_mature) {
146 Assert(outpoints_supply.insert(outpoint).second);
148 outpoints_rbf = outpoints_supply;
153 SetMempoolConstraints(*
node.args, fuzzed_data_provider);
155 MockedTxPool& tx_pool = *
static_cast<MockedTxPool*
>(&tx_pool_);
157 chainstate.SetMempool(&tx_pool);
161 const auto GetAmount = [&](
const COutPoint& outpoint) {
163 Assert(amount_view.GetCoin(outpoint, c));
172 for (
const auto& op : outpoints_supply) {
173 supply_now += GetAmount(op);
175 Assert(supply_now == SUPPLY_TOTAL);
177 Assert(!outpoints_supply.empty());
188 for (
int i = 0; i < num_in; ++i) {
190 auto pop = outpoints_rbf.begin();
192 const auto outpoint = *pop;
193 outpoints_rbf.erase(pop);
194 amount_in += GetAmount(outpoint);
198 const auto script_sig =
CScript{};
206 tx_mut.
vin.push_back(in);
209 const auto amount_out = (amount_in - amount_fee) / num_out;
210 for (
int i = 0; i < num_out; ++i) {
215 for (
const auto& in : tx->vin) {
222 MockTime(fuzzed_data_provider, chainstate);
225 tx_pool.RollingFeeUpdate();
228 const auto& txid = fuzzed_data_provider.
ConsumeBool() ?
230 PickValue(fuzzed_data_provider, outpoints_rbf).hash;
232 tx_pool.PrioritiseTransaction(txid, delta);
236 std::set<CTransactionRef> removed;
237 std::set<CTransactionRef> added;
238 auto txr = std::make_shared<TransactionsDelta>(removed, added);
240 const bool bypass_limits = fuzzed_data_provider.
ConsumeBool();
249 auto it = result_package.m_tx_results.find(tx->GetWitnessHash());
250 Assert(it != result_package.m_tx_results.end());
260 Assert(accepted != added.empty());
261 Assert(accepted == res.m_state.IsValid());
262 Assert(accepted != res.m_state.IsInvalid());
264 Assert(added.size() == 1);
265 Assert(tx == *added.begin());
272 using Sets = std::vector<std::reference_wrapper<std::set<COutPoint>>>;
273 const auto insert_tx = [](Sets created_by_tx, Sets consumed_by_tx,
const auto& tx) {
274 for (
size_t i{0}; i < tx.vout.size(); ++i) {
275 for (
auto&
set : created_by_tx) {
276 Assert(
set.
get().emplace(tx.GetHash(), i).second);
279 for (
const auto& in : tx.vin) {
280 for (
auto&
set : consumed_by_tx) {
288 std::set<COutPoint> consumed_erased;
290 std::set<COutPoint> consumed_supply;
291 for (
const auto& removed_tx : removed) {
292 insert_tx({consumed_erased}, {outpoints_supply}, *removed_tx);
294 for (
const auto& added_tx : added) {
295 insert_tx({outpoints_supply, outpoints_rbf}, {consumed_supply}, *added_tx);
297 for (
const auto& p : consumed_erased) {
298 Assert(outpoints_supply.erase(p) == 1);
299 Assert(outpoints_rbf.erase(p) == 1);
301 for (
const auto& p : consumed_supply) {
302 Assert(outpoints_supply.erase(p) == 1);
306 Finish(fuzzed_data_provider, tx_pool, chainstate);
312 const auto&
node = g_setup->m_node;
313 auto& chainstate =
node.chainman->ActiveChainstate();
315 MockTime(fuzzed_data_provider, chainstate);
317 std::vector<uint256> txids;
318 for (
const auto& outpoint : g_outpoints_coinbase_init_mature) {
319 txids.push_back(outpoint.hash);
321 for (
int i{0}; i <= 3; ++i) {
323 txids.push_back(g_outpoints_coinbase_init_immature.at(i).hash);
327 SetMempoolConstraints(*
node.args, fuzzed_data_provider);
329 MockedTxPool& tx_pool = *
static_cast<MockedTxPool*
>(&tx_pool_);
336 MockTime(fuzzed_data_provider, chainstate);
339 tx_pool.RollingFeeUpdate();
342 const auto& txid = fuzzed_data_provider.
ConsumeBool() ?
346 tx_pool.PrioritiseTransaction(txid, delta);
350 const bool bypass_limits = fuzzed_data_provider.
ConsumeBool();
354 txids.push_back(tx->GetHash());
357 Finish(fuzzed_data_provider, tx_pool, chainstate);
std::shared_ptr< const CTransaction > CTransactionRef
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
void SyncWithValidationInterfaceQueue()
This is a synonym for the following, which asserts certain locks are not held: std::promise<void> pro...
Generate a new block, without valid proof-of-work.
CTxIn MineBlock(const NodeContext &node, const CScript &coinbase_scriptPubKey)
Returns the generated coin.
The package itself is invalid (e.g. too many transactions).
CTxMemPool::Options MemPoolOptionsForTest(const NodeContext &node)
static const CScript P2WSH_OP_TRUE
CScriptWitness scriptWitness
Only serialized through CTransaction.
int Height() const
Return the maximal height in the chain.
CTxOut out
unspent transaction output
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule) ...
std::vector< std::vector< unsigned char > > stack
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
void insert(Tdst &dst, const Tsrc &src)
Simplification of std insertion.
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
void RegisterSharedValidationInterface(std::shared_ptr< CValidationInterface > callbacks)
Register subscriber.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
CChain m_chain
The current chain of blockheaders we consult and build on.
void UnregisterSharedValidationInterface(std::shared_ptr< CValidationInterface > callbacks)
Unregister subscriber.
Implement this to subscribe to events generated in validation.
static const unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule)
int64_t CAmount
Amount in satoshis (Can be negative)
MempoolAcceptResult AcceptToMemoryPool(Chainstate &active_chainstate, const CTransactionRef &tx, int64_t accept_time, bool bypass_limits, bool test_accept) EXCLUSIVE_LOCKS_REQUIRED(
Try to add a transaction to the mempool.
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
std::string ToString(const T &t)
Locale-independent version of std::to_string.
NodeContext struct containing references to chain state and connection state.
Chainstate stores and provides an API to update our local knowledge of the current best chain...
An input of a transaction.
static const std::vector< uint8_t > WITNESS_STACK_ELEM_OP_TRUE
PackageMempoolAcceptResult ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool, const Package &package, bool test_accept)
Validate (and maybe submit) a package to the mempool.
An outpoint - a combination of a transaction hash and an index n into its vout.
std::vector< CTxOut > vout
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
int64_t GetMedianTimePast() const
#define FUZZ_TARGET_INIT(name, init_fun)
static CTransactionRef MakeTransactionRef(Tx &&txIn)
CBlockPolicyEstimator * estimator
#define EXCLUSIVE_LOCKS_REQUIRED(...)
int64_t ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Serialized script, used inside transaction inputs and outputs.
CAmount ConsumeMoney(FuzzedDataProvider &fuzzed_data_provider, const std::optional< CAmount > &max) noexcept
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
A mutable version of CTransaction.
CMutableTransaction ConsumeTransaction(FuzzedDataProvider &fuzzed_data_provider, const std::optional< std::vector< uint256 >> &prevout_txids, const int max_num_in, const int max_num_out) noexcept
Options struct containing options for constructing a CTxMemPool.
auto & PickValue(FuzzedDataProvider &fuzzed_data_provider, Collection &col)
static const int32_t CURRENT_VERSION
T ConsumeIntegralInRange(T min, T max)
uint256 ConsumeUInt256(FuzzedDataProvider &fuzzed_data_provider) noexcept
int64_t GetTime()
DEPRECATED, see GetTime.
CCoinsView that brings transactions from a mempool into view.
Testing setup that configures a complete environment.
#define Assert(val)
Identity function.
uint32_t ConsumeSequence(FuzzedDataProvider &fuzzed_data_provider) noexcept
static constexpr CAmount COIN
The amount of satoshis in one BTC.