-
Notifications
You must be signed in to change notification settings - Fork 365
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.
lightning/src/ln/channel.rs
Outdated
pub fn context(&'a self) -> &'a ChannelContext<SP> { | ||
self.phase.context() | ||
} | ||
|
||
pub fn context_mut(&'a mut self) -> &'a mut ChannelContext<SP> { | ||
self.phase.context_mut() | ||
} |
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.
Lifetimes shouldn't be need as they would be inferred.
self.phase | ||
} | ||
|
||
pub fn get_funded_channel(&self) -> Option<&Channel<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.
We aren't consistent about this, but no need to use get_
prefix for accessor methods.
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?
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.
/// 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
.
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.