From 52042bde800de967d2b0ca336d391216bc1bba18 Mon Sep 17 00:00:00 2001 From: lisa neigut Date: Thu, 23 May 2019 17:15:53 -0700 Subject: [PATCH] opening: stash amount outside of the wtx Some channels won't be opened with a wtx struct, so keep the total funding amount separate from it so we can show some stats for listpeers. Note that we're going to need to update/confirm this once the transaction gets confirmed. --- lightningd/opening_control.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 870412328..647c77c6c 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -73,6 +73,7 @@ struct funding_channel { struct wallet_tx *wtx; struct amount_msat push; + struct amount_sat funding; u8 channel_flags; /* Variables we need to compose fields in cmd's response */ @@ -132,7 +133,7 @@ void json_add_uncommitted_channel(struct json_stream *response, } /* These should never fail. */ - if (amount_sat_to_msat(&total, uc->fc->wtx->amount) + if (amount_sat_to_msat(&total, uc->fc->funding) && amount_msat_sub(&ours, total, uc->fc->push)) { json_add_amount_msat_compat(response, ours, "msatoshi_to_us", "to_us_msat"); @@ -1076,6 +1077,7 @@ static struct command_result *json_fund_channel_start(struct command *cmd, type_to_string(tmpctx, struct amount_sat, &max_funding_satoshi)); + fc->funding = *amount; if (!feerate_per_kw) { feerate_per_kw = tal(cmd, u32); *feerate_per_kw = opening_feerate(cmd->ld->topology); @@ -1219,6 +1221,9 @@ static struct command_result *json_fund_channel(struct command *cmd, return res; assert(!amount_sat_greater(fc->wtx->amount, max_funding_satoshi)); + /* Stash total amount in fc as well, as externally funded + * channels don't have a wtx */ + fc->funding = fc->wtx->amount; peer->uncommitted_channel->fc = tal_steal(peer->uncommitted_channel, fc); fc->uc = peer->uncommitted_channel;