mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-22 00:24:19 +01:00
lease_rates: prepare for msats fields as raw numbers.
We would otherwise multiply them by 1000. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -81,11 +81,14 @@ bool lease_rates_set_chan_fee_base_msat(struct lease_rates *rates,
|
|||||||
amt.millisatoshis); /* Raw: conversion */
|
amt.millisatoshis); /* Raw: conversion */
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lease_rates_set_lease_fee_sat(struct lease_rates *rates,
|
bool lease_rates_set_lease_fee_msat(struct lease_rates *rates,
|
||||||
struct amount_sat amt)
|
struct amount_msat amt)
|
||||||
{
|
{
|
||||||
|
struct amount_sat sat;
|
||||||
|
if (!amount_msat_to_sat(&sat, amt))
|
||||||
|
return false;
|
||||||
return assign_overflow_u32(&rates->lease_fee_base_sat,
|
return assign_overflow_u32(&rates->lease_fee_base_sat,
|
||||||
amt.satoshis); /* Raw: conversion */
|
sat.satoshis); /* Raw: conversion */
|
||||||
}
|
}
|
||||||
|
|
||||||
char *lease_rates_tohex(const tal_t *ctx, const struct lease_rates *rates)
|
char *lease_rates_tohex(const tal_t *ctx, const struct lease_rates *rates)
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ bool lease_rates_calc_fee(const struct lease_rates *rates,
|
|||||||
|
|
||||||
WARN_UNUSED_RESULT bool lease_rates_set_chan_fee_base_msat(struct lease_rates *rates, struct amount_msat amt);
|
WARN_UNUSED_RESULT bool lease_rates_set_chan_fee_base_msat(struct lease_rates *rates, struct amount_msat amt);
|
||||||
|
|
||||||
WARN_UNUSED_RESULT bool lease_rates_set_lease_fee_sat(struct lease_rates *rates, struct amount_sat amt);
|
WARN_UNUSED_RESULT bool lease_rates_set_lease_fee_msat(struct lease_rates *rates,
|
||||||
|
struct amount_msat amt);
|
||||||
|
|
||||||
/* Convert 'lease_rates' into a hexstring */
|
/* Convert 'lease_rates' into a hexstring */
|
||||||
char *lease_rates_tohex(const tal_t *ctx, const struct lease_rates *rates);
|
char *lease_rates_tohex(const tal_t *ctx, const struct lease_rates *rates);
|
||||||
|
|||||||
@@ -747,8 +747,7 @@ openchannel2_hook_deserialize(struct openchannel2_payload *payload,
|
|||||||
payload->our_shutdown_scriptpubkey = shutdown_script;
|
payload->our_shutdown_scriptpubkey = shutdown_script;
|
||||||
|
|
||||||
|
|
||||||
struct amount_sat sats;
|
struct amount_msat fee_base, fee_max_base;
|
||||||
struct amount_msat msats;
|
|
||||||
payload->rates = tal(payload, struct lease_rates);
|
payload->rates = tal(payload, struct lease_rates);
|
||||||
err = json_scan(payload, buffer, toks,
|
err = json_scan(payload, buffer, toks,
|
||||||
"{lease_fee_base_msat:%"
|
"{lease_fee_base_msat:%"
|
||||||
@@ -756,10 +755,10 @@ openchannel2_hook_deserialize(struct openchannel2_payload *payload,
|
|||||||
",channel_fee_max_base_msat:%"
|
",channel_fee_max_base_msat:%"
|
||||||
",channel_fee_max_proportional_thousandths:%"
|
",channel_fee_max_proportional_thousandths:%"
|
||||||
",funding_weight:%}",
|
",funding_weight:%}",
|
||||||
JSON_SCAN(json_to_sat, &sats),
|
JSON_SCAN(json_to_msat, &fee_base),
|
||||||
JSON_SCAN(json_to_u16,
|
JSON_SCAN(json_to_u16,
|
||||||
&payload->rates->lease_fee_basis),
|
&payload->rates->lease_fee_basis),
|
||||||
JSON_SCAN(json_to_msat, &msats),
|
JSON_SCAN(json_to_msat, &fee_max_base),
|
||||||
JSON_SCAN(json_to_u16,
|
JSON_SCAN(json_to_u16,
|
||||||
&payload->rates->channel_fee_max_proportional_thousandths),
|
&payload->rates->channel_fee_max_proportional_thousandths),
|
||||||
JSON_SCAN(json_to_u16,
|
JSON_SCAN(json_to_u16,
|
||||||
@@ -771,11 +770,11 @@ openchannel2_hook_deserialize(struct openchannel2_payload *payload,
|
|||||||
|
|
||||||
/* Convert to u32s */
|
/* Convert to u32s */
|
||||||
if (payload->rates &&
|
if (payload->rates &&
|
||||||
!lease_rates_set_lease_fee_sat(payload->rates, sats))
|
!lease_rates_set_lease_fee_msat(payload->rates, fee_base))
|
||||||
fatal("Plugin sent overflowing `lease_fee_base_msat`");
|
fatal("Plugin sent overflowing/non-sat `lease_fee_base_msat`");
|
||||||
|
|
||||||
if (payload->rates &&
|
if (payload->rates &&
|
||||||
!lease_rates_set_chan_fee_base_msat(payload->rates, msats))
|
!lease_rates_set_chan_fee_base_msat(payload->rates, fee_max_base))
|
||||||
fatal("Plugin sent overflowing `channel_fee_max_base_msat`");
|
fatal("Plugin sent overflowing `channel_fee_max_base_msat`");
|
||||||
|
|
||||||
/* Add a serial_id to everything that doesn't have one yet */
|
/* Add a serial_id to everything that doesn't have one yet */
|
||||||
|
|||||||
@@ -363,12 +363,11 @@ static struct command_result *json_setleaserates(struct command *cmd,
|
|||||||
{
|
{
|
||||||
struct json_stream *res;
|
struct json_stream *res;
|
||||||
struct lease_rates *rates;
|
struct lease_rates *rates;
|
||||||
struct amount_sat *lease_base_sat;
|
struct amount_msat *channel_fee_base_msat, *lease_base_msat;
|
||||||
struct amount_msat *channel_fee_base_msat;
|
|
||||||
u32 *lease_basis, *channel_fee_max_ppt, *funding_weight;
|
u32 *lease_basis, *channel_fee_max_ppt, *funding_weight;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req("lease_fee_base_msat", param_sat, &lease_base_sat),
|
p_req("lease_fee_base_msat", param_msat, &lease_base_msat),
|
||||||
p_req("lease_fee_basis", param_number, &lease_basis),
|
p_req("lease_fee_basis", param_number, &lease_basis),
|
||||||
p_req("funding_weight", param_number, &funding_weight),
|
p_req("funding_weight", param_number, &funding_weight),
|
||||||
p_req("channel_fee_max_base_msat", param_msat,
|
p_req("channel_fee_max_base_msat", param_msat,
|
||||||
@@ -380,7 +379,7 @@ static struct command_result *json_setleaserates(struct command *cmd,
|
|||||||
|
|
||||||
rates = tal(tmpctx, struct lease_rates);
|
rates = tal(tmpctx, struct lease_rates);
|
||||||
rates->lease_fee_basis = *lease_basis;
|
rates->lease_fee_basis = *lease_basis;
|
||||||
rates->lease_fee_base_sat = lease_base_sat->satoshis; /* Raw: conversion */
|
rates->lease_fee_base_sat = lease_base_msat->millisatoshis / 1000; /* Raw: conversion */
|
||||||
rates->channel_fee_max_base_msat = channel_fee_base_msat->millisatoshis; /* Raw: conversion */
|
rates->channel_fee_max_base_msat = channel_fee_base_msat->millisatoshis; /* Raw: conversion */
|
||||||
|
|
||||||
rates->funding_weight = *funding_weight;
|
rates->funding_weight = *funding_weight;
|
||||||
@@ -388,7 +387,7 @@ static struct command_result *json_setleaserates(struct command *cmd,
|
|||||||
= *channel_fee_max_ppt;
|
= *channel_fee_max_ppt;
|
||||||
|
|
||||||
/* Gotta check that we didn't overflow */
|
/* Gotta check that we didn't overflow */
|
||||||
if (lease_base_sat->satoshis > rates->lease_fee_base_sat) /* Raw: comparison */
|
if (lease_base_msat->millisatoshis != rates->lease_fee_base_sat * (u64)1000) /* Raw: comparison */
|
||||||
return command_fail_badparam(cmd, "lease_fee_base_msat",
|
return command_fail_badparam(cmd, "lease_fee_base_msat",
|
||||||
buffer, params, "Overflow");
|
buffer, params, "Overflow");
|
||||||
|
|
||||||
|
|||||||
@@ -1049,16 +1049,15 @@ static void tell_lightningd_lease_rates(struct plugin *p,
|
|||||||
struct lease_rates *rates)
|
struct lease_rates *rates)
|
||||||
{
|
{
|
||||||
struct json_out *jout;
|
struct json_out *jout;
|
||||||
struct amount_sat val;
|
|
||||||
struct amount_msat mval;
|
struct amount_msat mval;
|
||||||
|
|
||||||
/* Tell lightningd with our lease rates*/
|
/* Tell lightningd with our lease rates*/
|
||||||
jout = json_out_new(NULL);
|
jout = json_out_new(NULL);
|
||||||
json_out_start(jout, NULL, '{');
|
json_out_start(jout, NULL, '{');
|
||||||
|
|
||||||
val = amount_sat(rates->lease_fee_base_sat);
|
mval = amount_msat(rates->lease_fee_base_sat * 1000);
|
||||||
json_out_addstr(jout, "lease_fee_base_msat",
|
json_out_addstr(jout, "lease_fee_base_msat",
|
||||||
type_to_string(tmpctx, struct amount_sat, &val));
|
type_to_string(tmpctx, struct amount_msat, &mval));
|
||||||
json_out_add(jout, "lease_fee_basis", false,
|
json_out_add(jout, "lease_fee_basis", false,
|
||||||
"%d", rates->lease_fee_basis);
|
"%d", rates->lease_fee_basis);
|
||||||
|
|
||||||
@@ -1077,7 +1076,7 @@ static void tell_lightningd_lease_rates(struct plugin *p,
|
|||||||
rpc_scan(p, "setleaserates", take(jout),
|
rpc_scan(p, "setleaserates", take(jout),
|
||||||
/* Unused */
|
/* Unused */
|
||||||
"{lease_fee_base_msat:%}",
|
"{lease_fee_base_msat:%}",
|
||||||
JSON_SCAN(json_to_msat_as_sats, &val));
|
JSON_SCAN(json_to_msat, &mval));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user