mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-23 09:04:22 +01:00
openingd: Add reserve to fundchannel and multifundchannel
Changelog-Added: JSON-RPC: `fundchannel`, `multifundchannel` and `fundchannel_start` now accept a `reserve` parameter to indicate the absolute reserve to impose on the peer.
This commit is contained in:
@@ -393,6 +393,7 @@
|
|||||||
"FundChannel.mindepth": 12,
|
"FundChannel.mindepth": 12,
|
||||||
"FundChannel.push_msat": 5,
|
"FundChannel.push_msat": 5,
|
||||||
"FundChannel.request_amt": 7,
|
"FundChannel.request_amt": 7,
|
||||||
|
"FundChannel.reserve": 13,
|
||||||
"FundChannel.utxos[]": 11
|
"FundChannel.utxos[]": 11
|
||||||
},
|
},
|
||||||
"FundchannelResponse": {
|
"FundchannelResponse": {
|
||||||
|
|||||||
@@ -1158,6 +1158,7 @@ message FundchannelRequest {
|
|||||||
optional string compact_lease = 8;
|
optional string compact_lease = 8;
|
||||||
repeated Outpoint utxos = 11;
|
repeated Outpoint utxos = 11;
|
||||||
optional uint32 mindepth = 12;
|
optional uint32 mindepth = 12;
|
||||||
|
optional Amount reserve = 13;
|
||||||
}
|
}
|
||||||
|
|
||||||
message FundchannelResponse {
|
message FundchannelResponse {
|
||||||
|
|||||||
@@ -1464,6 +1464,7 @@ impl From<&pb::FundchannelRequest> for requests::FundchannelRequest {
|
|||||||
compact_lease: c.compact_lease.clone(), // Rule #1 for type string?
|
compact_lease: c.compact_lease.clone(), // Rule #1 for type string?
|
||||||
utxos: Some(c.utxos.iter().map(|s| s.into()).collect()), // Rule #4
|
utxos: Some(c.utxos.iter().map(|s| s.into()).collect()), // Rule #4
|
||||||
mindepth: c.mindepth.clone(), // Rule #1 for type u32?
|
mindepth: c.mindepth.clone(), // Rule #1 for type u32?
|
||||||
|
reserve: c.reserve.as_ref().map(|a| a.into()), // Rule #1 for type msat?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -726,6 +726,8 @@ pub mod requests {
|
|||||||
pub utxos: Option<Vec<Outpoint>>,
|
pub utxos: Option<Vec<Outpoint>>,
|
||||||
#[serde(alias = "mindepth", skip_serializing_if = "Option::is_none")]
|
#[serde(alias = "mindepth", skip_serializing_if = "Option::is_none")]
|
||||||
pub mindepth: Option<u32>,
|
pub mindepth: Option<u32>,
|
||||||
|
#[serde(alias = "reserve", skip_serializing_if = "Option::is_none")]
|
||||||
|
pub reserve: Option<Amount>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
|||||||
@@ -730,7 +730,8 @@ class LightningRpc(UnixDomainSocketRpc):
|
|||||||
def fundchannel(self, node_id, amount, feerate=None, announce=True,
|
def fundchannel(self, node_id, amount, feerate=None, announce=True,
|
||||||
minconf=None, utxos=None, push_msat=None, close_to=None,
|
minconf=None, utxos=None, push_msat=None, close_to=None,
|
||||||
request_amt=None, compact_lease=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
|
Fund channel with {id} using {amount} satoshis with feerate
|
||||||
of {feerate} (uses default feerate if unset).
|
of {feerate} (uses default feerate if unset).
|
||||||
@@ -756,6 +757,7 @@ class LightningRpc(UnixDomainSocketRpc):
|
|||||||
"request_amt": request_amt,
|
"request_amt": request_amt,
|
||||||
"compact_lease": compact_lease,
|
"compact_lease": compact_lease,
|
||||||
"mindepth": mindepth,
|
"mindepth": mindepth,
|
||||||
|
"reserve": reserve,
|
||||||
}
|
}
|
||||||
return self.call("fundchannel", payload)
|
return self.call("fundchannel", payload)
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -44,6 +44,10 @@
|
|||||||
"mindepth": {
|
"mindepth": {
|
||||||
"description": "Number of confirmations required before we consider the channel active",
|
"description": "Number of confirmations required before we consider the channel active",
|
||||||
"type": "u32"
|
"type": "u32"
|
||||||
|
},
|
||||||
|
"reserve": {
|
||||||
|
"type": "msat",
|
||||||
|
"description": "The amount we want the peer to maintain on its side"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,13 @@ new_uncommitted_channel(struct peer *peer)
|
|||||||
/* We override this in openchannel hook if we want zeroconf */
|
/* We override this in openchannel hook if we want zeroconf */
|
||||||
uc->minimum_depth = ld->config.anchor_confirms;
|
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. */
|
/* Declare the new channel to the HSM. */
|
||||||
new_channel_msg = towire_hsmd_new_channel(NULL, &uc->peer->id, uc->dbid);
|
new_channel_msg = towire_hsmd_new_channel(NULL, &uc->peer->id, uc->dbid);
|
||||||
if (!wire_sync_write(ld->hsm_fd, take(new_channel_msg)))
|
if (!wire_sync_write(ld->hsm_fd, take(new_channel_msg)))
|
||||||
|
|||||||
@@ -58,6 +58,12 @@ struct uncommitted_channel {
|
|||||||
|
|
||||||
/* Our channel config. */
|
/* Our channel config. */
|
||||||
struct channel_config our_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 {
|
struct funding_channel {
|
||||||
@@ -66,6 +72,7 @@ struct funding_channel {
|
|||||||
struct wallet_tx *wtx;
|
struct wallet_tx *wtx;
|
||||||
struct amount_msat push;
|
struct amount_msat push;
|
||||||
struct amount_sat funding_sats;
|
struct amount_sat funding_sats;
|
||||||
|
|
||||||
u8 channel_flags;
|
u8 channel_flags;
|
||||||
const u8 *our_upfront_shutdown_script;
|
const u8 *our_upfront_shutdown_script;
|
||||||
|
|
||||||
|
|||||||
@@ -1095,7 +1095,7 @@ static struct command_result *json_fundchannel_start(struct command *cmd,
|
|||||||
bool *announce_channel;
|
bool *announce_channel;
|
||||||
u32 *feerate_per_kw, *mindepth;
|
u32 *feerate_per_kw, *mindepth;
|
||||||
int fds[2];
|
int fds[2];
|
||||||
struct amount_sat *amount;
|
struct amount_sat *amount, *reserve;
|
||||||
struct amount_msat *push_msat;
|
struct amount_msat *push_msat;
|
||||||
u32 *upfront_shutdown_script_wallet_index;
|
u32 *upfront_shutdown_script_wallet_index;
|
||||||
struct channel_id tmp_channel_id;
|
struct channel_id tmp_channel_id;
|
||||||
@@ -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("close_to", param_bitcoin_address, &fc->our_upfront_shutdown_script),
|
||||||
p_opt("push_msat", param_msat, &push_msat),
|
p_opt("push_msat", param_msat, &push_msat),
|
||||||
p_opt_def("mindepth", param_u32, &mindepth, cmd->ld->config.anchor_confirms),
|
p_opt_def("mindepth", param_u32, &mindepth, cmd->ld->config.anchor_confirms),
|
||||||
|
p_opt("reserve", param_sat, &reserve),
|
||||||
NULL))
|
NULL))
|
||||||
return command_param_failed();
|
return command_param_failed();
|
||||||
|
|
||||||
@@ -1223,6 +1224,8 @@ static struct command_result *json_fundchannel_start(struct command *cmd,
|
|||||||
assert(mindepth != NULL);
|
assert(mindepth != NULL);
|
||||||
fc->uc->minimum_depth = *mindepth;
|
fc->uc->minimum_depth = *mindepth;
|
||||||
|
|
||||||
|
fc->uc->reserve = reserve;
|
||||||
|
|
||||||
/* Needs to be stolen away from cmd */
|
/* Needs to be stolen away from cmd */
|
||||||
if (fc->our_upfront_shutdown_script)
|
if (fc->our_upfront_shutdown_script)
|
||||||
fc->our_upfront_shutdown_script
|
fc->our_upfront_shutdown_script
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ json_fundchannel(struct command *cmd,
|
|||||||
const jsmntok_t *request_amt;
|
const jsmntok_t *request_amt;
|
||||||
const jsmntok_t *compact_lease;
|
const jsmntok_t *compact_lease;
|
||||||
const jsmntok_t *mindepth;
|
const jsmntok_t *mindepth;
|
||||||
|
const jsmntok_t *reserve;
|
||||||
|
|
||||||
struct out_req *req;
|
struct out_req *req;
|
||||||
|
|
||||||
@@ -69,6 +70,7 @@ json_fundchannel(struct command *cmd,
|
|||||||
p_opt("request_amt", param_tok, &request_amt),
|
p_opt("request_amt", param_tok, &request_amt),
|
||||||
p_opt("compact_lease", param_tok, &compact_lease),
|
p_opt("compact_lease", param_tok, &compact_lease),
|
||||||
p_opt("mindepth", param_tok, &mindepth),
|
p_opt("mindepth", param_tok, &mindepth),
|
||||||
|
p_opt("reserve", param_tok, &reserve),
|
||||||
NULL))
|
NULL))
|
||||||
return command_param_failed();
|
return command_param_failed();
|
||||||
|
|
||||||
@@ -99,6 +101,9 @@ json_fundchannel(struct command *cmd,
|
|||||||
if (mindepth)
|
if (mindepth)
|
||||||
json_add_tok(req->js, "mindepth", mindepth, buf);
|
json_add_tok(req->js, "mindepth", mindepth, buf);
|
||||||
|
|
||||||
|
if (reserve)
|
||||||
|
json_add_tok(req->js, "reserve", reserve, buf);
|
||||||
|
|
||||||
json_object_end(req->js);
|
json_object_end(req->js);
|
||||||
json_array_end(req->js);
|
json_array_end(req->js);
|
||||||
if (feerate)
|
if (feerate)
|
||||||
|
|||||||
@@ -1125,6 +1125,11 @@ fundchannel_start_dest(struct multifundchannel_destination *dest)
|
|||||||
if (dest->mindepth)
|
if (dest->mindepth)
|
||||||
json_add_u32(req->js, "mindepth", *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);
|
send_outreq(cmd->plugin, req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1914,6 +1919,7 @@ param_destinations_array(struct command *cmd, const char *name,
|
|||||||
AMOUNT_SAT(0)),
|
AMOUNT_SAT(0)),
|
||||||
p_opt("compact_lease", param_lease_hex, &rates),
|
p_opt("compact_lease", param_lease_hex, &rates),
|
||||||
p_opt("mindepth", param_u32, &dest->mindepth),
|
p_opt("mindepth", param_u32, &dest->mindepth),
|
||||||
|
p_opt("reserve", param_sat, &dest->reserve),
|
||||||
NULL))
|
NULL))
|
||||||
return command_param_failed();
|
return command_param_failed();
|
||||||
|
|
||||||
|
|||||||
@@ -112,6 +112,8 @@ struct multifundchannel_destination {
|
|||||||
bool all;
|
bool all;
|
||||||
struct amount_sat amount;
|
struct amount_sat amount;
|
||||||
|
|
||||||
|
struct amount_sat *reserve;
|
||||||
|
|
||||||
/* the output index for this destination. */
|
/* the output index for this destination. */
|
||||||
unsigned int outnum;
|
unsigned int outnum;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user