20std::vector<COutPoint> g_outpoints_coinbase_init_mature;
21std::vector<COutPoint> g_outpoints_coinbase_init_immature;
27 lastRollingFeeUpdate =
GetTime();
28 blockSinceLastRollingFeeBump =
true;
32void initialize_tx_pool()
34 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
35 g_setup = testing_setup.get();
41 g_outpoints_coinbase_init_mature :
42 g_outpoints_coinbase_init_immature;
43 outpoints.push_back(in.
prevout);
49 std::set<CTransactionRef>& m_removed;
50 std::set<CTransactionRef>& m_added;
52 explicit TransactionsDelta(std::set<CTransactionRef>& r, std::set<CTransactionRef>& a)
53 : m_removed{r}, m_added{a} {}
57 Assert(m_added.insert(tx).second);
62 Assert(m_removed.insert(tx).second);
90 auto block_template = assembler.CreateNewBlock(
CScript{} <<
OP_TRUE);
91 Assert(block_template->block.vtx.size() >= 1);
93 const auto info_all = tx_pool.infoAll();
94 if (!info_all.empty()) {
95 const auto& tx_to_remove = *
PickValue(fuzzed_data_provider, info_all).tx;
97 std::vector<uint256> all_txids;
98 tx_pool.queryHashes(all_txids);
99 assert(all_txids.size() < info_all.size());
107 const auto time =
ConsumeTime(fuzzed_data_provider,
109 std::numeric_limits<
decltype(chainstate.
m_chain.
Tip()->
nTime)>::max());
117 auto& chainstate =
node.chainman->ActiveChainstate();
119 MockTime(fuzzed_data_provider, chainstate);
120 SetMempoolConstraints(*
node.args, fuzzed_data_provider);
123 std::set<COutPoint> outpoints_rbf;
125 std::set<COutPoint> outpoints_supply;
126 for (
const auto& outpoint : g_outpoints_coinbase_init_mature) {
127 Assert(outpoints_supply.insert(outpoint).second);
129 outpoints_rbf = outpoints_supply;
135 MockedTxPool& tx_pool = *
static_cast<MockedTxPool*
>(&tx_pool_);
139 const auto GetAmount = [&](
const COutPoint& outpoint) {
141 Assert(amount_view.GetCoin(outpoint, c));
150 for (
const auto& op : outpoints_supply) {
151 supply_now += GetAmount(op);
153 Assert(supply_now == SUPPLY_TOTAL);
155 Assert(!outpoints_supply.empty());
166 for (
int i = 0; i < num_in; ++i) {
168 auto pop = outpoints_rbf.begin();
170 const auto outpoint = *pop;
171 outpoints_rbf.erase(pop);
172 amount_in += GetAmount(outpoint);
176 const auto script_sig =
CScript{};
184 tx_mut.
vin.push_back(in);
187 const auto amount_out = (amount_in - amount_fee) / num_out;
188 for (
int i = 0; i < num_out; ++i) {
193 for (
const auto& in : tx->vin) {
200 MockTime(fuzzed_data_provider, chainstate);
203 SetMempoolConstraints(*
node.args, fuzzed_data_provider);
206 tx_pool.RollingFeeUpdate();
209 const auto& txid = fuzzed_data_provider.
ConsumeBool() ?
211 PickValue(fuzzed_data_provider, outpoints_rbf).hash;
213 tx_pool.PrioritiseTransaction(txid, delta);
217 std::set<CTransactionRef> removed;
218 std::set<CTransactionRef> added;
219 auto txr = std::make_shared<TransactionsDelta>(removed, added);
221 const bool bypass_limits = fuzzed_data_provider.
ConsumeBool();
228 auto it = result_package.m_tx_results.find(tx->GetWitnessHash());
229 Assert(it != result_package.m_tx_results.end());
238 Assert(accepted != added.empty());
239 Assert(accepted == res.m_state.IsValid());
240 Assert(accepted != res.m_state.IsInvalid());
242 Assert(added.size() == 1);
243 Assert(tx == *added.begin());
250 using Sets = std::vector<std::reference_wrapper<std::set<COutPoint>>>;
251 const auto insert_tx = [](Sets created_by_tx, Sets consumed_by_tx,
const auto& tx) {
252 for (
size_t i{0}; i < tx.vout.size(); ++i) {
253 for (
auto& set : created_by_tx) {
254 Assert(set.get().emplace(tx.GetHash(), i).second);
257 for (
const auto& in : tx.vin) {
258 for (
auto& set : consumed_by_tx) {
266 std::set<COutPoint> consumed_erased;
268 std::set<COutPoint> consumed_supply;
269 for (
const auto& removed_tx : removed) {
270 insert_tx( {consumed_erased}, {outpoints_supply}, *removed_tx);
272 for (
const auto& added_tx : added) {
273 insert_tx( {outpoints_supply, outpoints_rbf}, {consumed_supply}, *added_tx);
275 for (
const auto& p : consumed_erased) {
276 Assert(outpoints_supply.erase(p) == 1);
277 Assert(outpoints_rbf.erase(p) == 1);
279 for (
const auto& p : consumed_supply) {
280 Assert(outpoints_supply.erase(p) == 1);
284 Finish(fuzzed_data_provider, tx_pool, chainstate);
291 auto& chainstate =
node.chainman->ActiveChainstate();
293 MockTime(fuzzed_data_provider, chainstate);
294 SetMempoolConstraints(*
node.args, fuzzed_data_provider);
296 std::vector<uint256> txids;
297 for (
const auto& outpoint : g_outpoints_coinbase_init_mature) {
298 txids.push_back(outpoint.hash);
300 for (
int i{0}; i <= 3; ++i) {
302 txids.push_back(g_outpoints_coinbase_init_immature.at(i).hash);
307 MockedTxPool& tx_pool = *
static_cast<MockedTxPool*
>(&tx_pool_);
314 MockTime(fuzzed_data_provider, chainstate);
317 SetMempoolConstraints(*
node.args, fuzzed_data_provider);
320 tx_pool.RollingFeeUpdate();
323 const auto& txid = fuzzed_data_provider.
ConsumeBool() ?
327 tx_pool.PrioritiseTransaction(txid, delta);
331 const bool bypass_limits = fuzzed_data_provider.
ConsumeBool();
336 txids.push_back(tx->GetHash());
339 Finish(fuzzed_data_provider, tx_pool, chainstate);
int64_t CAmount
Amount in satoshis (Can be negative)
static constexpr CAmount COIN
The amount of satoshis in one BTC.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
const CChainParams & Params()
Return the currently selected parameters.
#define Assert(val)
Identity function.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
Generate a new block, without valid proof-of-work.
int64_t GetMedianTimePast() const
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
int Height() const
Return the maximal height in the chain.
CChainState stores and provides an API to update our local knowledge of the current best chain.
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
CChain m_chain
The current chain of blockheaders we consult and build on.
CCoinsView that brings transactions from a mempool into view.
Fee rate in satoshis per kilobyte: CAmount / kB.
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
static const int32_t CURRENT_VERSION
An input of a transaction.
CScriptWitness scriptWitness
Only serialized through CTransaction.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Implement this to subscribe to events generated in validation.
virtual void TransactionAddedToMempool(const CTransactionRef &tx, uint64_t mempool_sequence)
Notifies listeners of a transaction having been added to mempool.
virtual void TransactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason reason, uint64_t mempool_sequence)
Notifies listeners of a transaction leaving mempool.
CTxOut out
unspent transaction output
T ConsumeIntegralInRange(T min, T max)
static const unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule)
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule)
#define FUZZ_TARGET_INIT(name, init_fun)
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
std::string ToString(const T &t)
Locale-independent version of std::to_string.
A mutable version of CTransaction.
std::vector< CTxOut > vout
std::vector< std::vector< unsigned char > > stack
@ INVALID
Fully validated, valid.
Testing setup that configures a complete environment.
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
uint32_t ConsumeSequence(FuzzedDataProvider &fuzzed_data_provider) noexcept
int64_t ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
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
CAmount ConsumeMoney(FuzzedDataProvider &fuzzed_data_provider, const std::optional< CAmount > &max) noexcept
auto & PickValue(FuzzedDataProvider &fuzzed_data_provider, Collection &col)
uint256 ConsumeUInt256(FuzzedDataProvider &fuzzed_data_provider) noexcept
CTxIn MineBlock(const NodeContext &node, const CScript &coinbase_scriptPubKey)
Returns the generated coin.
static const std::vector< uint8_t > WITNESS_STACK_ELEM_OP_TRUE
static const CScript P2WSH_OP_TRUE
#define EXCLUSIVE_LOCKS_REQUIRED(...)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
int64_t GetTime()
DEPRECATED Use either GetTimeSeconds (not mockable) or GetTime<T> (mockable)
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
@ BLOCK
Removed for block.
PackageMempoolAcceptResult ProcessNewPackage(CChainState &active_chainstate, CTxMemPool &pool, const Package &package, bool test_accept)
Atomically test acceptance of a package.
MempoolAcceptResult AcceptToMemoryPool(CChainState &active_chainstate, CTxMemPool &pool, const CTransactionRef &tx, bool bypass_limits, bool test_accept)
(Try to) add a transaction to the memory pool.
void UnregisterSharedValidationInterface(std::shared_ptr< CValidationInterface > callbacks)
Unregister subscriber.
void SyncWithValidationInterfaceQueue()
This is a synonym for the following, which asserts certain locks are not held: std::promise<void> pro...
void RegisterSharedValidationInterface(std::shared_ptr< CValidationInterface > callbacks)
Register subscriber.