mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
setchannel: add minhtlc
Suggested by @m-schmook, I realized that if we append it later I'll never get it right: I expect parameters min and max, not max and min! Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-Added: Protocol: you can now alter the `htlc_minimum_msat` and `htlc_maximum_msat` your node advertizes.
This commit is contained in:
@@ -861,6 +861,9 @@ static void json_add_channel(struct lightningd *ld,
|
||||
channel->our_config.htlc_minimum,
|
||||
"htlc_minimum_msat",
|
||||
"minimum_htlc_in_msat");
|
||||
json_add_amount_msat_only(response,
|
||||
"minimum_htlc_out_msat",
|
||||
channel->htlc_minimum_msat);
|
||||
json_add_amount_msat_only(response,
|
||||
"maximum_htlc_out_msat",
|
||||
channel->htlc_maximum_msat);
|
||||
@@ -2010,21 +2013,27 @@ static struct command_result *param_msat_u32(struct command *cmd,
|
||||
static void set_channel_config(struct command *cmd, struct channel *channel,
|
||||
u32 *base,
|
||||
u32 *ppm,
|
||||
struct amount_msat *htlc_min,
|
||||
struct amount_msat *htlc_max,
|
||||
u32 delaysecs,
|
||||
struct json_stream *response,
|
||||
bool add_details)
|
||||
{
|
||||
bool warn_cannot_set_min = false;
|
||||
|
||||
/* We only need to defer values if we *increase* fees (or drop
|
||||
* max); we always allow users to overpay fees. */
|
||||
* max, increase min); we always allow users to overpay fees. */
|
||||
if ((base && *base > channel->feerate_base)
|
||||
|| (ppm && *ppm > channel->feerate_ppm)
|
||||
|| (htlc_min
|
||||
&& amount_msat_greater(*htlc_min, channel->htlc_minimum_msat))
|
||||
|| (htlc_max
|
||||
&& amount_msat_less(*htlc_max, channel->htlc_maximum_msat))) {
|
||||
channel->old_feerate_timeout
|
||||
= timeabs_add(time_now(), time_from_sec(delaysecs));
|
||||
channel->old_feerate_base = channel->feerate_base;
|
||||
channel->old_feerate_ppm = channel->feerate_ppm;
|
||||
channel->old_htlc_minimum_msat = channel->htlc_minimum_msat;
|
||||
channel->old_htlc_maximum_msat = channel->htlc_maximum_msat;
|
||||
}
|
||||
|
||||
@@ -2033,6 +2042,17 @@ static void set_channel_config(struct command *cmd, struct channel *channel,
|
||||
channel->feerate_base = *base;
|
||||
if (ppm)
|
||||
channel->feerate_ppm = *ppm;
|
||||
if (htlc_min) {
|
||||
struct amount_msat actual_min;
|
||||
|
||||
/* We can't send something they'll refuse: check that here. */
|
||||
actual_min = channel->channel_info.their_config.htlc_minimum;
|
||||
if (amount_msat_less(*htlc_min, actual_min)) {
|
||||
warn_cannot_set_min = true;
|
||||
channel->htlc_minimum_msat = actual_min;
|
||||
} else
|
||||
channel->htlc_minimum_msat = *htlc_min;
|
||||
}
|
||||
if (htlc_max)
|
||||
channel->htlc_maximum_msat = *htlc_max;
|
||||
|
||||
@@ -2040,7 +2060,7 @@ static void set_channel_config(struct command *cmd, struct channel *channel,
|
||||
if (channel->owner && streq(channel->owner->name, "channeld"))
|
||||
subd_send_msg(channel->owner,
|
||||
take(towire_channeld_config_channel(NULL, base, ppm,
|
||||
htlc_max)));
|
||||
htlc_min, htlc_max)));
|
||||
|
||||
/* save values to database */
|
||||
wallet_channel_save(cmd->ld->wallet, channel);
|
||||
@@ -2059,6 +2079,12 @@ static void set_channel_config(struct command *cmd, struct channel *channel,
|
||||
amount_msat(channel->feerate_base));
|
||||
json_add_u32(response, "fee_proportional_millionths",
|
||||
channel->feerate_ppm);
|
||||
json_add_amount_msat_only(response,
|
||||
"minimum_htlc_out_msat",
|
||||
channel->htlc_minimum_msat);
|
||||
if (warn_cannot_set_min)
|
||||
json_add_string(response, "warning_htlcmin_too_low",
|
||||
"Set minimum_htlc_out_msat to minimum allowed by peer");
|
||||
json_add_amount_msat_only(response,
|
||||
"maximum_htlc_out_msat",
|
||||
channel->htlc_maximum_msat);
|
||||
@@ -2110,13 +2136,13 @@ static struct command_result *json_setchannelfee(struct command *cmd,
|
||||
channel->state != CHANNELD_AWAITING_LOCKIN &&
|
||||
channel->state != DUALOPEND_AWAITING_LOCKIN)
|
||||
continue;
|
||||
set_channel_config(cmd, channel, base, ppm, NULL,
|
||||
set_channel_config(cmd, channel, base, ppm, NULL, NULL,
|
||||
*delaysecs, response, false);
|
||||
}
|
||||
|
||||
/* single channel should be updated */
|
||||
} else {
|
||||
set_channel_config(cmd, channel, base, ppm, NULL,
|
||||
set_channel_config(cmd, channel, base, ppm, NULL, NULL,
|
||||
*delaysecs, response, false);
|
||||
}
|
||||
|
||||
@@ -2149,13 +2175,14 @@ static struct command_result *json_setchannel(struct command *cmd,
|
||||
struct peer *peer;
|
||||
struct channel *channel;
|
||||
u32 *base, *ppm, *delaysecs;
|
||||
struct amount_msat *htlc_max;
|
||||
struct amount_msat *htlc_min, *htlc_max;
|
||||
|
||||
/* Parse the JSON command */
|
||||
if (!param(cmd, buffer, params,
|
||||
p_req("id", param_channel_or_all, &channel),
|
||||
p_opt("feebase", param_msat_u32, &base),
|
||||
p_opt("feeppm", param_number, &ppm),
|
||||
p_opt("htlcmin", param_msat, &htlc_min),
|
||||
p_opt("htlcmax", param_msat, &htlc_max),
|
||||
p_opt_def("enforcedelay", param_number, &delaysecs, 600),
|
||||
NULL))
|
||||
@@ -2182,13 +2209,15 @@ static struct command_result *json_setchannel(struct command *cmd,
|
||||
channel->state != CHANNELD_AWAITING_LOCKIN &&
|
||||
channel->state != DUALOPEND_AWAITING_LOCKIN)
|
||||
continue;
|
||||
set_channel_config(cmd, channel, base, ppm, htlc_max,
|
||||
set_channel_config(cmd, channel, base, ppm,
|
||||
htlc_min, htlc_max,
|
||||
*delaysecs, response, true);
|
||||
}
|
||||
|
||||
/* single channel should be updated */
|
||||
} else {
|
||||
set_channel_config(cmd, channel, base, ppm, htlc_max,
|
||||
set_channel_config(cmd, channel, base, ppm,
|
||||
htlc_min, htlc_max,
|
||||
*delaysecs, response, true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user