From e067dc73b7092ecd42b626f84923918431d98632 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Mon, 27 Sep 2021 22:21:50 +0200 Subject: [PATCH] rpcserver: fix nil issue with historical channels [skip ci] Fixes #5796. Some historical channels might not have the forwarding packages recorded. And since the error might be silenced, the historical channel might be nil. --- rpcserver.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index ea50dd193..cea1d24a7 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -3233,23 +3233,23 @@ func (r *rpcServer) PendingChannels(ctx context.Context, historical.ChanType, ) + // Get the number of forwarding packages from the + // historical channel. + fwdPkgs, err := historical.LoadFwdPkgs() + if err != nil { + rpcsLog.Errorf("unable to load forwarding "+ + "packages for channel:%s, %v", + historical.ShortChannelID, err) + return nil, err + } + channel.NumForwardingPackages = int64(len(fwdPkgs)) + // If the error is non-nil, and not due to older versions of lnd // not persisting historical channels, return it. default: return nil, err } - // Get the number of forwarding packages from the historical - // channel. - fwdPkgs, err := historical.LoadFwdPkgs() - if err != nil { - rpcsLog.Errorf("unable to load forwarding packages "+ - "for channel:%s, %v", - historical.ShortChannelID, err) - return nil, err - } - channel.NumForwardingPackages = int64(len(fwdPkgs)) - closeTXID := pendingClose.ClosingTXID.String() switch pendingClose.CloseType {