-
Notifications
You must be signed in to change notification settings - Fork 406
Remove Channel's ChannelMonitor copy #667
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
Remove Channel's ChannelMonitor copy #667
Conversation
Codecov Report
@@ Coverage Diff @@
## master #667 +/- ##
==========================================
+ Coverage 91.36% 91.46% +0.10%
==========================================
Files 35 35
Lines 21703 21888 +185
==========================================
+ Hits 19828 20019 +191
+ Misses 1875 1869 -6
Continue to review full report at Codecov.
|
26bf274
to
6b693e6
Compare
Oops, broke build -- will fix in a bit |
613ff14
to
a7f185f
Compare
I looked into extracting some common HTLC selection functionality between |
Hmm, fuzzing seems slow still. Looking into it. |
ad02c3d
to
a97ec8c
Compare
a97ec8c
to
d0056d2
Compare
684dba8
to
70c58d9
Compare
lightning/src/ln/channel.rs
Outdated
@@ -908,7 +969,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> { | |||
InboundHTLCState::AwaitingRemoteRevokeToAnnounce(_) => (!generated_by_local, "AwaitingRemoteRevokeToAnnounce"), |
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.
not so much related to this diff in particular, but is the string literal the most elegant way to get the state name?
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.
Open to other options 😄 (for a future PR)
70c58d9
to
528cea5
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.
I'm all in to remove Channel's ChannelMonitor copy but I think there is a easier way than dc9ef2c
. If I understand new would_broadcast_at_height_functionality
well, its purpose is only to verify that ChannelMonitor accomplish its job well and broadcast channel update accordingly.
I'm not sure if it's a great approach, in the future if we add new conditions in ChannelMonitor to force-close channel we would need to access them too. Like in case of mempools-congestion, preemptively close channel at risk.
Another way to solve this would be a) pass a reference to ChainWatchInterface to ChannelManager b) at funding_tx detection, return its output to watch c) monitor commitment transaction broadcast. Parsing positively commitment transaction is easy to do due to transaction pattern (one-input), LN commitment number watermark and overall funding outpoint spending. It's more robust also as we shouldn't assume that our ChannelManager and ChannelMonitor are running on the same block provider and thus may have block view latency.
I know that's already the current model to query ChannelMonitor to decide if we should shutdown and broadcast channel update, but I think it's fine to wait a bit for channel update broadcast. Shutdown/broadcast will happen either sooner after any attempt to unsuccessfully update monitors. Or latter after block processing.
If you still want to be quick in term of updating global network view of our channel maybe we can ChannelMonitor signal broadcast with a boolean and us periodically querying it like we're doing for get_and_clear_pending_htlcs_updated
?
Overall, I may miss some onchain/offchain coupling assumptions but it feels like we can short-cut some complexity ?
Ooooo, right, so I think that's true - |
905dbe2
to
df55910
Compare
df55910
to
76fe424
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.
I had to admit I'm somewhat surprised that's the only test changes you need, but looks good.
2b86ba7
to
8b5502b
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.
Aside from the one clarifying change I suggested and the two comment nits, looks good!
@@ -148,6 +148,16 @@ pub enum ChannelMonitorUpdateErr { | |||
#[derive(Debug)] | |||
pub struct MonitorUpdateError(pub &'static str); | |||
|
|||
/// An event to be processed by the ChannelManager. | |||
#[derive(PartialEq)] | |||
pub enum MonitorEvent { |
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.
Out of curiosity, how do we decide which events are monitor events? For example, why is HTLCEvent for claiming one, but forwarding offered HTLCs isn'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.
In this context, its basically "a thing which we detected on-chain which has an impact on our understanding of a channel's state" (ie, basically, "channel has been closed on chain" or "transaction on-chain resolved an HTLC which was outstanding when we went on chain").
0 => MonitorEvent::HTLCEvent(Readable::read(reader)?), | ||
1 => MonitorEvent::CommitmentTxBroadcasted(funding_info.0), | ||
_ => return Err(DecodeError::InvalidValue) | ||
}; |
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 day we'll have versioning for reads lol :)
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.
Indeed lol
To do this, we replace get_and_clear_pending_htlcs_updated with get_and_clear_pending_monitor_events, and which still transmits HTLCUpdates as before, but now also transmits a new MonitorEvent::CommitmentTxBroadcasted event when a channel's commitment transaction is broadcasted.
84ea158
to
28d9036
Compare
if let Some(commitment_tx) = self.onchain_tx_handler.get_fully_signed_local_tx(&self.funding_redeemscript) { | ||
self.local_tx_signed = true; |
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 this is breaking one of the property of our distributed watchtower infrastructure as documented here : https://github.com/rust-bitcoin/rust-lightning/blob/3defcc896266f3d67848ce28981a756e971a3f0c/lightning/src/ln/channelmonitor.rs#L1174
AFAICT, by adding logs flag is true beyond updating local view with latest local state.
I'll fix it and add coverage for this.
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.
Logs flag? Ok I think I see what you mean though, thanks for catching this!
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're discussing on IRC still, but I don't think this change is correct - we should refuse to accept updates after we've signed a local tx irrespective of why we signed it.
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.
In service to the larger refactor of removing the Channel's reference
to its ChannelMonitor.
This also allows us to remove the Channel's
channel_monitor()
function. Next we can remove all of the Channel's logic for keeping its channel monitor up to date, as well as theupdate_monitor_ooo
logic inChannelMonitor
.Partially resolvesCloses #657