From d6e1d19fa156b8e32599438aec46d6d40db005c9 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 7 Jun 2024 15:38:12 +0200 Subject: [PATCH 1/2] chancloser: always set close output We always need to set the close output in order for us to be able to calculate the closing keys. Especially if there is only a dust balance in BTC terms but perhaps a valuable amount in custom channel funds. --- lnwallet/chancloser/chancloser.go | 42 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/lnwallet/chancloser/chancloser.go b/lnwallet/chancloser/chancloser.go index b42ec38ad0..a1d2c9b88c 100644 --- a/lnwallet/chancloser/chancloser.go +++ b/lnwallet/chancloser/chancloser.go @@ -432,17 +432,16 @@ func (c *ChanCloser) initChanShutdown() (*lnwire.Shutdown, error) { return nil, err } - // If the local balance isn't dust, then we'll track that we have an - // active close output. - if isDust, dustAmt := c.cfg.Channel.LocalBalanceDust(); !isDust { - localBalance, _ := c.cfg.Channel.CommitBalances() - c.localCloseOutput = fn.Some(CloseOutput{ - Amt: localBalance, - DustLimit: dustAmt, - PkScript: c.localDeliveryScript, - ShutdownRecords: shutdown.CustomRecords, - }) - } + // We'll track our local close output, even if it's dust in BTC terms, + // it might still carry value in custom channel terms. + _, dustAmt := c.cfg.Channel.LocalBalanceDust() + localBalance, _ := c.cfg.Channel.CommitBalances() + c.localCloseOutput = fn.Some(CloseOutput{ + Amt: localBalance, + DustLimit: dustAmt, + PkScript: c.localDeliveryScript, + ShutdownRecords: shutdown.CustomRecords, + }) return shutdown, nil } @@ -587,17 +586,16 @@ func (c *ChanCloser) ReceiveShutdown(msg lnwire.Shutdown) ( noShutdown := fn.None[lnwire.Shutdown]() - // If the remote balance isn't dust, then we'll track that they have an - // active close output. - if isDust, dustAmt := c.cfg.Channel.RemoteBalanceDust(); !isDust { - _, remoteBalance := c.cfg.Channel.CommitBalances() - c.remoteCloseOutput = fn.Some(CloseOutput{ - Amt: remoteBalance, - DustLimit: dustAmt, - PkScript: msg.Address, - ShutdownRecords: msg.CustomRecords, - }) - } + // We'll track their remote close output, even if it's dust in BTC + // terms, it might still carry value in custom channel terms. + _, dustAmt := c.cfg.Channel.RemoteBalanceDust() + _, remoteBalance := c.cfg.Channel.CommitBalances() + c.remoteCloseOutput = fn.Some(CloseOutput{ + Amt: remoteBalance, + DustLimit: dustAmt, + PkScript: msg.Address, + ShutdownRecords: msg.CustomRecords, + }) switch c.state { // If we're in the close idle state, and we're receiving a channel From 77339a83d49cec20701a743307db607f9f3d146e Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 7 Jun 2024 15:39:28 +0200 Subject: [PATCH 2/2] rpcserver: send pending channels to aux data parser We added the custom data to the pending channels but forgot to also send the response RPC message to the custom channel parser so it can turn it into human-readable JSON. --- rpcserver.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rpcserver.go b/rpcserver.go index db913cb078..a05219f53c 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -4180,6 +4180,16 @@ func (r *rpcServer) PendingChannels(ctx context.Context, resp.WaitingCloseChannels = waitingCloseChannels resp.TotalLimboBalance += limbo + err = fn.MapOptionZ( + r.server.implCfg.AuxDataParser, + func(parser AuxDataParser) error { + return parser.InlineParseCustomData(resp) + }, + ) + if err != nil { + return nil, fmt.Errorf("error parsing custom data: %w", err) + } + return resp, nil }