From 9b68ba0903bf122ffab7cfb37180304e96ec95e7 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 18 Aug 2025 14:27:18 +0930 Subject: [PATCH] openingd: test that channel open seems possible before bothering peer. Fixes: https://github.com/ElementsProject/lightning/issues/4873 In particular, we used to get upset when a peer accepts our channel, if it was too small! We should do reasonable checks first. We no longer try to send requests to delay for 2017 blocks though, so remove that test. Signed-off-by: Rusty Russell Changelog-Fixed: Protocol: trying to create a channel below our own min-capacity-sat will now fail before asking the peer, not with an error blaming the peer when they accept! --- openingd/openingd.c | 14 ++++++++++++++ tests/test_connection.py | 20 -------------------- tests/test_opening.py | 2 +- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/openingd/openingd.c b/openingd/openingd.c index 1990a9d293..23331faff7 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -316,6 +316,20 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags, state->feerate_per_kw = nonanchor_feerate; } + /* If they use the same settings as us, would we fail? If so, do that now. */ + if (!check_config_bounds(tmpctx, state->funding_sats, + state->feerate_per_kw, + state->max_to_self_delay, + state->min_effective_htlc_capacity, + &state->localconf, + &state->localconf, + channel_type_has(state->channel_type, OPT_ANCHORS_ZERO_FEE_HTLC_TX), + &err_reason)) { + negotiation_aborted(state, + tal_fmt(tmpctx, "Not opening because if they used the same setting as us %s", + err_reason)); + } + open_tlvs = tlv_open_channel_tlvs_new(tmpctx); open_tlvs->upfront_shutdown_script = state->upfront_shutdown_script[LOCAL]; diff --git a/tests/test_connection.py b/tests/test_connection.py index defeeea430..ed81c75f52 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -327,26 +327,6 @@ def test_balance(node_factory): assert p2['total_msat'] == 10**6 * 1000 -@pytest.mark.openchannel('v1') -@pytest.mark.openchannel('v2') -def test_bad_opening(node_factory): - # l1 asks for a too-long locktime - l1 = node_factory.get_node(options={'watchtime-blocks': 2017}) - l2 = node_factory.get_node() - ret = l1.rpc.connect(l2.info['id'], 'localhost', l2.port) - - assert ret['id'] == l2.info['id'] - - l1.daemon.wait_for_log('Handed peer, entering loop') - l2.daemon.wait_for_log('Handed peer, entering loop') - - l1.fundwallet(10**6 + 1000000) - with pytest.raises(RpcError): - l1.rpc.fundchannel(l2.info['id'], 10**6) - - l2.daemon.wait_for_log('to_self_delay 2017 larger than 2016') - - @unittest.skipIf(TEST_NETWORK != 'regtest', "Fee computation and limits are network specific") @pytest.mark.slow_test @pytest.mark.openchannel('v1') diff --git a/tests/test_opening.py b/tests/test_opening.py index 65fa44b5c9..e533d1f873 100644 --- a/tests/test_opening.py +++ b/tests/test_opening.py @@ -2799,7 +2799,7 @@ def test_zeroconf_forget(node_factory, bitcoind, dopay: bool): @unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd gives different numbers') -@pytest.mark.xfail(strict=True) +@pytest.mark.openchannel('v1') def test_opening_below_min_capacity_sat(bitcoind, node_factory): """OK, here's what happens: