Browse Source

plugins/fundchannel: make 'all' do the right thing for wumbo.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
travis-debug
Rusty Russell 5 years ago
parent
commit
28e3ffc66b
  1. 5
      doc/lightning-fundchannel.7
  2. 5
      doc/lightning-fundchannel.7.md
  3. 27
      plugins/fundchannel.c
  4. 14
      tests/test_connection.py

5
doc/lightning-fundchannel.7

@ -27,11 +27,12 @@ for the channel\.
\fIamount\fR is the amount in satoshis taken from the internal wallet to
fund the channel\. The string \fIall\fR can be used to specify all available
funds (or 16777215 satoshi if more is available)\. Otherwise, it is in
funds (or 16777215 satoshi if more is available and large channels were not negotiated with the peer)\. Otherwise, it is in
satoshi precision; it can be a whole number, a whole number ending in
\fIsat\fR, a whole number ending in \fI000msat\fR, or a number with 1 to 8
decimal places ending in \fIbtc\fR\. The value cannot be less than the dust
limit, currently set to 546, nor more than 16777215 satoshi\.
limit, currently set to 546, nor more than 16777215 satoshi (unless large
channels were negotiated with the peer)\.
\fIfeerate\fR is an optional feerate used for the opening transaction and as

5
doc/lightning-fundchannel.7.md

@ -27,11 +27,12 @@ for the channel.
*amount* is the amount in satoshis taken from the internal wallet to
fund the channel. The string *all* can be used to specify all available
funds (or 16777215 satoshi if more is available). Otherwise, it is in
funds (or 16777215 satoshi if more is available and large channels were not negotiated with the peer). Otherwise, it is in
satoshi precision; it can be a whole number, a whole number ending in
*sat*, a whole number ending in *000msat*, or a number with 1 to 8
decimal places ending in *btc*. The value cannot be less than the dust
limit, currently set to 546, nor more than 16777215 satoshi.
limit, currently set to 546, nor more than 16777215 satoshi (unless large
channels were negotiated with the peer).
*feerate* is an optional feerate used for the opening transaction and as
initial feerate for commitment and HTLC transactions. It can be one of

27
plugins/fundchannel.c

@ -5,6 +5,7 @@
#include <ccan/tal/str/str.h>
#include <common/addr.h>
#include <common/amount.h>
#include <common/features.h>
#include <common/json_stream.h>
#include <common/json_tok.h>
#include <common/type_to_string.h>
@ -25,6 +26,9 @@ struct funding_req {
bool funding_all;
struct amount_msat *push_msat;
/* Features offered by this peer. */
const u8 *features;
bool *announce_channel;
u32 *minconf;
@ -329,7 +333,10 @@ static struct command_result *post_dryrun(struct command *cmd,
plugin_err(cmd->plugin, "Error creating placebo funding tx, funding_out not found. %s", hex);
/* Update funding to actual amount */
if (fr->funding_all && amount_sat_greater(funding, chainparams->max_funding))
if (fr->funding_all
&& !feature_negotiated(plugin_feature_set(cmd->plugin),
fr->features, OPT_LARGE_CHANNELS)
&& amount_sat_greater(funding, chainparams->max_funding))
funding = chainparams->max_funding;
fr->funding_str = type_to_string(fr, struct amount_sat, &funding);
@ -341,9 +348,21 @@ static struct command_result *exec_dryrun(struct command *cmd,
const jsmntok_t *result,
struct funding_req *fr)
{
struct out_req *req = jsonrpc_request_start(cmd->plugin, cmd, "txprepare",
post_dryrun, forward_error,
fr);
struct out_req *req;
const jsmntok_t *t;
/* Stash features so we can wumbo. */
t = json_get_member(buf, result, "features");
if (!t)
plugin_err(cmd->plugin, "No features found in connect response?");
fr->features = json_tok_bin_from_hex(fr, buf, t);
if (!fr->features)
plugin_err(cmd->plugin, "Bad features '%.*s' in connect response?",
t->end - t->start, buf + t->start);
req = jsonrpc_request_start(cmd->plugin, cmd, "txprepare",
post_dryrun, forward_error,
fr);
/* Now that we've tried connecting, we do a 'dry-run' of txprepare,
* so we can get an accurate idea of the funding amount */

14
tests/test_connection.py

@ -2264,3 +2264,17 @@ def test_wumbo_channels(node_factory, bitcoind):
# Make sure l2 sees correct size.
wait_for(lambda: [c['amount_msat'] for c in l2.rpc.listchannels(l1.get_channel_scid(l3))['channels']]
== [Millisatoshi(str((1 << 24) - 1) + "sat")] * 2)
# Make sure 'all' works with wumbo peers.
l1.rpc.close(l2.info['id'])
bitcoind.generate_block(1, wait_for_mempool=1)
wait_for(lambda: l1.channel_state(l2) == 'ONCHAIN')
l1.rpc.connect(l2.info['id'], 'localhost', port=l2.port)
l1.rpc.fundchannel(l2.info['id'], 'all')
bitcoind.generate_block(1, wait_for_mempool=1)
wait_for(lambda: 'CHANNELD_NORMAL' in [c['state'] for c in only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['channels']])
# Exact amount depends on fees, but it will be wumbo!
amount = [c['funding_msat'][l1.info['id']] for c in only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['channels'] if c['state'] == 'CHANNELD_NORMAL'][0]
assert Millisatoshi(amount) > Millisatoshi(str((1 << 24) - 1) + "sat")

Loading…
Cancel
Save