-
Notifications
You must be signed in to change notification settings - Fork 412
Expose counterparty-revoked-outputs in get_claimable_balance
#1495
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
Expose counterparty-revoked-outputs in get_claimable_balance
#1495
Conversation
8a0d83b
to
0c3b9dc
Compare
Codecov Report
@@ Coverage Diff @@
## main #1495 +/- ##
==========================================
+ Coverage 90.77% 90.87% +0.10%
==========================================
Files 80 80
Lines 44763 45173 +410
Branches 44763 45173 +410
==========================================
+ Hits 40632 41052 +420
+ Misses 4131 4121 -10
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
0c3b9dc
to
dee10c5
Compare
313ec8c
to
8441ba2
Compare
Okay, sorry for the delay, finally responded to all feedback here. |
Feel free to squash the existing commits before your next push. |
e3d7e64
to
d565ab2
Compare
Rebased due to a trivial conflict. Squashed previous fixups from the previous review, new fixups address this review. Still need to address #1495 (comment) and #1495 (comment) and we need to decide on #1495 (comment) |
b8f272f
to
e6d3a24
Compare
Okay, addressed all the comments except for the one asking for a new test, will look into that when I get a chance. |
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.
Fixups look good, feel free to squash. Will do another full pass once the test is up.
e6d3a24
to
c9b128a
Compare
Okay, sorry for the delay here. I added the requested test (code already worked right!) and addressed all the outstanding feedback. |
c9b128a
to
d079767
Compare
@@ -1427,67 +1427,82 @@ impl<Signer: Sign> ChannelMonitor<Signer> { | |||
($holder_commitment: expr, $htlc_iter: expr) => { | |||
for htlc in $htlc_iter { | |||
if let Some(htlc_commitment_tx_output_idx) = htlc.transaction_output_index { |
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.
It would be nice to get rid of the nesting here too with a similar strategy to 200c3c6
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.
I mean its all in a single if? We can also try to clean up a few things in a followup.
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.
Fine to revisit in follow-up. My philosophy is that this seems like the #1 module to be made as readable as possible
} else if us.payment_preimages.get(&htlc.payment_hash).is_some() { | ||
// Otherwise (the payment was inbound), only expose it as claimable if | ||
// we know the preimage. | ||
// Note that if there is a pending claim, but it did not use the |
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.
3 lines up, we have an else if we know the preimage
, but should there be an additional else
adding a ContentiousClaimable
given we may receive the preimage at some point in the future, in time to claim?
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.
Oh! Great catch!
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.
Actually, that's an existing issue and this PR is already huge. I'm gonna punt it to a followup if that's okay. #1620
bb09577
to
e8a1b37
Compare
Squashed, difference from yesterday is just some comment fixes and whitespace:
|
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, just have two minor comments.
095041c
to
a52cf41
Compare
Rebased after merge of the new HTLCHandlingFailed event, which now need to be handled. |
Not worth delaying 110 for this, I think, given it doesn't resolve all the issues with missing entries. |
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.
I'm ACK after squash :)
Github seems to think it needs a rebase, though it doesn't list any conflicted filenames?
When we see a transaction which generates some `OnchainEvent`, its useful to have the full transaction around for later analysis. Specifically, it lets us check the list of outputs which were spent in the transaction, allowing us to look up, e.g. which HTLC outpoint was spent in a transaction. This will be used in a few commits to do exactly that - figure out which HTLC a given `OnchainEvent` corresponds with.
When handling a revoked counterparty commitment transaction which was broadcast on-chain, we occasionally need to look up which output (and its value) was to the counterparty (the `to_self` output). This will allow us to generate `Balance`s for the user for the revoked output.
The test intended to disconnect a transaction previously connected but didn't disconnect enough blocks to do so, leading to it confirming two conflicting transactions. In the next few commits this will become an assertion failure.
When a counterparty broadcasts a revoked commitment transaction, followed immediately by HTLC-Success/-Timeout spends thereof, we'd like to have an `onchain_events_awaiting_threshold_conf` entry for them. This does so using the `HTLCSpendConfirmation` entry, giving it (slightly) new meaning. Because all existing uses of `HTLCSpendConfirmation` already check if the relevant commitment transaction is revoked first, this should be trivially backwards compatible. We will ultimately figure out if something is being spent via the `OnchainTxHandler`, but to do so we need to look up the output via the HTLC transaction txid, which this allows us to do.
We need this information when we look up if we still need to spend a revoked output from an HTLC-Success/HTLC-Timeout transaction for balance calculation.
Instead of a series of different `onchain_events_awaiting_threshold_conf.iter()...` calls to scan for HTLC status in balance calculation, pull them all out into one `for ... { match ... }` to do it once and simplify the code somewhat.
a52cf41
to
c6ea2e3
Compare
Squashed and rebased (which conflicted due to the rust-bitcoin bump):
|
This uses the various new tracking added in the prior commits to expose a new `Balance` type - `CounterpartyRevokedOutputClaimable`. Some nontrivial work is required, however, as we now have to track HTLC outputs as spendable in a transaction that comes *after* an HTLC-Success/HTLC-Timeout transaction, which we previously didn't need to do. Thus, we have to check if an `onchain_events_awaiting_threshold_conf` event spends a commitment transaction's HTLC output while walking events. Further, because we now need to track HTLC outputs after the HTLC-Success/HTLC-Timeout confirms, and because we have to track the counterparty's `to_self` output as a contentious output which could be claimed by either party, we have to examine the `OnchainTxHandler`'s set of outputs to spend when determining if certain outputs are still spendable. Two new tests are added which test various different transaction formats, and hopefully provide good test coverage of the various revoked output paths.
Val suggested this as an obvious cleanup to separate per_HTLC logic from the total commitment transaction logic, separating the large function into two.
c6ea2e3
to
d8651e3
Compare
Depends on
#1494, #1481, and #1486. Fixes #1466.Currently, users have no way of (easily) determining if a
ChannelMonitor
for a closed channel has claimed all available outpoints and can do no further work (implying it can be safely deleted). The intention was always to allowget_claimable_balances
to provide that information, however it was (until now) not able to reportBalance
s for revoked counterparty outputs.This implements that final missing feature, allowing us to prune
ChannelMonitor
s after this lands (and we give it some time to simmer).