lnrpc+rpcserver: add custom channel data for closed channels

This commit adds the custom channel data for closed channels which
represents the initial funding state as well as the final balances at
closing time.
This commit is contained in:
Oliver Gugger committed 2025-03-27 12:38:47 -05:00
1 parent a53c6dda64
commit bab5cabd90
4 files changed
+45 -6

No files matched your search

+21 -4
View File
@@ -4517,6 +4517,16 @@ func (r *rpcServer) ClosedChannels(ctx context.Context,
resp.Channels = append(resp.Channels, channel)
}
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
}
@@ -4990,7 +5000,8 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
// createRPCClosedChannel creates an *lnrpc.ClosedChannelSummary from a
// *channeldb.ChannelCloseSummary.
func (r *rpcServer) createRPCClosedChannel(
dbChannel *channeldb.ChannelCloseSummary) (*lnrpc.ChannelCloseSummary, error) {
dbChannel *channeldb.ChannelCloseSummary) (*lnrpc.ChannelCloseSummary,
error) {
nodePub := dbChannel.RemotePub
nodeID := hex.EncodeToString(nodePub.SerializeCompressed())
@@ -5004,9 +5015,7 @@ func (r *rpcServer) createRPCClosedChannel(
// Lookup local and remote cooperative initiators. If these values
// are not known they will just return unknown.
openInit, closeInitiator, err = r.getInitiators(
&dbChannel.ChanPoint,
)
openInit, closeInitiator, err = r.getInitiators(&dbChannel.ChanPoint)
if err != nil {
return nil, err
}
@@ -5073,6 +5082,14 @@ func (r *rpcServer) createRPCClosedChannel(
channel.ZeroConfConfirmedScid = confirmedScid
}
// Finally we'll attempt to encode the custom channel data if
// any exists.
channel.CustomChannelData, err = encodeCustomChanData(histChan)
if err != nil {
return nil, fmt.Errorf("unable to encode open chan "+
"data: %w", err)
}
// Non-nil error not due to older versions of lnd.
default:
return nil, err