Skip to content

Commit 1adfd7d

Browse files
committed
Load chan mgr from monitors
1 parent d4d0879 commit 1adfd7d

15 files changed

+123
-2
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,14 +2389,17 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23892389
self.inner.lock().unwrap().sign_to_local_justice_tx(justice_tx, input_idx, value, commitment_number)
23902390
}
23912391

2392+
#[cfg(not(feature = "safe_channels"))]
23922393
pub(crate) fn get_min_seen_secret(&self) -> u64 {
23932394
self.inner.lock().unwrap().get_min_seen_secret()
23942395
}
23952396

2397+
#[cfg(not(feature = "safe_channels"))]
23962398
pub(crate) fn get_cur_counterparty_commitment_number(&self) -> u64 {
23972399
self.inner.lock().unwrap().get_cur_counterparty_commitment_number()
23982400
}
23992401

2402+
#[cfg(not(feature = "safe_channels"))]
24002403
pub(crate) fn get_cur_holder_commitment_number(&self) -> u64 {
24012404
self.inner.lock().unwrap().get_cur_holder_commitment_number()
24022405
}
@@ -7180,6 +7183,7 @@ mod tests {
71807183
check_added_monitors(&nodes[1], 1);
71817184
}
71827185

7186+
#[cfg(not(feature = "safe_channels"))]
71837187
#[test]
71847188
fn test_funding_spend_refuses_updates() {
71857189
do_test_funding_spend_refuses_updates(true);

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2840,6 +2840,8 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
28402840
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_1);
28412841
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2);
28422842
}
2843+
2844+
#[cfg(not(feature = "safe_channels"))]
28432845
#[test]
28442846
fn channel_holding_cell_serialize() {
28452847
do_channel_holding_cell_serialize(true, true);
@@ -3313,6 +3315,7 @@ fn do_test_outbound_reload_without_init_mon(use_0conf: bool) {
33133315
assert!(nodes[0].node.list_channels().is_empty());
33143316
}
33153317

3318+
#[cfg(not(feature = "safe_channels"))]
33163319
#[test]
33173320
fn test_outbound_reload_without_init_mon() {
33183321
do_test_outbound_reload_without_init_mon(true);
@@ -3421,6 +3424,7 @@ fn do_test_inbound_reload_without_init_mon(use_0conf: bool, lock_commitment: boo
34213424
assert!(nodes[1].node.list_channels().is_empty());
34223425
}
34233426

3427+
#[cfg(not(feature = "safe_channels"))]
34243428
#[test]
34253429
fn test_inbound_reload_without_init_mon() {
34263430
do_test_inbound_reload_without_init_mon(true, true);
@@ -3570,6 +3574,7 @@ fn do_test_blocked_chan_preimage_release(completion_mode: BlockedUpdateComplMode
35703574
expect_payment_sent(&nodes[2], payment_preimage_2, None, true, true);
35713575
}
35723576

3577+
#[cfg(not(feature = "safe_channels"))]
35733578
#[test]
35743579
fn test_blocked_chan_preimage_release() {
35753580
do_test_blocked_chan_preimage_release(BlockedUpdateComplMode::AtReload);
@@ -3760,6 +3765,7 @@ fn do_test_inverted_mon_completion_order(
37603765
expect_payment_sent(&nodes[0], payment_preimage, None, true, true);
37613766
}
37623767

3768+
#[cfg(not(feature = "safe_channels"))]
37633769
#[test]
37643770
fn test_inverted_mon_completion_order() {
37653771
do_test_inverted_mon_completion_order(true, true);
@@ -3962,6 +3968,7 @@ fn do_test_durable_preimages_on_closed_channel(
39623968
}
39633969
}
39643970

3971+
#[cfg(not(feature = "safe_channels"))]
39653972
#[test]
39663973
fn test_durable_preimages_on_closed_channel() {
39673974
do_test_durable_preimages_on_closed_channel(true, true, true);
@@ -4086,6 +4093,7 @@ fn do_test_reload_mon_update_completion_actions(close_during_reload: bool) {
40864093
send_payment(&nodes[1], &[&nodes[2]], 100_000);
40874094
}
40884095

4096+
#[cfg(not(feature = "safe_channels"))]
40894097
#[test]
40904098
fn test_reload_mon_update_completion_actions() {
40914099
do_test_reload_mon_update_completion_actions(true);
@@ -4454,6 +4462,7 @@ fn do_test_partial_claim_mon_update_compl_actions(reload_a: bool, reload_b: bool
44544462
assert!(!get_monitor!(nodes[3], chan_4_id).get_stored_preimages().contains_key(&payment_hash));
44554463
}
44564464

4465+
#[cfg(not(feature = "safe_channels"))]
44574466
#[test]
44584467
fn test_partial_claim_mon_update_compl_actions() {
44594468
do_test_partial_claim_mon_update_compl_actions(true, true);

lightning/src/ln/channel.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,6 +2423,7 @@ impl FundingScope {
24232423
self.channel_transaction_parameters.channel_value_satoshis
24242424
}
24252425

2426+
#[cfg(not(feature = "safe_channels"))]
24262427
pub(crate) fn get_value_to_self_msat(&self) -> u64 {
24272428
self.value_to_self_msat
24282429
}
@@ -10853,10 +10854,12 @@ where
1085310854
.try_for_each(|funding| self.context.can_accept_incoming_htlc(funding, dust_exposure_limiting_feerate, &logger))
1085410855
}
1085510856

10857+
#[cfg(not(feature = "safe_channels"))]
1085610858
pub fn get_cur_holder_commitment_transaction_number(&self) -> u64 {
1085710859
self.holder_commitment_point.current_transaction_number()
1085810860
}
1085910861

10862+
#[cfg(not(feature = "safe_channels"))]
1086010863
pub fn get_cur_counterparty_commitment_transaction_number(&self) -> u64 {
1086110864
self.context.counterparty_next_commitment_transaction_number + 1
1086210865
- if self.context.channel_state.is_awaiting_remote_revoke() { 1 } else { 0 }
@@ -10970,6 +10973,7 @@ where
1097010973
/// transaction. If the channel is inbound, this implies simply that the channel has not
1097110974
/// advanced state.
1097210975
#[rustfmt::skip]
10976+
#[cfg(not(feature = "safe_channels"))]
1097310977
pub fn is_awaiting_initial_mon_persist(&self) -> bool {
1097410978
if !self.is_awaiting_monitor_update() { return false; }
1097510979
if matches!(

lightning/src/ln/channel_open_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,7 @@ pub fn test_batch_channel_open() {
20952095
)));
20962096
}
20972097

2098+
#[cfg(not(feature = "safe_channels"))]
20982099
#[xtest(feature = "_externalize_tests")]
20992100
pub fn test_close_in_funding_batch() {
21002101
// This test ensures that if one of the channels
@@ -2183,6 +2184,7 @@ pub fn test_close_in_funding_batch() {
21832184
assert!(nodes[0].node.list_channels().is_empty());
21842185
}
21852186

2187+
#[cfg(not(feature = "safe_channels"))]
21862188
#[xtest(feature = "_externalize_tests")]
21872189
pub fn test_batch_funding_close_after_funding_signed() {
21882190
let chanmon_cfgs = create_chanmon_cfgs(3);

lightning/src/ln/channelmanager.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16769,6 +16769,8 @@ where
1676916769
let mut short_to_chan_info = hash_map_with_capacity(cmp::min(channel_count as usize, 128));
1677016770
let mut channel_closures = VecDeque::new();
1677116771
let mut close_background_events = Vec::new();
16772+
16773+
#[cfg(not(feature = "safe_channels"))]
1677216774
for _ in 0..channel_count {
1677316775
let mut channel: FundedChannel<SP> = FundedChannel::read(
1677416776
reader,
@@ -16968,6 +16970,74 @@ where
1696816970
}
1696916971
}
1697016972

16973+
// Suppress unused mutable variable warning when safe_channels is enabled.
16974+
#[cfg(feature = "safe_channels")]
16975+
let _ = &mut args;
16976+
16977+
// Discard channel manager versions of channels.
16978+
#[cfg(feature = "safe_channels")]
16979+
for _ in 0..channel_count {
16980+
_ = FundedChannel::read(
16981+
reader,
16982+
(
16983+
&args.entropy_source,
16984+
&args.signer_provider,
16985+
&provided_channel_type_features(&args.config),
16986+
),
16987+
)?;
16988+
}
16989+
16990+
// Decode channels from monitors.
16991+
#[cfg(feature = "safe_channels")]
16992+
for (_, monitor) in args.channel_monitors.iter() {
16993+
let opt_encoded_channel = monitor.get_encoded_channel();
16994+
if opt_encoded_channel.is_none() {
16995+
// Monitor still exists, but there is no more channel state. This can happen after channel shut down.
16996+
continue;
16997+
}
16998+
let encoded_channel = opt_encoded_channel.unwrap();
16999+
let encoded_channel_reader = &mut &encoded_channel[..];
17000+
let mut channel: FundedChannel<SP> = FundedChannel::read(
17001+
encoded_channel_reader,
17002+
(
17003+
&args.entropy_source,
17004+
&args.signer_provider,
17005+
&provided_channel_type_features(&args.config),
17006+
),
17007+
)?;
17008+
let logger = WithChannelContext::from(&args.logger, &channel.context, None);
17009+
let channel_id = channel.context.channel_id();
17010+
channel_id_set.insert(channel_id);
17011+
17012+
channel.on_startup_drop_completed_blocked_mon_updates_through(
17013+
&logger,
17014+
monitor.get_latest_update_id(),
17015+
);
17016+
log_info!(logger, "Successfully loaded at update_id {} against monitor at update id {} with {} blocked updates",
17017+
channel.context.get_latest_monitor_update_id(),
17018+
monitor.get_latest_update_id(), channel.blocked_monitor_updates_pending());
17019+
if let Some(short_channel_id) = channel.funding.get_short_channel_id() {
17020+
short_to_chan_info.insert(
17021+
short_channel_id,
17022+
(channel.context.get_counterparty_node_id(), channel.context.channel_id()),
17023+
);
17024+
}
17025+
17026+
for short_channel_id in channel.context.historical_scids() {
17027+
let cp_id = channel.context.get_counterparty_node_id();
17028+
let chan_id = channel.context.channel_id();
17029+
short_to_chan_info.insert(*short_channel_id, (cp_id, chan_id));
17030+
}
17031+
17032+
per_peer_state
17033+
.entry(channel.context.get_counterparty_node_id())
17034+
.or_insert_with(|| Mutex::new(empty_peer_state()))
17035+
.get_mut()
17036+
.unwrap()
17037+
.channel_by_id
17038+
.insert(channel.context.channel_id(), Channel::from(channel));
17039+
}
17040+
1697117041
for (channel_id, monitor) in args.channel_monitors.iter() {
1697217042
if !channel_id_set.contains(channel_id) {
1697317043
let mut should_queue_fc_update = false;

lightning/src/ln/functional_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9894,6 +9894,7 @@ fn do_test_multi_post_event_actions(do_reload: bool) {
98949894
check_added_monitors(&nodes[0], 3);
98959895
}
98969896

9897+
#[cfg(not(feature = "safe_channels"))]
98979898
#[xtest(feature = "_externalize_tests")]
98989899
pub fn test_multi_post_event_actions() {
98999900
do_test_multi_post_event_actions(true);

lightning/src/ln/monitor_tests.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,6 +2387,7 @@ fn do_test_restored_packages_retry(check_old_monitor_retries_after_upgrade: bool
23872387
}
23882388
}
23892389

2390+
#[cfg(not(feature = "safe_channels"))]
23902391
#[test]
23912392
fn test_restored_packages_retry() {
23922393
do_test_restored_packages_retry(false);
@@ -3021,6 +3022,7 @@ fn do_test_anchors_aggregated_revoked_htlc_tx(p2a_anchor: bool) {
30213022
assert_eq!(nodes[1].chain_monitor.chain_monitor.get_claimable_balances(&[]).len(), 6);
30223023
}
30233024

3025+
#[cfg(not(feature = "safe_channels"))]
30243026
#[test]
30253027
fn test_anchors_aggregated_revoked_htlc_tx() {
30263028
do_test_anchors_aggregated_revoked_htlc_tx(false);
@@ -3112,6 +3114,7 @@ fn do_test_anchors_monitor_fixes_counterparty_payment_script_on_reload(confirm_c
31123114
}
31133115
}
31143116

3117+
#[cfg(not(feature = "safe_channels"))]
31153118
#[test]
31163119
fn test_anchors_monitor_fixes_counterparty_payment_script_on_reload() {
31173120
do_test_anchors_monitor_fixes_counterparty_payment_script_on_reload(false);
@@ -3339,6 +3342,7 @@ fn test_update_replay_panics() {
33393342
monitor.update_monitor(&updates[3], &nodes[1].tx_broadcaster, &nodes[1].fee_estimator, &nodes[1].logger).unwrap();
33403343
}
33413344

3345+
#[cfg(not(feature = "safe_channels"))]
33423346
#[test]
33433347
fn test_claim_event_never_handled() {
33443348
// When a payment is claimed, the `ChannelMonitorUpdate` containing the payment preimage goes
@@ -3566,6 +3570,7 @@ fn do_test_lost_preimage_monitor_events(on_counterparty_tx: bool, p2a_anchor: bo
35663570
expect_payment_sent(&nodes[0], preimage_a, None, true, true);
35673571
}
35683572

3573+
#[cfg(not(feature = "safe_channels"))]
35693574
#[test]
35703575
fn test_lost_preimage_monitor_events() {
35713576
do_test_lost_preimage_monitor_events(true, false);
@@ -3811,6 +3816,7 @@ fn do_test_lost_timeout_monitor_events(confirm_tx: CommitmentType, dust_htlcs: b
38113816
expect_payment_failed!(nodes[0], hash_a, false);
38123817
}
38133818

3819+
#[cfg(not(feature = "safe_channels"))]
38143820
#[test]
38153821
fn test_lost_timeout_monitor_events() {
38163822
do_test_lost_timeout_monitor_events(CommitmentType::RevokedCounterparty, false, false);

lightning/src/ln/offers_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,6 +2430,7 @@ fn rejects_keysend_to_non_static_invoice_path() {
24302430
expect_payment_failed_conditions(&nodes[0], payment_hash, true, PaymentFailedConditions::new());
24312431
}
24322432

2433+
#[cfg(not(feature = "safe_channels"))]
24332434
#[test]
24342435
fn no_double_pay_with_stale_channelmanager() {
24352436
// This tests the following bug:

lightning/src/ln/onion_route_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,6 +1797,7 @@ fn do_test_onion_failure_stale_channel_update(announce_for_forwarding: bool) {
17971797
assert_eq!(config, config_after_restart);
17981798
}
17991799

1800+
#[cfg(not(feature = "safe_channels"))]
18001801
#[test]
18011802
fn test_onion_failure_stale_channel_update() {
18021803
do_test_onion_failure_stale_channel_update(false);

lightning/src/ln/payment_tests.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
10021002
expect_payment_sent!(nodes[0], payment_preimage, Some(new_route.paths[0].hops[0].fee_msat));
10031003
}
10041004

1005+
#[cfg(not(feature = "safe_channels"))]
10051006
#[test]
10061007
fn retry_with_no_persist() {
10071008
do_retry_with_no_persist(true);
@@ -1231,6 +1232,7 @@ fn do_test_completed_payment_not_retryable_on_reload(use_dust: bool) {
12311232
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
12321233
}
12331234

1235+
#[cfg(not(feature = "safe_channels"))]
12341236
#[test]
12351237
fn test_completed_payment_not_retryable_on_reload() {
12361238
do_test_completed_payment_not_retryable_on_reload(true);
@@ -1409,6 +1411,7 @@ fn do_test_dup_htlc_onchain_doesnt_fail_on_reload(
14091411
assert!(nodes[0].node.get_and_clear_pending_events().is_empty());
14101412
}
14111413

1414+
#[cfg(not(feature = "safe_channels"))]
14121415
#[test]
14131416
fn test_dup_htlc_onchain_doesnt_fail_on_reload() {
14141417
do_test_dup_htlc_onchain_doesnt_fail_on_reload(true, true, true, true);
@@ -1422,6 +1425,7 @@ fn test_dup_htlc_onchain_doesnt_fail_on_reload() {
14221425
do_test_dup_htlc_onchain_doesnt_fail_on_reload(false, false, false, false);
14231426
}
14241427

1428+
#[cfg(not(feature = "safe_channels"))]
14251429
#[test]
14261430
fn test_fulfill_restart_failure() {
14271431
// When we receive an update_fulfill_htlc message, we immediately consider the HTLC fully
@@ -4213,12 +4217,14 @@ fn do_no_missing_sent_on_reload(persist_manager_with_payment: bool, at_midpoint:
42134217
assert!(events.is_empty());
42144218
}
42154219

4220+
#[cfg(not(feature = "safe_channels"))]
42164221
#[test]
42174222
fn no_missing_sent_on_midpoint_reload() {
42184223
do_no_missing_sent_on_reload(false, true);
42194224
do_no_missing_sent_on_reload(true, true);
42204225
}
42214226

4227+
#[cfg(not(feature = "safe_channels"))]
42224228
#[test]
42234229
fn no_missing_sent_on_reload() {
42244230
do_no_missing_sent_on_reload(false, false);
@@ -4932,6 +4938,7 @@ fn do_test_payment_metadata_consistency(do_reload: bool, do_modify: bool) {
49324938
}
49334939
}
49344940

4941+
#[cfg(not(feature = "safe_channels"))]
49354942
#[test]
49364943
fn test_payment_metadata_consistency() {
49374944
do_test_payment_metadata_consistency(true, true);

0 commit comments

Comments
 (0)