Skip to content

Commit 66d7b7d

Browse files
committed
Handle transaction_unconfirmed as a full reorg to the tx height
In `ChannelMonitor`, if we see a `transaction_unconfirmed` for a transaction we last saw in a block at height X, we shouldn't *only* remove the `onchain_events_awaiting_threshold_conf` entry for the given tx but rather for all transactions that we last saw at height >= X. This avoids any potential `onchain_events_awaiting_threshold_conf` inconsistencies due to the order in whcih users mark transactions unconfirmed (which the `chain::Confirm` docs do not currently set any requirements on). This also matches the `OnchainTxHandler` behavior, which does the same lookup.
1 parent 384c4dc commit 66d7b7d

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lightning/src/chain/channelmonitor.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -3111,10 +3111,24 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
31113111
F::Target: FeeEstimator,
31123112
L::Target: Logger,
31133113
{
3114-
self.onchain_events_awaiting_threshold_conf.retain(|ref entry| if entry.txid == *txid {
3115-
log_info!(logger, "Removing onchain event with txid {}", txid);
3116-
false
3117-
} else { true });
3114+
let mut removed_height = None;
3115+
for entry in self.onchain_events_awaiting_threshold_conf.iter() {
3116+
if entry.txid == *txid {
3117+
removed_height = Some(entry.height);
3118+
break;
3119+
}
3120+
}
3121+
3122+
if let Some(removed_height) = removed_height {
3123+
log_info!(logger, "transaction_unconfirmed of txid {} implies height {} was reorg'd out", txid, removed_height);
3124+
self.onchain_events_awaiting_threshold_conf.retain(|ref entry| if entry.height >= removed_height {
3125+
log_info!(logger, "Transaction {} reorg'd out", entry.txid);
3126+
false
3127+
} else { true });
3128+
}
3129+
3130+
debug_assert!(!self.onchain_events_awaiting_threshold_conf.iter().any(|ref entry| entry.txid == *txid));
3131+
31183132
self.onchain_tx_handler.transaction_unconfirmed(txid, broadcaster, fee_estimator, logger);
31193133
}
31203134

0 commit comments

Comments
 (0)