Skip to content

Commit

Permalink
dual-funding: update fee_step to be a feerate
Browse files Browse the repository at this point in the history
Using a 'feestep' is more restrictive than you'd want, instead we
enforce that the next feerate must be at least 1/64th more than the
last, but put no upper limit on it

Includes update to lnprototest changes

Contributed-By: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Changelog-EXPERIMENTAL: Protocol: Replaces init_rbf's `fee_step` for RBF of v2 opens with `funding_feerate_perkw`, breaking change
  • Loading branch information
niftynei committed Jul 19, 2021
1 parent 04b6ad0 commit 376e6f8
Show file tree
Hide file tree
Showing 20 changed files with 181 additions and 174 deletions.
3 changes: 2 additions & 1 deletion contrib/pyln-client/pyln/client/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,12 +1039,13 @@ def openchannel_update(self, channel_id, psbt, *args, **kwargs):
}
return self.call("openchannel_update", payload)

def openchannel_bump(self, channel_id, amount, initialpsbt):
def openchannel_bump(self, channel_id, amount, initialpsbt, funding_feerate=None):
""" Initiate an RBF for an in-progress open """
payload = {
"channel_id": channel_id,
"amount": amount,
"initialpsbt": initialpsbt,
"funding_feerate": funding_feerate,
}
return self.call("openchannel_bump", payload)

Expand Down
4 changes: 1 addition & 3 deletions doc/lightning-listpeers.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions doc/lightning-listpeers.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ On success, an object containing **peers** is returned. It is an array of objec
- **initial_feerate** (string): The feerate for the initial funding transaction in per-1000-weight, with "kpw" appended
- **last_feerate** (string): The feerate for the latest funding transaction in per-1000-weight, with "kpw" appended
- **next_feerate** (string): The minimum feerate for the next funding transaction in per-1000-weight, with "kpw" appended
- **next_fee_step** (u32): The number of fee steps so far, plus one
- **log** (array of objects, optional): if *level* is specified, logs for this peer:
- **type** (string) (one of "SKIPPED", "BROKEN", "UNUSUAL", "INFO", "DEBUG", "IO_IN", "IO_OUT")

Expand Down Expand Up @@ -376,4 +375,4 @@ Main web site: <https://github.com/ElementsProject/lightning> Lightning
RFC site (BOLT \#9):
<https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md>

[comment]: # ( SHA256STAMP:6db6eb853f6c1953f05160cd9026ad6a8ccb97a016b15bc76242adc8026fa4ca)
[comment]: # ( SHA256STAMP:91d30768a795456c75c72cf499df529ae8dbcc8088d06d1ed27150272425ab37)
9 changes: 7 additions & 2 deletions doc/lightning-openchannel_bump.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion doc/lightning-openchannel_bump.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ lightning-openchannel\_bump -- Command to initiate a channel RBF
SYNOPSIS
--------

**openchannel_bump** *channel_id* *amount* *initalpsbt*
**openchannel_bump** *channel_id* *amount* *initalpsbt* \[*funding_feerate*\]

DESCRIPTION
-----------
Expand All @@ -26,6 +26,10 @@ Must have the Non-Witness UTXO (PSBT\_IN\_NON\_WITNESS\_UTXO) set for
every input. An error (code 309) will be returned if this requirement
is not met.

*funding_feerate* is an optional field. Sets the feerate for the
funding transaction. Defaults to 1/64th greater than the last
feerate used for this channel.

RETURN VALUE
------------

Expand Down
19 changes: 7 additions & 12 deletions doc/schemas/listpeers.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,6 @@
"short_channel_id": { },
"channel_id": { },
"funding_txid": { },
"inflight": { },
"close_to": { },
"private": { },
"opener": { },
Expand Down Expand Up @@ -635,7 +634,6 @@
"initial_feerate": { },
"last_feerate": { },
"next_feerate": { },
"next_fee_step": { },
"inflight": { },
"last_tx_fee": { },
"last_tx_fee_msat": { },
Expand Down Expand Up @@ -715,12 +713,13 @@
"out_fulfilled_msat": { },
"out_msatoshi_fulfilled": { },
"htlcs": { },
"inflight": { },
"initial_feerate": { },
"last_feerate": { },
"next_feerate": { },
"close_to_addr": { },
"initial_feerate": { },
"last_feerate": { },
"next_feerate": { },
"next_fee_step": { },
"direction": { },
"last_tx_fee": {
"deprecated": true
Expand Down Expand Up @@ -800,13 +799,14 @@
"out_fulfilled_msat": { },
"out_msatoshi_fulfilled": { },
"htlcs": { },
"inflight": { },
"initial_feerate": { },
"last_feerate": { },
"next_feerate": { },
"last_tx_fee": { },
"close_to_addr": { },
"initial_feerate": { },
"last_feerate": { },
"next_feerate": { },
"next_fee_step": { },
"last_tx_fee": { },
"last_tx_fee_msat": { },
"direction": {
Expand All @@ -822,7 +822,7 @@
},
"then": {
"additionalProperties": false,
"required": [ "initial_feerate", "last_feerate", "next_feerate", "next_fee_step" ],
"required": [ "initial_feerate", "last_feerate", "next_feerate" ],
"properties": {
"state": { },
"scratch_txid": { },
Expand All @@ -831,7 +831,6 @@
"short_channel_id": { },
"channel_id": { },
"funding_txid": { },
"inflight": { },
"close_to": { },
"private": { },
"opener": { },
Expand Down Expand Up @@ -901,10 +900,6 @@
"next_feerate": {
"type": "string",
"description": "The minimum feerate for the next funding transaction in per-1000-weight, with \"kpw\" appended"
},
"next_fee_step": {
"type": "u32",
"description": "The number of fee steps so far, plus one"
}
}
}
Expand Down
30 changes: 21 additions & 9 deletions lightningd/dual_open_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1986,12 +1986,15 @@ json_openchannel_bump(struct command *cmd,
struct channel *channel;
struct amount_sat *amount, psbt_val;
struct wally_psbt *psbt;
u32 last_feerate_perkw, next_feerate_min, *feerate_per_kw_funding;
struct open_attempt *oa;

if (!param(cmd, buffer, params,
p_req("channel_id", param_channel_id, &cid),
p_req("amount", param_sat, &amount),
p_req("initialpsbt", param_psbt, &psbt),
p_opt("funding_feerate", param_feerate,
&feerate_per_kw_funding),
NULL))
return command_param_failed();

Expand Down Expand Up @@ -2033,6 +2036,20 @@ json_openchannel_bump(struct command *cmd,
type_to_string(tmpctx, struct channel_id,
cid));

last_feerate_perkw = channel_last_funding_feerate(channel);
next_feerate_min = last_feerate_perkw * 65 / 64;
assert(next_feerate_min > last_feerate_perkw);
if (!feerate_per_kw_funding) {
feerate_per_kw_funding = tal(cmd, u32);
*feerate_per_kw_funding = next_feerate_min;
} else if (*feerate_per_kw_funding < next_feerate_min)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Next feerate must be at least 1/64th"
" greater than the last. Min req %u,"
" you proposed %u",
next_feerate_min,
*feerate_per_kw_funding);

/* BOLT #2:
* - if both nodes advertised `option_support_large_channel`:
* - MAY set `funding_satoshis` greater than or equal to 2^24 satoshi.
Expand Down Expand Up @@ -2092,7 +2109,9 @@ json_openchannel_bump(struct command *cmd,
psbt));

subd_send_msg(channel->owner,
take(towire_dualopend_rbf_init(NULL, *amount, psbt)));
take(towire_dualopend_rbf_init(NULL, *amount,
*feerate_per_kw_funding,
psbt)));
return command_still_pending(cmd);
}

Expand Down Expand Up @@ -2876,7 +2895,7 @@ void peer_restart_dualopend(struct peer *peer,
u32 max_to_self_delay;
struct amount_msat min_effective_htlc_capacity;
struct channel_config unused_config;
struct channel_inflight *inflight, *first_inflight;
struct channel_inflight *inflight;
int hsmfd;
u8 *msg;

Expand Down Expand Up @@ -2917,12 +2936,6 @@ void peer_restart_dualopend(struct peer *peer,
inflight = channel_current_inflight(channel);
assert(inflight);

/* Get the first inflight to figure out the original feerate
* for this channel. It's fine if it's the same as the current */
first_inflight = list_top(&channel->inflights,
struct channel_inflight,
list);
assert(first_inflight);
msg = towire_dualopend_reinit(NULL,
chainparams,
peer->ld->our_features,
Expand All @@ -2939,7 +2952,6 @@ void peer_restart_dualopend(struct peer *peer,
channel->minimum_depth,
&inflight->funding->txid,
inflight->funding->outnum,
first_inflight->funding->feerate,
inflight->funding->feerate,
channel->funding,
channel->our_msat,
Expand Down
28 changes: 14 additions & 14 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,32 +774,32 @@ static void json_add_channel(struct lightningd *ld,

if (!list_empty(&channel->inflights)) {
struct channel_inflight *initial, *inflight;
u32 last_feerate, next_feerate, feerate;
u8 feestep;

last_feerate = channel_last_funding_feerate(channel);
assert(last_feerate > 0);
next_feerate = last_feerate + last_feerate / 4;
u32 last_feerate, next_feerate;

initial = list_top(&channel->inflights,
struct channel_inflight, list);
feerate = initial->funding->feerate;

json_add_string(response, "initial_feerate",
tal_fmt(tmpctx, "%d%s", feerate,
tal_fmt(tmpctx, "%d%s",
initial->funding->feerate,
feerate_style_name(FEERATE_PER_KSIPA)));

last_feerate = channel_last_funding_feerate(channel);
assert(last_feerate > 0);
json_add_string(response, "last_feerate",
tal_fmt(tmpctx, "%d%s", last_feerate,
feerate_style_name(FEERATE_PER_KSIPA)));

/* BOLT-9e7723387c8859b511e178485605a0b9133b9869 #2:
* - MUST set `funding_feerate_perkw` greater than or equal to
* 65/64 times the last sent `funding_feerate_perkw`
* rounded down.
*/
next_feerate = last_feerate * 65 / 64;
assert(next_feerate > last_feerate);
json_add_string(response, "next_feerate",
tal_fmt(tmpctx, "%d%s", next_feerate,
feerate_style_name(FEERATE_PER_KSIPA)));

/* Now we derive the feestep */
for (feestep = 0; feerate < next_feerate; feestep++)
feerate += feerate / 4;
json_add_num(response, "next_fee_step", feestep);

/* List the inflights */
json_array_start(response, "inflight");
list_for_each(&channel->inflights, inflight, list) {
Expand Down
Loading

0 comments on commit 376e6f8

Please sign in to comment.