Skip to content

Handle transaction_unconfirmed as a full reorg to the tx height #1846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3111,10 +3111,24 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
F::Target: FeeEstimator,
L::Target: Logger,
{
self.onchain_events_awaiting_threshold_conf.retain(|ref entry| if entry.txid == *txid {
log_info!(logger, "Removing onchain event with txid {}", txid);
false
} else { true });
let mut removed_height = None;
for entry in self.onchain_events_awaiting_threshold_conf.iter() {
if entry.txid == *txid {
removed_height = Some(entry.height);
break;
}
}

if let Some(removed_height) = removed_height {
log_info!(logger, "transaction_unconfirmed of txid {} implies height {} was reorg'd out", txid, removed_height);
self.onchain_events_awaiting_threshold_conf.retain(|ref entry| if entry.height >= removed_height {
log_info!(logger, "Transaction {} reorg'd out", entry.txid);
false
} else { true });
}

debug_assert!(!self.onchain_events_awaiting_threshold_conf.iter().any(|ref entry| entry.txid == *txid));

self.onchain_tx_handler.transaction_unconfirmed(txid, broadcaster, fee_estimator, logger);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well all the OnchainEventEntry do have a txid we could go batch the call to transaction_unconfirmed() ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you're suggesting here? I don't think batching from the user level works, and I'm not sure how we could "batch" without that?

Copy link
Contributor

@wpaulino wpaulino Nov 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps @ariard is suggesting that since OnchainTxHandler::transaction_unconfirmed also only requires the txid, which is already present in each OnchainEventEntry, we can call OnchainTxHandler::transaction_unconfirmed for each txid in onchain_events_awaiting_threshold_conf with a height >= the height disconnected. This doesn't seem necessary though as OnchainTxHandler::transaction_unconfirmed/block_disconnected already take care of this.

}

Expand Down