-
Notifications
You must be signed in to change notification settings - Fork 411
[Custom Transactions] Provide Built Counterparty Commitment Transactions To ChannelMonitor
#3654
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
[Custom Transactions] Provide Built Counterparty Commitment Transactions To ChannelMonitor
#3654
Conversation
👋 I see @valentinewallace was un-assigned. |
ChannelMonitor
ChannelMonitor
ad98735
to
9f88056
Compare
ChannelMonitor
ChannelMonitor
6e70599
to
52a2eb8
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3654 +/- ##
==========================================
+ Coverage 89.18% 89.23% +0.04%
==========================================
Files 155 155
Lines 119274 119280 +6
Branches 119274 119280 +6
==========================================
+ Hits 106379 106440 +61
+ Misses 10290 10241 -49
+ Partials 2605 2599 -6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
52a2eb8
to
29a8b9f
Compare
ChannelMonitor
ChannelMonitor
🔔 1st Reminder Hey @valentinewallace! This PR has been waiting for your review. |
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
let htlc_outputs = vec![]; | ||
|
||
let commitment_tx = self.build_counterparty_commitment_tx(INITIAL_COMMITMENT_NUMBER, | ||
&their_per_commitment_point, to_broadcaster_value, to_countersignatory_value, | ||
feerate_per_kw, htlc_outputs); | ||
// Take the opportunity to populate this recently introduced field | ||
self.initial_counterparty_commitment_tx = Some(commitment_tx.clone()); | ||
commitment_tx |
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.
Nit: indentation seems off here
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.
Thank you I addressed this below, ran the block through fmt.
&ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTX { htlc_outputs: _, | ||
ref commitment_tx, |
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.
&ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTX { htlc_outputs: _, | |
ref commitment_tx, | |
&ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTX { | |
htlc_outputs: _, ref commitment_tx, |
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.
Thank you, addressed below.
29a8b9f
to
e1b5fe0
Compare
to_broadcaster_value_sat: u64, to_countersignatory_value_sat: u64, logger: &L, | ||
) | ||
where L::Target: Logger | ||
&self, commitment_tx: CommitmentTransaction, logger: &L, |
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.
Let's update the docs accordingly.
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.
Thanks ! Addressed below.
self.initial_counterparty_commitment_tx.clone().or_else(|| { | ||
// This provides forward compatibility; an old monitor will not contain the full | ||
// transaction; only enough information to rebuild it | ||
self.initial_counterparty_commitment_info.map( |
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.
Could we ever return None
now? It seems before we couldn't.
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.
Before we could return None
at this call self.initial_counterparty_commitment_info?;
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.
Ah, for reason I was unaware that ?
worked with Option
return types.
`LatestCounterpartyCommitmentTXInfo` provides `ChannelMonitor` with the data it needs to build counterparty commitment transactions. `ChannelMonitor` then rebuilds commitment transactions from these pieces of data when requested. This commit adds a new variant to `ChannelMonitorUpdateStep` called `LatestCounterpartyCommitmentTX`, which will provide fully built commitment transactions to `ChannelMonitor`. When `ChannelMonitor` is asked for counterparty commitment transactions, it will not rebuild them, but just clone them. As a result, this new variant eliminates any calls to the upcoming `TxBuilder` trait in `ChannelMonitor`, which avoids adding a generic parameter on `ChannelMonitor`. This commit also stomps any bugs that might come from passing around disparate pieces of data to re-build commitment transactions from scratch. We also add a `htlc_outputs` field to the variant to include the dust HTLCs, as well as all the HTLC sources. This means that this new variant will store non-dust HTLCs both in the `htlc_outputs` field, and in the `commitment_tx` field. This is ok for now as the number of HTLCs per commitment nowadays is very low. We add code to handle this new variant, but refrain from immediately setting it. This will allow us to atomically switch from `LatestCounterpartyCommitmentTXInfo` to `LatestCounterpartyCommitmentTX` in the future while still allowing downgrades.
e1b5fe0
to
b8a03cd
Compare
ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo { commitment_txid, htlc_outputs, commitment_number, their_per_commitment_point, .. } => { | ||
log_trace!(logger, "Updating ChannelMonitor with latest counterparty commitment transaction info"); | ||
self.provide_latest_counterparty_commitment_tx(*commitment_txid, htlc_outputs.clone(), *commitment_number, *their_per_commitment_point, logger) | ||
}, | ||
ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTX { htlc_outputs, commitment_tx } => { | ||
log_trace!(logger, "Updating ChannelMonitor with latest counterparty commitment transaction info"); | ||
self.provide_latest_counterparty_commitment_tx(commitment_tx.trust().txid(), htlc_outputs.clone(), commitment_tx.commitment_number(), commitment_tx.per_commitment_point(), 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.
Should we handle having both the legacy and new version? I guess i was hoping we wouldn't have to wait a release or two for this stuff (which we have to do if we're trying to bridge versions here).
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.
We could -- I think it was done that way first in #3606 but I was concerned about the extra storage cost. We're planning to use this new variant (along with a similar one for latest holder commitment) for spliced channels as a way to move to the new format sooner since you can't downgrade with a pending splice anyway.
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 think it was done that way first in #3606 but I was concerned about the extra storage cost.
Right yes we previously added another field to the legacy variant that contained the full transaction. This made most of the fields in the legacy variant redundant so we went for a new variant.
Then to alleviate the storage cost we decided against immediately setting this new variant.
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.
Yea, okay, that all makes sense, just annoying that we have to wait a release or two to ship things. Alas.
This was previously part of #3606