Skip to content

Expose a Balance for inbound HTLCs even without a preimage #1673

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

Conversation

TheBlueMatt
Copy link
Collaborator

If we don't currently have the preimage for an inbound HTLC, that
does not guarantee we can never claim it, but instead only that we
cannot claim it unless we receive the preimage from the channel we
forwarded the channel out on.

Thus, we cannot consider a channel to have no claimable balances if
the only remaining output on the commitment ransaction is an
inbound HTLC for which we do not have the preimage, as we may be
able to claim it in the future.

This commit addresses this issue by adding a new `Balance` variant
- `MaybePreimageClaimableHTLCAwaitingTimeout`, which is generated
until the HTLC output is spent.

Fixes #1620, based on #1495.

@TheBlueMatt TheBlueMatt added this to the 0.0.111 milestone Aug 17, 2022
Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

Looks good, test_claim_value_force_close just needs to be updated to handle the new variant.

@TheBlueMatt TheBlueMatt force-pushed the 2022-08-may-learn-preimage-balance branch from 57f4228 to 190e6be Compare August 17, 2022 22:54
@TheBlueMatt
Copy link
Collaborator Author

Fixed the failing test and rebased after #1495 landed.

@TheBlueMatt TheBlueMatt force-pushed the 2022-08-may-learn-preimage-balance branch from 190e6be to c6440b1 Compare August 17, 2022 23:19
wpaulino
wpaulino previously approved these changes Aug 18, 2022
Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

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

The new variant LGTM, I'm just not following the test 100% right now. Will give it another run-through later.

Just left a few nits.

dunxen
dunxen previously approved these changes Aug 18, 2022
Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

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

Went through the test, LGTM besides the rename idea and a nit

@codecov-commenter
Copy link

codecov-commenter commented Aug 24, 2022

Codecov Report

Merging #1673 (39cede6) into main (b84b53a) will increase coverage by 0.13%.
The diff coverage is 93.63%.

@@            Coverage Diff             @@
##             main    #1673      +/-   ##
==========================================
+ Coverage   90.77%   90.90%   +0.13%     
==========================================
  Files          80       85       +5     
  Lines       44763    45888    +1125     
  Branches    44763    45888    +1125     
==========================================
+ Hits        40632    41715    +1083     
- Misses       4131     4173      +42     
Impacted Files Coverage Δ
lightning-block-sync/src/lib.rs 93.23% <ø> (ø)
lightning-block-sync/src/test_utils.rs 93.46% <ø> (ø)
lightning-invoice/src/lib.rs 87.39% <ø> (ø)
lightning-invoice/src/payment.rs 89.93% <0.00%> (+2.16%) ⬆️
lightning-net-tokio/src/lib.rs 77.16% <0.00%> (+0.30%) ⬆️
lightning-rapid-gossip-sync/src/lib.rs 90.90% <ø> (ø)
lightning/src/chain/mod.rs 68.18% <ø> (ø)
lightning/src/lib.rs 100.00% <ø> (ø)
lightning/src/ln/mod.rs 95.00% <ø> (ø)
lightning/src/util/chacha20poly1305rfc.rs 96.25% <ø> (ø)
... and 48 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

dunxen
dunxen previously approved these changes Aug 25, 2022
Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

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

ACK after squash

@@ -1565,6 +1576,11 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
timeout_height: htlc.cltv_expiry,
});
}
} else if htlc_resolved.is_none() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Fwiw, tests pass when this is just else

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, right, it'd be unreachable otherwise as we have a separate else clause for resolved.is_some && !spend_pending (and spend_pending would require that we have the preimage, which ends up in the previous clause). I'm still gonna leave it as-is if that's okay.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sg, it reads fine IMO

If we don't currently have the preimage for an inbound HTLC, that
does not guarantee we can never claim it, but instead only that we
cannot claim it unless we receive the preimage from the channel we
forwarded the channel out on.

Thus, we cannot consider a channel to have no claimable balances if
the only remaining output on the commitment ransaction is an
inbound HTLC for which we do not have the preimage, as we may be
able to claim it in the future.

This commit addresses this issue by adding a new `Balance` variant
- `MaybePreimageClaimableHTLCAwaitingTimeout`, which is generated
until the HTLC output is spent.

Fixes lightningdevkit#1620
As we now have a MaybePreimageClaimableHTLC, its more consistent
to rename `MaybeClaimableHTLCAwaitingTimeout` to
`MaybeTimeoutClaimableHTLC`.
@TheBlueMatt
Copy link
Collaborator Author

Squashed without further changes.

@TheBlueMatt TheBlueMatt force-pushed the 2022-08-may-learn-preimage-balance branch from c7e98b8 to 39cede6 Compare August 25, 2022 18:51
@TheBlueMatt TheBlueMatt merged commit fa62b00 into lightningdevkit:main Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose a claimable Balance for no-preimage-but-may-learn-one
5 participants