diff --git a/doc/lightning-fundchannel.7.md b/doc/lightning-fundchannel.7.md index b8c15e842..5a5cbae5d 100644 --- a/doc/lightning-fundchannel.7.md +++ b/doc/lightning-fundchannel.7.md @@ -36,8 +36,9 @@ 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 (see NOTES in -lightning-feerates(7)). The default is *normal*. +(unless *option\_anchors\_zero\_fee\_htlc\_tx* is negotiated), as initial feerate +for commitment and HTLC transactions (see NOTES in lightning-feerates(7)). +The default is *normal*. *announce* is an optional flag that triggers whether to announce this channel or not. Defaults to `true`. An unannounced channel is considered diff --git a/doc/lightning-fundchannel_start.7.md b/doc/lightning-fundchannel_start.7.md index 3a00230ec..3cbd5e0f6 100644 --- a/doc/lightning-fundchannel_start.7.md +++ b/doc/lightning-fundchannel_start.7.md @@ -19,7 +19,9 @@ value MUST be accurate, otherwise the negotiated commitment transactions will not encompass the correct channel value. *feerate* is an optional field. Sets the feerate for subsequent -commitment transactions: see **fundchannel**. +commitment transactions: see **fundchannel**. Note that this is ignored +for channels with *option\_anchors\_zero\_fee\_htlc\_tx* (we always use a low +commitment fee for these). *announce* whether or not to announce this channel. diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index ceb7f77d7..f89f474a6 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -1276,6 +1276,7 @@ static struct command_result *json_fundchannel_start(struct command *cmd, fc->our_upfront_shutdown_script, upfront_shutdown_script_wallet_index, *feerate_per_kw, + unilateral_feerate(cmd->ld->topology, true), &tmp_channel_id, fc->channel_flags, fc->uc->reserve); diff --git a/openingd/openingd.c b/openingd/openingd.c index cdac1d884..87166f2b0 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -326,7 +326,8 @@ static bool intuit_scid_alias_type(struct state *state, u8 channel_flags, /* We start the 'open a channel' negotation with the supplied peer, but * stop when we get to the part where we need the funding txid */ -static u8 *funder_channel_start(struct state *state, u8 channel_flags) +static u8 *funder_channel_start(struct state *state, u8 channel_flags, + u32 nonanchor_feerate, u32 anchor_feerate) { u8 *msg; u8 *funding_output_script; @@ -374,6 +375,14 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags) channel_type_set_scid_alias(state->channel_type); } + /* Which feerate do we use? (We can lowball fees if using anchors!) */ + if (channel_type_has(state->channel_type, OPT_ANCHOR_OUTPUTS) + || channel_type_has(state->channel_type, OPT_ANCHORS_ZERO_FEE_HTLC_TX)) { + state->feerate_per_kw = anchor_feerate; + } else { + state->feerate_per_kw = nonanchor_feerate; + } + open_tlvs = tlv_open_channel_tlvs_new(tmpctx); open_tlvs->upfront_shutdown_script = state->upfront_shutdown_script[LOCAL]; @@ -1437,6 +1446,7 @@ static u8 *handle_master_in(struct state *state) u8 channel_flags; struct bitcoin_txid funding_txid; u16 funding_txout; + u32 nonanchor_feerate, anchor_feerate; switch (t) { case WIRE_OPENINGD_FUNDER_START: @@ -1445,12 +1455,13 @@ static u8 *handle_master_in(struct state *state) &state->push_msat, &state->upfront_shutdown_script[LOCAL], &state->local_upfront_shutdown_wallet_index, - &state->feerate_per_kw, + &nonanchor_feerate, + &anchor_feerate, &state->channel_id, &channel_flags, &state->reserve)) master_badmsg(WIRE_OPENINGD_FUNDER_START, msg); - msg = funder_channel_start(state, channel_flags); + msg = funder_channel_start(state, channel_flags, nonanchor_feerate, anchor_feerate); /* We want to keep openingd alive, since we're not done yet */ if (msg) diff --git a/openingd/openingd_wire.csv b/openingd/openingd_wire.csv index 4ab658773..40c97b36c 100644 --- a/openingd/openingd_wire.csv +++ b/openingd/openingd_wire.csv @@ -82,6 +82,7 @@ msgdata,openingd_funder_start,len_upfront,u16, msgdata,openingd_funder_start,upfront_shutdown_script,u8,len_upfront msgdata,openingd_funder_start,upfront_shutdown_wallet_index,?u32, msgdata,openingd_funder_start,feerate_per_kw,u32, +msgdata,openingd_funder_start,anchor_feerate_per_kw,u32, msgdata,openingd_funder_start,temporary_channel_id,channel_id, msgdata,openingd_funder_start,channel_flags,u8, msgdata,openingd_funder_start,reserve,?amount_sat, diff --git a/tests/test_opening.py b/tests/test_opening.py index 452550a1c..8034d54d5 100644 --- a/tests/test_opening.py +++ b/tests/test_opening.py @@ -2182,7 +2182,13 @@ def test_no_anchor_liquidity_ads(node_factory, bitcoind): def test_commitment_feerate(bitcoind, node_factory): l1, l2 = node_factory.get_nodes(2) - opening_feerate = commitment_feerate = 2000 + opening_feerate = 2000 + if anchor_expected(): + # anchors use lowball fees + commitment_feerate = 3750 + else: + commitment_feerate = opening_feerate + l1.fundwallet(10**8) l1.rpc.connect(l2.info['id'], 'localhost', l2.port) l1.rpc.fundchannel(l2.info['id'], 10**6,