fundchannel, txprepare, multiwithdraw: don't assume "excess_msat" will have "msat" appended.

After next patch, it's a raw u64, and this code broke.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-06-20 19:52:09 +09:30
parent 08d5776ebc
commit 98c264de66
3 changed files with 12 additions and 6 deletions

View file

@ -1316,6 +1316,7 @@ after_fundpsbt(struct command *cmd,
struct multifundchannel_command *mfc)
{
const jsmntok_t *field;
struct amount_msat msat;
plugin_log(mfc->cmd->plugin, LOG_DBG,
"mfc %"PRIu64": %s done.",
@ -1341,9 +1342,10 @@ after_fundpsbt(struct command *cmd,
/* msat LOL. */
field = json_get_member(buf, result, "excess_msat");
if (!field || !parse_amount_sat(&mfc->excess_sat,
buf + field->start,
field->end - field->start))
if (!field || !parse_amount_msat(&msat,
buf + field->start,
field->end - field->start)
|| !amount_msat_to_sat(&mfc->excess_sat, msat))
goto fail;
if (has_all(mfc))

View file

@ -410,6 +410,7 @@ mw_after_fundpsbt(struct command *cmd,
u32 feerate_per_kw;
u32 estimated_final_weight;
struct amount_sat excess_sat;
struct amount_msat excess_msat;
bool ok = true;
/* Extract results. */
@ -430,7 +431,8 @@ mw_after_fundpsbt(struct command *cmd,
field = ok ? json_get_member(buf, result, "excess_msat") : NULL;
ok = ok && field;
ok = ok && json_to_sat(buf, field, &excess_sat);
ok = ok && json_to_msat(buf, field, &excess_msat);
ok = ok && amount_msat_to_sat(&excess_sat, excess_msat);
if (!ok)
plugin_err(mw->cmd->plugin,

View file

@ -282,6 +282,7 @@ static struct command_result *psbt_created(struct command *cmd,
{
const jsmntok_t *psbttok;
struct out_req *req;
struct amount_msat excess_msat;
struct amount_sat excess;
u32 weight;
@ -300,8 +301,9 @@ static struct command_result *psbt_created(struct command *cmd,
result->end - result->start,
buf + result->start);
if (!json_to_sat(buf, json_get_member(buf, result, "excess_msat"),
&excess))
if (!json_to_msat(buf, json_get_member(buf, result, "excess_msat"),
&excess_msat)
|| !amount_msat_to_sat(&excess, excess_msat))
return command_fail(cmd, LIGHTNINGD,
"Unparsable excess_msat: '%.*s'",
result->end - result->start,