Skip to content

Commit dd9d6db

Browse files
committed
store channel with monitor
1 parent c7e5c70 commit dd9d6db

16 files changed

+334
-207
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub trait Persist<ChannelSigner: EcdsaChannelSigner> {
180180
/// [`Writeable::write`]: crate::util::ser::Writeable::write
181181
fn update_persisted_channel(
182182
&self, monitor_name: MonitorName, monitor_update: Option<&ChannelMonitorUpdate>,
183-
monitor: &ChannelMonitor<ChannelSigner>,
183+
encoded_channel: Option<&[u8]>, monitor: &ChannelMonitor<ChannelSigner>,
184184
) -> ChannelMonitorUpdateStatus;
185185
/// Prevents the channel monitor from being loaded on startup.
186186
///
@@ -320,6 +320,7 @@ where
320320

321321
fn update_persisted_channel(
322322
&self, monitor_name: MonitorName, monitor_update: Option<&ChannelMonitorUpdate>,
323+
encoded_channel: Option<&[u8]>,
323324
monitor: &ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>,
324325
) -> ChannelMonitorUpdateStatus {
325326
self.persister.spawn_async_update_persisted_channel(monitor_name, monitor_update, monitor);
@@ -579,8 +580,12 @@ where
579580
// `ChannelMonitorUpdate` after a channel persist for a channel with the same
580581
// `latest_update_id`.
581582
let _pending_monitor_updates = monitor_state.pending_monitor_updates.lock().unwrap();
582-
match self.persister.update_persisted_channel(monitor.persistence_key(), None, monitor)
583-
{
583+
match self.persister.update_persisted_channel(
584+
monitor.persistence_key(),
585+
None,
586+
None,
587+
monitor,
588+
) {
584589
ChannelMonitorUpdateStatus::Completed => log_trace!(
585590
logger,
586591
"Finished syncing Channel Monitor for channel {} for block-data",
@@ -944,6 +949,7 @@ where
944949
self.persister.update_persisted_channel(
945950
monitor_holder.monitor.persistence_key(),
946951
None,
952+
None,
947953
&monitor_holder.monitor,
948954
);
949955
}
@@ -1392,7 +1398,7 @@ where
13921398
}
13931399

13941400
fn update_channel(
1395-
&self, channel_id: ChannelId, update: &ChannelMonitorUpdate,
1401+
&self, channel_id: ChannelId, update: &ChannelMonitorUpdate, encoded_channel: Option<&[u8]>,
13961402
) -> ChannelMonitorUpdateStatus {
13971403
// `ChannelMonitorUpdate`'s `channel_id` is `None` prior to 0.0.121 and all channels in those
13981404
// versions are V1-established. For 0.0.121+ the `channel_id` fields is always `Some`.
@@ -1445,12 +1451,14 @@ where
14451451
self.persister.update_persisted_channel(
14461452
monitor.persistence_key(),
14471453
None,
1454+
encoded_channel,
14481455
monitor,
14491456
)
14501457
} else {
14511458
self.persister.update_persisted_channel(
14521459
monitor.persistence_key(),
14531460
Some(update),
1461+
encoded_channel,
14541462
monitor,
14551463
)
14561464
};

lightning/src/chain/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ pub trait Watch<ChannelSigner: EcdsaChannelSigner> {
326326
///
327327
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
328328
fn update_channel(
329-
&self, channel_id: ChannelId, update: &ChannelMonitorUpdate,
329+
&self, channel_id: ChannelId, update: &ChannelMonitorUpdate, encoded_channel: Option<&[u8]>,
330330
) -> ChannelMonitorUpdateStatus;
331331

332332
/// Returns any monitor events since the last call. Subsequent calls must only return new

lightning/src/ln/async_payments_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2188,7 +2188,7 @@ fn offer_cache_round_trip_ser() {
21882188
// offers.
21892189
let cached_offers_pre_ser = recipient.node.flow.test_get_async_receive_offers();
21902190
let config = test_default_channel_config();
2191-
let serialized_monitor = get_monitor!(recipient, chan_id).encode();
2191+
let serialized_monitor = get_monitor_and_channel(recipient, chan_id);
21922192
reload_node!(
21932193
nodes[1],
21942194
config,

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ fn test_monitor_and_persister_update_fail() {
143143
// Check that the persister returns InProgress (and will never actually complete)
144144
// as the monitor update errors.
145145
if let ChannelMonitorUpdateStatus::InProgress =
146-
chain_mon.chain_monitor.update_channel(chan.2, &update)
146+
chain_mon.chain_monitor.update_channel(chan.2, &update, None)
147147
{
148148
} else {
149149
panic!("Expected monitor paused");
@@ -158,7 +158,7 @@ fn test_monitor_and_persister_update_fail() {
158158
// Apply the monitor update to the original ChainMonitor, ensuring the
159159
// ChannelManager and ChannelMonitor aren't out of sync.
160160
assert_eq!(
161-
nodes[0].chain_monitor.update_channel(chan.2, &update),
161+
nodes[0].chain_monitor.update_channel(chan.2, &update, None),
162162
ChannelMonitorUpdateStatus::Completed
163163
);
164164
} else {
@@ -2702,7 +2702,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
27022702
nodes[0].node.send_payment_with_route(route, payment_hash_2, onion_2, id_2).unwrap();
27032703
check_added_monitors!(nodes[0], 0);
27042704

2705-
let chan_0_monitor_serialized = get_monitor!(nodes[0], chan_id).encode();
2705+
let chan_0_monitor_serialized = get_monitor_and_channel(&nodes[0], chan_id);
27062706
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
27072707
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
27082708
nodes[0].node.claim_funds(payment_preimage_0);
@@ -2723,7 +2723,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
27232723
// deserializing a ChannelManager in this state causes an assertion failure.
27242724
if reload_a {
27252725
let node_ser = nodes[0].node.encode();
2726-
let mons = &[&chan_0_monitor_serialized[..]];
2726+
let mons = &[&chan_0_monitor_serialized];
27272727
reload_node!(nodes[0], &node_ser, mons, persister, new_chain_mon, nodes_0_reload);
27282728
persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
27292729
persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
@@ -3503,10 +3503,10 @@ fn do_test_blocked_chan_preimage_release(completion_mode: BlockedUpdateComplMode
35033503
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
35043504
if completion_mode == BlockedUpdateComplMode::AtReload {
35053505
let node_ser = nodes[1].node.encode();
3506-
let chan_mon_0 = get_monitor!(nodes[1], chan_id_1).encode();
3507-
let chan_mon_1 = get_monitor!(nodes[1], chan_id_2).encode();
3506+
let chan_mon_0 = get_monitor_and_channel(&nodes[1], chan_id_1);
3507+
let chan_mon_1 = get_monitor_and_channel(&nodes[1], chan_id_2);
35083508

3509-
let mons = &[&chan_mon_0[..], &chan_mon_1[..]];
3509+
let mons = &[&chan_mon_0, &chan_mon_1];
35103510
reload_node!(nodes[1], &node_ser, mons, persister, new_chain_mon, nodes_1_reload);
35113511

35123512
nodes[0].node.peer_disconnected(node_b_id);
@@ -3617,7 +3617,7 @@ fn do_test_inverted_mon_completion_order(
36173617
let (payment_preimage, payment_hash, ..) =
36183618
route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 100_000);
36193619

3620-
let mon_ab = get_monitor!(nodes[1], chan_id_ab).encode();
3620+
let mon_ab = get_monitor_and_channel(&nodes[1], chan_id_ab);
36213621
let mut manager_b = Vec::new();
36223622
if !with_latest_manager {
36233623
manager_b = nodes[1].node.encode();
@@ -3663,7 +3663,7 @@ fn do_test_inverted_mon_completion_order(
36633663
manager_b = nodes[1].node.encode();
36643664
}
36653665

3666-
let mon_bc = get_monitor!(nodes[1], chan_id_bc).encode();
3666+
let mon_bc = get_monitor_and_channel(&nodes[1], chan_id_bc);
36673667
reload_node!(nodes[1], &manager_b, &[&mon_ab, &mon_bc], persister, chain_mon, node_b_reload);
36683668

36693669
nodes[0].node.peer_disconnected(node_b_id);
@@ -3809,7 +3809,7 @@ fn do_test_durable_preimages_on_closed_channel(
38093809
let (payment_preimage, payment_hash, ..) =
38103810
route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1_000_000);
38113811

3812-
let mon_ab = get_monitor!(nodes[1], chan_id_ab).encode();
3812+
let mon_ab = get_monitor_and_channel(&nodes[1], chan_id_ab);
38133813

38143814
nodes[2].node.claim_funds(payment_preimage);
38153815
check_added_monitors(&nodes[2], 1);
@@ -3831,7 +3831,7 @@ fn do_test_durable_preimages_on_closed_channel(
38313831
check_added_monitors(&nodes[1], 1);
38323832
let _ = get_revoke_commit_msgs!(nodes[1], node_c_id);
38333833

3834-
let mon_bc = get_monitor!(nodes[1], chan_id_bc).encode();
3834+
let mon_bc = get_monitor_and_channel(&nodes[1], chan_id_bc);
38353835

38363836
if close_chans_before_reload {
38373837
if !close_only_a {
@@ -4036,8 +4036,8 @@ fn do_test_reload_mon_update_completion_actions(close_during_reload: bool) {
40364036
// Finally, reload node B and check that after we call `process_pending_events` once we realize
40374037
// we've completed the A<->B preimage-including monitor update and so can release the B<->C
40384038
// preimage-removing monitor update.
4039-
let mon_ab = get_monitor!(nodes[1], chan_id_ab).encode();
4040-
let mon_bc = get_monitor!(nodes[1], chan_id_bc).encode();
4039+
let mon_ab = get_monitor_and_channel(&nodes[1], chan_id_ab);
4040+
let mon_bc = get_monitor_and_channel(&nodes[1], chan_id_bc);
40414041
let manager_b = nodes[1].node.encode();
40424042
reload_node!(nodes[1], &manager_b, &[&mon_ab, &mon_bc], persister, chain_mon, node_b_reload);
40434043

@@ -4271,7 +4271,7 @@ fn do_test_partial_claim_mon_update_compl_actions(reload_a: bool, reload_b: bool
42714271
send_along_route_with_secret(&nodes[0], route, paths, 200_000, payment_hash, payment_secret);
42724272

42734273
// Store the monitor for channel 4 without the preimage to use on reload
4274-
let chan_4_monitor_serialized = get_monitor!(nodes[3], chan_4_id).encode();
4274+
let chan_4_monitor_serialized = get_monitor_and_channel(&nodes[3], chan_4_id);
42754275
// Claim along both paths, but only complete one of the two monitor updates.
42764276
chanmon_cfgs[3].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
42774277
chanmon_cfgs[3].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
@@ -4312,8 +4312,8 @@ fn do_test_partial_claim_mon_update_compl_actions(reload_a: bool, reload_b: bool
43124312
// After a reload (with the monitor not yet fully updated), the RAA should still be blocked
43134313
// waiting until the monitor update completes.
43144314
let node_ser = nodes[3].node.encode();
4315-
let chan_3_monitor_serialized = get_monitor!(nodes[3], chan_3_id).encode();
4316-
let mons = &[&chan_3_monitor_serialized[..], &chan_4_monitor_serialized[..]];
4315+
let chan_3_monitor_serialized = get_monitor_and_channel(&nodes[3], chan_3_id);
4316+
let mons = &[&chan_3_monitor_serialized, &chan_4_monitor_serialized];
43174317
reload_node!(nodes[3], &node_ser, mons, persister, new_chain_mon, nodes_3_reload);
43184318
// The final update to channel 4 should be replayed.
43194319
persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
@@ -4391,9 +4391,9 @@ fn do_test_partial_claim_mon_update_compl_actions(reload_a: bool, reload_b: bool
43914391
// reload once the HTLCs for the first payment have been removed and the monitors
43924392
// completed.
43934393
let node_ser = nodes[3].node.encode();
4394-
let chan_3_monitor_serialized = get_monitor!(nodes[3], chan_3_id).encode();
4395-
let chan_4_monitor_serialized = get_monitor!(nodes[3], chan_4_id).encode();
4396-
let mons = &[&chan_3_monitor_serialized[..], &chan_4_monitor_serialized[..]];
4394+
let chan_3_monitor_serialized = get_monitor_and_channel(&nodes[3], chan_3_id);
4395+
let chan_4_monitor_serialized = get_monitor_and_channel(&nodes[3], chan_4_id);
4396+
let mons = &[&chan_3_monitor_serialized, &chan_4_monitor_serialized];
43974397
reload_node!(nodes[3], &node_ser, mons, persister_2, new_chain_mon_2, nodes_3_reload_2);
43984398
check_added_monitors(&nodes[3], 0);
43994399

@@ -4418,9 +4418,9 @@ fn do_test_partial_claim_mon_update_compl_actions(reload_a: bool, reload_b: bool
44184418
// reload once the HTLCs for the first payment have been removed and the monitors
44194419
// completed, even if only one of the two monitors still knows about the first payment.
44204420
let node_ser = nodes[3].node.encode();
4421-
let chan_3_monitor_serialized = get_monitor!(nodes[3], chan_3_id).encode();
4422-
let chan_4_monitor_serialized = get_monitor!(nodes[3], chan_4_id).encode();
4423-
let mons = &[&chan_3_monitor_serialized[..], &chan_4_monitor_serialized[..]];
4421+
let chan_3_monitor_serialized = get_monitor_and_channel(&nodes[3], chan_3_id);
4422+
let chan_4_monitor_serialized = get_monitor_and_channel(&nodes[3], chan_4_id);
4423+
let mons = &[&chan_3_monitor_serialized, &chan_4_monitor_serialized];
44244424
reload_node!(nodes[3], &node_ser, mons, persister_3, new_chain_mon_3, nodes_3_reload_3);
44254425
check_added_monitors(&nodes[3], 0);
44264426

@@ -4961,10 +4961,10 @@ fn native_async_persist() {
49614961

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

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

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

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

50195019
persist_futures.poll_futures();

0 commit comments

Comments
 (0)