-
Notifications
You must be signed in to change notification settings - Fork 385
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
Fail HTLCs which were removed from a channel but not persisted #1857
Fail HTLCs which were removed from a channel but not persisted #1857
Conversation
5180e9e
to
d793bb8
Compare
Codecov ReportBase: 90.60% // Head: 91.78% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1857 +/- ##
==========================================
+ Coverage 90.60% 91.78% +1.17%
==========================================
Files 91 91
Lines 47969 56197 +8228
Branches 47969 56197 +8228
==========================================
+ Hits 43463 51581 +8118
- Misses 4506 4616 +110
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. |
d793bb8
to
227a8bd
Compare
Needs rebase |
227a8bd
to
f9f1f81
Compare
Rebased. |
f9f1f81
to
d17ce49
Compare
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.
LGTM AFAICT. Just nits. One optional.
d17ce49
to
3149544
Compare
This expands the outbound-HTLC-listing support in `ChannelMonitor` to include not only the set of outbound HTLCs which have not yet been resolved but to also include the full set of HTLCs which the `ChannelMonitor` is currently able to to or has already finalized. This will be used in the next commit to fail-back HTLCs which were removed from a channel in the ChannelMonitor but not in a Channel. Using the existing `get_pending_outbound_htlcs` for this purpose is subtly broken - if the channel is already closed, an HTLC fail may have completed on chain and is no longer "pending" to the monitor, but the fail event is still in the monitor waiting to be handed back to the `ChannelMonitor` when polled.
If, after forwarding a payment to our counterparty, we restart with a ChannelMonitor update having been persisted, but the corresponding ChannelManager update was not persisted, we'll still have the forwarded HTLC in the `forward_htlcs` map on start. This will cause us to generate a (spurious) `PendingHTLCsForwardable` event. However, when we go to forward said HTLC, we'll notice the channel has been closed and leave it up to the `ChannelMontior` to finalize the HTLC. This is all fine today - we won't lose any funds, we'll just generate an excess forwardable event and then fail to forward. However, in the future when we allow for forward-time channel changes this could break. Thus, its worth adding tests for this behavior today, and, while we're at it, removing the spurious forwardable HTLCs event.
When a channel is force-closed, if a `ChannelMonitor` update is completed but a `ChannelManager` persist has not yet happened, HTLCs which were removed in the latest (persisted) `ChannelMonitor` update will not be failed even though they do not appear in the commitment transaction which went on chain. This is because the `ChannelManager` thinks the `ChannelMonitor` is responsible for them (as it is stale), but the `ChannelMonitor` has no knowledge of the HTLC at all (as it is not stale). The fix for this is relatively simple - we need to check for this specific case and fail back such HTLCs when deserializing a `ChannelManager`
3149544
to
dbe4aad
Compare
Squashed fixups. |
Based on #1830 (I didn't pull it all in, but there's one commit that just takes one function from there).When a channel is force-closed, if a
ChannelMonitor
update iscompleted but a
ChannelManager
persist has not yet happened,HTLCs which were removed in the latest (persisted)
ChannelMonitor
update will not be failed even though they do not appear in the
commitment transaction which went on chain. This is because the
ChannelManager
thinks theChannelMonitor
is responsible forthem (as it is stale), but the
ChannelMonitor
has no knowledge ofthe HTLC at all (as it is not stale).
The fix for this is relatively simple - we need to check for this
specific case and fail back such HTLCs when deserializing a
ChannelManager