Skip to content

Commit 92a3aee

Browse files
committed
[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.
1 parent 36167fa commit 92a3aee

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

src/consensus/validation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ enum class TxValidationResult {
5353
*/
5454
TX_CONFLICT,
5555
TX_MEMPOOL_POLICY, //!< violated mempool's fee/size/descendant/RBF/etc limits
56+
TX_NO_MEMPOOL, //!< this node does not have a mempool so can't validate the transaction
5657
};
5758

5859
/** A "reason" why a block was invalid, suitable for determining whether the

src/net_processing.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,7 @@ bool PeerManagerImpl::MaybePunishNodeForTx(NodeId nodeid, const TxValidationStat
14091409
case TxValidationResult::TX_WITNESS_STRIPPED:
14101410
case TxValidationResult::TX_CONFLICT:
14111411
case TxValidationResult::TX_MEMPOOL_POLICY:
1412+
case TxValidationResult::TX_NO_MEMPOOL:
14121413
break;
14131414
}
14141415
if (message != "") {

src/validation.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3421,6 +3421,17 @@ bool ChainstateManager::ProcessNewBlock(const CChainParams& chainparams, const s
34213421
return true;
34223422
}
34233423

3424+
MempoolAcceptResult ChainstateManager::ProcessTransaction(const CTransactionRef& tx, bool test_accept)
3425+
{
3426+
CChainState& active_chainstate = ActiveChainstate();
3427+
if (!active_chainstate.m_mempool) {
3428+
TxValidationState state;
3429+
state.Invalid(TxValidationResult::TX_NO_MEMPOOL, "no-mempool");
3430+
return MempoolAcceptResult::Failure(state);
3431+
}
3432+
return AcceptToMemoryPool(active_chainstate, *active_chainstate.m_mempool, tx, /*bypass_limits=*/ false, test_accept);
3433+
}
3434+
34243435
bool TestBlockValidity(BlockValidationState& state,
34253436
const CChainParams& chainparams,
34263437
CChainState& chainstate,

src/validation.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,15 @@ class ChainstateManager
994994
*/
995995
bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& block, BlockValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex = nullptr) LOCKS_EXCLUDED(cs_main);
996996

997+
/**
998+
* Try to add a transaction to the memory pool.
999+
*
1000+
* @param[in] tx The transaction to submit for mempool acceptance.
1001+
* @param[in] test_accept When true, run validation checks but don't submit to mempool.
1002+
*/
1003+
[[nodiscard]] MempoolAcceptResult ProcessTransaction(const CTransactionRef& tx, bool test_accept=false)
1004+
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1005+
9971006
//! Load the block tree and coins database from disk, initializing state if we're running with -reindex
9981007
bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
9991008

0 commit comments

Comments
 (0)