-
Notifications
You must be signed in to change notification settings - Fork 421
Reload channelmanager with channel data from monitors #4151
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
base: main
Are you sure you want to change the base?
Reload channelmanager with channel data from monitors #4151
Conversation
|
👋 Hi! I see this is a draft PR. |
dd9d6db to
c9d03d4
Compare
a7debb3 to
2eb7981
Compare
Additional trace logs to help with debugging.
Add a new `safe_channels` feature flag that gates in-development work toward persisting channel monitors and channels atomically, preventing them from desynchronizing and causing force closures. This commit begins that transition by storing both pieces together and adding consistency checks during writes. These checks mirror what the channel manager currently validates only on reload, but performing them earlier increases coverage and surfaces inconsistencies sooner.
2eb7981 to
4eb87c1
Compare
lightning/src/ln/channelmanager.rs
Outdated
| let mut failed_htlcs = Vec::new(); | ||
| let channel_count: u64 = Readable::read(reader)?; | ||
|
|
||
| // Discard channel manager versions of channels. |
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 like we'll need to use these manager versions of channels if the monitor versions aren't set (i.e. reading a manager that was last serialized on <= 0.2). Ideal would be to have an upgrade test, i.e. in upgrade_downgrade_tests.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.
I think we want to leave this until we've got solid confidence in the approach taken? Ofc agreed that we need to implement upgrade.
|
|
||
| /// The encoded channel data associated with this ChannelMonitor, if any. | ||
| #[cfg(feature = "safe_channels")] | ||
| pub encoded_channel: Option<Vec<u8>>, |
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.
Did you explore encoding the FundedChannel itself rather than a bag of bytes? I guess it would require propagating the signer trait parameter, which is kind of annoying?
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 considered it, but indeed, the signer parameter is annoying. But your comment did make me think again. I will try and see what we can do with a copy of FundedChannel just for data storage. Perhaps that's useful too once we start stripping out the redundant fields?
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.
One thing I noticed while trying this is that ChannelContext contains blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>. PendingChannelMonitorUpdate will contain FundedChannel snapshots. Nesting 😨
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.
| // for the safe_channels feature. | ||
| #[cfg(feature = "safe_channels")] | ||
| if let Some(ref encoded_channel) = channel_monitor.encoded_channel { | ||
| channel_monitor.check_encoded_channel_consistency(encoded_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.
May be better to have the above docs (or duplicate them) on the method itself
| /// The serialized channel state as provided via the last `ChannelMonitorUpdate` or via a call to | ||
| /// [`ChannelMonitor::update_encoded_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.
Maybe note that this is a FundedChannel and explain why we're encoding it here?
| if let Ok(check_data) = check_res { | ||
| debug_assert!( | ||
| check_data.cur_holder_commitment_transaction_number | ||
| <= self.get_cur_holder_commitment_number(), |
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 document generally why it's okay for the channel to be behind the monitor (but not ahead)?
| } | ||
|
|
||
| #[cfg(feature = "safe_channels")] | ||
| pub fn read_check_data<R: io::Read>(reader: &mut R) -> Result<ChannelStateCheckData, DecodeError> { |
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.
Docs on this method?
4eb87c1 to
1adfd7d
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4151 +/- ##
========================================
Coverage 89.33% 89.33%
========================================
Files 180 180
Lines 138353 138521 +168
Branches 138353 138521 +168
========================================
+ Hits 123598 123754 +156
- Misses 12132 12138 +6
- Partials 2623 2629 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Added more cfg gating for |
7364632 to
5967f55
Compare
5967f55 to
b096bf7
Compare
PoC branch to try out persisting channels with the monitors rather than chanmgr. Goal: fix force closures.
Builds on #4218