mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
closing: add option to set closing range.
This affects the range we offer even without quick-close, but it's more critical for quick-close. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-Added: JSONRPC: `close` now takes a `feerange` parameter to set min/max fee rates for mutual close.
This commit is contained in:
@@ -263,6 +263,7 @@ struct channel *new_unsaved_channel(struct peer *peer,
|
||||
channel->closing_fee_negotiation_step_unit
|
||||
= CLOSING_FEE_NEGOTIATION_STEP_UNIT_PERCENTAGE;
|
||||
channel->shutdown_wrong_funding = NULL;
|
||||
channel->closing_feerate_range = NULL;
|
||||
|
||||
/* Channel is connected! */
|
||||
channel->connected = true;
|
||||
@@ -429,6 +430,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
||||
= CLOSING_FEE_NEGOTIATION_STEP_UNIT_PERCENTAGE;
|
||||
channel->shutdown_wrong_funding
|
||||
= tal_steal(channel, shutdown_wrong_funding);
|
||||
channel->closing_feerate_range = NULL;
|
||||
if (local_shutdown_scriptpubkey)
|
||||
channel->shutdown_scriptpubkey[LOCAL]
|
||||
= tal_steal(channel, local_shutdown_scriptpubkey);
|
||||
|
||||
@@ -174,6 +174,9 @@ struct channel {
|
||||
/* optional wrong_funding for mutual close */
|
||||
const struct bitcoin_outpoint *shutdown_wrong_funding;
|
||||
|
||||
/* optional feerate min/max for mutual close */
|
||||
u32 *closing_feerate_range;
|
||||
|
||||
/* Reestablishment stuff: last sent commit and revocation details. */
|
||||
bool last_was_revoke;
|
||||
struct changed_htlc *last_sent_commit;
|
||||
|
||||
@@ -193,7 +193,7 @@ void peer_start_closingd(struct channel *channel,
|
||||
struct per_peer_state *pps)
|
||||
{
|
||||
u8 *initmsg;
|
||||
u32 feerate, *max_feerate;
|
||||
u32 min_feerate, feerate, *max_feerate;
|
||||
struct amount_msat their_msat;
|
||||
struct amount_sat feelimit;
|
||||
int hsmfd;
|
||||
@@ -266,6 +266,14 @@ void peer_start_closingd(struct channel *channel,
|
||||
} else
|
||||
max_feerate = NULL;
|
||||
|
||||
min_feerate = feerate_min(ld, NULL);
|
||||
|
||||
/* If they specified feerates in `close`, they apply now! */
|
||||
if (channel->closing_feerate_range) {
|
||||
min_feerate = channel->closing_feerate_range[0];
|
||||
max_feerate = &channel->closing_feerate_range[1];
|
||||
}
|
||||
|
||||
/* BOLT #3:
|
||||
*
|
||||
* Each node offering a signature:
|
||||
@@ -298,8 +306,7 @@ void peer_start_closingd(struct channel *channel,
|
||||
amount_msat_to_sat_round_down(channel->our_msat),
|
||||
amount_msat_to_sat_round_down(their_msat),
|
||||
channel->our_config.dust_limit,
|
||||
feerate_min(ld, NULL), feerate,
|
||||
max_feerate,
|
||||
min_feerate, feerate, max_feerate,
|
||||
feelimit,
|
||||
channel->shutdown_scriptpubkey[LOCAL],
|
||||
channel->shutdown_scriptpubkey[REMOTE],
|
||||
|
||||
@@ -1661,6 +1661,31 @@ static struct command_result *param_outpoint(struct command *cmd,
|
||||
"should be a txid:outnum");
|
||||
}
|
||||
|
||||
static struct command_result *param_feerate_range(struct command *cmd,
|
||||
const char *name,
|
||||
const char *buffer,
|
||||
const jsmntok_t *tok,
|
||||
u32 **feerate_range)
|
||||
{
|
||||
struct command_result *ret;
|
||||
u32 *rate;
|
||||
|
||||
*feerate_range = tal_arr(cmd, u32, 2);
|
||||
if (tok->type != JSMN_ARRAY || tok->size != 2)
|
||||
return command_fail_badparam(cmd, name, buffer, tok,
|
||||
"should be an array of 2 entries");
|
||||
|
||||
ret = param_feerate(cmd, name, buffer, tok+1, &rate);
|
||||
if (ret)
|
||||
return ret;
|
||||
(*feerate_range)[0] = *rate;
|
||||
ret = param_feerate(cmd, name, buffer, tok+2, &rate);
|
||||
if (ret)
|
||||
return ret;
|
||||
(*feerate_range)[1] = *rate;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct command_result *json_close(struct command *cmd,
|
||||
const char *buffer,
|
||||
const jsmntok_t *obj UNNEEDED,
|
||||
@@ -1674,6 +1699,7 @@ static struct command_result *json_close(struct command *cmd,
|
||||
bool close_script_set, wrong_funding_changed, *force_lease_close;
|
||||
const char *fee_negotiation_step_str;
|
||||
struct bitcoin_outpoint *wrong_funding;
|
||||
u32 *feerate_range;
|
||||
char* end;
|
||||
bool anysegwit;
|
||||
|
||||
@@ -1687,6 +1713,7 @@ static struct command_result *json_close(struct command *cmd,
|
||||
p_opt("wrong_funding", param_outpoint, &wrong_funding),
|
||||
p_opt_def("force_lease_closed", param_bool,
|
||||
&force_lease_close, false),
|
||||
p_opt("feerange", param_feerate_range, &feerate_range),
|
||||
NULL))
|
||||
return command_param_failed();
|
||||
|
||||
@@ -1845,6 +1872,9 @@ static struct command_result *json_close(struct command *cmd,
|
||||
wrong_funding_changed = false;
|
||||
}
|
||||
|
||||
/* Works fine if feerate_range is NULL */
|
||||
channel->closing_feerate_range = tal_steal(channel, feerate_range);
|
||||
|
||||
/* Normal case.
|
||||
* We allow states shutting down and sigexchange; a previous
|
||||
* close command may have timed out, and this current command
|
||||
|
||||
@@ -534,6 +534,11 @@ struct command_result *param_escaped_string(struct command *cmd UNNEEDED,
|
||||
const jsmntok_t *tok UNNEEDED,
|
||||
const char **str UNNEEDED)
|
||||
{ fprintf(stderr, "param_escaped_string called!\n"); abort(); }
|
||||
/* Generated stub for param_feerate */
|
||||
struct command_result *param_feerate(struct command *cmd UNNEEDED, const char *name UNNEEDED,
|
||||
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||
u32 **feerate UNNEEDED)
|
||||
{ fprintf(stderr, "param_feerate called!\n"); abort(); }
|
||||
/* Generated stub for param_label */
|
||||
struct command_result *param_label(struct command *cmd UNNEEDED, const char *name UNNEEDED,
|
||||
const char * buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||
|
||||
Reference in New Issue
Block a user