[refactor] Don't call AcceptToMemoryPool() from outside validation.cpp
This commit is contained in:
1 parent
92a3aeecf6
commit
2c64270bbe
9 files changed
+28
-24
No files matched your search
@@ -34,10 +34,10 @@ static void AssembleBlock(benchmark::Bench& bench)
|
|||||||
txs.at(b) = MakeTransactionRef(tx);
|
txs.at(b) = MakeTransactionRef(tx);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
LOCK(::cs_main); // Required for ::AcceptToMemoryPool.
|
LOCK(::cs_main);
|
||||||
|
|
||||||
for (const auto& txr : txs) {
|
for (const auto& txr : txs) {
|
||||||
const MempoolAcceptResult res = ::AcceptToMemoryPool(test_setup->m_node.chainman->ActiveChainstate(), *test_setup->m_node.mempool, txr, false /* bypass_limits */);
|
const MempoolAcceptResult res = test_setup->m_node.chainman->ProcessTransaction(txr);
|
||||||
assert(res.m_result_type == MempoolAcceptResult::ResultType::VALID);
|
assert(res.m_result_type == MempoolAcceptResult::ResultType::VALID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -461,9 +461,9 @@ private:
|
|||||||
bool AlreadyHaveTx(const GenTxid& gtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
bool AlreadyHaveTx(const GenTxid& gtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter for transactions that were recently rejected by
|
* Filter for transactions that were recently rejected by the mempool.
|
||||||
* AcceptToMemoryPool. These are not rerequested until the chain tip
|
* These are not rerequested until the chain tip changes, at which point
|
||||||
* changes, at which point the entire filter is reset.
|
* the entire filter is reset.
|
||||||
*
|
*
|
||||||
* Without this filter we'd be re-requesting txs from each of our peers,
|
* Without this filter we'd be re-requesting txs from each of our peers,
|
||||||
* increasing bandwidth consumption considerably. For instance, with 100
|
* increasing bandwidth consumption considerably. For instance, with 100
|
||||||
@@ -2243,7 +2243,7 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
|
|||||||
const auto [porphanTx, from_peer] = m_orphanage.GetTx(orphanHash);
|
const auto [porphanTx, from_peer] = m_orphanage.GetTx(orphanHash);
|
||||||
if (porphanTx == nullptr) continue;
|
if (porphanTx == nullptr) continue;
|
||||||
|
|
||||||
const MempoolAcceptResult result = AcceptToMemoryPool(m_chainman.ActiveChainstate(), m_mempool, porphanTx, false /* bypass_limits */);
|
const MempoolAcceptResult result = m_chainman.ProcessTransaction(porphanTx);
|
||||||
const TxValidationState& state = result.m_state;
|
const TxValidationState& state = result.m_state;
|
||||||
|
|
||||||
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
|
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
|
||||||
@@ -3260,7 +3260,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MempoolAcceptResult result = AcceptToMemoryPool(m_chainman.ActiveChainstate(), m_mempool, ptx, false /* bypass_limits */);
|
const MempoolAcceptResult result = m_chainman.ProcessTransaction(ptx);
|
||||||
const TxValidationState& state = result.m_state;
|
const TxValidationState& state = result.m_state;
|
||||||
|
|
||||||
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
|
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
|
||||||
@@ -3384,8 +3384,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If a tx has been detected by m_recent_rejects, we will have reached
|
// If a tx has been detected by m_recent_rejects, we will have reached
|
||||||
// this point and the tx will have been ignored. Because we haven't run
|
// this point and the tx will have been ignored. Because we haven't
|
||||||
// the tx through AcceptToMemoryPool, we won't have computed a DoS
|
// submitted the tx to our mempool, we won't have computed a DoS
|
||||||
// score for it or determined exactly why we consider it invalid.
|
// score for it or determined exactly why we consider it invalid.
|
||||||
//
|
//
|
||||||
// This means we won't penalize any peer subsequently relaying a DoSy
|
// This means we won't penalize any peer subsequently relaying a DoSy
|
||||||
|
|||||||
@@ -70,8 +70,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
|
|||||||
if (max_tx_fee > 0) {
|
if (max_tx_fee > 0) {
|
||||||
// First, call ATMP with test_accept and check the fee. If ATMP
|
// First, call ATMP with test_accept and check the fee. If ATMP
|
||||||
// fails here, return error immediately.
|
// fails here, return error immediately.
|
||||||
const MempoolAcceptResult result = AcceptToMemoryPool(node.chainman->ActiveChainstate(), *node.mempool, tx, false /* bypass_limits */,
|
const MempoolAcceptResult result = node.chainman->ProcessTransaction(tx, /*test_accept=*/ true);
|
||||||
true /* test_accept */);
|
|
||||||
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
|
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
|
||||||
return HandleATMPError(result.m_state, err_string);
|
return HandleATMPError(result.m_state, err_string);
|
||||||
} else if (result.m_base_fees.value() > max_tx_fee) {
|
} else if (result.m_base_fees.value() > max_tx_fee) {
|
||||||
@@ -79,8 +78,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Try to submit the transaction to the mempool.
|
// Try to submit the transaction to the mempool.
|
||||||
const MempoolAcceptResult result = AcceptToMemoryPool(node.chainman->ActiveChainstate(), *node.mempool, tx, false /* bypass_limits */,
|
const MempoolAcceptResult result = node.chainman->ProcessTransaction(tx, /*test_accept=*/ false);
|
||||||
false /* test_accept */);
|
|
||||||
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
|
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
|
||||||
return HandleATMPError(result.m_state, err_string);
|
return HandleATMPError(result.m_state, err_string);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -946,12 +946,13 @@ static RPCHelpMan testmempoolaccept()
|
|||||||
|
|
||||||
NodeContext& node = EnsureAnyNodeContext(request.context);
|
NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||||
CTxMemPool& mempool = EnsureMemPool(node);
|
CTxMemPool& mempool = EnsureMemPool(node);
|
||||||
CChainState& chainstate = EnsureChainman(node).ActiveChainstate();
|
ChainstateManager& chainman = EnsureChainman(node);
|
||||||
|
CChainState& chainstate = chainman.ActiveChainstate();
|
||||||
const PackageMempoolAcceptResult package_result = [&] {
|
const PackageMempoolAcceptResult package_result = [&] {
|
||||||
LOCK(::cs_main);
|
LOCK(::cs_main);
|
||||||
if (txns.size() > 1) return ProcessNewPackage(chainstate, mempool, txns, /* test_accept */ true);
|
if (txns.size() > 1) return ProcessNewPackage(chainstate, mempool, txns, /* test_accept */ true);
|
||||||
return PackageMempoolAcceptResult(txns[0]->GetWitnessHash(),
|
return PackageMempoolAcceptResult(txns[0]->GetWitnessHash(),
|
||||||
AcceptToMemoryPool(chainstate, mempool, txns[0], /* bypass_limits */ false, /* test_accept*/ true));
|
chainman.ProcessTransaction(txns[0], /*test_accept=*/ true));
|
||||||
}();
|
}();
|
||||||
|
|
||||||
UniValue rpc_result(UniValue::VARR);
|
UniValue rpc_result(UniValue::VARR);
|
||||||
|
|||||||
@@ -37,8 +37,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup)
|
|||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
||||||
unsigned int initialPoolSize = m_node.mempool->size();
|
unsigned int initialPoolSize = m_node.mempool->size();
|
||||||
const MempoolAcceptResult result = AcceptToMemoryPool(m_node.chainman->ActiveChainstate(), *m_node.mempool, MakeTransactionRef(coinbaseTx),
|
const MempoolAcceptResult result = m_node.chainman->ProcessTransaction(MakeTransactionRef(coinbaseTx));
|
||||||
false /* bypass_limits */);
|
|
||||||
|
|
||||||
BOOST_CHECK(result.m_result_type == MempoolAcceptResult::ResultType::INVALID);
|
BOOST_CHECK(result.m_result_type == MempoolAcceptResult::ResultType::INVALID);
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, Dersig100Setup)
|
|||||||
const auto ToMemPool = [this](const CMutableTransaction& tx) {
|
const auto ToMemPool = [this](const CMutableTransaction& tx) {
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
||||||
const MempoolAcceptResult result = AcceptToMemoryPool(m_node.chainman->ActiveChainstate(), *m_node.mempool, MakeTransactionRef(tx),
|
const MempoolAcceptResult result = m_node.chainman->ProcessTransaction(MakeTransactionRef(tx));
|
||||||
false /* bypass_limits */);
|
|
||||||
return result.m_result_type == MempoolAcceptResult::ResultType::VALID;
|
return result.m_result_type == MempoolAcceptResult::ResultType::VALID;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -315,7 +315,7 @@ CMutableTransaction TestChain100Setup::CreateValidMempoolTransaction(CTransactio
|
|||||||
// If submit=true, add transaction to the mempool.
|
// If submit=true, add transaction to the mempool.
|
||||||
if (submit) {
|
if (submit) {
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
const MempoolAcceptResult result = AcceptToMemoryPool(m_node.chainman->ActiveChainstate(), *m_node.mempool.get(), MakeTransactionRef(mempool_txn), /* bypass_limits */ false);
|
const MempoolAcceptResult result = m_node.chainman->ProcessTransaction(MakeTransactionRef(mempool_txn));
|
||||||
assert(result.m_result_type == MempoolAcceptResult::ResultType::VALID);
|
assert(result.m_result_type == MempoolAcceptResult::ResultType::VALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ BOOST_AUTO_TEST_CASE(mempool_locks_reorg)
|
|||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
for (const auto& tx : txs) {
|
for (const auto& tx : txs) {
|
||||||
const MempoolAcceptResult result = AcceptToMemoryPool(m_node.chainman->ActiveChainstate(), *m_node.mempool, tx, false /* bypass_limits */);
|
const MempoolAcceptResult result = m_node.chainman->ProcessTransaction(tx);
|
||||||
BOOST_REQUIRE(result.m_result_type == MempoolAcceptResult::ResultType::VALID);
|
BOOST_REQUIRE(result.m_result_type == MempoolAcceptResult::ResultType::VALID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-3
@@ -206,9 +206,16 @@ struct PackageMempoolAcceptResult
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (Try to) add a transaction to the memory pool.
|
* Try to add a transaction to the mempool. This is an internal function and is
|
||||||
* @param[in] bypass_limits When true, don't enforce mempool fee limits.
|
* exposed only for testing. Client code should use ChainstateManager::ProcessTransaction()
|
||||||
* @param[in] test_accept When true, run validation checks but don't submit to mempool.
|
*
|
||||||
|
* @param[in] active_chainstate Reference to the active chainstate.
|
||||||
|
* @param[in] pool Reference to the node's mempool.
|
||||||
|
* @param[in] tx The transaction to submit for mempool acceptance.
|
||||||
|
* @param[in] bypass_limits When true, don't enforce mempool fee and capacity limits.
|
||||||
|
* @param[in] test_accept When true, run validation checks but don't submit to mempool.
|
||||||
|
*
|
||||||
|
* @returns a MempoolAcceptResult indicating whether the transaction was accepted/rejected with reason.
|
||||||
*/
|
*/
|
||||||
MempoolAcceptResult AcceptToMemoryPool(CChainState& active_chainstate, CTxMemPool& pool, const CTransactionRef& tx,
|
MempoolAcceptResult AcceptToMemoryPool(CChainState& active_chainstate, CTxMemPool& pool, const CTransactionRef& tx,
|
||||||
bool bypass_limits, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
bool bypass_limits, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|||||||
Reference in new issue
Block a user