Skip to content

Commit a387837

Browse files
committed
Make sure we re-check the conditions of a feebump during commit
1 parent 9b9ca53 commit a387837

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

src/wallet/feebumper.cpp

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,31 @@ int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *pWal
4141
return GetVirtualTransactionSize(txNew);
4242
}
4343

44+
bool CFeeBumper::preconditionChecks(const CWallet *pWallet, const CWalletTx& wtx) {
45+
if (pWallet->HasWalletSpend(wtx.GetHash())) {
46+
vErrors.push_back("Transaction has descendants in the wallet");
47+
currentResult = BumpFeeResult::INVALID_PARAMETER;
48+
return false;
49+
}
50+
51+
{
52+
LOCK(mempool.cs);
53+
auto it_mp = mempool.mapTx.find(wtx.GetHash());
54+
if (it_mp != mempool.mapTx.end() && it_mp->GetCountWithDescendants() > 1) {
55+
vErrors.push_back("Transaction has descendants in the mempool");
56+
currentResult = BumpFeeResult::INVALID_PARAMETER;
57+
return false;
58+
}
59+
}
60+
61+
if (wtx.GetDepthInMainChain() != 0) {
62+
vErrors.push_back("Transaction has been mined, or is conflicted with a mined transaction");
63+
currentResult = BumpFeeResult::WALLET_ERROR;
64+
return false;
65+
}
66+
return true;
67+
}
68+
4469
CFeeBumper::CFeeBumper(const CWallet *pWallet, const uint256 txidIn, int newConfirmTarget, bool specifiedConfirmTarget, CAmount totalFee, bool newTxReplaceable)
4570
:
4671
txid(std::move(txidIn)),
@@ -58,25 +83,7 @@ CFeeBumper::CFeeBumper(const CWallet *pWallet, const uint256 txidIn, int newConf
5883
auto it = pWallet->mapWallet.find(txid);
5984
const CWalletTx& wtx = it->second;
6085

61-
if (pWallet->HasWalletSpend(txid)) {
62-
vErrors.push_back("Transaction has descendants in the wallet");
63-
currentResult = BumpFeeResult::INVALID_PARAMETER;
64-
return;
65-
}
66-
67-
{
68-
LOCK(mempool.cs);
69-
auto it_mp = mempool.mapTx.find(txid);
70-
if (it_mp != mempool.mapTx.end() && it_mp->GetCountWithDescendants() > 1) {
71-
vErrors.push_back("Transaction has descendants in the mempool");
72-
currentResult = BumpFeeResult::INVALID_PARAMETER;
73-
return;
74-
}
75-
}
76-
77-
if (wtx.GetDepthInMainChain() != 0) {
78-
vErrors.push_back("Transaction has been mined, or is conflicted with a mined transaction");
79-
currentResult = BumpFeeResult::WALLET_ERROR;
86+
if (!preconditionChecks(pWallet, wtx)) {
8087
return;
8188
}
8289

@@ -248,6 +255,11 @@ bool CFeeBumper::commit(CWallet *pWallet)
248255
}
249256
CWalletTx& oldWtx = pWallet->mapWallet[txid];
250257

258+
// make sure the transaction still has no descendants and hasen't been mined in the meantime
259+
if (!preconditionChecks(pWallet, oldWtx)) {
260+
return false;
261+
}
262+
251263
CWalletTx wtxBumped(pWallet, MakeTransactionRef(std::move(mtx)));
252264
// commit/broadcast the tx
253265
CReserveKey reservekey(pWallet);

src/wallet/feebumper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <primitives/transaction.h>
99

1010
class CWallet;
11+
class CWalletTx;
1112
class uint256;
1213

1314
enum class BumpFeeResult
@@ -44,6 +45,8 @@ class CFeeBumper
4445
bool commit(CWallet *pWalletNonConst);
4546

4647
private:
48+
bool preconditionChecks(const CWallet *pWallet, const CWalletTx& wtx);
49+
4750
const uint256 txid;
4851
uint256 bumpedTxid;
4952
CMutableTransaction mtx;

0 commit comments

Comments
 (0)