Skip to content

Commit d02b34c

Browse files
committed
Remove use of AcceptToMemoryPool in wallet code
This commit does not change behavior.
1 parent e2c8ba9 commit d02b34c

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

src/interfaces/chain.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <policy/policy.h>
1212
#include <policy/rbf.h>
1313
#include <primitives/block.h>
14+
#include <primitives/transaction.h>
1415
#include <protocol.h>
1516
#include <sync.h>
1617
#include <threadsafety.h>
@@ -146,6 +147,12 @@ class LockImpl : public Chain::Lock
146147
LockAnnotation lock(::cs_main);
147148
return CheckFinalTx(tx);
148149
}
150+
bool submitToMemoryPool(CTransactionRef tx, CAmount absurd_fee, CValidationState& state) override
151+
{
152+
LockAnnotation lock(::cs_main);
153+
return AcceptToMemoryPool(::mempool, state, tx, nullptr /* missing inputs */, nullptr /* txn replaced */,
154+
false /* bypass limits */, absurd_fee);
155+
}
149156
};
150157

151158
class LockingStateImpl : public LockImpl, public UniqueLock<CCriticalSection>
@@ -237,6 +244,7 @@ class ChainImpl : public Chain
237244
{
238245
return ::mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000);
239246
}
247+
CAmount maxTxFee() override { return ::maxTxFee; }
240248
bool getPruneMode() override { return ::fPruneMode; }
241249
bool p2pEnabled() override { return g_connman != nullptr; }
242250
int64_t getAdjustedTime() override { return GetAdjustedTime(); }

src/interfaces/chain.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <optional.h> // For Optional and nullopt
99
#include <policy/rbf.h> // For RBFTransactionState
10+
#include <primitives/transaction.h> // For CTransactionRef
1011

1112
#include <memory>
1213
#include <stddef.h>
@@ -16,7 +17,7 @@
1617

1718
class CBlock;
1819
class CScheduler;
19-
class CTransaction;
20+
class CValidationState;
2021
class uint256;
2122
struct CBlockLocator;
2223
struct FeeCalculation;
@@ -109,6 +110,10 @@ class Chain
109110

110111
//! Check if transaction will be final given chain height current time.
111112
virtual bool checkFinalTx(const CTransaction& tx) = 0;
113+
114+
//! Add transaction to memory pool if the transaction fee is below the
115+
//! amount specified by absurd_fee (as a safeguard). */
116+
virtual bool submitToMemoryPool(CTransactionRef tx, CAmount absurd_fee, CValidationState& state) = 0;
112117
};
113118

114119
//! Return Lock interface. Chain is locked when this is called, and
@@ -159,6 +164,12 @@ class Chain
159164
//! Pool min fee.
160165
virtual CFeeRate mempoolMinFee() = 0;
161166

167+
//! Get node max tx fee setting (-maxtxfee).
168+
//! This could be replaced by a per-wallet max fee, as proposed at
169+
//! https://github.com/bitcoin/bitcoin/issues/15355
170+
//! But for the time being, wallets call this to access the node setting.
171+
virtual CAmount maxTxFee() = 0;
172+
162173
//! Check if pruning is enabled.
163174
virtual bool getPruneMode() = 0;
164175

src/wallet/wallet.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,7 @@ void CWallet::ReacceptWalletTransactions()
18861886
for (const std::pair<const int64_t, CWalletTx*>& item : mapSorted) {
18871887
CWalletTx& wtx = *(item.second);
18881888
CValidationState state;
1889-
wtx.AcceptToMemoryPool(*locked_chain, maxTxFee, state);
1889+
wtx.AcceptToMemoryPool(*locked_chain, state);
18901890
}
18911891
}
18921892

@@ -1897,7 +1897,7 @@ bool CWalletTx::RelayWalletTransaction(interfaces::Chain::Lock& locked_chain)
18971897
{
18981898
CValidationState state;
18991899
/* GetDepthInMainChain already catches known conflicts. */
1900-
if (InMempool() || AcceptToMemoryPool(locked_chain, maxTxFee, state)) {
1900+
if (InMempool() || AcceptToMemoryPool(locked_chain, state)) {
19011901
pwallet->WalletLogPrintf("Relaying wtx %s\n", GetHash().ToString());
19021902
if (pwallet->chain().p2pEnabled()) {
19031903
pwallet->chain().relayTransaction(GetHash());
@@ -3180,7 +3180,7 @@ bool CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::ve
31803180
if (fBroadcastTransactions)
31813181
{
31823182
// Broadcast
3183-
if (!wtx.AcceptToMemoryPool(*locked_chain, maxTxFee, state)) {
3183+
if (!wtx.AcceptToMemoryPool(*locked_chain, state)) {
31843184
WalletLogPrintf("CommitTransaction(): Transaction cannot be broadcast immediately, %s\n", FormatStateMessage(state));
31853185
// TODO: if we expect the failure to be long term or permanent, instead delete wtx from the wallet and return failure.
31863186
} else {
@@ -4474,17 +4474,14 @@ bool CMerkleTx::IsImmatureCoinBase(interfaces::Chain::Lock& locked_chain) const
44744474
return GetBlocksToMaturity(locked_chain) > 0;
44754475
}
44764476

4477-
bool CWalletTx::AcceptToMemoryPool(interfaces::Chain::Lock& locked_chain, const CAmount& nAbsurdFee, CValidationState& state)
4477+
bool CWalletTx::AcceptToMemoryPool(interfaces::Chain::Lock& locked_chain, CValidationState& state)
44784478
{
4479-
LockAnnotation lock(::cs_main); // Temporary, for AcceptToMemoryPool below. Removed in upcoming commit.
4480-
44814479
// We must set fInMempool here - while it will be re-set to true by the
44824480
// entered-mempool callback, if we did not there would be a race where a
44834481
// user could call sendmoney in a loop and hit spurious out of funds errors
44844482
// because we think that this newly generated transaction's change is
44854483
// unavailable as we're not yet aware that it is in the mempool.
4486-
bool ret = ::AcceptToMemoryPool(mempool, state, tx, nullptr /* pfMissingInputs */,
4487-
nullptr /* plTxnReplaced */, false /* bypass_limits */, nAbsurdFee);
4484+
bool ret = locked_chain.submitToMemoryPool(tx, pwallet->chain().maxTxFee(), state);
44884485
fInMempool |= ret;
44894486
return ret;
44904487
}

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ class CWalletTx : public CMerkleTx
538538
bool RelayWalletTransaction(interfaces::Chain::Lock& locked_chain);
539539

540540
/** Pass this transaction to the mempool. Fails if absolute fee exceeds absurd fee. */
541-
bool AcceptToMemoryPool(interfaces::Chain::Lock& locked_chain, const CAmount& nAbsurdFee, CValidationState& state);
541+
bool AcceptToMemoryPool(interfaces::Chain::Lock& locked_chain, CValidationState& state);
542542

543543
// TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct
544544
// annotation "EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)". The annotation

0 commit comments

Comments
 (0)