Correct initial commitment check in inbound channel-open handling.
authorMatt Corallo <git@bluematt.me>
Wed, 1 Apr 2020 21:11:12 +0000 (17:11 -0400)
committerMatt Corallo <git@bluematt.me>
Mon, 25 May 2020 19:36:59 +0000 (15:36 -0400)
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
lightning/src/ln/functional_tests.rs

index 306d4c5954b9cb4a3d89aa7bb373f044e85020d6..f2f1ad766a9a195ff2306379c18cf9c878f6704f 100644 (file)
@@ -652,9 +652,10 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                        return Err(ChannelError::Close("Insufficient funding amount for initial commitment"));
                }
 
                        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;
                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"));
                }
 
                        return Err(ChannelError::Close("Insufficient funding amount for initial commitment"));
                }
 
index 2311a03fce17eeeb41769482e30500ddf3577a94..6663ed03daec68a438bb3c549bb12694d72b6a89 100644 (file)
@@ -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 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);
        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 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);
        nodes[0].node.force_close_channel(&chan.2);
        check_closed_broadcast!(nodes[0], false);
        check_added_monitors!(nodes[0], 1);