Skip to content

Commit

Permalink
validation: Pass in chainstate to ::AcceptToMemoryPool
Browse files Browse the repository at this point in the history
Summary:
This is a backport of [[bitcoin/bitcoin#20750 | core#20750]] [10, 11, 12 & 13/17]
bitcoin/bitcoin@229bc37

bitcoin/bitcoin@3704433

bitcoin/bitcoin@417dafc

bitcoin/bitcoin@120aaba

Depends on D11195

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11196
  • Loading branch information
dongcarl authored and PiRK committed Mar 17, 2022
1 parent 4afce42 commit e01f463
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 29 deletions.
6 changes: 3 additions & 3 deletions src/bench/block_assemble.cpp
Expand Up @@ -53,9 +53,9 @@ static void AssembleBlock(benchmark::Bench &bench) {

for (const auto &txr : txs) {
TxValidationState vstate;
bool ret{::AcceptToMemoryPool(config, *test_setup.m_node.mempool,
vstate, txr,
false /* bypass_limits */)};
bool ret{::AcceptToMemoryPool(::ChainstateActive(), config,
*test_setup.m_node.mempool, vstate,
txr, false /* bypass_limits */)};
assert(ret);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/net_processing.cpp
Expand Up @@ -3084,8 +3084,8 @@ void PeerManagerImpl::ProcessOrphanTx(const Config &config,
const CTransactionRef porphanTx = orphan_it->second.tx;
TxValidationState state;

if (AcceptToMemoryPool(config, m_mempool, state, porphanTx,
false /* bypass_limits */)) {
if (AcceptToMemoryPool(::ChainstateActive(), config, m_mempool, state,
porphanTx, false /* bypass_limits */)) {
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n",
orphanTxId.ToString());
RelayTransaction(orphanTxId, m_connman);
Expand Down Expand Up @@ -4380,8 +4380,8 @@ void PeerManagerImpl::ProcessMessage(

TxValidationState state;

if (AcceptToMemoryPool(config, m_mempool, state, ptx,
false /* bypass_limits */)) {
if (AcceptToMemoryPool(::ChainstateActive(), config, m_mempool, state,
ptx, false /* bypass_limits */)) {
m_mempool.check(&::ChainstateActive().CoinsTip());
// As this version of the transaction was acceptable, we can forget
// about any requests for it.
Expand Down
7 changes: 4 additions & 3 deletions src/node/transaction.cpp
Expand Up @@ -67,7 +67,8 @@ TransactionError BroadcastTransaction(NodeContext &node, const Config &config,
// First, call ATMP with test_accept and check the fee. If ATMP
// fails here, return error immediately.
Amount fee = Amount::zero();
if (!AcceptToMemoryPool(config, *node.mempool, state, tx,
if (!AcceptToMemoryPool(::ChainstateActive(), config,
*node.mempool, state, tx,
false /* bypass_limits */,
/* test_accept */ true, &fee)) {
return HandleATMPError(state, err_string);
Expand All @@ -76,8 +77,8 @@ TransactionError BroadcastTransaction(NodeContext &node, const Config &config,
}
}
// Try to submit the transaction to the mempool.
if (!AcceptToMemoryPool(config, *node.mempool, state, tx,
false /* bypass_limits */)) {
if (!AcceptToMemoryPool(::ChainstateActive(), config, *node.mempool,
state, tx, false /* bypass_limits */)) {
return HandleATMPError(state, err_string);
}

Expand Down
2 changes: 1 addition & 1 deletion src/rpc/rawtransaction.cpp
Expand Up @@ -1151,7 +1151,7 @@ static RPCHelpMan testmempoolaccept() {
{
LOCK(cs_main);
test_accept_res = AcceptToMemoryPool(
config, mempool, state, std::move(tx),
::ChainstateActive(), config, mempool, state, std::move(tx),
false /* bypass_limits */, true /* test_accept */, &fee);
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/txvalidation_tests.cpp
Expand Up @@ -38,10 +38,10 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup) {

unsigned int initialPoolSize = m_node.mempool->size();

BOOST_CHECK_EQUAL(false,
AcceptToMemoryPool(GetConfig(), *m_node.mempool, state,
MakeTransactionRef(coinbaseTx),
true /* bypass_limits */));
BOOST_CHECK_EQUAL(
false, AcceptToMemoryPool(
::ChainstateActive(), GetConfig(), *m_node.mempool, state,
MakeTransactionRef(coinbaseTx), true /* bypass_limits */));

// Check that the transaction hasn't been added to mempool.
BOOST_CHECK_EQUAL(m_node.mempool->size(), initialPoolSize);
Expand Down
6 changes: 3 additions & 3 deletions src/test/txvalidationcache_tests.cpp
Expand Up @@ -33,9 +33,9 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup) {
LOCK(cs_main);

TxValidationState state;
return AcceptToMemoryPool(GetConfig(), *m_node.mempool, state,
MakeTransactionRef(tx),
true /* bypass_limits */);
return AcceptToMemoryPool(
::ChainstateActive(), GetConfig(), *m_node.mempool, state,
MakeTransactionRef(tx), true /* bypass_limits */);
};

// Create a double-spend of mature coinbase txn:
Expand Down
3 changes: 2 additions & 1 deletion src/test/validation_block_tests.cpp
Expand Up @@ -331,7 +331,8 @@ BOOST_AUTO_TEST_CASE(mempool_locks_reorg) {
TxValidationState state;
for (const auto &tx : txs) {
BOOST_REQUIRE_MESSAGE(
AcceptToMemoryPool(config, *m_node.mempool, state, tx,
AcceptToMemoryPool(::ChainstateActive(), config,
*m_node.mempool, state, tx,
/* bypass_limits */ false),
state.GetRejectReason());
}
Expand Down
4 changes: 2 additions & 2 deletions src/txmempool.cpp
Expand Up @@ -1415,8 +1415,8 @@ void DisconnectedBlockTransactions::updateMempoolForReorg(const Config &config,
// ignore validation errors in resurrected transactions
TxValidationState stateDummy;
if (!fAddToMempool || tx->IsCoinBase() ||
!AcceptToMemoryPool(config, pool, stateDummy, tx,
true /* bypass_limits */)) {
!AcceptToMemoryPool(::ChainstateActive(), config, pool, stateDummy,
tx, true /* bypass_limits */)) {
// If the transaction doesn't make it in to the mempool, remove any
// transactions that depend on it (which would now be orphans).
pool.removeRecursive(*tx, MemPoolRemovalReason::REORG);
Expand Down
9 changes: 5 additions & 4 deletions src/validation.cpp
Expand Up @@ -808,10 +808,11 @@ static bool AcceptToMemoryPoolWithTime(
return res;
}

bool AcceptToMemoryPool(const Config &config, CTxMemPool &pool,
TxValidationState &state, const CTransactionRef &tx,
bool bypass_limits, bool test_accept, Amount *fee_out) {
return AcceptToMemoryPoolWithTime(config, pool, ::ChainstateActive(), state,
bool AcceptToMemoryPool(CChainState &active_chainstate, const Config &config,
CTxMemPool &pool, TxValidationState &state,
const CTransactionRef &tx, bool bypass_limits,
bool test_accept, Amount *fee_out) {
return AcceptToMemoryPoolWithTime(config, pool, active_chainstate, state,
tx, GetTime(), bypass_limits, test_accept,
fee_out);
}
Expand Down
8 changes: 4 additions & 4 deletions src/validation.h
Expand Up @@ -278,10 +278,10 @@ void PruneBlockFilesManual(int nManualPruneHeight);
* (try to) add transaction to memory pool
* @param[out] fee_out optional argument to return tx fee to the caller
*/
bool AcceptToMemoryPool(const Config &config, CTxMemPool &pool,
TxValidationState &state, const CTransactionRef &tx,
bool bypass_limits, bool test_accept = false,
Amount *fee_out = nullptr)
bool AcceptToMemoryPool(CChainState &active_chainstate, const Config &config,
CTxMemPool &pool, TxValidationState &state,
const CTransactionRef &tx, bool bypass_limits,
bool test_accept = false, Amount *fee_out = nullptr)
EXCLUSIVE_LOCKS_REQUIRED(cs_main);

/**
Expand Down

0 comments on commit e01f463

Please sign in to comment.