Skip to content

Commit edded80

Browse files
committed
Make ATMP optionally return the CTransactionRefs it replaced
1 parent c735540 commit edded80

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ UniValue sendrawtransaction(const JSONRPCRequest& request)
899899
// push to local node and sync with wallets
900900
CValidationState state;
901901
bool fMissingInputs;
902-
if (!AcceptToMemoryPool(mempool, state, std::move(tx), fLimitFree, &fMissingInputs, false, nMaxRawTxFee)) {
902+
if (!AcceptToMemoryPool(mempool, state, std::move(tx), fLimitFree, &fMissingInputs, NULL, false, nMaxRawTxFee)) {
903903
if (state.IsInvalid()) {
904904
throw JSONRPCError(RPC_TRANSACTION_REJECTED, strprintf("%i: %s", state.GetRejectCode(), state.GetRejectReason()));
905905
} else {

src/test/txvalidationcache_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ToMemPool(CMutableTransaction& tx)
2323
LOCK(cs_main);
2424

2525
CValidationState state;
26-
return AcceptToMemoryPool(mempool, state, MakeTransactionRef(tx), false, NULL, true, 0);
26+
return AcceptToMemoryPool(mempool, state, MakeTransactionRef(tx), false, NULL, NULL, true, 0);
2727
}
2828

2929
BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)

src/validation.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,8 @@ static bool IsCurrentForFeeEstimation()
538538
}
539539

540540
bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const CTransactionRef& ptx, bool fLimitFree,
541-
bool* pfMissingInputs, int64_t nAcceptTime, bool fOverrideMempoolLimit, const CAmount& nAbsurdFee,
542-
std::vector<uint256>& vHashTxnToUncache)
541+
bool* pfMissingInputs, int64_t nAcceptTime, std::list<CTransactionRef>* plTxnReplaced,
542+
bool fOverrideMempoolLimit, const CAmount& nAbsurdFee, std::vector<uint256>& vHashTxnToUncache)
543543
{
544544
const CTransaction& tx = *ptx;
545545
const uint256 hash = tx.GetHash();
@@ -950,6 +950,8 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
950950
hash.ToString(),
951951
FormatMoney(nModifiedFees - nConflictingFees),
952952
(int)nSize - (int)nConflictingSize);
953+
if (plTxnReplaced)
954+
plTxnReplaced->push_back(it->GetSharedTx());
953955
}
954956
pool.RemoveStaged(allConflicting, false);
955957

@@ -975,10 +977,11 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
975977
}
976978

977979
bool AcceptToMemoryPoolWithTime(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
978-
bool* pfMissingInputs, int64_t nAcceptTime, bool fOverrideMempoolLimit, const CAmount nAbsurdFee)
980+
bool* pfMissingInputs, int64_t nAcceptTime, std::list<CTransactionRef>* plTxnReplaced,
981+
bool fOverrideMempoolLimit, const CAmount nAbsurdFee)
979982
{
980983
std::vector<uint256> vHashTxToUncache;
981-
bool res = AcceptToMemoryPoolWorker(pool, state, tx, fLimitFree, pfMissingInputs, nAcceptTime, fOverrideMempoolLimit, nAbsurdFee, vHashTxToUncache);
984+
bool res = AcceptToMemoryPoolWorker(pool, state, tx, fLimitFree, pfMissingInputs, nAcceptTime, plTxnReplaced, fOverrideMempoolLimit, nAbsurdFee, vHashTxToUncache);
982985
if (!res) {
983986
BOOST_FOREACH(const uint256& hashTx, vHashTxToUncache)
984987
pcoinsTip->Uncache(hashTx);
@@ -990,9 +993,10 @@ bool AcceptToMemoryPoolWithTime(CTxMemPool& pool, CValidationState &state, const
990993
}
991994

992995
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
993-
bool* pfMissingInputs, bool fOverrideMempoolLimit, const CAmount nAbsurdFee)
996+
bool* pfMissingInputs, std::list<CTransactionRef>* plTxnReplaced,
997+
bool fOverrideMempoolLimit, const CAmount nAbsurdFee)
994998
{
995-
return AcceptToMemoryPoolWithTime(pool, state, tx, fLimitFree, pfMissingInputs, GetTime(), fOverrideMempoolLimit, nAbsurdFee);
999+
return AcceptToMemoryPoolWithTime(pool, state, tx, fLimitFree, pfMissingInputs, GetTime(), plTxnReplaced, fOverrideMempoolLimit, nAbsurdFee);
9961000
}
9971001

9981002
/** Return transaction in txOut, and if it was found inside a block, its hash is placed in hashBlock */
@@ -2138,7 +2142,7 @@ bool static DisconnectTip(CValidationState& state, const CChainParams& chainpara
21382142
const CTransaction& tx = *it;
21392143
// ignore validation errors in resurrected transactions
21402144
CValidationState stateDummy;
2141-
if (tx.IsCoinBase() || !AcceptToMemoryPool(mempool, stateDummy, it, false, NULL, true)) {
2145+
if (tx.IsCoinBase() || !AcceptToMemoryPool(mempool, stateDummy, it, false, NULL, NULL, true)) {
21422146
mempool.removeRecursive(tx);
21432147
} else if (mempool.exists(tx.GetHash())) {
21442148
vHashUpdate.push_back(tx.GetHash());

src/validation.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,16 @@ void FlushStateToDisk();
304304
/** Prune block files and flush state to disk. */
305305
void PruneAndFlush();
306306

307-
/** (try to) add transaction to memory pool **/
307+
/** (try to) add transaction to memory pool
308+
* plTxnReplaced will be appended to with all transactions replaced from mempool **/
308309
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
309-
bool* pfMissingInputs, bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0);
310+
bool* pfMissingInputs, std::list<CTransactionRef>* plTxnReplaced = NULL,
311+
bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0);
310312

311313
/** (try to) add transaction to memory pool with a specified acceptance time **/
312314
bool AcceptToMemoryPoolWithTime(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
313-
bool* pfMissingInputs, int64_t nAcceptTime, bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0);
315+
bool* pfMissingInputs, int64_t nAcceptTime, std::list<CTransactionRef>* plTxnReplaced = NULL,
316+
bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0);
314317

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

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3847,5 +3847,5 @@ int CMerkleTx::GetBlocksToMaturity() const
38473847

38483848
bool CMerkleTx::AcceptToMemoryPool(const CAmount& nAbsurdFee, CValidationState& state)
38493849
{
3850-
return ::AcceptToMemoryPool(mempool, state, tx, true, NULL, false, nAbsurdFee);
3850+
return ::AcceptToMemoryPool(mempool, state, tx, true, NULL, NULL, false, nAbsurdFee);
38513851
}

0 commit comments

Comments
 (0)