Skip to content

Commit

Permalink
openingd: Add reserve to fundchannel and multifundchannel
Browse files Browse the repository at this point in the history
Changelog-Added: JSON-RPC: `fundchannel`, `multifundchannel` and `fundchannel_start` now accept a `reserve` parameter to indicate the absolute reserve to impose on the peer.
  • Loading branch information
cdecker committed Sep 21, 2022
1 parent 7159a25 commit 5c1de80
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 50 deletions.
1 change: 1 addition & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@
"FundChannel.mindepth": 12,
"FundChannel.push_msat": 5,
"FundChannel.request_amt": 7,
"FundChannel.reserve": 13,
"FundChannel.utxos[]": 11
},
"FundchannelResponse": {
Expand Down
1 change: 1 addition & 0 deletions cln-grpc/proto/node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,7 @@ message FundchannelRequest {
optional string compact_lease = 8;
repeated Outpoint utxos = 11;
optional uint32 mindepth = 12;
optional Amount reserve = 13;
}

message FundchannelResponse {
Expand Down
1 change: 1 addition & 0 deletions cln-grpc/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,7 @@ impl From<&pb::FundchannelRequest> for requests::FundchannelRequest {
compact_lease: c.compact_lease.clone(), // Rule #1 for type string?
utxos: Some(c.utxos.iter().map(|s| s.into()).collect()), // Rule #4
mindepth: c.mindepth.clone(), // Rule #1 for type u32?
reserve: c.reserve.as_ref().map(|a| a.into()), // Rule #1 for type msat?
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions cln-rpc/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,8 @@ pub mod requests {
pub utxos: Option<Vec<Outpoint>>,
#[serde(alias = "mindepth", skip_serializing_if = "Option::is_none")]
pub mindepth: Option<u32>,
#[serde(alias = "reserve", skip_serializing_if = "Option::is_none")]
pub reserve: Option<Amount>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down
4 changes: 3 additions & 1 deletion contrib/pyln-client/pyln/client/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,8 @@ def feerates(self, style, urgent=None, normal=None, slow=None):
def fundchannel(self, node_id, amount, feerate=None, announce=True,
minconf=None, utxos=None, push_msat=None, close_to=None,
request_amt=None, compact_lease=None,
mindepth: Optional[int] = None):
mindepth: Optional[int] = None,
reserve: Optional[str] = None):
"""
Fund channel with {id} using {amount} satoshis with feerate
of {feerate} (uses default feerate if unset).
Expand All @@ -756,6 +757,7 @@ def fundchannel(self, node_id, amount, feerate=None, announce=True,
"request_amt": request_amt,
"compact_lease": compact_lease,
"mindepth": mindepth,
"reserve": reserve,
}
return self.call("fundchannel", payload)

Expand Down
96 changes: 48 additions & 48 deletions contrib/pyln-testing/pyln/testing/node_pb2.py

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions doc/schemas/fundchannel.request.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
"mindepth": {
"description": "Number of confirmations required before we consider the channel active",
"type": "u32"
},
"reserve": {
"type": "msat",
"description": "The amount we want the peer to maintain on its side"
}
}
}
7 changes: 7 additions & 0 deletions lightningd/opening_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ new_uncommitted_channel(struct peer *peer)
/* We override this in openchannel hook if we want zeroconf */
uc->minimum_depth = ld->config.anchor_confirms;

/* Use default 1% reserve if not otherwise specified. If this
* is not-NULL it will be used by openingd as absolute value
* (clamped to dust limit). */
uc->reserve = NULL;

memset(&uc->cid, 0xFF, sizeof(uc->cid));

/* Declare the new channel to the HSM. */
new_channel_msg = towire_hsmd_new_channel(NULL, &uc->peer->id, uc->dbid);
if (!wire_sync_write(ld->hsm_fd, take(new_channel_msg)))
Expand Down
7 changes: 7 additions & 0 deletions lightningd/opening_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ struct uncommitted_channel {

/* Our channel config. */
struct channel_config our_config;

/* Reserve we will impose on the other side. If this is NULL
* we will use our default of 1% of the funding
* amount. Otherwise it will be used by openingd as absolute
* value (clamped to dust limit). */
struct amount_sat *reserve;
};

struct funding_channel {
Expand All @@ -66,6 +72,7 @@ struct funding_channel {
struct wallet_tx *wtx;
struct amount_msat push;
struct amount_sat funding_sats;

u8 channel_flags;
const u8 *our_upfront_shutdown_script;

Expand Down
5 changes: 4 additions & 1 deletion lightningd/opening_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ static struct command_result *json_fundchannel_start(struct command *cmd,
bool *announce_channel;
u32 *feerate_per_kw, *mindepth;
int fds[2];
struct amount_sat *amount;
struct amount_sat *amount, *reserve;
struct amount_msat *push_msat;
u32 *upfront_shutdown_script_wallet_index;
struct channel_id tmp_channel_id;
Expand All @@ -1114,6 +1114,7 @@ static struct command_result *json_fundchannel_start(struct command *cmd,
p_opt("close_to", param_bitcoin_address, &fc->our_upfront_shutdown_script),
p_opt("push_msat", param_msat, &push_msat),
p_opt_def("mindepth", param_u32, &mindepth, cmd->ld->config.anchor_confirms),
p_opt("reserve", param_sat, &reserve),
NULL))
return command_param_failed();

Expand Down Expand Up @@ -1223,6 +1224,8 @@ static struct command_result *json_fundchannel_start(struct command *cmd,
assert(mindepth != NULL);
fc->uc->minimum_depth = *mindepth;

fc->uc->reserve = reserve;

/* Needs to be stolen away from cmd */
if (fc->our_upfront_shutdown_script)
fc->our_upfront_shutdown_script
Expand Down
5 changes: 5 additions & 0 deletions plugins/spender/fundchannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ json_fundchannel(struct command *cmd,
const jsmntok_t *request_amt;
const jsmntok_t *compact_lease;
const jsmntok_t *mindepth;
const jsmntok_t *reserve;

struct out_req *req;

Expand All @@ -69,6 +70,7 @@ json_fundchannel(struct command *cmd,
p_opt("request_amt", param_tok, &request_amt),
p_opt("compact_lease", param_tok, &compact_lease),
p_opt("mindepth", param_tok, &mindepth),
p_opt("reserve", param_tok, &reserve),
NULL))
return command_param_failed();

Expand Down Expand Up @@ -99,6 +101,9 @@ json_fundchannel(struct command *cmd,
if (mindepth)
json_add_tok(req->js, "mindepth", mindepth, buf);

if (reserve)
json_add_tok(req->js, "reserve", reserve, buf);

json_object_end(req->js);
json_array_end(req->js);
if (feerate)
Expand Down
6 changes: 6 additions & 0 deletions plugins/spender/multifundchannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,11 @@ fundchannel_start_dest(struct multifundchannel_destination *dest)
if (dest->mindepth)
json_add_u32(req->js, "mindepth", *dest->mindepth);

if (dest->reserve)
json_add_string(
req->js, "reserve",
type_to_string(tmpctx, struct amount_sat, dest->reserve));

send_outreq(cmd->plugin, req);
}

Expand Down Expand Up @@ -1914,6 +1919,7 @@ param_destinations_array(struct command *cmd, const char *name,
AMOUNT_SAT(0)),
p_opt("compact_lease", param_lease_hex, &rates),
p_opt("mindepth", param_u32, &dest->mindepth),
p_opt("reserve", param_sat, &dest->reserve),
NULL))
return command_param_failed();

Expand Down
2 changes: 2 additions & 0 deletions plugins/spender/multifundchannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ struct multifundchannel_destination {
bool all;
struct amount_sat amount;

struct amount_sat *reserve;

/* the output index for this destination. */
unsigned int outnum;

Expand Down

0 comments on commit 5c1de80

Please sign in to comment.