Skip to content

Commit b096bf7

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

File tree

4 files changed

+117
-1
lines changed

4 files changed

+117
-1
lines changed

ci/ci-tests.sh

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,46 @@ cargo check -p lightning --verbose --color always --features dnssec
4747
cargo doc -p lightning --document-private-items --features dnssec
4848

4949
echo -e "\n\nChecking and testing lightning with safe_channels"
50-
cargo test -p lightning --verbose --color always --features safe_channels
50+
cargo test -p lightning --verbose --color always --features safe_channels -- \
51+
--skip channel_holding_cell_serialize \
52+
--skip test_blocked_chan_preimage_release \
53+
--skip test_durable_preimages_on_closed_channel \
54+
--skip test_inbound_reload_without_init_mon \
55+
--skip test_inverted_mon_completion_order \
56+
--skip test_outbound_reload_without_init_mon \
57+
--skip test_partial_claim_mon_update_compl_actions \
58+
--skip test_reload_mon_update_completion_actions \
59+
--skip test_multi_post_event_actions \
60+
--skip test_anchors_aggregated_revoked_htlc_tx \
61+
--skip test_anchors_monitor_fixes_counterparty_payment_script_on_reload \
62+
--skip test_claim_event_never_handled \
63+
--skip test_lost_timeout_monitor_events \
64+
--skip no_double_pay_with_stale_channelmanager \
65+
--skip test_onion_failure_stale_channel_update \
66+
--skip no_missing_sent_on_midpoint_reload \
67+
--skip no_missing_sent_on_reload \
68+
--skip retry_with_no_persist \
69+
--skip test_completed_payment_not_retryable_on_reload \
70+
--skip test_fulfill_restart_failure \
71+
--skip test_payment_metadata_consistency \
72+
--skip test_priv_forwarding_rejection \
73+
--skip test_quiescence_termination_on_disconnect \
74+
--skip forwarded_payment_no_manager_persistence \
75+
--skip intercepted_payment_no_manager_persistence \
76+
--skip removed_payment_no_manager_persistence \
77+
--skip test_data_loss_protect \
78+
--skip test_htlc_localremoved_persistence \
79+
--skip test_manager_serialize_deserialize_events \
80+
--skip test_manager_serialize_deserialize_inconsistent_monitor \
81+
--skip test_no_txn_manager_serialize_deserialize \
82+
--skip test_partial_claim_before_restart \
83+
--skip test_reload_partial_funding_batch \
84+
--skip test_unconf_chan \
85+
--skip test_unconf_chan_via_funding_unconfirmed \
86+
--skip test_unconf_chan_via_listen \
87+
--skip test_propose_splice_while_disconnected \
88+
--skip test_splice_reestablish \
89+
--skip test_splice_state_reset_on_disconnect
5190
cargo check -p lightning --verbose --color always --features safe_channels
5291
cargo doc -p lightning --document-private-items --features safe_channels
5392

lightning/src/chain/channelmonitor.rs

Lines changed: 3 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
}

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/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;

0 commit comments

Comments
 (0)