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 <rusty@rustcorp.com.au>
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!
This commit is contained in:
Rusty Russell 2025-08-18 14:27:18 +09:30
parent 2ef776bd75
commit 9b68ba0903
3 changed files with 15 additions and 21 deletions

View file

@ -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];

View file

@ -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')

View file

@ -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: