Skip to content

Commit c44e4c4

Browse files
committed
Make AcceptToMemoryPool take CTransactionRef
1 parent e8cfe1e commit c44e4c4

File tree

10 files changed

+31
-26
lines changed

10 files changed

+31
-26
lines changed

src/bench/mempool_eviction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static void AddTx(const CTransaction& tx, const CAmount& nFee, CTxMemPool& pool)
1818
unsigned int sigOpCost = 4;
1919
LockPoints lp;
2020
pool.addUnchecked(tx.GetHash(), CTxMemPoolEntry(
21-
tx, nFee, nTime, dPriority, nHeight, pool.HasNoInputsOf(tx),
21+
MakeTransactionRef(tx), nFee, nTime, dPriority, nHeight, pool.HasNoInputsOf(tx),
2222
tx.GetValueOut(), spendsCoinbase, sigOpCost, lp));
2323
}
2424

src/net_processing.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
15961596

15971597
deque<COutPoint> vWorkQueue;
15981598
vector<uint256> vEraseQueue;
1599-
CTransaction tx(deserialize, vRecv);
1599+
CTransactionRef ptx;
1600+
vRecv >> ptx;
1601+
const CTransaction& tx = *ptx;
16001602

16011603
CInv inv(MSG_TX, tx.GetHash());
16021604
pfrom->AddInventoryKnown(inv);
@@ -1609,7 +1611,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
16091611
pfrom->setAskFor.erase(inv.hash);
16101612
mapAlreadyAskedFor.erase(inv.hash);
16111613

1612-
if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs)) {
1614+
if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, ptx, true, &fMissingInputs)) {
16131615
mempool.check(pcoinsTip);
16141616
RelayTransaction(tx, connman);
16151617
for (unsigned int i = 0; i < tx.vout.size(); i++) {
@@ -1646,7 +1648,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
16461648

16471649
if (setMisbehaving.count(fromPeer))
16481650
continue;
1649-
if (AcceptToMemoryPool(mempool, stateDummy, orphanTx, true, &fMissingInputs2)) {
1651+
if (AcceptToMemoryPool(mempool, stateDummy, MakeTransactionRef(orphanTx), true, &fMissingInputs2)) {
16501652
LogPrint("mempool", " accepted orphan tx %s\n", orphanHash.ToString());
16511653
RelayTransaction(orphanTx, connman);
16521654
for (unsigned int i = 0; i < orphanTx.vout.size(); i++) {

src/rpc/rawtransaction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,8 @@ UniValue sendrawtransaction(const JSONRPCRequest& request)
883883
CMutableTransaction mtx;
884884
if (!DecodeHexTx(mtx, request.params[0].get_str()))
885885
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
886-
CTransaction tx(std::move(mtx));
887-
uint256 hashTx = tx.GetHash();
886+
CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
887+
const uint256& hashTx = tx->GetHash();
888888

889889
bool fLimitFree = false;
890890
CAmount nMaxRawTxFee = maxTxFee;
@@ -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, tx, fLimitFree, &fMissingInputs, false, nMaxRawTxFee)) {
902+
if (!AcceptToMemoryPool(mempool, state, std::move(tx), fLimitFree, &fMissingInputs, false, nMaxRawTxFee)) {
903903
if (state.IsInvalid()) {
904904
throw JSONRPCError(RPC_TRANSACTION_REJECTED, strprintf("%i: %s", state.GetRejectCode(), state.GetRejectReason()));
905905
} else {

src/test/test_bitcoin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CTransaction &txn, CTxMemPo
151151
// Hack to assume either its completely dependent on other mempool txs or not at all
152152
CAmount inChainValue = hasNoDependencies ? txn.GetValueOut() : 0;
153153

154-
return CTxMemPoolEntry(txn, nFee, nTime, dPriority, nHeight,
154+
return CTxMemPoolEntry(MakeTransactionRef(txn), nFee, nTime, dPriority, nHeight,
155155
hasNoDependencies, inChainValue, spendsCoinbase, sigOpCost, lp);
156156
}
157157

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, tx, false, NULL, true, 0);
26+
return AcceptToMemoryPool(mempool, state, MakeTransactionRef(tx), false, NULL, true, 0);
2727
}
2828

2929
BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)

src/txmempool.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@
2020

2121
using namespace std;
2222

23-
CTxMemPoolEntry::CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
23+
CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
2424
int64_t _nTime, double _entryPriority, unsigned int _entryHeight,
2525
bool poolHasNoInputsOf, CAmount _inChainInputValue,
2626
bool _spendsCoinbase, int64_t _sigOpsCost, LockPoints lp):
27-
tx(MakeTransactionRef(_tx)), nFee(_nFee), nTime(_nTime), entryPriority(_entryPriority), entryHeight(_entryHeight),
27+
tx(_tx), nFee(_nFee), nTime(_nTime), entryPriority(_entryPriority), entryHeight(_entryHeight),
2828
hadNoDependencies(poolHasNoInputsOf), inChainInputValue(_inChainInputValue),
2929
spendsCoinbase(_spendsCoinbase), sigOpCost(_sigOpsCost), lockPoints(lp)
3030
{
31-
nTxWeight = GetTransactionWeight(_tx);
32-
nModSize = _tx.CalculateModifiedSize(GetTxSize());
31+
nTxWeight = GetTransactionWeight(*tx);
32+
nModSize = tx->CalculateModifiedSize(GetTxSize());
3333
nUsageSize = RecursiveDynamicUsage(*tx) + memusage::DynamicUsage(tx);
3434

3535
nCountWithDescendants = 1;
3636
nSizeWithDescendants = GetTxSize();
3737
nModFeesWithDescendants = nFee;
38-
CAmount nValueIn = _tx.GetValueOut()+nFee;
38+
CAmount nValueIn = tx->GetValueOut()+nFee;
3939
assert(inChainInputValue <= nValueIn);
4040

4141
feeDelta = 0;

src/txmempool.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,11 @@ class CTxMemPoolEntry
111111
int64_t nSigOpCostWithAncestors;
112112

113113
public:
114-
CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
114+
CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
115115
int64_t _nTime, double _entryPriority, unsigned int _entryHeight,
116116
bool poolHasNoInputsOf, CAmount _inChainInputValue, bool spendsCoinbase,
117117
int64_t nSigOpsCost, LockPoints lp);
118+
118119
CTxMemPoolEntry(const CTxMemPoolEntry& other);
119120

120121
const CTransaction& GetTx() const { return *this->tx; }

src/validation.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -525,10 +525,11 @@ std::string FormatStateMessage(const CValidationState &state)
525525
state.GetRejectCode());
526526
}
527527

528-
bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const CTransaction& tx, bool fLimitFree,
528+
bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const CTransactionRef& ptx, bool fLimitFree,
529529
bool* pfMissingInputs, int64_t nAcceptTime, bool fOverrideMempoolLimit, const CAmount& nAbsurdFee,
530530
std::vector<uint256>& vHashTxnToUncache)
531531
{
532+
const CTransaction& tx = *ptx;
532533
const uint256 hash = tx.GetHash();
533534
AssertLockHeld(cs_main);
534535
if (pfMissingInputs)
@@ -691,7 +692,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
691692
}
692693
}
693694

694-
CTxMemPoolEntry entry(tx, nFees, nAcceptTime, dPriority, chainActive.Height(), pool.HasNoInputsOf(tx), inChainInputValue, fSpendsCoinbase, nSigOpsCost, lp);
695+
CTxMemPoolEntry entry(ptx, nFees, nAcceptTime, dPriority, chainActive.Height(), pool.HasNoInputsOf(tx), inChainInputValue, fSpendsCoinbase, nSigOpsCost, lp);
695696
unsigned int nSize = entry.GetTxSize();
696697

697698
// Check that the transaction doesn't have an excessive number of
@@ -955,7 +956,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
955956
return true;
956957
}
957958

958-
bool AcceptToMemoryPoolWithTime(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,
959+
bool AcceptToMemoryPoolWithTime(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
959960
bool* pfMissingInputs, int64_t nAcceptTime, bool fOverrideMempoolLimit, const CAmount nAbsurdFee)
960961
{
961962
std::vector<uint256> vHashTxToUncache;
@@ -970,7 +971,7 @@ bool AcceptToMemoryPoolWithTime(CTxMemPool& pool, CValidationState &state, const
970971
return res;
971972
}
972973

973-
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,
974+
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
974975
bool* pfMissingInputs, bool fOverrideMempoolLimit, const CAmount nAbsurdFee)
975976
{
976977
return AcceptToMemoryPoolWithTime(pool, state, tx, fLimitFree, pfMissingInputs, GetTime(), fOverrideMempoolLimit, nAbsurdFee);
@@ -2116,7 +2117,7 @@ bool static DisconnectTip(CValidationState& state, const CChainParams& chainpara
21162117
const CTransaction& tx = *it;
21172118
// ignore validation errors in resurrected transactions
21182119
CValidationState stateDummy;
2119-
if (tx.IsCoinBase() || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL, true)) {
2120+
if (tx.IsCoinBase() || !AcceptToMemoryPool(mempool, stateDummy, it, false, NULL, true)) {
21202121
mempool.removeRecursive(tx);
21212122
} else if (mempool.exists(tx.GetHash())) {
21222123
vHashUpdate.push_back(tx.GetHash());
@@ -4054,15 +4055,16 @@ bool LoadMempool(void)
40544055
file >> num;
40554056
double prioritydummy = 0;
40564057
while (num--) {
4058+
CTransactionRef tx;
40574059
int64_t nTime;
40584060
int64_t nFeeDelta;
4059-
CTransaction tx(deserialize, file);
4061+
file >> tx;
40604062
file >> nTime;
40614063
file >> nFeeDelta;
40624064

40634065
CAmount amountdelta = nFeeDelta;
40644066
if (amountdelta) {
4065-
mempool.PrioritiseTransaction(tx.GetHash(), tx.GetHash().ToString(), prioritydummy, amountdelta);
4067+
mempool.PrioritiseTransaction(tx->GetHash(), tx->GetHash().ToString(), prioritydummy, amountdelta);
40664068
}
40674069
CValidationState state;
40684070
if (nTime + nExpiryTimeout > nNow) {

src/validation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,11 @@ void FlushStateToDisk();
309309
void PruneAndFlush();
310310

311311
/** (try to) add transaction to memory pool **/
312-
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,
312+
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
313313
bool* pfMissingInputs, bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0);
314314

315315
/** (try to) add transaction to memory pool with a specified acceptance time **/
316-
bool AcceptToMemoryPoolWithTime(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,
316+
bool AcceptToMemoryPoolWithTime(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
317317
bool* pfMissingInputs, int64_t nAcceptTime, bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0);
318318

319319
/** Convert CValidationState to a human-readable message for logging */

src/wallet/wallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,7 +2563,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
25632563
if (GetBoolArg("-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS)) {
25642564
// Lastly, ensure this tx will pass the mempool's chain limits
25652565
LockPoints lp;
2566-
CTxMemPoolEntry entry(txNew, 0, 0, 0, 0, false, 0, false, 0, lp);
2566+
CTxMemPoolEntry entry(wtxNew.tx, 0, 0, 0, 0, false, 0, false, 0, lp);
25672567
CTxMemPool::setEntries setAncestors;
25682568
size_t nLimitAncestors = GetArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT);
25692569
size_t nLimitAncestorSize = GetArg("-limitancestorsize", DEFAULT_ANCESTOR_SIZE_LIMIT)*1000;
@@ -3782,5 +3782,5 @@ int CMerkleTx::GetBlocksToMaturity() const
37823782

37833783
bool CMerkleTx::AcceptToMemoryPool(const CAmount& nAbsurdFee, CValidationState& state)
37843784
{
3785-
return ::AcceptToMemoryPool(mempool, state, *this, true, NULL, false, nAbsurdFee);
3785+
return ::AcceptToMemoryPool(mempool, state, tx, true, NULL, false, nAbsurdFee);
37863786
}

0 commit comments

Comments
 (0)