Skip to content

Commit fa6fd3d

Browse files
author
MarcoFalke
committed
wallet: Properly set fInMempool in mempool notifications
1 parent 8cdf917 commit fa6fd3d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/wallet/wallet.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ static void UpdateWalletSetting(interfaces::Chain& chain,
9494
}
9595
}
9696

97+
/**
98+
* Refresh mempool status so the wallet is in an internally consistent state and
99+
* immediately knows the transaction's status: Whether it can be considered
100+
* trusted and is eligible to be abandoned ...
101+
*/
102+
static void RefreshMempoolStatus(CWalletTx& tx, interfaces::Chain& chain)
103+
{
104+
tx.fInMempool = chain.isInMempool(tx.GetHash());
105+
}
106+
97107
bool AddWallet(const std::shared_ptr<CWallet>& wallet)
98108
{
99109
LOCK(cs_wallets);
@@ -788,10 +798,7 @@ bool CWallet::MarkReplaced(const uint256& originalHash, const uint256& newHash)
788798
wtx.mapValue["replaced_by_txid"] = newHash.ToString();
789799

790800
// Refresh mempool status without waiting for transactionRemovedFromMempool
791-
// notification so the wallet is in an internally consistent state and
792-
// immediately knows the old transaction should not be considered trusted
793-
// and is eligible to be abandoned
794-
wtx.fInMempool = chain().isInMempool(originalHash);
801+
RefreshMempoolStatus(wtx, chain());
795802

796803
WalletBatch batch(GetDatabase());
797804

@@ -1191,15 +1198,15 @@ void CWallet::transactionAddedToMempool(const CTransactionRef& tx, uint64_t memp
11911198

11921199
auto it = mapWallet.find(tx->GetHash());
11931200
if (it != mapWallet.end()) {
1194-
it->second.fInMempool = true;
1201+
RefreshMempoolStatus(it->second, chain());
11951202
}
11961203
}
11971204

11981205
void CWallet::transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) {
11991206
LOCK(cs_wallet);
12001207
auto it = mapWallet.find(tx->GetHash());
12011208
if (it != mapWallet.end()) {
1202-
it->second.fInMempool = false;
1209+
RefreshMempoolStatus(it->second, chain());
12031210
}
12041211
// Handle transactions that were removed from the mempool because they
12051212
// conflict with transactions in a newly connected block.

0 commit comments

Comments
 (0)