Skip to content

Commit 7148d4b

Browse files
committed
Added a 'dry run' option to AcceptToMemoryPool
1 parent 098b01d commit 7148d4b

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/validation.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ void UpdateMempoolForReorg(DisconnectedBlockTransactions &disconnectpool, bool f
394394

395395
bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const CTransactionRef& ptx, bool fLimitFree,
396396
bool* pfMissingInputs, int64_t nAcceptTime, std::list<CTransactionRef>* plTxnReplaced,
397-
bool fOverrideMempoolLimit, const CAmount& nAbsurdFee, std::vector<COutPoint>& coins_to_uncache)
397+
bool fOverrideMempoolLimit, const CAmount& nAbsurdFee, std::vector<COutPoint>& coins_to_uncache,
398+
bool fDryRun)
398399
{
399400
const CTransaction& tx = *ptx;
400401
const uint256 hash = tx.GetHash();
@@ -774,6 +775,9 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
774775
__func__, hash.ToString(), FormatStateMessage(state));
775776
}
776777

778+
// If this is a dry run, quit here before modifying any state
779+
if (fDryRun) return true;
780+
777781
// Remove conflicting transactions from the mempool
778782
BOOST_FOREACH(const CTxMemPool::txiter it, allConflicting)
779783
{
@@ -811,10 +815,11 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
811815

812816
bool AcceptToMemoryPoolWithTime(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
813817
bool* pfMissingInputs, int64_t nAcceptTime, std::list<CTransactionRef>* plTxnReplaced,
814-
bool fOverrideMempoolLimit, const CAmount nAbsurdFee)
818+
bool fOverrideMempoolLimit, const CAmount nAbsurdFee,
819+
bool fDryRun)
815820
{
816821
std::vector<COutPoint> coins_to_uncache;
817-
bool res = AcceptToMemoryPoolWorker(pool, state, tx, fLimitFree, pfMissingInputs, nAcceptTime, plTxnReplaced, fOverrideMempoolLimit, nAbsurdFee, coins_to_uncache);
822+
bool res = AcceptToMemoryPoolWorker(pool, state, tx, fLimitFree, pfMissingInputs, nAcceptTime, plTxnReplaced, fOverrideMempoolLimit, nAbsurdFee, coins_to_uncache, fDryRun);
818823
if (!res) {
819824
BOOST_FOREACH(const COutPoint& hashTx, coins_to_uncache)
820825
pcoinsTip->Uncache(hashTx);
@@ -827,9 +832,10 @@ bool AcceptToMemoryPoolWithTime(CTxMemPool& pool, CValidationState &state, const
827832

828833
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
829834
bool* pfMissingInputs, std::list<CTransactionRef>* plTxnReplaced,
830-
bool fOverrideMempoolLimit, const CAmount nAbsurdFee)
835+
bool fOverrideMempoolLimit, const CAmount nAbsurdFee,
836+
bool fDryRun)
831837
{
832-
return AcceptToMemoryPoolWithTime(pool, state, tx, fLimitFree, pfMissingInputs, GetTime(), plTxnReplaced, fOverrideMempoolLimit, nAbsurdFee);
838+
return AcceptToMemoryPoolWithTime(pool, state, tx, fLimitFree, pfMissingInputs, GetTime(), plTxnReplaced, fOverrideMempoolLimit, nAbsurdFee, fDryRun);
833839
}
834840

835841
/** Return transaction in txOut, and if it was found inside a block, its hash is placed in hashBlock */

src/validation.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,14 @@ void PruneBlockFilesManual(int nManualPruneHeight);
328328
* plTxnReplaced will be appended to with all transactions replaced from mempool **/
329329
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
330330
bool* pfMissingInputs, std::list<CTransactionRef>* plTxnReplaced = NULL,
331-
bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0);
331+
bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0,
332+
bool fDryRun=false);
332333

333334
/** (try to) add transaction to memory pool with a specified acceptance time **/
334335
bool AcceptToMemoryPoolWithTime(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
335336
bool* pfMissingInputs, int64_t nAcceptTime, std::list<CTransactionRef>* plTxnReplaced = NULL,
336-
bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0);
337+
bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0,
338+
bool fDryRun=false);
337339

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

0 commit comments

Comments
 (0)