Skip to content

Commit 2eb7981

Browse files
committed
Load chan mgr from monitors
1 parent d25845e commit 2eb7981

15 files changed

+223
-168
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,10 +1406,9 @@ where
14061406
let logger = WithChannelMonitor::from(&self.logger, &monitor, None);
14071407
log_trace!(
14081408
logger,
1409-
"Updating ChannelMonitor to id {} for channel {} with updates {:#?}",
1409+
"Updating ChannelMonitor to id {} for channel {}",
14101410
update.update_id,
1411-
log_funding_info!(monitor),
1412-
update.updates
1411+
log_funding_info!(monitor)
14131412
);
14141413

14151414
// We hold a `pending_monitor_updates` lock through `update_monitor` to ensure we

lightning/src/chain/channelmonitor.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,17 @@ impl Writeable for ChannelMonitorUpdate {
159159
for update_step in self.updates.iter() {
160160
update_step.write(w)?;
161161
}
162+
#[cfg(feature = "safe_channels")]
162163
write_tlv_fields!(w, {
163164
// 1 was previously used to store `counterparty_node_id`
164165
(3, self.channel_id, option),
165166
(5, self.encoded_channel, option)
166167
});
168+
#[cfg(not(feature = "safe_channels"))]
169+
write_tlv_fields!(w, {
170+
// 1 was previously used to store `counterparty_node_id`
171+
(3, self.channel_id, option),
172+
});
167173
Ok(())
168174
}
169175
}
@@ -1744,6 +1750,7 @@ pub(crate) fn write_chanmon_internal<Signer: EcdsaChannelSigner, W: Writer>(
17441750
_ => channel_monitor.pending_monitor_events.clone(),
17451751
};
17461752

1753+
#[cfg(feature = "safe_channels")]
17471754
write_tlv_fields!(writer, {
17481755
(1, channel_monitor.funding_spend_confirmed, option),
17491756
(3, channel_monitor.htlcs_resolved_on_chain, required_vec),
@@ -1768,6 +1775,30 @@ pub(crate) fn write_chanmon_internal<Signer: EcdsaChannelSigner, W: Writer>(
17681775
(37, channel_monitor.funding_seen_onchain, required),
17691776
(39, channel_monitor.encoded_channel, option),
17701777
});
1778+
#[cfg(not(feature = "safe_channels"))]
1779+
write_tlv_fields!(writer, {
1780+
(1, channel_monitor.funding_spend_confirmed, option),
1781+
(3, channel_monitor.htlcs_resolved_on_chain, required_vec),
1782+
(5, pending_monitor_events, required_vec),
1783+
(7, channel_monitor.funding_spend_seen, required),
1784+
(9, channel_monitor.counterparty_node_id, required),
1785+
(11, channel_monitor.confirmed_commitment_tx_counterparty_output, option),
1786+
(13, channel_monitor.spendable_txids_confirmed, required_vec),
1787+
(15, channel_monitor.counterparty_fulfilled_htlcs, required),
1788+
(17, channel_monitor.initial_counterparty_commitment_info, option),
1789+
(19, channel_monitor.channel_id, required),
1790+
(21, channel_monitor.balances_empty_height, option),
1791+
(23, channel_monitor.holder_pays_commitment_tx_fee, option),
1792+
(25, channel_monitor.payment_preimages, required),
1793+
(27, channel_monitor.first_negotiated_funding_txo, required),
1794+
(29, channel_monitor.initial_counterparty_commitment_tx, option),
1795+
(31, channel_monitor.funding.channel_parameters, required),
1796+
(32, channel_monitor.pending_funding, optional_vec),
1797+
(33, channel_monitor.htlcs_resolved_to_user, required),
1798+
(34, channel_monitor.alternative_funding_confirmed, option),
1799+
(35, channel_monitor.is_manual_broadcast, required),
1800+
(37, channel_monitor.funding_seen_onchain, required),
1801+
});
17711802

17721803
Ok(())
17731804
}
@@ -7100,6 +7131,7 @@ mod tests {
71007131
check_added_monitors(&nodes[1], 1);
71017132
}
71027133

7134+
#[cfg(not(feature = "safe_channels"))]
71037135
#[test]
71047136
fn test_funding_spend_refuses_updates() {
71057137
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
@@ -2838,6 +2838,8 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
28382838
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_1);
28392839
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2);
28402840
}
2841+
2842+
#[cfg(not(feature = "safe_channels"))]
28412843
#[test]
28422844
fn channel_holding_cell_serialize() {
28432845
do_channel_holding_cell_serialize(true, true);
@@ -3319,6 +3321,7 @@ fn do_test_outbound_reload_without_init_mon(use_0conf: bool) {
33193321
assert!(nodes[0].node.list_channels().is_empty());
33203322
}
33213323

3324+
#[cfg(not(feature = "safe_channels"))]
33223325
#[test]
33233326
fn test_outbound_reload_without_init_mon() {
33243327
do_test_outbound_reload_without_init_mon(true);
@@ -3427,6 +3430,7 @@ fn do_test_inbound_reload_without_init_mon(use_0conf: bool, lock_commitment: boo
34273430
assert!(nodes[1].node.list_channels().is_empty());
34283431
}
34293432

3433+
#[cfg(not(feature = "safe_channels"))]
34303434
#[test]
34313435
fn test_inbound_reload_without_init_mon() {
34323436
do_test_inbound_reload_without_init_mon(true, true);
@@ -3576,6 +3580,7 @@ fn do_test_blocked_chan_preimage_release(completion_mode: BlockedUpdateComplMode
35763580
expect_payment_sent(&nodes[2], payment_preimage_2, None, true, true);
35773581
}
35783582

3583+
#[cfg(not(feature = "safe_channels"))]
35793584
#[test]
35803585
fn test_blocked_chan_preimage_release() {
35813586
do_test_blocked_chan_preimage_release(BlockedUpdateComplMode::AtReload);
@@ -3766,6 +3771,7 @@ fn do_test_inverted_mon_completion_order(
37663771
expect_payment_sent(&nodes[0], payment_preimage, None, true, true);
37673772
}
37683773

3774+
#[cfg(not(feature = "safe_channels"))]
37693775
#[test]
37703776
fn test_inverted_mon_completion_order() {
37713777
do_test_inverted_mon_completion_order(true, true);
@@ -3968,6 +3974,7 @@ fn do_test_durable_preimages_on_closed_channel(
39683974
}
39693975
}
39703976

3977+
#[cfg(not(feature = "safe_channels"))]
39713978
#[test]
39723979
fn test_durable_preimages_on_closed_channel() {
39733980
do_test_durable_preimages_on_closed_channel(true, true, true);
@@ -4092,6 +4099,7 @@ fn do_test_reload_mon_update_completion_actions(close_during_reload: bool) {
40924099
send_payment(&nodes[1], &[&nodes[2]], 100_000);
40934100
}
40944101

4102+
#[cfg(not(feature = "safe_channels"))]
40954103
#[test]
40964104
fn test_reload_mon_update_completion_actions() {
40974105
do_test_reload_mon_update_completion_actions(true);
@@ -4458,6 +4466,7 @@ fn do_test_partial_claim_mon_update_compl_actions(reload_a: bool, reload_b: bool
44584466
assert!(!get_monitor!(nodes[3], chan_4_id).get_stored_preimages().contains_key(&payment_hash));
44594467
}
44604468

4469+
#[cfg(not(feature = "safe_channels"))]
44614470
#[test]
44624471
fn test_partial_claim_mon_update_compl_actions() {
44634472
do_test_partial_claim_mon_update_compl_actions(true, true);

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

0 commit comments

Comments
 (0)