-
Notifications
You must be signed in to change notification settings - Fork 411
Stop persisting background shutdown monitor updates #2287
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
Merged
TheBlueMatt
merged 2 commits into
lightningdevkit:main
from
TheBlueMatt:2023-05-no-background-event-dup-persist
May 10, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -501,9 +501,11 @@ struct ClaimablePayments { | |||||
/// for some reason. They are handled in timer_tick_occurred, so may be processed with | ||||||
/// quite some time lag. | ||||||
enum BackgroundEvent { | ||||||
/// Handle a ChannelMonitorUpdate that closes a channel, broadcasting its current latest holder | ||||||
/// commitment transaction. | ||||||
ClosingMonitorUpdate((OutPoint, ChannelMonitorUpdate)), | ||||||
/// Handle a ChannelMonitorUpdate | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Twice? I can only fix it once, tho :) |
||||||
/// | ||||||
/// Note that any such events are lost on shutdown, so in general they must be updates which | ||||||
/// are regenerated on startup. | ||||||
MonitorUpdateRegeneratedOnStartup((OutPoint, ChannelMonitorUpdate)), | ||||||
} | ||||||
|
||||||
#[derive(Debug)] | ||||||
|
@@ -3774,7 +3776,7 @@ where | |||||
|
||||||
for event in background_events.drain(..) { | ||||||
match event { | ||||||
BackgroundEvent::ClosingMonitorUpdate((funding_txo, update)) => { | ||||||
BackgroundEvent::MonitorUpdateRegeneratedOnStartup((funding_txo, update)) => { | ||||||
// The channel has already been closed, so no use bothering to care about the | ||||||
// monitor updating completing. | ||||||
let _ = self.chain_monitor.update_channel(funding_txo, &update); | ||||||
|
@@ -5694,7 +5696,7 @@ where | |||||
if let ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast } = update.updates[0] { | ||||||
assert!(should_broadcast); | ||||||
} else { unreachable!(); } | ||||||
self.pending_background_events.lock().unwrap().push(BackgroundEvent::ClosingMonitorUpdate((funding_txo, update))); | ||||||
self.pending_background_events.lock().unwrap().push(BackgroundEvent::MonitorUpdateRegeneratedOnStartup((funding_txo, update))); | ||||||
} | ||||||
self.finish_force_close_channel(failure); | ||||||
} | ||||||
|
@@ -7448,17 +7450,12 @@ where | |||||
} | ||||||
} | ||||||
|
||||||
let background_events = self.pending_background_events.lock().unwrap(); | ||||||
(background_events.len() as u64).write(writer)?; | ||||||
for event in background_events.iter() { | ||||||
match event { | ||||||
BackgroundEvent::ClosingMonitorUpdate((funding_txo, monitor_update)) => { | ||||||
0u8.write(writer)?; | ||||||
funding_txo.write(writer)?; | ||||||
monitor_update.write(writer)?; | ||||||
}, | ||||||
} | ||||||
} | ||||||
// LDK versions prior to 0.0.116 wrote the `pending_background_events` | ||||||
// `MonitorUpdateRegeneratedOnStartup`s here, however there was never a reason to do so - | ||||||
// the closing monitor updates were always effectively replayed on startup (either directly | ||||||
// by calling `broadcast_latest_holder_commitment_txn` on a `ChannelMonitor` during | ||||||
// deserialization or, in 0.0.115, by regenerating the monitor update itself). | ||||||
0u64.write(writer)?; | ||||||
|
||||||
// Prior to 0.0.111 we tracked node_announcement serials here, however that now happens in | ||||||
// `PeerManager`, and thus we simply write the `highest_seen_timestamp` twice, which is | ||||||
|
@@ -7773,7 +7770,7 @@ where | |||||
log_bytes!(channel.channel_id()), monitor.get_latest_update_id(), channel.get_latest_monitor_update_id()); | ||||||
let (monitor_update, mut new_failed_htlcs) = channel.force_shutdown(true); | ||||||
if let Some(monitor_update) = monitor_update { | ||||||
pending_background_events.push(BackgroundEvent::ClosingMonitorUpdate(monitor_update)); | ||||||
pending_background_events.push(BackgroundEvent::MonitorUpdateRegeneratedOnStartup(monitor_update)); | ||||||
} | ||||||
failed_htlcs.append(&mut new_failed_htlcs); | ||||||
channel_closures.push_back((events::Event::ChannelClosed { | ||||||
|
@@ -7848,7 +7845,7 @@ where | |||||
update_id: CLOSED_CHANNEL_UPDATE_ID, | ||||||
updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast: true }], | ||||||
}; | ||||||
pending_background_events.push(BackgroundEvent::ClosingMonitorUpdate((*funding_txo, monitor_update))); | ||||||
pending_background_events.push(BackgroundEvent::MonitorUpdateRegeneratedOnStartup((*funding_txo, monitor_update))); | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -7905,13 +7902,11 @@ where | |||||
for _ in 0..background_event_count { | ||||||
match <u8 as Readable>::read(reader)? { | ||||||
0 => { | ||||||
let (funding_txo, monitor_update): (OutPoint, ChannelMonitorUpdate) = (Readable::read(reader)?, Readable::read(reader)?); | ||||||
if pending_background_events.iter().find(|e| { | ||||||
let BackgroundEvent::ClosingMonitorUpdate((pending_funding_txo, pending_monitor_update)) = e; | ||||||
*pending_funding_txo == funding_txo && *pending_monitor_update == monitor_update | ||||||
}).is_none() { | ||||||
pending_background_events.push(BackgroundEvent::ClosingMonitorUpdate((funding_txo, monitor_update))); | ||||||
} | ||||||
// LDK versions prior to 0.0.116 wrote pending `MonitorUpdateRegeneratedOnStartup`s here, | ||||||
// however we really don't (and never did) need them - we regenerate all | ||||||
// on-startup monitor updates. | ||||||
let _: OutPoint = Readable::read(reader)?; | ||||||
let _: ChannelMonitorUpdate = Readable::read(reader)?; | ||||||
} | ||||||
_ => return Err(DecodeError::InvalidValue), | ||||||
} | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.