mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
Merge bitcoin/bitcoin#23465: Remove CTxMemPool params from ATMP
f1f10c0514
Remove CTxMemPool params from ATMP (lsilva01) Pull request description: Remove `CTxMemPool` parameter from `AcceptToMemoryPool` function, as suggested in https://github.com/bitcoin/bitcoin/pull/23437#issuecomment-962536149 . This requires that `CChainState` has access to `MockedTxPool` in `tx_pool.cpp` as mentioned https://github.com/bitcoin/bitcoin/pull/23173#discussion_r731895386. So the `MockedTxPool` is attributed to `CChainState::m_mempool` before calling `AcceptToMemoryPool`. Requires #23437. ACKs for top commit: jnewbery: utACKf1f10c0514
MarcoFalke: review ACKf1f10c0514
🔙 Tree-SHA512: 2a4885f4645014fc1fa98bb1090f13721c1a0796bc0021b9cb43bc8cc13920b6eaf057d1f5ed796e0a110e7813e41fe0196334ce7c80d1231fc057a9a3bdf349
This commit is contained in:
commit
84d921e79c
3 changed files with 33 additions and 15 deletions
|
@ -29,6 +29,15 @@ struct MockedTxPool : public CTxMemPool {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class DummyChainState final : public CChainState
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void SetMempool(CTxMemPool* mempool)
|
||||||
|
{
|
||||||
|
m_mempool = mempool;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void initialize_tx_pool()
|
void initialize_tx_pool()
|
||||||
{
|
{
|
||||||
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
|
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
|
||||||
|
@ -114,7 +123,7 @@ FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
|
||||||
{
|
{
|
||||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||||
const auto& node = g_setup->m_node;
|
const auto& node = g_setup->m_node;
|
||||||
auto& chainstate = node.chainman->ActiveChainstate();
|
auto& chainstate{static_cast<DummyChainState&>(node.chainman->ActiveChainstate())};
|
||||||
|
|
||||||
MockTime(fuzzed_data_provider, chainstate);
|
MockTime(fuzzed_data_provider, chainstate);
|
||||||
SetMempoolConstraints(*node.args, fuzzed_data_provider);
|
SetMempoolConstraints(*node.args, fuzzed_data_provider);
|
||||||
|
@ -134,6 +143,8 @@ FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
|
||||||
CTxMemPool tx_pool_{/*estimator=*/nullptr, /*check_ratio=*/1};
|
CTxMemPool tx_pool_{/*estimator=*/nullptr, /*check_ratio=*/1};
|
||||||
MockedTxPool& tx_pool = *static_cast<MockedTxPool*>(&tx_pool_);
|
MockedTxPool& tx_pool = *static_cast<MockedTxPool*>(&tx_pool_);
|
||||||
|
|
||||||
|
chainstate.SetMempool(&tx_pool);
|
||||||
|
|
||||||
// Helper to query an amount
|
// Helper to query an amount
|
||||||
const CCoinsViewMemPool amount_view{WITH_LOCK(::cs_main, return &chainstate.CoinsTip()), tx_pool};
|
const CCoinsViewMemPool amount_view{WITH_LOCK(::cs_main, return &chainstate.CoinsTip()), tx_pool};
|
||||||
const auto GetAmount = [&](const COutPoint& outpoint) {
|
const auto GetAmount = [&](const COutPoint& outpoint) {
|
||||||
|
@ -230,7 +241,7 @@ FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
|
||||||
Assert(it->second.m_result_type == MempoolAcceptResult::ResultType::VALID ||
|
Assert(it->second.m_result_type == MempoolAcceptResult::ResultType::VALID ||
|
||||||
it->second.m_result_type == MempoolAcceptResult::ResultType::INVALID);
|
it->second.m_result_type == MempoolAcceptResult::ResultType::INVALID);
|
||||||
|
|
||||||
const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(tx_pool, chainstate, tx, GetTime(), bypass_limits, /* test_accept= */ false));
|
const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(chainstate, tx, GetTime(), bypass_limits, /*test_accept=*/false));
|
||||||
const bool accepted = res.m_result_type == MempoolAcceptResult::ResultType::VALID;
|
const bool accepted = res.m_result_type == MempoolAcceptResult::ResultType::VALID;
|
||||||
SyncWithValidationInterfaceQueue();
|
SyncWithValidationInterfaceQueue();
|
||||||
UnregisterSharedValidationInterface(txr);
|
UnregisterSharedValidationInterface(txr);
|
||||||
|
@ -330,7 +341,7 @@ FUZZ_TARGET_INIT(tx_pool, initialize_tx_pool)
|
||||||
const auto tx = MakeTransactionRef(mut_tx);
|
const auto tx = MakeTransactionRef(mut_tx);
|
||||||
const bool bypass_limits = fuzzed_data_provider.ConsumeBool();
|
const bool bypass_limits = fuzzed_data_provider.ConsumeBool();
|
||||||
::fRequireStandard = fuzzed_data_provider.ConsumeBool();
|
::fRequireStandard = fuzzed_data_provider.ConsumeBool();
|
||||||
const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(tx_pool, chainstate, tx, GetTime(), bypass_limits, /* test_accept= */ false));
|
const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(chainstate, tx, GetTime(), bypass_limits, /*test_accept=*/false));
|
||||||
const bool accepted = res.m_result_type == MempoolAcceptResult::ResultType::VALID;
|
const bool accepted = res.m_result_type == MempoolAcceptResult::ResultType::VALID;
|
||||||
if (accepted) {
|
if (accepted) {
|
||||||
txids.push_back(tx->GetHash());
|
txids.push_back(tx->GetHash());
|
||||||
|
|
|
@ -331,8 +331,8 @@ void CChainState::MaybeUpdateMempoolForReorg(
|
||||||
while (it != disconnectpool.queuedTx.get<insertion_order>().rend()) {
|
while (it != disconnectpool.queuedTx.get<insertion_order>().rend()) {
|
||||||
// ignore validation errors in resurrected transactions
|
// ignore validation errors in resurrected transactions
|
||||||
if (!fAddToMempool || (*it)->IsCoinBase() ||
|
if (!fAddToMempool || (*it)->IsCoinBase() ||
|
||||||
AcceptToMemoryPool(*m_mempool, *this, *it, GetTime(),
|
AcceptToMemoryPool(*this, *it, GetTime(),
|
||||||
/* bypass_limits= */true, /* test_accept= */ false).m_result_type !=
|
/*bypass_limits=*/true, /*test_accept=*/false).m_result_type !=
|
||||||
MempoolAcceptResult::ResultType::VALID) {
|
MempoolAcceptResult::ResultType::VALID) {
|
||||||
// If the transaction doesn't make it in to the mempool, remove any
|
// If the transaction doesn't make it in to the mempool, remove any
|
||||||
// transactions that depend on it (which would now be orphans).
|
// transactions that depend on it (which would now be orphans).
|
||||||
|
@ -1094,11 +1094,14 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions(const std::
|
||||||
|
|
||||||
} // anon namespace
|
} // anon namespace
|
||||||
|
|
||||||
MempoolAcceptResult AcceptToMemoryPool(CTxMemPool& pool, CChainState& active_chainstate, const CTransactionRef& tx,
|
MempoolAcceptResult AcceptToMemoryPool(CChainState& active_chainstate, const CTransactionRef& tx,
|
||||||
int64_t accept_time, bool bypass_limits, bool test_accept)
|
int64_t accept_time, bool bypass_limits, bool test_accept)
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||||
{
|
{
|
||||||
const CChainParams& chainparams{active_chainstate.m_params};
|
const CChainParams& chainparams{active_chainstate.m_params};
|
||||||
|
assert(active_chainstate.GetMempool() != nullptr);
|
||||||
|
CTxMemPool& pool{*active_chainstate.GetMempool()};
|
||||||
|
|
||||||
std::vector<COutPoint> coins_to_uncache;
|
std::vector<COutPoint> coins_to_uncache;
|
||||||
auto args = MemPoolAccept::ATMPArgs::SingleAccept(chainparams, accept_time, bypass_limits, coins_to_uncache, test_accept);
|
auto args = MemPoolAccept::ATMPArgs::SingleAccept(chainparams, accept_time, bypass_limits, coins_to_uncache, test_accept);
|
||||||
const MempoolAcceptResult result = MemPoolAccept(pool, active_chainstate).AcceptSingleTransaction(tx, args);
|
const MempoolAcceptResult result = MemPoolAccept(pool, active_chainstate).AcceptSingleTransaction(tx, args);
|
||||||
|
@ -3496,13 +3499,13 @@ bool ChainstateManager::ProcessNewBlock(const CChainParams& chainparams, const s
|
||||||
MempoolAcceptResult ChainstateManager::ProcessTransaction(const CTransactionRef& tx, bool test_accept)
|
MempoolAcceptResult ChainstateManager::ProcessTransaction(const CTransactionRef& tx, bool test_accept)
|
||||||
{
|
{
|
||||||
CChainState& active_chainstate = ActiveChainstate();
|
CChainState& active_chainstate = ActiveChainstate();
|
||||||
if (!active_chainstate.m_mempool) {
|
if (!active_chainstate.GetMempool()) {
|
||||||
TxValidationState state;
|
TxValidationState state;
|
||||||
state.Invalid(TxValidationResult::TX_NO_MEMPOOL, "no-mempool");
|
state.Invalid(TxValidationResult::TX_NO_MEMPOOL, "no-mempool");
|
||||||
return MempoolAcceptResult::Failure(state);
|
return MempoolAcceptResult::Failure(state);
|
||||||
}
|
}
|
||||||
auto result = AcceptToMemoryPool(*active_chainstate.m_mempool, active_chainstate, tx, GetTime(), /* bypass_limits= */ false, test_accept);
|
auto result = AcceptToMemoryPool(active_chainstate, tx, GetTime(), /*bypass_limits=*/ false, test_accept);
|
||||||
active_chainstate.m_mempool->check(active_chainstate.CoinsTip(), active_chainstate.m_chain.Height() + 1);
|
active_chainstate.GetMempool()->check(active_chainstate.CoinsTip(), active_chainstate.m_chain.Height() + 1);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4568,8 +4571,8 @@ bool LoadMempool(CTxMemPool& pool, CChainState& active_chainstate, FopenFn mocka
|
||||||
}
|
}
|
||||||
if (nTime > nNow - nExpiryTimeout) {
|
if (nTime > nNow - nExpiryTimeout) {
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
if (AcceptToMemoryPool(pool, active_chainstate, tx, nTime, /* bypass_limits= */ false,
|
const auto& accepted = AcceptToMemoryPool(active_chainstate, tx, nTime, /*bypass_limits=*/false, /*test_accept=*/false);
|
||||||
/* test_accept= */ false).m_result_type == MempoolAcceptResult::ResultType::VALID) {
|
if (accepted.m_result_type == MempoolAcceptResult::ResultType::VALID) {
|
||||||
++count;
|
++count;
|
||||||
} else {
|
} else {
|
||||||
// mempool may contain the transaction already, e.g. from
|
// mempool may contain the transaction already, e.g. from
|
||||||
|
|
|
@ -211,18 +211,16 @@ struct PackageMempoolAcceptResult
|
||||||
* Try to add a transaction to the mempool. This is an internal function and is exposed only for testing.
|
* Try to add a transaction to the mempool. This is an internal function and is exposed only for testing.
|
||||||
* Client code should use ChainstateManager::ProcessTransaction()
|
* Client code should use ChainstateManager::ProcessTransaction()
|
||||||
*
|
*
|
||||||
* @param[in] pool Reference to the node's mempool.
|
|
||||||
* @param[in] active_chainstate Reference to the active chainstate.
|
* @param[in] active_chainstate Reference to the active chainstate.
|
||||||
* @param[in] tx The transaction to submit for mempool acceptance.
|
* @param[in] tx The transaction to submit for mempool acceptance.
|
||||||
* @param[in] accept_time The timestamp for adding the transaction to the mempool. Usually
|
* @param[in] accept_time The timestamp for adding the transaction to the mempool.
|
||||||
* the current system time, but may be different.
|
|
||||||
* It is also used to determine when the entry expires.
|
* It is also used to determine when the entry expires.
|
||||||
* @param[in] bypass_limits When true, don't enforce mempool fee and capacity limits.
|
* @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.
|
* @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.
|
* @returns a MempoolAcceptResult indicating whether the transaction was accepted/rejected with reason.
|
||||||
*/
|
*/
|
||||||
MempoolAcceptResult AcceptToMemoryPool(CTxMemPool& pool, CChainState& active_chainstate, const CTransactionRef& tx,
|
MempoolAcceptResult AcceptToMemoryPool(CChainState& active_chainstate, const CTransactionRef& tx,
|
||||||
int64_t accept_time, bool bypass_limits, bool test_accept)
|
int64_t accept_time, bool bypass_limits, bool test_accept)
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
|
@ -649,6 +647,12 @@ public:
|
||||||
return m_coins_views->m_dbview;
|
return m_coins_views->m_dbview;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! @returns A pointer to the mempool.
|
||||||
|
CTxMemPool* GetMempool()
|
||||||
|
{
|
||||||
|
return m_mempool;
|
||||||
|
}
|
||||||
|
|
||||||
//! @returns A reference to a wrapped view of the in-memory UTXO set that
|
//! @returns A reference to a wrapped view of the in-memory UTXO set that
|
||||||
//! handles disk read errors gracefully.
|
//! handles disk read errors gracefully.
|
||||||
CCoinsViewErrorCatcher& CoinsErrorCatcher() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
CCoinsViewErrorCatcher& CoinsErrorCatcher() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||||
|
|
Loading…
Add table
Reference in a new issue