Skip to content

Commit 8c2b981

Browse files
committed
Clean up existing and add range-based closing_signed negotiation
This adds the new range-based closing_signed negotiation specified in lightning/bolts#847 as well as cleans up the existing closing_signed negotiation to unify the new codepaths and the old ones. Note that because the new range-based closing_signed negotiation allows the channel fundee to ultimately select the fee out of a range specified by the funder, which we, of course, always select the highest allowed amount from. Thus, we've added an extra round of closing_signed in the common case as we will not simply accept the first fee we see, always preferring to make the funder pay as much as they're willing to.
1 parent dfb3de4 commit 8c2b981

File tree

7 files changed

+273
-131
lines changed

7 files changed

+273
-131
lines changed

fuzz/src/full_stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
476476
let channel_id = get_slice!(1)[0] as usize;
477477
if channel_id >= channels.len() { return; }
478478
channels.sort_by(|a, b| { a.channel_id.cmp(&b.channel_id) });
479-
if channelmanager.close_channel(&channels[channel_id].channel_id).is_err() { return; }
479+
if channelmanager.close_channel(&channels[channel_id].channel_id, None).is_err() { return; }
480480
},
481481
7 => {
482482
if should_forward {

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,7 +2576,7 @@ fn test_temporary_error_during_shutdown() {
25762576
*nodes[0].chain_monitor.update_ret.lock().unwrap() = Some(Err(ChannelMonitorUpdateErr::TemporaryFailure));
25772577
*nodes[1].chain_monitor.update_ret.lock().unwrap() = Some(Err(ChannelMonitorUpdateErr::TemporaryFailure));
25782578

2579-
nodes[0].node.close_channel(&channel_id).unwrap();
2579+
nodes[0].node.close_channel(&channel_id, None).unwrap();
25802580
nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &InitFeatures::known(), &get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()));
25812581
check_added_monitors!(nodes[1], 1);
25822582

@@ -2597,14 +2597,16 @@ fn test_temporary_error_during_shutdown() {
25972597
*nodes[1].chain_monitor.update_ret.lock().unwrap() = None;
25982598
let (outpoint, latest_update) = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&channel_id).unwrap().clone();
25992599
nodes[1].node.channel_monitor_updated(&outpoint, latest_update);
2600-
let (_, closing_signed_b) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id());
2601-
nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &closing_signed_b.unwrap());
2602-
let txn_b = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
26032600

2604-
let (_, none_a) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id());
2605-
assert!(none_a.is_none());
2601+
nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id()));
2602+
let (_, closing_signed_a) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id());
26062603
let txn_a = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
26072604

2605+
nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &closing_signed_a.unwrap());
2606+
let (_, none_b) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id());
2607+
assert!(none_b.is_none());
2608+
let txn_b = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
2609+
26082610
assert_eq!(txn_a, txn_b);
26092611
assert_eq!(txn_a.len(), 1);
26102612
check_spends!(txn_a[0], funding_tx);
@@ -2625,7 +2627,7 @@ fn test_permanent_error_during_sending_shutdown() {
26252627
let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2;
26262628
*nodes[0].chain_monitor.update_ret.lock().unwrap() = Some(Err(ChannelMonitorUpdateErr::PermanentFailure));
26272629

2628-
assert!(nodes[0].node.close_channel(&channel_id).is_ok());
2630+
assert!(nodes[0].node.close_channel(&channel_id, None).is_ok());
26292631
check_closed_broadcast!(nodes[0], true);
26302632
check_added_monitors!(nodes[0], 2);
26312633
}
@@ -2645,7 +2647,7 @@ fn test_permanent_error_during_handling_shutdown() {
26452647
let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2;
26462648
*nodes[1].chain_monitor.update_ret.lock().unwrap() = Some(Err(ChannelMonitorUpdateErr::PermanentFailure));
26472649

2648-
assert!(nodes[0].node.close_channel(&channel_id).is_ok());
2650+
assert!(nodes[0].node.close_channel(&channel_id, None).is_ok());
26492651
let shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id());
26502652
nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &InitFeatures::known(), &shutdown);
26512653
check_closed_broadcast!(nodes[1], true);

0 commit comments

Comments
 (0)