Skip to content

Commit fd849e1

Browse files
committed
Change AcceptToMemoryPool function signature
Combine fLimitFree and fOverrideMempoolLimit into a single boolean: bypass_limits. This is used to indicate that mempool limiting based on feerate should be bypassed. It is used when readding transactions from a reorg and then the mempool is trimmed to size after all transactions are added and they can be evaluated in the context of their descendants. No changes to behavior.
1 parent b9bceaf commit fd849e1

File tree

6 files changed

+27
-21
lines changed

6 files changed

+27
-21
lines changed

src/net_processing.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,8 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
17881788

17891789
std::list<CTransactionRef> lRemovedTxn;
17901790

1791-
if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, ptx, true, &fMissingInputs, &lRemovedTxn)) {
1791+
if (!AlreadyHave(inv) &&
1792+
AcceptToMemoryPool(mempool, state, ptx, &fMissingInputs, &lRemovedTxn, false /* bypass_limits */, 0 /* nAbsurdFee */)) {
17921793
mempool.check(pcoinsTip);
17931794
RelayTransaction(tx, connman);
17941795
for (unsigned int i = 0; i < tx.vout.size(); i++) {
@@ -1826,7 +1827,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
18261827

18271828
if (setMisbehaving.count(fromPeer))
18281829
continue;
1829-
if (AcceptToMemoryPool(mempool, stateDummy, porphanTx, true, &fMissingInputs2, &lRemovedTxn)) {
1830+
if (AcceptToMemoryPool(mempool, stateDummy, porphanTx, &fMissingInputs2, &lRemovedTxn, false /* bypass_limits */, 0 /* nAbsurdFee */)) {
18301831
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString());
18311832
RelayTransaction(orphanTx, connman);
18321833
for (unsigned int i = 0; i < orphanTx.vout.size(); i++) {

src/rpc/rawtransaction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,8 @@ UniValue sendrawtransaction(const JSONRPCRequest& request)
937937
// push to local node and sync with wallets
938938
CValidationState state;
939939
bool fMissingInputs;
940-
bool fLimitFree = true;
941-
if (!AcceptToMemoryPool(mempool, state, std::move(tx), fLimitFree, &fMissingInputs, nullptr, false, nMaxRawTxFee)) {
940+
if (!AcceptToMemoryPool(mempool, state, std::move(tx), &fMissingInputs,
941+
nullptr /* plTxnReplaced */, false /* bypass_limits */, nMaxRawTxFee)) {
942942
if (state.IsInvalid()) {
943943
throw JSONRPCError(RPC_TRANSACTION_REJECTED, strprintf("%i: %s", state.GetRejectCode(), state.GetRejectReason()));
944944
} else {

src/test/txvalidationcache_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ ToMemPool(CMutableTransaction& tx)
2929
LOCK(cs_main);
3030

3131
CValidationState state;
32-
return AcceptToMemoryPool(mempool, state, MakeTransactionRef(tx), false, nullptr, nullptr, true, 0);
32+
return AcceptToMemoryPool(mempool, state, MakeTransactionRef(tx), nullptr /* pfMissingInputs */,
33+
nullptr /* plTxnReplaced */, true /* bypass_limits */, 0 /* nAbsurdFee */);
3334
}
3435

3536
BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)

src/validation.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,9 @@ void UpdateMempoolForReorg(DisconnectedBlockTransactions &disconnectpool, bool f
384384
while (it != disconnectpool.queuedTx.get<insertion_order>().rend()) {
385385
// ignore validation errors in resurrected transactions
386386
CValidationState stateDummy;
387-
if (!fAddToMempool || (*it)->IsCoinBase() || !AcceptToMemoryPool(mempool, stateDummy, *it, false, nullptr, nullptr, true)) {
387+
if (!fAddToMempool || (*it)->IsCoinBase() ||
388+
!AcceptToMemoryPool(mempool, stateDummy, *it, nullptr /* pfMissingInputs */,
389+
nullptr /* plTxnReplaced */, true /* bypass_limits */, 0 /* nAbsurdFee */)) {
388390
// If the transaction doesn't make it in to the mempool, remove any
389391
// transactions that depend on it (which would now be orphans).
390392
mempool.removeRecursive(**it, MemPoolRemovalReason::REORG);
@@ -443,9 +445,9 @@ static bool CheckInputsFromMempoolAndCache(const CTransaction& tx, CValidationSt
443445
return CheckInputs(tx, state, view, true, flags, cacheSigStore, true, txdata);
444446
}
445447

446-
static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool& pool, CValidationState& state, const CTransactionRef& ptx, bool fLimitFree,
448+
static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool& pool, CValidationState& state, const CTransactionRef& ptx,
447449
bool* pfMissingInputs, int64_t nAcceptTime, std::list<CTransactionRef>* plTxnReplaced,
448-
bool fOverrideMempoolLimit, const CAmount& nAbsurdFee, std::vector<COutPoint>& coins_to_uncache)
450+
bool bypass_limits, const CAmount& nAbsurdFee, std::vector<COutPoint>& coins_to_uncache)
449451
{
450452
const CTransaction& tx = *ptx;
451453
const uint256 hash = tx.GetHash();
@@ -623,7 +625,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
623625
}
624626

625627
// No transactions are allowed below minRelayTxFee except from disconnected blocks
626-
if (fLimitFree && nModifiedFees < ::minRelayTxFee.GetFee(nSize)) {
628+
if (!bypass_limits && nModifiedFees < ::minRelayTxFee.GetFee(nSize)) {
627629
return state.DoS(0, false, REJECT_INSUFFICIENTFEE, "min relay fee not met");
628630
}
629631

@@ -865,7 +867,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
865867
pool.addUnchecked(hash, entry, setAncestors, validForFeeEstimation);
866868

867869
// trim mempool and check if tx was trimmed
868-
if (!fOverrideMempoolLimit) {
870+
if (!bypass_limits) {
869871
LimitMempoolSize(pool, gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60);
870872
if (!pool.exists(hash))
871873
return state.DoS(0, false, REJECT_INSUFFICIENTFEE, "mempool full");
@@ -878,12 +880,12 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
878880
}
879881

880882
/** (try to) add transaction to memory pool with a specified acceptance time **/
881-
static bool AcceptToMemoryPoolWithTime(const CChainParams& chainparams, CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
883+
static bool AcceptToMemoryPoolWithTime(const CChainParams& chainparams, CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx,
882884
bool* pfMissingInputs, int64_t nAcceptTime, std::list<CTransactionRef>* plTxnReplaced,
883-
bool fOverrideMempoolLimit, const CAmount nAbsurdFee)
885+
bool bypass_limits, const CAmount nAbsurdFee)
884886
{
885887
std::vector<COutPoint> coins_to_uncache;
886-
bool res = AcceptToMemoryPoolWorker(chainparams, pool, state, tx, fLimitFree, pfMissingInputs, nAcceptTime, plTxnReplaced, fOverrideMempoolLimit, nAbsurdFee, coins_to_uncache);
888+
bool res = AcceptToMemoryPoolWorker(chainparams, pool, state, tx, pfMissingInputs, nAcceptTime, plTxnReplaced, bypass_limits, nAbsurdFee, coins_to_uncache);
887889
if (!res) {
888890
for (const COutPoint& hashTx : coins_to_uncache)
889891
pcoinsTip->Uncache(hashTx);
@@ -894,12 +896,12 @@ static bool AcceptToMemoryPoolWithTime(const CChainParams& chainparams, CTxMemPo
894896
return res;
895897
}
896898

897-
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
899+
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx,
898900
bool* pfMissingInputs, std::list<CTransactionRef>* plTxnReplaced,
899-
bool fOverrideMempoolLimit, const CAmount nAbsurdFee)
901+
bool bypass_limits, const CAmount nAbsurdFee)
900902
{
901903
const CChainParams& chainparams = Params();
902-
return AcceptToMemoryPoolWithTime(chainparams, pool, state, tx, fLimitFree, pfMissingInputs, GetTime(), plTxnReplaced, fOverrideMempoolLimit, nAbsurdFee);
904+
return AcceptToMemoryPoolWithTime(chainparams, pool, state, tx, pfMissingInputs, GetTime(), plTxnReplaced, bypass_limits, nAbsurdFee);
903905
}
904906

905907
/** Return transaction in txOut, and if it was found inside a block, its hash is placed in hashBlock */
@@ -4306,7 +4308,8 @@ bool LoadMempool(void)
43064308
CValidationState state;
43074309
if (nTime + nExpiryTimeout > nNow) {
43084310
LOCK(cs_main);
4309-
AcceptToMemoryPoolWithTime(chainparams, mempool, state, tx, true, nullptr, nTime, nullptr, false, 0);
4311+
AcceptToMemoryPoolWithTime(chainparams, mempool, state, tx, nullptr /* pfMissingInputs */, nTime,
4312+
nullptr /* plTxnReplaced */, false /* bypass_limits */, 0 /* nAbsurdFee */);
43104313
if (state.IsValid()) {
43114314
++count;
43124315
} else {

src/validation.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ void PruneBlockFilesManual(int nManualPruneHeight);
301301

302302
/** (try to) add transaction to memory pool
303303
* plTxnReplaced will be appended to with all transactions replaced from mempool **/
304-
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
305-
bool* pfMissingInputs, std::list<CTransactionRef>* plTxnReplaced = nullptr,
306-
bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0);
304+
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx,
305+
bool* pfMissingInputs, std::list<CTransactionRef>* plTxnReplaced,
306+
bool bypass_limits, const CAmount nAbsurdFee);
307307

308308
/** Convert CValidationState to a human-readable message for logging */
309309
std::string FormatStateMessage(const CValidationState &state);

src/wallet/wallet.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4014,5 +4014,6 @@ int CMerkleTx::GetBlocksToMaturity() const
40144014

40154015
bool CMerkleTx::AcceptToMemoryPool(const CAmount& nAbsurdFee, CValidationState& state)
40164016
{
4017-
return ::AcceptToMemoryPool(mempool, state, tx, true, nullptr, nullptr, false, nAbsurdFee);
4017+
return ::AcceptToMemoryPool(mempool, state, tx, nullptr /* pfMissingInputs */,
4018+
nullptr /* plTxnReplaced */, false /* bypass_limits */, nAbsurdFee);
40184019
}

0 commit comments

Comments
 (0)