81 .coinbase_output_script = P2WSH_OP_TRUE,
87 outpoints.push_back(prevout);
105 std::set<CTransactionRef>& m_removed;
106 std::set<CTransactionRef>& m_added;
108 explicit TransactionsDelta(std::set<CTransactionRef>& r, std::set<CTransactionRef>&
a)
109 : m_removed{r}, m_added{
a} {}
118 Assert(m_removed.insert(tx).second);
139 std::vector<Wtxid>
res;
234 chainstate.m_chain.Tip()->GetMedianTimePast() + 1,
235 std::numeric_limits<
decltype(
chainstate.m_chain.Tip()->nTime)>::max());
250 auto mempool{std::make_unique<CTxMemPool>(std::move(
mempool_opts), error)};
260 switch (
res.m_result_type) {
338 return coin.out.nValue;
361 for (
int i = 0; i <
num_in; ++i) {
365 const auto outpoint = *
pop;
387 for (
int i = 0; i <
num_out; ++i) {
397 for (
const auto& in : tx->vin) {
414 tx_pool.PrioritiseTransaction(txid, delta);
418 std::set<CTransactionRef> removed;
419 std::set<CTransactionRef>
added;
420 auto txr = std::make_shared<TransactionsDelta>(removed,
added);
421 node.validation_signals->RegisterSharedValidationInterface(
txr);
439 node.validation_signals->SyncWithValidationInterfaceQueue();
440 node.validation_signals->UnregisterSharedValidationInterface(
txr);
457 using Sets = std::vector<std::reference_wrapper<std::set<COutPoint>>>;
459 for (
size_t i{0}; i < tx.vout.size(); ++i) {
461 Assert(set.get().emplace(tx.GetHash(), i).second);
464 for (
const auto& in : tx.vin) {
504 std::vector<Txid> txids;
507 txids.push_back(outpoint.hash);
509 for (
int i{0}; i <= 3; ++i) {
540 tx_pool.PrioritiseTransaction(txid, delta);
551 txids.push_back(tx->GetHash());
int64_t CAmount
Amount in satoshis (Can be negative)
constexpr CAmount COIN
The amount of satoshis in one BTC.
const TestingSetup * g_setup
#define Assert(val)
Identity function.
void ForceSetArg(const std::string &strArg, const std::string &strValue) EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
CCoinsView that brings transactions from a mempool into view.
std::optional< Coin > GetCoin(const COutPoint &outpoint) const override
GetCoin, returning whether it exists and is not spent.
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
static constexpr uint32_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 and mempool.
virtual void TransactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason reason, uint64_t mempool_sequence)
Notifies listeners of a transaction leaving mempool.
virtual void TransactionAddedToMempool(const NewMempoolTransactionInfo &tx, uint64_t mempool_sequence)
Notifies listeners of a transaction having been added to mempool.
Chainstate stores and provides an API to update our local knowledge of the current best chain.
T ConsumeIntegralInRange(T min, T max)
Generate a new block, without valid proof-of-work.
std::unique_ptr< CBlockTemplate > CreateNewBlock()
Construct a new block template.
static transaction_identifier FromUint256(const uint256 &id)
@ TX_RECONSIDERABLE
fails some policy, but might be acceptable if submitted in a (different) package
constexpr int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule)
constexpr unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
@ BLOCK
Removed for block.
@ REORG
Removed for reorganization.
is used externally by mining IPC clients, so it should only declare simple data definitions.
std::string ToString(const T &t)
Locale-independent version of std::to_string.
@ PCKG_POLICY
The package itself is invalid (e.g. too many transactions).
constexpr unsigned int DEFAULT_BLOCK_RESERVED_WEIGHT
Default for -blockreservedweight.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
void ObserveReachabilityGoal(bool reached, const ReachabilityGoal &goal)
Record whether a registered goal is satisfied by at least one fuzz input.
void RegisterReachabilityGoal(const ReachabilityGoal &goal)
Register a goal before executing any fuzz inputs.
A mutable version of CTransaction.
std::vector< std::vector< unsigned char > > stack
Validation result for a transaction evaluated by MemPoolAccept (single or package).
@ DIFFERENT_WITNESS
Valid, transaction was already in the mempool.
@ INVALID
Fully validated, valid.
A reachability condition explicitly registered by a fuzz target.
Testing setup that configures a complete environment.
const CTransactionRef m_tx
Options struct containing options for constructing a CTxMemPool.
Block template creation options.
std::optional< CFeeRate > block_min_fee_rate
Minimum fee rate for transactions to be included.
NodeContext struct containing references to chain state and connection state.
std::unique_ptr< ValidationSignals > validation_signals
Issues calls about blocks and transactions.
std::unique_ptr< ChainstateManager > chainman
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
SeedRandomStateForTest(SeedRand::ZEROS)
NodeSeconds ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
uint32_t ConsumeSequence(FuzzedDataProvider &fuzzed_data_provider) noexcept
CMutableTransaction ConsumeTransaction(FuzzedDataProvider &fuzzed_data_provider, const std::optional< std::vector< Txid > > &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
COutPoint MineBlock(const NodeContext &node, const node::BlockCreateOptions &assembler_options)
Returns the generated coin.
@ ZEROS
Seed with a compile time constant of zeros.
static const std::vector< uint8_t > WITNESS_STACK_ELEM_OP_TRUE
static const CScript P2WSH_OP_TRUE
void CheckMempoolTRUCInvariants(const CTxMemPool &tx_pool)
For every transaction in tx_pool, check TRUC invariants:
CTxMemPool::Options MemPoolOptionsForTest(const NodeContext &node)
#define EXCLUSIVE_LOCKS_REQUIRED(...)
constexpr decltype(CTransaction::version) TRUC_VERSION
void SetMockTime(std::chrono::time_point< NodeClock, std::chrono::seconds > mock)
std::chrono::seconds GetMockTime()
For testing.
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
PackageMempoolAcceptResult ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool, const Package &package, bool test_accept, const std::optional< CFeeRate > &client_maxfeerate)
Validate (and maybe submit) a package to the mempool.
MempoolAcceptResult AcceptToMemoryPool(Chainstate &active_chainstate, const CTransactionRef &tx, int64_t accept_time, bool bypass_limits, bool test_accept)
Try to add a transaction to the mempool.
FuzzedDataProvider & fuzzed_data_provider