From 9a97f8c154dfc84e69d494a1a72bfdc00041de5a Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 8 Jun 2022 13:54:18 +0200 Subject: [PATCH] plugin: Add `reserve` to `openchannel` hook result Changelog-Added: plugin: The `openchannel` hook may return a custom absolute `reserve` value that the peer must not dip below. --- doc/PLUGINS.md | 18 +++++++++++++++++- lightningd/opening_control.c | 11 +++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/doc/PLUGINS.md b/doc/PLUGINS.md index 563e34fe0..6152bed95 100644 --- a/doc/PLUGINS.md +++ b/doc/PLUGINS.md @@ -1198,13 +1198,29 @@ e.g. { "result": "continue", "close_to": "bc1qlq8srqnz64wgklmqvurv7qnr4rvtq2u96hhfg2" + "mindepth": 0, + "reserve": "1234sat" } ``` Note that `close_to` must be a valid address for the current chain, an invalid address will cause the node to exit with an error. -Note that `openchannel` is a chained hook. Therefore `close_to` will only be + - `mindepth` is the number of confirmations to require before making + the channel usable. Notice that setting this to 0 (`zeroconf`) or + some other low value might expose you to double-spending issues, so + only lower this value from the default if you trust the peer not to + double-spend, or you reject incoming payments, including forwards, + until the funding is confirmed. + + - `reserve` is an absolute value for the amount in the channel that + the peer must keep on their side. This ensures that they always + have something to lose, so only lower this below the 1% of funding + amount if you trust the peer. The protocol requires this to be + larger than the dust limit, hence it will be adjusted to be the + dust limit if the specified value is below. + +Note that `openchannel` is a chained hook. Therefore `close_to`, `reserve` will only be evaluated for the first plugin that sets it. If more than one plugin tries to set a `close_to` address an error will be logged. diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index a82959a53..bbdcf7745 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -732,6 +732,7 @@ openchannel_hook_deserialize(struct openchannel_hook_payload *payload, const jsmntok_t *t_errmsg = json_get_member(buffer, toks, "error_message"); const jsmntok_t *t_closeto = json_get_member(buffer, toks, "close_to"); const jsmntok_t *t_mindepth = json_get_member(buffer, toks, "mindepth"); + const jsmntok_t *t_reserve = json_get_member(buffer, toks, "reserve"); if (!t_result) fatal("Plugin returned an invalid response to the" @@ -793,6 +794,16 @@ openchannel_hook_deserialize(struct openchannel_hook_payload *payload, payload->uc->minimum_depth); } + if (t_reserve != NULL) { + payload->uc->reserve = tal(payload->uc, struct amount_sat); + json_to_sat(buffer, t_reserve, payload->uc->reserve); + log_debug(openingd->ld->log, + "Setting reserve=%s for this channel as requested by " + "the openchannel hook", + type_to_string(tmpctx, struct amount_sat, + payload->uc->reserve)); + } + return true; }