Skip to content

Commit 474139a

Browse files
committed
wallet: abandon inactive coinbase tx and their descendants during startup
1 parent 0a931a9 commit 474139a

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/wallet/wallet.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -1315,12 +1315,15 @@ void CWallet::MarkInputsDirty(const CTransactionRef& tx)
13151315
bool CWallet::AbandonTransaction(const uint256& hashTx)
13161316
{
13171317
LOCK(cs_wallet);
1318-
1319-
// Can't mark abandoned if confirmed or in mempool
13201318
auto it = mapWallet.find(hashTx);
13211319
assert(it != mapWallet.end());
1322-
const CWalletTx& origtx = it->second;
1323-
if (GetTxDepthInMainChain(origtx) != 0 || origtx.InMempool()) {
1320+
return AbandonTransaction(it->second);
1321+
}
1322+
1323+
bool CWallet::AbandonTransaction(CWalletTx& tx)
1324+
{
1325+
// Can't mark abandoned if confirmed or in mempool
1326+
if (GetTxDepthInMainChain(tx) != 0 || tx.InMempool()) {
13241327
return false;
13251328
}
13261329

@@ -1342,7 +1345,7 @@ bool CWallet::AbandonTransaction(const uint256& hashTx)
13421345
// Note: If the reorged coinbase is re-added to the main chain, the descendants that have not had their
13431346
// states change will remain abandoned and will require manual broadcast if the user wants them.
13441347

1345-
RecursiveUpdateTxState(hashTx, try_updating_state);
1348+
RecursiveUpdateTxState(tx.GetHash(), try_updating_state);
13461349

13471350
return true;
13481351
}

src/wallet/wallet.h

+1
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
871871

872872
/* Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent. */
873873
bool AbandonTransaction(const uint256& hashTx);
874+
bool AbandonTransaction(CWalletTx& tx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
874875

875876
/** Mark a transaction as replaced by another transaction. */
876877
bool MarkReplaced(const uint256& originalHash, const uint256& newHash);

src/wallet/walletdb.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,14 @@ static DBErrors LoadTxRecords(CWallet* pwallet, DatabaseBatch& batch, std::vecto
11151115
});
11161116
result = std::max(result, order_pos_res.m_result);
11171117

1118+
// After loading all tx records, abandon any coinbase that is no longer in the active chain.
1119+
// This could happen during an external wallet load, or if the user replaced the chain data.
1120+
for (auto& [id, wtx] : pwallet->mapWallet) {
1121+
if (wtx.IsCoinBase() && wtx.isInactive()) {
1122+
pwallet->AbandonTransaction(wtx);
1123+
}
1124+
}
1125+
11181126
return result;
11191127
}
11201128

0 commit comments

Comments
 (0)