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

libplugin: show default option values #7306

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
35 changes: 25 additions & 10 deletions plugins/autoclean.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,21 +581,29 @@ static const char *init(struct plugin *p,

static char *cycle_seconds_option(struct plugin *plugin, const char *arg,
bool check_only,
void *unused)
u64 *cycle_seconds)
{
char *problem = u64_option(plugin, arg, check_only, &cycle_seconds);
char *problem = u64_option(plugin, arg, check_only, cycle_seconds);
if (problem || check_only)
return problem;

/* If timer is not running right now, reset it to new cycle_seconds */
if (cleantimer) {
tal_free(cleantimer);
cleantimer = plugin_timer(plugin, time_from_sec(cycle_seconds),
cleantimer = plugin_timer(plugin, time_from_sec(*cycle_seconds),
do_clean_timer, NULL);
}
return NULL;
}

static bool u64_jsonfmt_unless_zero(struct plugin *plugin,
struct json_stream *js, const char *fieldname, u64 *i)
{
if (!*i)
return false;
return u64_jsonfmt(plugin, js, fieldname, i);
}

static const struct plugin_command commands[] = { {
"autocleaninvoice",
"payment",
Expand Down Expand Up @@ -628,30 +636,37 @@ int main(int argc, char *argv[])
"int",
"Perform cleanup every"
" given seconds",
cycle_seconds_option, NULL),
cycle_seconds_option, u64_jsonfmt,
&cycle_seconds),
plugin_option_dynamic("autoclean-succeededforwards-age",
"int",
"How old do successful forwards have to be before deletion (0 = never)",
u64_option, &timer_cinfo.subsystem_age[SUCCEEDEDFORWARDS]),
u64_option, u64_jsonfmt_unless_zero,
&timer_cinfo.subsystem_age[SUCCEEDEDFORWARDS]),
plugin_option_dynamic("autoclean-failedforwards-age",
"int",
"How old do failed forwards have to be before deletion (0 = never)",
u64_option, &timer_cinfo.subsystem_age[FAILEDFORWARDS]),
u64_option, u64_jsonfmt_unless_zero,
&timer_cinfo.subsystem_age[FAILEDFORWARDS]),
plugin_option_dynamic("autoclean-succeededpays-age",
"int",
"How old do successful pays have to be before deletion (0 = never)",
u64_option, &timer_cinfo.subsystem_age[SUCCEEDEDPAYS]),
u64_option, u64_jsonfmt_unless_zero,
&timer_cinfo.subsystem_age[SUCCEEDEDPAYS]),
plugin_option_dynamic("autoclean-failedpays-age",
"int",
"How old do failed pays have to be before deletion (0 = never)",
u64_option, &timer_cinfo.subsystem_age[FAILEDPAYS]),
u64_option, u64_jsonfmt_unless_zero,
&timer_cinfo.subsystem_age[FAILEDPAYS]),
plugin_option_dynamic("autoclean-paidinvoices-age",
"int",
"How old do paid invoices have to be before deletion (0 = never)",
u64_option, &timer_cinfo.subsystem_age[PAIDINVOICES]),
u64_option, u64_jsonfmt_unless_zero,
&timer_cinfo.subsystem_age[PAIDINVOICES]),
plugin_option_dynamic("autoclean-expiredinvoices-age",
"int",
"How old do expired invoices have to be before deletion (0 = never)",
u64_option, &timer_cinfo.subsystem_age[EXPIREDINVOICES]),
u64_option, u64_jsonfmt_unless_zero,
&timer_cinfo.subsystem_age[EXPIREDINVOICES]),
NULL);
}
18 changes: 9 additions & 9 deletions plugins/bcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1257,39 +1257,39 @@ int main(int argc, char *argv[])
plugin_option("bitcoin-datadir",
"string",
"-datadir arg for bitcoin-cli",
charp_option, &bitcoind->datadir),
charp_option, NULL, &bitcoind->datadir),
plugin_option("bitcoin-cli",
"string",
"bitcoin-cli pathname",
charp_option, &bitcoind->cli),
charp_option, NULL, &bitcoind->cli),
plugin_option("bitcoin-rpcuser",
"string",
"bitcoind RPC username",
charp_option, &bitcoind->rpcuser),
charp_option, NULL, &bitcoind->rpcuser),
plugin_option("bitcoin-rpcpassword",
"string",
"bitcoind RPC password",
charp_option, &bitcoind->rpcpass),
charp_option, NULL, &bitcoind->rpcpass),
plugin_option("bitcoin-rpcconnect",
"string",
"bitcoind RPC host to connect to",
charp_option, &bitcoind->rpcconnect),
charp_option, NULL, &bitcoind->rpcconnect),
plugin_option("bitcoin-rpcport",
"int",
"bitcoind RPC host's port",
charp_option, &bitcoind->rpcport),
charp_option, NULL, &bitcoind->rpcport),
plugin_option("bitcoin-rpcclienttimeout",
"int",
"bitcoind RPC timeout in seconds during HTTP requests",
u64_option, &bitcoind->rpcclienttimeout),
u64_option, u64_jsonfmt, &bitcoind->rpcclienttimeout),
plugin_option("bitcoin-retry-timeout",
"int",
"how long to keep retrying to contact bitcoind"
" before fatally exiting",
u64_option, &bitcoind->retry_timeout),
u64_option, u64_jsonfmt, &bitcoind->retry_timeout),
plugin_option_dev("dev-no-fake-fees",
"bool",
"Suppress fee faking for regtest",
bool_option, &bitcoind->dev_no_fake_fees),
bool_option, NULL, &bitcoind->dev_no_fake_fees),
NULL);
}
4 changes: 2 additions & 2 deletions plugins/bkpr/bookkeeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1839,11 +1839,11 @@ int main(int argc, char *argv[])
plugin_option("bookkeeper-dir",
"string",
"Location for bookkeeper records.",
charp_option, &datadir),
charp_option, NULL, &datadir),
plugin_option("bookkeeper-db",
"string",
"Location of the bookkeeper database",
charp_option, &db_dsn),
charp_option, NULL, &db_dsn),
NULL);

return 0;
Expand Down
2 changes: 1 addition & 1 deletion plugins/fetchinvoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,6 @@ int main(int argc, char *argv[])
NULL, 0,
plugin_option("fetchinvoice-noconnect", "flag",
"Don't try to connect directly to fetch an invoice.",
flag_option, &disable_connect),
flag_option, flag_jsonfmt, &disable_connect),
NULL);
}
56 changes: 47 additions & 9 deletions plugins/funder.c
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,17 @@ static char *amount_option(struct plugin *plugin, const char *arg, bool check_on
return NULL;
}

static bool jsonfmt_amount_sat(struct plugin *plugin,
struct json_stream *js,
const char *fieldname,
struct amount_sat *sats)
{
/* We do not expose raw numbers for sats fields: raw numbers
* in our interface means MSAT! */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. It's one thing for the user to set these parameters in the config, but another thing to consume them here. It might be nice if we could enforce a suffix/formatting on non-default configs as well.

json_add_str_fmt(js, fieldname, "%"PRIu64"sat", sats->satoshis /* Raw: fmt */);
return true;
}

static char *option_lease_fee_base(struct plugin *plugin, const char *arg,
bool check_only,
struct funder_policy *policy)
Expand Down Expand Up @@ -1673,6 +1684,15 @@ static char *amount_sat_or_u64_option(struct plugin *plugin,
return NULL;
}

static bool jsonfmt_policy_mod(struct plugin *plugin,
struct json_stream *js,
const char *fieldname,
u64 *amt)
{
json_add_u64(js, fieldname, *amt);
return true;
}

int main(int argc, char **argv)
{
setup_locale();
Expand All @@ -1690,93 +1710,111 @@ int main(int argc, char **argv)
"string",
"Policy to use for dual-funding requests."
" [match, available, fixed]",
funding_option, &current_policy->opt),
funding_option,
jsonfmt_funding_option,
&current_policy->opt),
plugin_option("funder-policy-mod",
"string",
"Percent to apply policy at"
" (match/available); or amount to fund"
" (fixed)",
amount_sat_or_u64_option,
jsonfmt_policy_mod,
&current_policy->mod),
plugin_option("funder-min-their-funding",
"string",
"Minimum funding peer must open with"
" to activate our policy",
amount_option,
jsonfmt_amount_sat,
&current_policy->min_their_funding),
plugin_option("funder-max-their-funding",
"string",
"Maximum funding peer may open with"
" to activate our policy",
amount_option,
jsonfmt_amount_sat,
&current_policy->max_their_funding),
plugin_option("funder-per-channel-min",
"string",
"Minimum funding we'll add to a channel."
" If we can't meet this, we don't fund",
amount_option,
jsonfmt_amount_sat,
&current_policy->per_channel_min),
plugin_option("funder-per-channel-max",
"string",
"Maximum funding we'll add to a channel."
" We cap all contributions to this",
amount_option,
jsonfmt_amount_sat,
&current_policy->per_channel_max),
plugin_option("funder-reserve-tank",
"string",
"Amount of funds we'll always leave"
" available.",
amount_option,
jsonfmt_amount_sat,
&current_policy->reserve_tank),
plugin_option("funder-fuzz-percent",
"int",
"Percent to fuzz the policy contribution by."
" Defaults to 0%. Max is 100%",
u32_option,
u32_option, u32_jsonfmt,
&current_policy->fuzz_factor),
plugin_option("funder-fund-probability",
"int",
"Percent of requests to consider."
" Defaults to 100%. Setting to 0% will"
" disable dual-funding",
u32_option,
u32_option, u32_jsonfmt,
&current_policy->fund_probability),
plugin_option("funder-lease-requests-only",
"bool",
"Only fund lease requests. Defaults to"
" true if channel lease rates are"
" being advertised",
bool_option,
bool_option, bool_jsonfmt,
&current_policy->leases_only),
plugin_option("lease-fee-base-sat",
"string",
"Channel lease rates, base fee for leased"
" funds, in satoshi.",
option_lease_fee_base, current_policy),
option_lease_fee_base,
NULL,
current_policy),
plugin_option("lease-fee-basis",
"int",
"Channel lease rates, basis charged"
" for leased funds (per 10,000 satoshi.)",
option_lease_fee_basis, current_policy),
option_lease_fee_basis,
NULL,
current_policy),
plugin_option("lease-funding-weight",
"int",
"Channel lease rates, weight"
" we'll ask opening peer to pay for in"
" funding transaction",
option_lease_weight_max, current_policy),
option_lease_weight_max,
NULL,
current_policy),
plugin_option("channel-fee-max-base-msat",
"string",
"Channel lease rates, maximum channel"
" fee base we'll charge for funds"
" routed through a leased channel.",
option_channel_base, current_policy),
option_channel_base,
NULL,
current_policy),
plugin_option("channel-fee-max-proportional-thousandths",
"int",
"Channel lease rates, maximum"
" proportional fee (in thousandths, or ppt)"
" we'll charge for funds routed through a"
" leased channel. Note: 1ppt = 1,000ppm",
option_channel_fee_proportional_thousandths_max, current_policy),
option_channel_fee_proportional_thousandths_max,
NULL,
current_policy),
NULL);

tal_free(current_policy);
Expand Down
10 changes: 10 additions & 0 deletions plugins/funder_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <assert.h>
#include <bitcoin/script.h>
#include <ccan/tal/str/str.h>
#include <common/json_stream.h>
#include <common/lease_rates.h>
#include <common/pseudorand.h>
#include <inttypes.h>
Expand Down Expand Up @@ -39,6 +40,15 @@ char *funding_option(struct plugin *plugin, const char *arg, bool check_only, en
return NULL;
}

bool jsonfmt_funding_option(struct plugin *plugin,
struct json_stream *js,
const char *fieldname,
enum funder_opt *opt)
{
json_add_string(js, fieldname, funder_opt_name(*opt));
return true;
}

const char *funder_policy_desc(const tal_t *ctx,
const struct funder_policy *policy)
{
Expand Down
6 changes: 6 additions & 0 deletions plugins/funder_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ const char *funder_policy_desc(const tal_t *ctx,
char *funding_option(struct plugin *plugin, const char *arg, bool check_only,
enum funder_opt *opt);

/* Convert to JSON field */
bool jsonfmt_funding_option(struct plugin *plugin,
struct json_stream *js,
const char *fieldname,
enum funder_opt *opt);

/* Check policy settings, return error if fails */
char *funder_check_policy(const struct funder_policy *policy);
#endif /* LIGHTNING_PLUGINS_FUNDER_POLICY_H */
Loading
Loading