-
Couldn't load subscription status.
- Fork 421
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
Handle transaction_unconfirmed as a full reorg to the tx height
#1846
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If so, I think it should be noted somewhere that our default implementation of Chain::transaction_unconfirmed in fact alleviate the caller to trigger it for all transaction returned by get_relevant_txids. At least clarify things.
|
|
||
| if let Some(height) = height { | ||
| log_info!(logger, "transaction_unconfirmed of txid {} implies height {} was reorg'd out", txid, height); | ||
| self.onchain_events_awaiting_threshold_conf.retain(|ref entry| entry.height < height); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I think it's correct to not call ChannelMonitor::block_disconnected as chain::Confirm doc implies to call best_block_updated. This method updates our best_block and call OnchainTxHandler::block_disconnected.
|
|
||
| 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); |
There was a problem hiding this comment.
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() ?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
I don't think that's true - for example if the user calls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This avoids any potential
onchain_events_awaiting_threshold_conf
inconsistencies due to the order in whcih users mark transactions
unconfirmed (which thechain::Confirmdocs do not currently set
any requirements on).
Wouldn't it be ok as long as users also call best_block_updated for each disconnected block? So this patch keeps things consistent for users that don't, and perhaps only call best_block_updated with the latest tip after the reorg.
|
|
||
| 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); |
There was a problem hiding this comment.
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.
Hmm, so per the docs we actually don't require calling |
It would've been nice to have it documented before, but with this patch I'd say there's no reason for a user to worry about it anymore. |
|
Tagging 113 cause I don't feel super comfortable with the current code for users doing electrum syncs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two questions/nits, otherwise LGTM.
Codecov ReportBase: 90.81% // Head: 91.81% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1846 +/- ##
==========================================
+ Coverage 90.81% 91.81% +0.99%
==========================================
Files 89 91 +2
Lines 48011 57634 +9623
Branches 48011 57634 +9623
==========================================
+ Hits 43601 52916 +9315
- Misses 4410 4718 +308
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
|
LGTM, feel free to squash! |
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.
3bb6762 to
66d7b7d
Compare
|
Rebased without changes. |
In
ChannelMonitor, if we see atransaction_unconfirmedfor a transaction we last saw in a block at height X, we shouldn't only remove theonchain_events_awaiting_threshold_confentry for the given tx but rather for all transactions that we last saw at height >= X.This avoids any potential
onchain_events_awaiting_threshold_confinconsistencies due to the order in whcih users mark transactions unconfirmed (which thechain::Confirmdocs do not currently set any requirements on).This also matches the
OnchainTxHandlerbehavior, which does the same lookup.