27 std::vector<COutPoint> g_outpoints_coinbase_init_mature;
28 std::vector<COutPoint> g_outpoints_coinbase_init_immature;
34 lastRollingFeeUpdate =
GetTime();
35 blockSinceLastRollingFeeBump =
true;
39 void initialize_tx_pool()
41 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
42 g_setup = testing_setup.get();
48 g_outpoints_coinbase_init_mature :
49 g_outpoints_coinbase_init_immature;
50 outpoints.push_back(prevout);
56 std::set<CTransactionRef>& m_removed;
57 std::set<CTransactionRef>& m_added;
59 explicit TransactionsDelta(std::set<CTransactionRef>& r, std::set<CTransactionRef>& a)
60 : m_removed{r}, m_added{a} {}
62 void TransactionAddedToMempool(
const CTransactionRef& tx, uint64_t )
override 64 Assert(m_added.insert(tx).second);
69 Assert(m_removed.insert(tx).second);
93 BlockAssembler::Options options;
97 auto block_template = assembler.CreateNewBlock(
CScript{} <<
OP_TRUE);
98 Assert(block_template->block.vtx.size() >= 1);
100 const auto info_all = tx_pool.infoAll();
101 if (!info_all.empty()) {
102 const auto& tx_to_remove = *
PickValue(fuzzed_data_provider, info_all).tx;
104 std::vector<uint256> all_txids;
105 tx_pool.queryHashes(all_txids);
106 assert(all_txids.size() < info_all.size());
114 const auto time =
ConsumeTime(fuzzed_data_provider,
116 std::numeric_limits<decltype(chainstate.
m_chain.
Tip()->
nTime)>::max());
127 mempool_opts.check_ratio = 1;
128 mempool_opts.require_standard = fuzzed_data_provider.
ConsumeBool();
137 const auto&
node = g_setup->m_node;
140 MockTime(fuzzed_data_provider, chainstate);
143 std::set<COutPoint> outpoints_rbf;
145 std::set<COutPoint> outpoints_supply;
146 for (
const auto& outpoint : g_outpoints_coinbase_init_mature) {
147 Assert(outpoints_supply.insert(outpoint).second);
149 outpoints_rbf = outpoints_supply;
154 SetMempoolConstraints(*
node.args, fuzzed_data_provider);
156 MockedTxPool& tx_pool = *
static_cast<MockedTxPool*
>(&tx_pool_);
158 chainstate.SetMempool(&tx_pool);
162 const auto GetAmount = [&](
const COutPoint& outpoint) {
164 Assert(amount_view.GetCoin(outpoint, c));
173 for (
const auto& op : outpoints_supply) {
174 supply_now += GetAmount(op);
176 Assert(supply_now == SUPPLY_TOTAL);
178 Assert(!outpoints_supply.empty());
189 for (
int i = 0; i < num_in; ++i) {
191 auto pop = outpoints_rbf.begin();
193 const auto outpoint = *pop;
194 outpoints_rbf.erase(pop);
195 amount_in += GetAmount(outpoint);
199 const auto script_sig =
CScript{};
207 tx_mut.
vin.push_back(in);
210 const auto amount_out = (amount_in - amount_fee) / num_out;
211 for (
int i = 0; i < num_out; ++i) {
216 for (
const auto& in : tx->vin) {
223 MockTime(fuzzed_data_provider, chainstate);
226 tx_pool.RollingFeeUpdate();
229 const auto& txid = fuzzed_data_provider.
ConsumeBool() ?
231 PickValue(fuzzed_data_provider, outpoints_rbf).hash;
233 tx_pool.PrioritiseTransaction(txid, delta);
237 std::set<CTransactionRef> removed;
238 std::set<CTransactionRef> added;
239 auto txr = std::make_shared<TransactionsDelta>(removed, added);
241 const bool bypass_limits = fuzzed_data_provider.
ConsumeBool();
250 auto it = result_package.m_tx_results.find(tx->GetWitnessHash());
251 Assert(it != result_package.m_tx_results.end());
261 Assert(accepted != added.empty());
262 Assert(accepted == res.m_state.IsValid());
263 Assert(accepted != res.m_state.IsInvalid());
265 Assert(added.size() == 1);
266 Assert(tx == *added.begin());
273 using Sets = std::vector<std::reference_wrapper<std::set<COutPoint>>>;
274 const auto insert_tx = [](Sets created_by_tx, Sets consumed_by_tx,
const auto& tx) {
275 for (
size_t i{0}; i < tx.vout.size(); ++i) {
276 for (
auto&
set : created_by_tx) {
277 Assert(
set.
get().emplace(tx.GetHash(), i).second);
280 for (
const auto& in : tx.vin) {
281 for (
auto&
set : consumed_by_tx) {
289 std::set<COutPoint> consumed_erased;
291 std::set<COutPoint> consumed_supply;
292 for (
const auto& removed_tx : removed) {
293 insert_tx({consumed_erased}, {outpoints_supply}, *removed_tx);
295 for (
const auto& added_tx : added) {
296 insert_tx({outpoints_supply, outpoints_rbf}, {consumed_supply}, *added_tx);
298 for (
const auto& p : consumed_erased) {
299 Assert(outpoints_supply.erase(p) == 1);
300 Assert(outpoints_rbf.erase(p) == 1);
302 for (
const auto& p : consumed_supply) {
303 Assert(outpoints_supply.erase(p) == 1);
307 Finish(fuzzed_data_provider, tx_pool, chainstate);
313 const auto&
node = g_setup->m_node;
316 MockTime(fuzzed_data_provider, chainstate);
318 std::vector<uint256> txids;
319 txids.reserve(g_outpoints_coinbase_init_mature.size());
320 for (
const auto& outpoint : g_outpoints_coinbase_init_mature) {
321 txids.push_back(outpoint.hash);
323 for (
int i{0}; i <= 3; ++i) {
325 txids.push_back(g_outpoints_coinbase_init_immature.at(i).hash);
329 SetMempoolConstraints(*
node.args, fuzzed_data_provider);
331 MockedTxPool& tx_pool = *
static_cast<MockedTxPool*
>(&tx_pool_);
333 chainstate.SetMempool(&tx_pool);
340 MockTime(fuzzed_data_provider, chainstate);
343 tx_pool.RollingFeeUpdate();
346 const auto& txid = fuzzed_data_provider.
ConsumeBool() ?
350 tx_pool.PrioritiseTransaction(txid, delta);
354 const bool bypass_limits = fuzzed_data_provider.
ConsumeBool();
358 txids.push_back(tx->GetHash());
361 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.
The package itself is invalid (e.g. too many transactions).
static const CScript P2WSH_OP_TRUE
CScriptWitness scriptWitness
Only serialized through CTransaction.
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
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.
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
static CTransactionRef MakeTransactionRef(Tx &&txIn)
COutPoint MineBlock(const NodeContext &node, const CScript &coinbase_scriptPubKey)
Returns the generated coin.
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
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.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
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
CTxMemPool::Options MemPoolOptionsForTest(const NodeContext &node)
static constexpr CAmount COIN
The amount of satoshis in one BTC.