0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00

[validation] Add CChainState::ProcessTransaction()

This just calls through to AcceptToMemoryPool() internally, and is currently unused.

Also add a new transaction validation failure reason TX_NO_MEMPOOL to
indicate that there is no mempool.
This commit is contained in:
John Newbery 2021-09-27 16:55:42 +01:00
parent 36167faea9
commit 92a3aeecf6
4 changed files with 22 additions and 0 deletions

View file

@ -53,6 +53,7 @@ enum class TxValidationResult {
*/ */
TX_CONFLICT, TX_CONFLICT,
TX_MEMPOOL_POLICY, //!< violated mempool's fee/size/descendant/RBF/etc limits TX_MEMPOOL_POLICY, //!< violated mempool's fee/size/descendant/RBF/etc limits
TX_NO_MEMPOOL, //!< this node does not have a mempool so can't validate the transaction
}; };
/** A "reason" why a block was invalid, suitable for determining whether the /** A "reason" why a block was invalid, suitable for determining whether the

View file

@ -1409,6 +1409,7 @@ bool PeerManagerImpl::MaybePunishNodeForTx(NodeId nodeid, const TxValidationStat
case TxValidationResult::TX_WITNESS_STRIPPED: case TxValidationResult::TX_WITNESS_STRIPPED:
case TxValidationResult::TX_CONFLICT: case TxValidationResult::TX_CONFLICT:
case TxValidationResult::TX_MEMPOOL_POLICY: case TxValidationResult::TX_MEMPOOL_POLICY:
case TxValidationResult::TX_NO_MEMPOOL:
break; break;
} }
if (message != "") { if (message != "") {

View file

@ -3421,6 +3421,17 @@ bool ChainstateManager::ProcessNewBlock(const CChainParams& chainparams, const s
return true; return true;
} }
MempoolAcceptResult ChainstateManager::ProcessTransaction(const CTransactionRef& tx, bool test_accept)
{
CChainState& active_chainstate = ActiveChainstate();
if (!active_chainstate.m_mempool) {
TxValidationState state;
state.Invalid(TxValidationResult::TX_NO_MEMPOOL, "no-mempool");
return MempoolAcceptResult::Failure(state);
}
return AcceptToMemoryPool(active_chainstate, *active_chainstate.m_mempool, tx, /*bypass_limits=*/ false, test_accept);
}
bool TestBlockValidity(BlockValidationState& state, bool TestBlockValidity(BlockValidationState& state,
const CChainParams& chainparams, const CChainParams& chainparams,
CChainState& chainstate, CChainState& chainstate,

View file

@ -994,6 +994,15 @@ public:
*/ */
bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& block, BlockValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex = nullptr) LOCKS_EXCLUDED(cs_main); bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& block, BlockValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex = nullptr) LOCKS_EXCLUDED(cs_main);
/**
* Try to add a transaction to the memory pool.
*
* @param[in] tx The transaction to submit for mempool acceptance.
* @param[in] test_accept When true, run validation checks but don't submit to mempool.
*/
[[nodiscard]] MempoolAcceptResult ProcessTransaction(const CTransactionRef& tx, bool test_accept=false)
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
//! Load the block tree and coins database from disk, initializing state if we're running with -reindex //! Load the block tree and coins database from disk, initializing state if we're running with -reindex
bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main); bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main);