Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config: revive --commit-fee #3732

Merged
merged 3 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/lightningd-config.5
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ opens a channel before the channel is usable\.


\fBcommit-fee\fR=\fIPERCENT\fR
The percentage of \fIestimatesmartfee 2\fR to use for the bitcoin
transaction which funds a channel: can be greater than 100\.
The percentage of \fIestimatesmartfee 2/CONSERVATIVE\fR to use for the commitment
transactions: default is 100\.


\fBcommit-fee-min\fR=\fIPERCENT\fR
Expand Down
4 changes: 2 additions & 2 deletions doc/lightningd-config.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ Confirmations required for the funding transaction when the other side
opens a channel before the channel is usable.

**commit-fee**=*PERCENT*
The percentage of *estimatesmartfee 2* to use for the bitcoin
transaction which funds a channel: can be greater than 100.
The percentage of *estimatesmartfee 2/CONSERVATIVE* to use for the commitment
transactions: default is 100.

**commit-fee-min**=*PERCENT*
**commit-fee-max**=*PERCENT*
Expand Down
3 changes: 0 additions & 3 deletions lightningd/lightningd.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ struct config {
/* Minimum percent of fee rate we'll accept. */
u32 commitment_fee_min_percent;

/* Percent of fee rate we'll use. */
u32 commitment_fee_percent;

/* Minimum CLTV to subtract from incoming HTLCs to outgoing */
u32 cltv_expiry_delta;

Expand Down
9 changes: 0 additions & 9 deletions lightningd/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,6 @@ static const struct config testnet_config = {
.commitment_fee_min_percent = 0,
.commitment_fee_max_percent = 0,

/* We offer to pay 5 times 2-block fee */
.commitment_fee_percent = 500,

/* Testnet blockspace is free. */
.max_concurrent_htlcs = 483,

Expand Down Expand Up @@ -619,9 +616,6 @@ static const struct config mainnet_config = {
.commitment_fee_min_percent = 200,
.commitment_fee_max_percent = 2000,

/* We offer to pay 5 times 2-block fee */
.commitment_fee_percent = 500,

/* While up to 483 htlcs are possible we do 30 by default (as eclair does) to save blockspace */
.max_concurrent_htlcs = 30,

Expand Down Expand Up @@ -820,9 +814,6 @@ static void register_opts(struct lightningd *ld)
opt_register_arg("--commit-fee-max=<percent>", opt_set_u32, opt_show_u32,
&ld->config.commitment_fee_max_percent,
"Maximum percentage of fee to accept for commitment (0 for unlimited)");
opt_register_arg("--commit-fee=<percent>", opt_set_u32, opt_show_u32,
&ld->config.commitment_fee_percent,
"Percentage of fee to request for their commitment");
opt_register_arg("--cltv-delta", opt_set_u32, opt_show_u32,
&ld->config.cltv_expiry_delta,
"Number of blocks for cltv_expiry_delta");
Expand Down
43 changes: 30 additions & 13 deletions plugins/bcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ struct bitcoind {
/* The factor to time the urgent feerate by to get the maximum
* acceptable feerate. */
u32 max_fee_multiplier;

/* Percent of CONSERVATIVE/2 feerate we'll use for commitment txs. */
u64 commit_fee_percent;
};

static struct bitcoind *bitcoind;
Expand Down Expand Up @@ -531,7 +534,8 @@ static struct command_result *estimatefees_final_step(struct bitcoin_cli *bcli)
response = jsonrpc_stream_success(bcli->cmd);
json_add_u64(response, "opening", stash->normal);
json_add_u64(response, "mutual_close", stash->normal);
json_add_u64(response, "unilateral_close", stash->very_urgent);
json_add_u64(response, "unilateral_close",
stash->very_urgent * bitcoind->commit_fee_percent / 100);
json_add_u64(response, "delayed_to_us", stash->normal);
json_add_u64(response, "htlc_resolution", stash->urgent);
json_add_u64(response, "penalty", stash->urgent);
Expand Down Expand Up @@ -580,7 +584,7 @@ static struct command_result *estimatefees_third_step(struct bitcoin_cli *bcli)
struct estimatefees_stash *stash = bcli->stash;
const char **params = tal_arr(bcli->cmd, const char *, 2);

/* If we cannot estimatefees, no need to continue bothering bitcoind. */
/* If we cannot estimate fees, no need to continue bothering bitcoind. */
if (*bcli->exitstatus != 0)
return estimatefees_null_response(bcli);

Expand All @@ -603,7 +607,7 @@ static struct command_result *estimatefees_second_step(struct bitcoin_cli *bcli)
struct estimatefees_stash *stash = bcli->stash;
const char **params = tal_arr(bcli->cmd, const char *, 2);

/* If we cannot estimatefees, no need to continue bothering bitcoind. */
/* If we cannot estimate fees, no need to continue bothering bitcoind. */
if (*bcli->exitstatus != 0)
return estimatefees_null_response(bcli);

Expand Down Expand Up @@ -750,13 +754,13 @@ static struct command_result *getchaininfo(struct command *cmd,
return command_still_pending(cmd);
}

/* Get the current feerates. We us an urgent feerate for unilateral_close and max,
/* Get the current feerates. We use an urgent feerate for unilateral_close and max,
* a slightly less urgent feerate for htlc_resolution and penalty transactions,
* a slow feerate for min, and a normal one for all others.
*
* Calls `estimatesmartfee` with targets 2/CONSERVATIVE (urgent),
* 4/ECONOMICAL (normal), and 100/ECONOMICAL (slow) then returns the
* feerates as sat/kVB.
* Calls `estimatesmartfee` with targets 2/CONSERVATIVE (very urgent),
* 3/CONSERVATIVE (urgent), 4/ECONOMICAL (normal), and 100/ECONOMICAL (slow)
* then returns the feerates as sat/kVB.
*/
static struct command_result *estimatefees(struct command *cmd,
const char *buf UNUSED,
Expand All @@ -768,7 +772,8 @@ static struct command_result *estimatefees(struct command *cmd,
if (!param(cmd, buf, toks, NULL))
return command_param_failed();

/* First call to estimatesmartfee, for urgent estimation. */
/* First call to estimatesmartfee, for very urgent estimation (unilateral
* and max_acceptable feerates). */
params[0] = "2";
params[1] = "CONSERVATIVE";
start_bitcoin_cli(NULL, cmd, estimatefees_second_step, true,
Expand Down Expand Up @@ -927,12 +932,9 @@ static const struct plugin_command commands[] = {
},
};

int main(int argc, char *argv[])
static struct bitcoind *new_bitcoind(const tal_t *ctx)
{
setup_locale();

/* Initialize our global context object here to handle startup options. */
bitcoind = tal(NULL, struct bitcoind);
bitcoind = tal(ctx, struct bitcoind);

bitcoind->cli = NULL;
bitcoind->datadir = NULL;
Expand All @@ -947,6 +949,17 @@ int main(int argc, char *argv[])
bitcoind->rpcconnect = NULL;
bitcoind->rpcport = NULL;
bitcoind->max_fee_multiplier = 10;
bitcoind->commit_fee_percent = 100;

return bitcoind;
}

int main(int argc, char *argv[])
{
setup_locale();

/* Initialize our global context object here to handle startup options. */
bitcoind = new_bitcoind(NULL);

plugin_main(argv, init, PLUGIN_STATIC, NULL, commands, ARRAY_SIZE(commands),
NULL, 0, NULL, 0,
Expand Down Expand Up @@ -979,6 +992,10 @@ int main(int argc, char *argv[])
"how long to keep retrying to contact bitcoind"
" before fatally exiting",
u64_option, &bitcoind->retry_timeout),
plugin_option("commit-fee",
"string",
"Percentage of fee to request for their commitment",
u64_option, &bitcoind->commit_fee_percent),
#if DEVELOPER
plugin_option("dev-max-fee-multiplier",
"string",
Expand Down
13 changes: 13 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2375,3 +2375,16 @@ def test_getsharedsecret(node_factory):
# knowing only the public key of the other.
assert (l1.rpc.getsharedsecret(l2.info["id"])["shared_secret"]
== l2.rpc.getsharedsecret(l1.info["id"])["shared_secret"])


def test_commitfee_option(node_factory):
"""Sanity check for the --commit-fee startup option."""
l1, l2 = node_factory.get_nodes(2, opts=[{"commit-fee": "200"}, {}])

mock_wu = 5000
for l in [l1, l2]:
l.set_feerates((mock_wu, 0, 0, 0), True)
l1_commit_fees = l1.rpc.call("estimatefees")["unilateral_close"]
l2_commit_fees = l2.rpc.call("estimatefees")["unilateral_close"]

assert l1_commit_fees == 2 * l2_commit_fees == 2 * 4 * mock_wu # WU->VB
1 change: 0 additions & 1 deletion wallet/test/test_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const struct config test_config = {
.anchor_confirms = 1,
.commitment_fee_min_percent = 0,
.commitment_fee_max_percent = 0,
.commitment_fee_percent = 500,
.cltv_expiry_delta = 6,
.cltv_final = 10,
.commit_time_ms = 10,
Expand Down