-
Notifications
You must be signed in to change notification settings - Fork 367
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
Channel phase refactor, wrap channel phase, store wrapped phase in map #3418
base: main
Are you sure you want to change the base?
Conversation
Preferably we should get this in before further substantial dual funding or splicing changes |
Thanks! Discussed this @jkczyz in some calls, makes sense and agree with moving the enum inward effectively. Happy to prioritise this as it will reduce |
Please note that this is not complete, but only the basic change to the map, further steps are possible (as noted in description). Various handling logic in |
Sounds good! :) I wasn't too worried about the extra wrapper, just wanted to get the bigger picture of its specific use. |
ed42039
to
a8f83dc
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3418 +/- ##
==========================================
- Coverage 89.22% 89.21% -0.01%
==========================================
Files 130 130
Lines 106965 107038 +73
Branches 106965 107038 +73
==========================================
+ Hits 95438 95496 +58
- Misses 8734 8748 +14
- Partials 2793 2794 +1 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
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.
Next steps:
- Rename
Channel
->FundedChannel
andChannelWrapper
->Channel
- Create more handling method on
Channel
(channel wrapper), that dispatch into different phases.
We may as well do this now. At very least the rename.
return close_chan!(chan_err, api_err, chan); | ||
}, | ||
} | ||
Some(channel) => { |
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 you pattern match on the struct to reduce the diff size here and elsewhere?
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 change here comes from the fact that the Option and the Enum are now in different level, hence it's not possible to match them in one.
For the second match with one positive and one error arm I think the if let() construct is more readable. If I change to match, the diff is still there, the unchanged inner part is only indented.
lightning/src/ln/channel.rs
Outdated
pub fn phase_take(self) -> ChannelPhase<SP> { | ||
self.phase | ||
} |
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.
Seems like we could move context
to ChannelWrapper
to avoid needing to deconstruct it. Otherwise, we still need to re-insert into the map. So, IIUC, this change doesn't really help us any.
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.
Maybe we should discuss this offline, I don't fully get it.
When a pending channel becomes funded, we need to remove&insert because the channel ID changed.
But when only the phase changes, there is no longer need for removal, see move_v2_to_funded
.
The method to change the phase internally is a bit tricky, as the context owned by the old phase needs to be moved to the new phase.
Moving the context to ChannelWrapper would not solve the cases when there are (will be) more than one channel contexts.
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.
Maybe we should discuss this offline, I don't fully get it. When a pending channel becomes funded, we need to remove&insert because the channel ID changed. But when only the phase changes, there is no longer need for removal, see
move_v2_to_funded
.
Right, for outbound channels the id will change. I had splicing on my mind where we shouldn't change once already funded, IIRC.
The method to change the phase internally is a bit tricky, as the context owned by the old phase needs to be moved to the new phase. Moving the context to ChannelWrapper would not solve the cases when there are (will be) more than one channel contexts.
That's why I was saying to move context
into ChannelWrapper
. Then you can simply override phase
with a new variant. Could you remind me when we'll have more than one channel context and how they'll be stored? Is that for splicing? Will that involve a phase transition? They could possibly be swap
ed if contained within a Vec
, for instance, or take
n from an internal Option
if not required.
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 you remind me when we'll have more than one channel context and how they'll be stored?
enum ChannelPhase {
...
Funded(FundedChannel<SP>),
RefundingV2((FundedChannel<SP>, ChannelVariants<SP>)),
First is the pre-splice channel, with its context. Second has the negotiating splice channel, and possible 0 or more negotiated unconfirmed splice variants.
/// The inner channel phase | ||
/// Option is used to facilitate in-place replacement (see e.g. move_v2_to_funded), | ||
/// but it is never None, ensured in new() and set_phase() | ||
phase: Option<ChannelPhase<SP>>, |
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.
See other comment about moving ChannelContext
here. Seems we shouldn't need to use an Option
.
The rename of |
92f8bc3
to
4d886fe
Compare
I don't think |
Rationale:
Changes in this PR:
ChannelWrapper
struct to wrap aChannelPhase
ChannelManager.channel_by_id
map holdsChannelWrapper
structs, as opposed toChannelPhase
enumsNext steps:
Channel
->FundedChannel
andChannelWrapper
->Channel
Channel
(channel wrapper), that dispatch into different phases.