lightningd: add option opening_anchor_channel to fundpsbt, utxopsbt.

This is needed when we know we're *opening* an anchor channel, to
override the "do we already have an anchor channel open?" logic.

Also, document the nonwrapped arg added in v23.02.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `fundpsbt` and `utxopsbt` new parameter `opening_anchor_channel` so lightningd knowns it needs emergency reserve for anchors.
This commit is contained in:
Rusty Russell 2023-06-29 09:44:10 +09:30
parent 391da2f440
commit 0402e645f0
8 changed files with 242 additions and 186 deletions

View file

@ -664,6 +664,8 @@
"FundPsbt.locktime": 6,
"FundPsbt.min_witness_weight": 7,
"FundPsbt.minconf": 4,
"FundPsbt.nonwrapped": 9,
"FundPsbt.opening_anchor_channel": 10,
"FundPsbt.reserve": 5,
"FundPsbt.satoshi": 1,
"FundPsbt.startweight": 3
@ -1468,6 +1470,7 @@
"UtxoPsbt.feerate": 2,
"UtxoPsbt.locktime": 6,
"UtxoPsbt.min_witness_weight": 7,
"UtxoPsbt.opening_anchor_channel": 10,
"UtxoPsbt.reserve": 5,
"UtxoPsbt.reservedok": 8,
"UtxoPsbt.satoshi": 1,
@ -2780,6 +2783,14 @@
"added": "pre-v0.10.1",
"deprecated": false
},
"FundPsbt.nonwrapped": {
"added": "v23.02",
"deprecated": false
},
"FundPsbt.opening_anchor_channel": {
"added": "v23.08",
"deprecated": false
},
"FundPsbt.psbt": {
"added": "pre-v0.10.1",
"deprecated": false
@ -5192,6 +5203,10 @@
"added": "pre-v0.10.1",
"deprecated": false
},
"UtxoPsbt.opening_anchor_channel": {
"added": "v23.08",
"deprecated": false
},
"UtxoPsbt.psbt": {
"added": "pre-v0.10.1",
"deprecated": false

View file

@ -977,6 +977,8 @@ message FundpsbtRequest {
optional uint32 locktime = 6;
optional uint32 min_witness_weight = 7;
optional bool excess_as_change = 8;
optional bool nonwrapped = 9;
optional bool opening_anchor_channel = 10;
}
message FundpsbtResponse {
@ -1025,6 +1027,7 @@ message UtxopsbtRequest {
optional uint32 locktime = 6;
optional uint32 min_witness_weight = 7;
optional bool excess_as_change = 9;
optional bool opening_anchor_channel = 10;
}
message UtxopsbtResponse {

View file

@ -1987,6 +1987,8 @@ impl From<requests::FundpsbtRequest> for pb::FundpsbtRequest {
locktime: c.locktime, // Rule #2 for type u32?
min_witness_weight: c.min_witness_weight, // Rule #2 for type u32?
excess_as_change: c.excess_as_change, // Rule #2 for type boolean?
nonwrapped: c.nonwrapped, // Rule #2 for type boolean?
opening_anchor_channel: c.opening_anchor_channel, // Rule #2 for type boolean?
}
}
}
@ -2026,6 +2028,7 @@ impl From<requests::UtxopsbtRequest> for pb::UtxopsbtRequest {
locktime: c.locktime, // Rule #2 for type u32?
min_witness_weight: c.min_witness_weight, // Rule #2 for type u32?
excess_as_change: c.excess_as_change, // Rule #2 for type boolean?
opening_anchor_channel: c.opening_anchor_channel, // Rule #2 for type boolean?
}
}
}
@ -2656,6 +2659,8 @@ impl From<pb::FundpsbtRequest> for requests::FundpsbtRequest {
locktime: c.locktime, // Rule #1 for type u32?
min_witness_weight: c.min_witness_weight, // Rule #1 for type u32?
excess_as_change: c.excess_as_change, // Rule #1 for type boolean?
nonwrapped: c.nonwrapped, // Rule #1 for type boolean?
opening_anchor_channel: c.opening_anchor_channel, // Rule #1 for type boolean?
}
}
}
@ -2693,6 +2698,7 @@ impl From<pb::UtxopsbtRequest> for requests::UtxopsbtRequest {
locktime: c.locktime, // Rule #1 for type u32?
min_witness_weight: c.min_witness_weight, // Rule #1 for type u32?
excess_as_change: c.excess_as_change, // Rule #1 for type boolean?
opening_anchor_channel: c.opening_anchor_channel, // Rule #1 for type boolean?
}
}
}

6
cln-rpc/src/model.rs generated
View file

@ -887,6 +887,10 @@ pub mod requests {
pub min_witness_weight: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub excess_as_change: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub nonwrapped: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub opening_anchor_channel: Option<bool>,
}
impl From<FundpsbtRequest> for Request {
@ -949,6 +953,8 @@ pub mod requests {
pub min_witness_weight: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub excess_as_change: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub opening_anchor_channel: Option<bool>,
}
impl From<UtxopsbtRequest> for Request {

File diff suppressed because one or more lines are too long

View file

@ -32,6 +32,14 @@
},
"excess_as_change": {
"type": "boolean"
},
"nonwrapped": {
"added": "v23.02",
"type": "boolean"
},
"opening_anchor_channel": {
"added": "v23.08",
"type": "boolean"
}
}
}

View file

@ -39,6 +39,10 @@
},
"excess_as_change": {
"type": "boolean"
},
"opening_anchor_channel": {
"added": "v23.08",
"type": "boolean"
}
}
}

View file

@ -492,7 +492,7 @@ static struct command_result *json_fundpsbt(struct command *cmd,
u32 *feerate_per_kw;
u32 *minconf, *weight, *min_witness_weight;
struct amount_sat *amount, input, diff, change;
bool all, *excess_as_change, *nonwrapped;
bool all, *excess_as_change, *nonwrapped, *keep_emergency_funds;
u32 *locktime, *reserve, maxheight;
u32 current_height;
@ -510,9 +510,16 @@ static struct command_result *json_fundpsbt(struct command *cmd,
&excess_as_change, false),
p_opt_def("nonwrapped", param_bool,
&nonwrapped, false),
p_opt_def("opening_anchor_channel", param_bool,
&keep_emergency_funds, false),
NULL))
return command_param_failed();
/* If we have anchor channels, we definitely need to keep
* emergency funds. */
if (have_anchor_channel(cmd->ld))
*keep_emergency_funds = true;
all = amount_sat_eq(*amount, AMOUNT_SAT(-1ULL));
maxheight = minconf_to_maxheight(*minconf, cmd->ld);
@ -608,7 +615,7 @@ static struct command_result *json_fundpsbt(struct command *cmd,
/* If needed, add change output for emergency_sat */
if (!change_for_emergency(cmd->ld,
have_anchor_channel(cmd->ld),
*keep_emergency_funds,
utxos, *feerate_per_kw, *weight,
&diff, &change)) {
return command_fail(cmd, FUND_CANNOT_AFFORD_WITH_EMERGENCY,
@ -699,7 +706,7 @@ static struct command_result *json_utxopsbt(struct command *cmd,
{
struct utxo **utxos;
u32 *feerate_per_kw, *weight, *min_witness_weight;
bool all, *reserved_ok, *excess_as_change;
bool all, *reserved_ok, *excess_as_change, *keep_emergency_funds;
struct amount_sat *amount, input, excess, change;
u32 current_height, *locktime, *reserve;
@ -716,9 +723,16 @@ static struct command_result *json_utxopsbt(struct command *cmd,
&min_witness_weight, 0),
p_opt_def("excess_as_change", param_bool,
&excess_as_change, false),
p_opt_def("opening_anchor_channel", param_bool,
&keep_emergency_funds, false),
NULL))
return command_param_failed();
/* If we have anchor channels, we definitely need to keep
* emergency funds. */
if (have_anchor_channel(cmd->ld))
*keep_emergency_funds = true;
all = amount_sat_eq(*amount, AMOUNT_SAT(-1ULL));
input = AMOUNT_SAT(0);
@ -787,7 +801,7 @@ static struct command_result *json_utxopsbt(struct command *cmd,
/* If needed, add change output for emergency_sat */
if (!change_for_emergency(cmd->ld,
have_anchor_channel(cmd->ld),
*keep_emergency_funds,
utxos, *feerate_per_kw, *weight,
&excess, &change)) {
return command_fail(cmd, FUND_CANNOT_AFFORD_WITH_EMERGENCY,