mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
merge bitcoin#23465: Remove CTxMemPool params from ATMP
This commit is contained in:
parent
d2cbdc40d5
commit
87257347c2
@ -28,6 +28,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) {
|
||||||
@ -228,7 +239,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);
|
||||||
@ -328,7 +339,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());
|
||||||
|
@ -354,8 +354,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).
|
||||||
@ -983,11 +983,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;
|
||||||
MemPoolAccept::ATMPArgs args { chainparams, accept_time, bypass_limits, coins_to_uncache, test_accept };
|
MemPoolAccept::ATMPArgs args { 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);
|
||||||
@ -3985,13 +3988,13 @@ bool ChainstateManager::ProcessNewBlock(const CChainParams& chainparams, const s
|
|||||||
MempoolAcceptResult ChainstateManager::ProcessTransaction(const CTransactionRef& tx, bool test_accept, bool bypass_limits)
|
MempoolAcceptResult ChainstateManager::ProcessTransaction(const CTransactionRef& tx, bool test_accept, bool bypass_limits)
|
||||||
{
|
{
|
||||||
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, test_accept);
|
auto result = AcceptToMemoryPool(active_chainstate, tx, GetTime(), bypass_limits, 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4993,8 +4996,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
|
||||||
|
@ -243,18 +243,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);
|
||||||
|
|
||||||
@ -589,6 +587,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…
Reference in New Issue
Block a user