From a0723643d2a0d69a8037e6bb2e35b4a4c7788ba2 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 1 Apr 2020 17:11:12 -0400 Subject: [PATCH] Correct initial commitment check in inbound channel-open handling. Previously, we would reject inbound channels if the funder wasn't able to afford both the initial commitment transaction fee and the initial commitment didn't meet both our and our counterparty's reserve value. We never bothered to check if it was impossible for them to meet both reserve values, and meeting their own reserve is perfectly acceptable anyway (as long as they eventually meet it). The easy fix is to just check that they at least have enough funds back to themselves on the initial commitment to meet our reserve, though we could be more careful in the future. --- lightning/src/ln/channel.rs | 5 +++-- lightning/src/ln/functional_tests.rs | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 306d4c595..f2f1ad766 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -652,9 +652,10 @@ impl Channel { return Err(ChannelError::Close("Insufficient funding amount for initial commitment")); } - let to_local_msat = msg.push_msat; let to_remote_msat = funders_amount_msat - background_feerate * COMMITMENT_TX_BASE_WEIGHT; - if to_local_msat <= msg.channel_reserve_satoshis * 1000 && to_remote_msat <= remote_channel_reserve_satoshis * 1000 { + // While its reasonable for us to not meet the channel reserve initially (if they don't + // want to push much to us), our counterparty should always have more than the reserve. + if to_remote_msat <= remote_channel_reserve_satoshis * 1000 { return Err(ChannelError::Close("Insufficient funding amount for initial commitment")); } diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 2311a03fc..6663ed03d 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -4384,7 +4384,7 @@ fn test_claim_sizeable_push_msat() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 99000000, InitFeatures::known(), InitFeatures::known()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100_000, 98_000_000, InitFeatures::known(), InitFeatures::known()); nodes[1].node.force_close_channel(&chan.2); check_closed_broadcast!(nodes[1], false); check_added_monitors!(nodes[1], 1); @@ -4411,7 +4411,7 @@ fn test_claim_on_remote_sizeable_push_msat() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 99000000, InitFeatures::known(), InitFeatures::known()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100_000, 98_000_000, InitFeatures::known(), InitFeatures::known()); nodes[0].node.force_close_channel(&chan.2); check_closed_broadcast!(nodes[0], false); check_added_monitors!(nodes[0], 1); -- 2.39.5