Skip to content

Commit 9b68ba0

Browse files
committed
openingd: test that channel open seems possible before bothering peer.
Fixes: #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 <[email protected]> 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!
1 parent 2ef776b commit 9b68ba0

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

openingd/openingd.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,20 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags,
316316
state->feerate_per_kw = nonanchor_feerate;
317317
}
318318

319+
/* If they use the same settings as us, would we fail? If so, do that now. */
320+
if (!check_config_bounds(tmpctx, state->funding_sats,
321+
state->feerate_per_kw,
322+
state->max_to_self_delay,
323+
state->min_effective_htlc_capacity,
324+
&state->localconf,
325+
&state->localconf,
326+
channel_type_has(state->channel_type, OPT_ANCHORS_ZERO_FEE_HTLC_TX),
327+
&err_reason)) {
328+
negotiation_aborted(state,
329+
tal_fmt(tmpctx, "Not opening because if they used the same setting as us %s",
330+
err_reason));
331+
}
332+
319333
open_tlvs = tlv_open_channel_tlvs_new(tmpctx);
320334
open_tlvs->upfront_shutdown_script
321335
= state->upfront_shutdown_script[LOCAL];

tests/test_connection.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -327,26 +327,6 @@ def test_balance(node_factory):
327327
assert p2['total_msat'] == 10**6 * 1000
328328

329329

330-
@pytest.mark.openchannel('v1')
331-
@pytest.mark.openchannel('v2')
332-
def test_bad_opening(node_factory):
333-
# l1 asks for a too-long locktime
334-
l1 = node_factory.get_node(options={'watchtime-blocks': 2017})
335-
l2 = node_factory.get_node()
336-
ret = l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
337-
338-
assert ret['id'] == l2.info['id']
339-
340-
l1.daemon.wait_for_log('Handed peer, entering loop')
341-
l2.daemon.wait_for_log('Handed peer, entering loop')
342-
343-
l1.fundwallet(10**6 + 1000000)
344-
with pytest.raises(RpcError):
345-
l1.rpc.fundchannel(l2.info['id'], 10**6)
346-
347-
l2.daemon.wait_for_log('to_self_delay 2017 larger than 2016')
348-
349-
350330
@unittest.skipIf(TEST_NETWORK != 'regtest', "Fee computation and limits are network specific")
351331
@pytest.mark.slow_test
352332
@pytest.mark.openchannel('v1')

tests/test_opening.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2799,7 +2799,7 @@ def censoring_sendrawtx(tx):
27992799

28002800

28012801
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd gives different numbers')
2802-
@pytest.mark.xfail(strict=True)
2802+
@pytest.mark.openchannel('v1')
28032803
def test_opening_below_min_capacity_sat(bitcoind, node_factory):
28042804
"""OK, here's what happens:
28052805

0 commit comments

Comments
 (0)