Skip to content

Commit c8571c0

Browse files
committed
merge bitcoin#23173: Add ChainstateManager::ProcessTransaction
We need to extend `bypass_limits` to `ProcessTransaction()` because Dash allows the `sendrawtransaction` RPC to bypass limits with the optional `bypasslimits` boolean (introduced in dash#2110). The bool arguments are not in alphabetical order to prevent breakage with Bitcoin code that expects `bypass_limits` to always be false.
1 parent a21bfd0 commit c8571c0

File tree

12 files changed

+55
-30
lines changed

12 files changed

+55
-30
lines changed

src/bench/block_assemble.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ static void AssembleBlock(benchmark::Bench& bench)
3939
txs.at(b) = MakeTransactionRef(tx);
4040
}
4141
{
42-
LOCK(::cs_main); // Required for ::AcceptToMemoryPool.
42+
LOCK(::cs_main);
4343

4444
for (const auto& txr : txs) {
45-
const MempoolAcceptResult res = ::AcceptToMemoryPool(test_setup->m_node.chainman->ActiveChainstate(), *test_setup->m_node.mempool, txr, false /* bypass_limits */);
45+
const MempoolAcceptResult res = test_setup->m_node.chainman->ProcessTransaction(txr);
4646
assert(res.m_result_type == MempoolAcceptResult::ResultType::VALID);
4747
}
4848
}

src/consensus/validation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ enum class TxValidationResult {
3131
TX_CONFLICT,
3232
TX_CONFLICT_LOCK, //!< conflicts with InstantSend lock
3333
TX_MEMPOOL_POLICY, //!< violated mempool's fee/size/descendant/etc limits
34+
TX_NO_MEMPOOL, //!< this node does not have a mempool so can't validate the transaction
3435
};
3536

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

src/net_processing.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,9 @@ class PeerManagerImpl final : public PeerManager
856856
EXCLUSIVE_LOCKS_REQUIRED(cs_main, !m_recent_confirmed_transactions_mutex);
857857

858858
/**
859-
* Filter for transactions that were recently rejected by
860-
* AcceptToMemoryPool. These are not rerequested until the chain tip
861-
* changes, at which point the entire filter is reset.
859+
* Filter for transactions that were recently rejected by the mempool.
860+
* These are not rerequested until the chain tip changes, at which point
861+
* the entire filter is reset.
862862
*
863863
* Without this filter we'd be re-requesting txs from each of our peers,
864864
* increasing bandwidth consumption considerably. For instance, with 100
@@ -1816,6 +1816,7 @@ bool PeerManagerImpl::MaybePunishNodeForTx(NodeId nodeid, const TxValidationStat
18161816
case TxValidationResult::TX_PREMATURE_SPEND:
18171817
case TxValidationResult::TX_CONFLICT:
18181818
case TxValidationResult::TX_MEMPOOL_POLICY:
1819+
case TxValidationResult::TX_NO_MEMPOOL:
18191820
// moved from BLOCK
18201821
case TxValidationResult::TX_BAD_SPECIAL:
18211822
case TxValidationResult::TX_CONFLICT_LOCK:
@@ -3039,7 +3040,7 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
30393040
const auto [porphanTx, from_peer] = m_orphanage.GetTx(orphanHash);
30403041
if (porphanTx == nullptr) continue;
30413042

3042-
const MempoolAcceptResult result = AcceptToMemoryPool(m_chainman.ActiveChainstate(), m_mempool, porphanTx, false /* bypass_limits */);
3043+
const MempoolAcceptResult result = m_chainman.ProcessTransaction(porphanTx);
30433044
const TxValidationState& state = result.m_state;
30443045

30453046
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
@@ -3065,8 +3066,6 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
30653066
break;
30663067
}
30673068
}
3068-
CChainState& active_chainstate = m_chainman.ActiveChainstate();
3069-
m_mempool.check(active_chainstate.CoinsTip(), active_chainstate.m_chain.Height() + 1);
30703069
}
30713070

30723071
bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& node, Peer& peer,
@@ -4224,7 +4223,7 @@ void PeerManagerImpl::ProcessMessage(
42244223
return;
42254224
}
42264225

4227-
const MempoolAcceptResult result = AcceptToMemoryPool(m_chainman.ActiveChainstate(), m_mempool, ptx, false /* bypass_limits */);
4226+
const MempoolAcceptResult result = m_chainman.ProcessTransaction(ptx);
42284227
const TxValidationState& state = result.m_state;
42294228

42304229
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
@@ -4235,8 +4234,6 @@ void PeerManagerImpl::ProcessMessage(
42354234
m_cj_ctx->dstxman->AddDSTX(dstx);
42364235
}
42374236

4238-
CChainState& active_chainstate = m_chainman.ActiveChainstate();
4239-
m_mempool.check(active_chainstate.CoinsTip(), active_chainstate.m_chain.Height() + 1);
42404237
RelayTransaction(tx.GetHash());
42414238
m_orphanage.AddChildrenToWorkSet(tx, peer->m_orphan_work_set);
42424239

@@ -4308,8 +4305,8 @@ void PeerManagerImpl::ProcessMessage(
43084305
}
43094306

43104307
// If a tx has been detected by m_recent_rejects, we will have reached
4311-
// this point and the tx will have been ignored. Because we haven't run
4312-
// the tx through AcceptToMemoryPool, we won't have computed a DoS
4308+
// this point and the tx will have been ignored. Because we haven't
4309+
// submitted the tx to our mempool, we won't have computed a DoS
43134310
// score for it or determined exactly why we consider it invalid.
43144311
//
43154312
// This means we won't penalize any peer subsequently relaying a DoSy

src/node/transaction.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,15 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
6565
if (max_tx_fee > 0) {
6666
// First, call ATMP with test_accept and check the fee. If ATMP
6767
// fails here, return error immediately.
68-
const MempoolAcceptResult result = AcceptToMemoryPool(node.chainman->ActiveChainstate(), *node.mempool, tx,
69-
bypass_limits, true /* test_accept */);
68+
const MempoolAcceptResult result = node.chainman->ProcessTransaction(tx, /*test_accept=*/true, bypass_limits);
7069
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
7170
return HandleATMPError(result.m_state, err_string.original);
7271
} else if (result.m_base_fees.value() > max_tx_fee) {
7372
return TransactionError::MAX_FEE_EXCEEDED;
7473
}
7574
}
7675
// Try to submit the transaction to the mempool.
77-
const MempoolAcceptResult result = AcceptToMemoryPool(node.chainman->ActiveChainstate(), *node.mempool, tx,
78-
bypass_limits, false /* test_accept */);
76+
const MempoolAcceptResult result = node.chainman->ProcessTransaction(tx, /*test_accept=*/false, bypass_limits);
7977
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
8078
return HandleATMPError(result.m_state, err_string.original);
8179
}

src/rpc/rawtransaction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,12 +1246,13 @@ static RPCHelpMan testmempoolaccept()
12461246

12471247
NodeContext& node = EnsureAnyNodeContext(request.context);
12481248
CTxMemPool& mempool = EnsureMemPool(node);
1249-
CChainState& chainstate = EnsureChainman(node).ActiveChainstate();
1249+
ChainstateManager& chainman = EnsureChainman(node);
1250+
CChainState& chainstate = chainman.ActiveChainstate();
12501251
const PackageMempoolAcceptResult package_result = [&] {
12511252
LOCK(::cs_main);
12521253
if (txns.size() > 1) return ProcessNewPackage(chainstate, mempool, txns, /* test_accept */ true);
12531254
return PackageMempoolAcceptResult(txns[0]->GetHash(),
1254-
AcceptToMemoryPool(chainstate, mempool, txns[0], /* bypass_limits */ false, /* test_accept*/ true));
1255+
chainman.ProcessTransaction(txns[0], /*test_accept=*/ true));
12551256
}();
12561257

12571258
UniValue rpc_result(UniValue::VARR);

src/test/txvalidation_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup)
4343
LOCK(cs_main);
4444

4545
unsigned int initialPoolSize = m_node.mempool->size();
46-
const MempoolAcceptResult result = AcceptToMemoryPool(m_node.chainman->ActiveChainstate(), *m_node.mempool, MakeTransactionRef(coinbaseTx), true /* bypass_limits */);
46+
const MempoolAcceptResult result = m_node.chainman->ProcessTransaction(MakeTransactionRef(coinbaseTx));
4747

4848
BOOST_CHECK(result.m_result_type == MempoolAcceptResult::ResultType::INVALID);
4949

src/test/txvalidationcache_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, Dersig100Setup)
3232
const auto ToMemPool = [this](const CMutableTransaction& tx) {
3333
LOCK(cs_main);
3434

35-
const MempoolAcceptResult result = AcceptToMemoryPool(m_node.chainman->ActiveChainstate(), *m_node.mempool, MakeTransactionRef(tx), true /* bypass_limits */);
35+
const MempoolAcceptResult result = m_node.chainman->ProcessTransaction(MakeTransactionRef(tx));
3636
return result.m_result_type == MempoolAcceptResult::ResultType::VALID;
3737
};
3838

src/test/util/setup_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ CMutableTransaction TestChainSetup::CreateValidMempoolTransaction(CTransactionRe
519519
// If submit=true, add transaction to the mempool.
520520
if (submit) {
521521
LOCK(cs_main);
522-
const MempoolAcceptResult result = AcceptToMemoryPool(m_node.chainman->ActiveChainstate(), *m_node.mempool, MakeTransactionRef(mempool_txn), /* bypass_limits */ false);
522+
const MempoolAcceptResult result = m_node.chainman->ProcessTransaction(MakeTransactionRef(mempool_txn));
523523
assert(result.m_result_type == MempoolAcceptResult::ResultType::VALID);
524524
}
525525

src/test/validation_block_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ BOOST_AUTO_TEST_CASE(mempool_locks_reorg)
279279
{
280280
LOCK(cs_main);
281281
for (const auto& tx : txs) {
282-
const MempoolAcceptResult result = AcceptToMemoryPool(m_node.chainman->ActiveChainstate(), *m_node.mempool, tx, false /* bypass_limits */);
282+
const MempoolAcceptResult result = m_node.chainman->ProcessTransaction(tx);
283283
BOOST_REQUIRE(result.m_result_type == MempoolAcceptResult::ResultType::VALID);
284284
}
285285
}

src/util/error.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ bilingual_str TransactionErrorString(const TransactionError err)
2020
case TransactionError::P2P_DISABLED:
2121
return Untranslated("Peer-to-peer functionality missing or disabled");
2222
case TransactionError::MEMPOOL_REJECTED:
23-
return Untranslated("Transaction rejected by AcceptToMemoryPool");
23+
return Untranslated("Transaction rejected by mempool");
2424
case TransactionError::MEMPOOL_ERROR:
25-
return Untranslated("AcceptToMemoryPool failed");
25+
return Untranslated("Mempool internal error");
2626
case TransactionError::INVALID_PSBT:
2727
return Untranslated("PSBT is not well-formed");
2828
case TransactionError::PSBT_MISMATCH:

0 commit comments

Comments
 (0)