-
Notifications
You must be signed in to change notification settings - Fork 364
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
Implement accepting dual-funded channels without contributing #3137
base: main
Are you sure you want to change the base?
Implement accepting dual-funded channels without contributing #3137
Conversation
b981cd7
to
0caf60e
Compare
0caf60e
to
44821af
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3137 +/- ##
==========================================
- Coverage 89.58% 89.19% -0.40%
==========================================
Files 127 127
Lines 103534 104949 +1415
Branches 103534 104949 +1415
==========================================
+ Hits 92750 93608 +858
- Misses 8080 8600 +520
- Partials 2704 2741 +37 ☔ View full report in Codecov by Sentry. |
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.
Looks great, mostly localized code improvements suggested.
As I see, the |
Looks to me that #2989 is in fact included in this PR (good!) |
0db700b
to
7dceedd
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.
Some initial comments, sorry this took so long to get back to.
lightning/src/ln/channelmanager.rs
Outdated
|
||
if chan.interactive_tx_signing_session.is_some() { | ||
let monitor = try_chan_phase_entry!(self, | ||
chan.commitment_signed_initial_v2(&msg, best_block, &self.signer_provider, &&logger), chan_phase_entry); |
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.
Ugh...So the spec changed the definition of commitment_signed
to now also include the initial funding commitment tx signing? Even though it implies other things inside the interactive state machine? Is it too late to change this? This seems nuts.
Does this mean that we should support adding HTLCs prior to the initial commitment transaction?
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.
The previous things it implies should really be looked at in the spec and changed there. We don't want to support adding HTLCs prior to initial commitment. So I really need to investigate what is going on with the spec and what might need to be fixed there.
lightning/src/ln/channelmanager.rs
Outdated
if chan.interactive_tx_signing_session.is_some() { | ||
let monitor = try_chan_phase_entry!(self, | ||
chan.commitment_signed_initial_v2(&msg, best_block, &self.signer_provider, &&logger), chan_phase_entry); | ||
if let Ok(persist_status) = self.chain_monitor.watch_channel(chan.context.get_funding_txo().unwrap(), monitor) { |
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 the persist status is pending we need to handle the later stuff in monitor_updating_restored
. Really the whole contents of the block here should be in monitor_updating_restored
.
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 @TheBlueMatt, for review and some good points raised. I'll address these ASAP ❤️
7dceedd
to
64c35f4
Compare
Still working on remaining initial feedback. |
64c35f4
to
a46da5a
Compare
No rush, let me know when you want another pass. |
0613f64
to
93896c4
Compare
9af670e
to
df187b8
Compare
86ddc27
to
a932c92
Compare
Rebased and working through drying up and continuing to address: #3137 (comment) |
LMK when you want another round of review here. I think it was mostly there so kinda waiting for you to tell me you've DRY'd things up and will take a look. |
a932c92
to
7e1cde2
Compare
DRY'd up new initial commitment in latest push. Now moving over some tests from #2302 and modifying them to have manual V2 open channel messages so we can at least test them here. |
lightning/src/ln/channel.rs
Outdated
fn context(&self) -> &ChannelContext<SP>; | ||
|
||
fn initial_commitment_signed<L: Deref>( | ||
&mut self, holder_commitment_tx: HolderCommitmentTransaction, |
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 should be able to shift more code here. eg assert_no_commitment_advancement()
is shared across both places. The checking logic in check_funding_created_signature
is shared in both sides (its broken out in the funding_created
handler so that we can reset the state if it fails, but there's not really a strong reason to do that, we always FC the channel if we fail anyway, but we should still reset the funding_outpoint to None
if we fail but the common code can check that case and do so). The call to .validate_holder_commitment
is shared. There may be more too.
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.
Ok yeah I was a bit too prudent in sharing the code but there are still some obvious pieces like you pointed out. Will push them up in the existing DRY commit and a new commit with tests.
7e1cde2
to
14a5e14
Compare
Pushed the DRYing up. Migrating the appropriate tests from 2302 is taking some time as more manual helper methods are needed. Almost there, though. |
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.
Some comments based on our offline discussion. Will take a closer look at your recent changes.
pub interactive_tx_constructor: Option<InteractiveTxConstructor>, | ||
pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>, |
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.
Are these mutually exclusive? Actually, when would we have an InteractiveTxSigningSession
when in ChannelPhase::Funded
?
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.
Sorry, that should have said InteractiveTxConstructor
when in ChannelPhase::Funded
.
Ok(tx_constructor) => { | ||
channel.set_interactive_tx_constructor(tx_constructor); | ||
}, |
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 construct InteractiveTxConstructor
before InboundV2Channel
such that we can simply include the former when constructing the latter rather than needing a mutator?
ChannelPhase::Funded(chan) => &mut chan.interactive_tx_constructor, | ||
_ => try_chan_phase_entry!(self, Err(ChannelError::Close( | ||
( | ||
"Got an unexpected tx_signatures message".into(), |
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 this say tx_abort
message?
if self.commitment_secrets.get_min_seen_secret() != (1 << 48) || | ||
self.cur_counterparty_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER || | ||
self.holder_commitment_point.transaction_number() != INITIAL_COMMITMENT_NUMBER { | ||
panic!("Should not have advanced channel commitment tx numbers prior to funding_created"); |
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.
Since we're moving this, let's make it a debug_assert!(false, ...)
// If we've sent `commtiment_signed` for an interactive transaction construction, | ||
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the | ||
// txid of that interactive transaction, else we MUST NOT set it. | ||
next_funding_txid: Option<Txid>, |
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.
Can you elaborate more in the comment on what issue(s) this addresses? Does this need a persistence of some kind to make it safe?
initiator_input_value_satoshis: u64, | ||
} | ||
|
||
// TODO(dual_funding): Use real node and API for creating V2 channels as initiator when available, |
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.
bleh, if possible can we avoid adding more test code to channelmanager.rs
...that file is huge (or do we need too many variables directly from ChannelManager
that aren't pub 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.
I'd recommend the functional_tests.rs
or new functional_tests_dual_funding.rs
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.
functional_tests.rs
is also kinda huge. Ideally we keep our test files way smaller than most of them are :(
temporary_channel_id.clone())); | ||
} | ||
|
||
// Version-specific checks and logic |
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.
Most of the code in both sides of this branch is the same, can we DRY it up more?
) -> Result<(Self, Option<InteractiveTxMessageSend>), AbortReason> | ||
/// If the holder is the initiator, they need to send the first message which is a `TxAddInput` | ||
/// message. | ||
pub fn new<ES: Deref>(args: InteractiveTxConstructorArgs<ES>) -> Result<Self, AbortReason> |
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.
Can most of the changes in here be split into separate commit(s) so they can be described in commit messages?
|
||
// TODO(dual_funding): Check all sigs are SIGHASH_ALL. | ||
|
||
// TODO(dual_funding): I don't see how we're going to be able to ensure witness-standardness |
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, in general I think we aren't gonna bother, at least not for some time. We should carefully document when we add local-funding logic that the counterparty can add inputs which will prevent the funding tx from confirming, and we make no attempt to prevent that. We should also document this in the open channel logic now (and in release notes added in this PR since its a major change).
msg, | ||
}); | ||
} | ||
Ok(()) |
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 close the channel here?
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub(crate) struct InteractiveTxSigningSession { |
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.
Same here, can this go in a separate commit? Could also use some documentation.
Git history is weird here looks like some commits from upstream got cherry-picked, can just rebase to fix it. |
Yeah, I see now. Fixing. Will address outstanding feedback from today. |
We'll only gate public API related to contributing toward an inbound or opening a dual funded channel.
Here we add the `interactive_tx_constructor` field to the `Channel`, `OutboundV2Channel`, and `InboundV2Channel` structs.
…nnel::funding_signed`
494413c
to
009512f
Compare
009512f
to
67e0c12
Compare
We split this out from #2302 for easier review and to address the common non-public API parts of the V2 channel establishment implementation.
This will allow the holder to be an acceptor, but not initiator of V2 channels. We also don't expose an API for contributing to an inbound channel.
The functionality to initiate V2 channels and fund inbound channels forms part of #2302.