From 70bf57d54bd72682d6bb883bec109bfce8ad233a Mon Sep 17 00:00:00 2001 From: niftynei Date: Tue, 6 Jul 2021 12:17:51 -0500 Subject: [PATCH] channel-lease: reject if we're not currently advertising liquidity If there's no plugin currently in place, we simply won't return any funding at all, in which case we'd expect them to handle however they want. (our implementation would fail the open, as we only accept opens that have at least as much as we've requested provided) --- openingd/dualopend.c | 1 - plugins/funder.c | 13 +++++++++++++ tests/test_opening.py | 6 ++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/openingd/dualopend.c b/openingd/dualopend.c index cf7492ea7..4bdfe4ae2 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -2050,7 +2050,6 @@ static void accepter_start(struct state *state, const u8 *oc2_msg) /* This is an `option_will_fund` request */ if (open_tlv->request_funds) { - /* FIXME: Do we support this? */ requested_amt = amount_sat(open_tlv->request_funds->requested_sats); tx_state->blockheight diff --git a/plugins/funder.c b/plugins/funder.c index b44fdb80b..9dbbba5a4 100644 --- a/plugins/funder.c +++ b/plugins/funder.c @@ -577,6 +577,19 @@ json_openchannel2_call(struct command *cmd, return command_hook_success(cmd); } + /* If they've requested funds, but we're not actually + * supporting requested funds...*/ + if (!current_policy->rates && + !amount_sat_zero(info->requested_lease)) { + struct json_stream *res = jsonrpc_stream_success(cmd); + json_add_string(res, "result", "reject"); + json_add_string(res, "error_message", + "Peer requested funds but we're not advertising" + " liquidity right now"); + return command_finished(cmd, res); + } + + /* Check that their block height isn't too far behind */ if (!amount_sat_zero(info->requested_lease)) { u32 upper_bound, lower_bound; diff --git a/tests/test_opening.py b/tests/test_opening.py index c38e4eb3a..dbb239a5e 100644 --- a/tests/test_opening.py +++ b/tests/test_opening.py @@ -26,10 +26,8 @@ def test_queryrates(node_factory, bitcoind): l2.fundwallet(amount * 10) l1.rpc.connect(l2.info['id'], 'localhost', l2.port) - result = l1.rpc.queryrates(l2.info['id'], amount, amount * 10) - assert result['our_funding_msat'] == Millisatoshi(amount * 1000) - assert result['their_funding_msat'] == Millisatoshi(0) - assert 'weight_charge' not in result + with pytest.raises(RpcError, match=r'not advertising liquidity'): + l1.rpc.queryrates(l2.info['id'], amount, amount * 10) l2.rpc.call('funderupdate', {'policy': 'match', 'policy_mod': 100,