@@ -1067,6 +1067,33 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const TxState& state, const
1067
1067
}
1068
1068
}
1069
1069
1070
+ // Mark inactive coinbase transactions and their descendants as abandoned
1071
+ if (wtx.IsCoinBase () && wtx.isInactive ()) {
1072
+ std::vector<CWalletTx*> txs{&wtx};
1073
+
1074
+ TxStateInactive inactive_state = TxStateInactive{/* abandoned=*/ true };
1075
+
1076
+ while (!txs.empty ()) {
1077
+ CWalletTx* desc_tx = txs.back ();
1078
+ txs.pop_back ();
1079
+ desc_tx->m_state = inactive_state;
1080
+ // Break caches since we have changed the state
1081
+ desc_tx->MarkDirty ();
1082
+ batch.WriteTx (*desc_tx);
1083
+ MarkInputsDirty (desc_tx->tx );
1084
+ for (unsigned int i = 0 ; i < desc_tx->tx ->vout .size (); ++i) {
1085
+ COutPoint outpoint (desc_tx->GetHash (), i);
1086
+ std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = mapTxSpends.equal_range (outpoint);
1087
+ for (TxSpends::const_iterator it = range.first ; it != range.second ; ++it) {
1088
+ const auto wit = mapWallet.find (it->second );
1089
+ if (wit != mapWallet.end ()) {
1090
+ txs.push_back (&wit->second );
1091
+ }
1092
+ }
1093
+ }
1094
+ }
1095
+ }
1096
+
1070
1097
// // debug print
1071
1098
WalletLogPrintf (" AddToWallet %s %s%s\n " , hash.ToString (), (fInsertedNew ? " new" : " " ), (fUpdated ? " update" : " " ));
1072
1099
@@ -1276,7 +1303,11 @@ bool CWallet::AbandonTransaction(const uint256& hashTx)
1276
1303
wtx.MarkDirty ();
1277
1304
batch.WriteTx (wtx);
1278
1305
NotifyTransactionChanged (wtx.GetHash (), CT_UPDATED);
1279
- // Iterate over all its outputs, and mark transactions in the wallet that spend them abandoned too
1306
+ // Iterate over all its outputs, and mark transactions in the wallet that spend them abandoned too.
1307
+ // States are not permanent, so these transactions can become unabandoned if they are re-added to the
1308
+ // mempool, or confirmed in a block, or conflicted.
1309
+ // Note: If the reorged coinbase is re-added to the main chain, the descendants that have not had their
1310
+ // states change will remain abandoned and will require manual broadcast if the user wants them.
1280
1311
for (unsigned int i = 0 ; i < wtx.tx ->vout .size (); ++i) {
1281
1312
std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = mapTxSpends.equal_range (COutPoint (now, i));
1282
1313
for (TxSpends::const_iterator iter = range.first ; iter != range.second ; ++iter) {
0 commit comments