Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lightning/src/chain/chainmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub trait Persist<ChannelSigner: EcdsaChannelSigner> {
/// [`Writeable::write`]: crate::util::ser::Writeable::write
fn update_persisted_channel(
&self, monitor_name: MonitorName, monitor_update: Option<&ChannelMonitorUpdate>,
monitor: &ChannelMonitor<ChannelSigner>,
encoded_channel: Option<&[u8]>, monitor: &ChannelMonitor<ChannelSigner>,
) -> ChannelMonitorUpdateStatus;
/// Prevents the channel monitor from being loaded on startup.
///
Expand Down Expand Up @@ -320,6 +320,7 @@ where

fn update_persisted_channel(
&self, monitor_name: MonitorName, monitor_update: Option<&ChannelMonitorUpdate>,
encoded_channel: Option<&[u8]>,
monitor: &ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>,
) -> ChannelMonitorUpdateStatus {
self.persister.spawn_async_update_persisted_channel(monitor_name, monitor_update, monitor);
Expand Down Expand Up @@ -579,8 +580,12 @@ where
// `ChannelMonitorUpdate` after a channel persist for a channel with the same
// `latest_update_id`.
let _pending_monitor_updates = monitor_state.pending_monitor_updates.lock().unwrap();
match self.persister.update_persisted_channel(monitor.persistence_key(), None, monitor)
{
match self.persister.update_persisted_channel(
monitor.persistence_key(),
None,
None,
monitor,
) {
ChannelMonitorUpdateStatus::Completed => log_trace!(
logger,
"Finished syncing Channel Monitor for channel {} for block-data",
Expand Down Expand Up @@ -944,6 +949,7 @@ where
self.persister.update_persisted_channel(
monitor_holder.monitor.persistence_key(),
None,
None,
&monitor_holder.monitor,
);
}
Expand Down Expand Up @@ -1392,7 +1398,7 @@ where
}

fn update_channel(
&self, channel_id: ChannelId, update: &ChannelMonitorUpdate,
&self, channel_id: ChannelId, update: &ChannelMonitorUpdate, encoded_channel: Option<&[u8]>,
) -> ChannelMonitorUpdateStatus {
// `ChannelMonitorUpdate`'s `channel_id` is `None` prior to 0.0.121 and all channels in those
// versions are V1-established. For 0.0.121+ the `channel_id` fields is always `Some`.
Expand Down Expand Up @@ -1445,12 +1451,14 @@ where
self.persister.update_persisted_channel(
monitor.persistence_key(),
None,
encoded_channel,
monitor,
)
} else {
self.persister.update_persisted_channel(
monitor.persistence_key(),
Some(update),
encoded_channel,
monitor,
)
};
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ pub trait Watch<ChannelSigner: EcdsaChannelSigner> {
///
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
fn update_channel(
&self, channel_id: ChannelId, update: &ChannelMonitorUpdate,
&self, channel_id: ChannelId, update: &ChannelMonitorUpdate, encoded_channel: Option<&[u8]>,
) -> ChannelMonitorUpdateStatus;

/// Returns any monitor events since the last call. Subsequent calls must only return new
Expand Down
7 changes: 2 additions & 5 deletions lightning/src/ln/async_payments_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2167,8 +2167,7 @@ fn offer_cache_round_trip_ser() {
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let payee_node_deserialized;
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
let chan_id =
create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0).0.channel_id;
create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0);
let server = &nodes[0];
let recipient = &nodes[1];

Expand All @@ -2188,12 +2187,10 @@ fn offer_cache_round_trip_ser() {
// offers.
let cached_offers_pre_ser = recipient.node.flow.test_get_async_receive_offers();
let config = test_default_channel_config();
let serialized_monitor = get_monitor!(recipient, chan_id).encode();
reload_node!(
reload_node_and_monitors!(
nodes[1],
config,
recipient.node.encode(),
&[&serialized_monitor],
persister,
chain_monitor,
payee_node_deserialized
Expand Down
12 changes: 6 additions & 6 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn test_monitor_and_persister_update_fail() {
// Check that the persister returns InProgress (and will never actually complete)
// as the monitor update errors.
if let ChannelMonitorUpdateStatus::InProgress =
chain_mon.chain_monitor.update_channel(chan.2, &update)
chain_mon.chain_monitor.update_channel(chan.2, &update, None)
{
} else {
panic!("Expected monitor paused");
Expand All @@ -158,7 +158,7 @@ fn test_monitor_and_persister_update_fail() {
// Apply the monitor update to the original ChainMonitor, ensuring the
// ChannelManager and ChannelMonitor aren't out of sync.
assert_eq!(
nodes[0].chain_monitor.update_channel(chan.2, &update),
nodes[0].chain_monitor.update_channel(chan.2, &update, None),
ChannelMonitorUpdateStatus::Completed
);
} else {
Expand Down Expand Up @@ -4961,10 +4961,10 @@ fn native_async_persist() {

// Now test two async `ChannelMonitorUpdate`s in flight at once, completing them in-order but
// separately.
let update_status = async_chain_monitor.update_channel(chan_id, &updates[0]);
let update_status = async_chain_monitor.update_channel(chan_id, &updates[0], None);
assert_eq!(update_status, ChannelMonitorUpdateStatus::InProgress);

let update_status = async_chain_monitor.update_channel(chan_id, &updates[1]);
let update_status = async_chain_monitor.update_channel(chan_id, &updates[1], None);
assert_eq!(update_status, ChannelMonitorUpdateStatus::InProgress);

persist_futures.poll_futures();
Expand Down Expand Up @@ -5010,10 +5010,10 @@ fn native_async_persist() {
// Finally, test two async `ChanelMonitorUpdate`s in flight at once, completing them
// out-of-order and ensuring that no `MonitorEvent::Completed` is generated until they are both
// completed (and that it marks both as completed when it is generated).
let update_status = async_chain_monitor.update_channel(chan_id, &updates[2]);
let update_status = async_chain_monitor.update_channel(chan_id, &updates[2], None);
assert_eq!(update_status, ChannelMonitorUpdateStatus::InProgress);

let update_status = async_chain_monitor.update_channel(chan_id, &updates[3]);
let update_status = async_chain_monitor.update_channel(chan_id, &updates[3], None);
assert_eq!(update_status, ChannelMonitorUpdateStatus::InProgress);

persist_futures.poll_futures();
Expand Down
Loading