Skip to content

Commit bab5cab

Browse files
committed
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.
1 parent a53c6dd commit bab5cab

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

lnrpc/lightning.pb.go

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lnrpc/lightning.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,10 @@ message ChannelCloseSummary {
17581758

17591759
// The confirmed SCID for a zero-conf channel.
17601760
uint64 zero_conf_confirmed_scid = 15 [jstype = JS_STRING];
1761+
1762+
// The TLV encoded custom channel data records for this output, which might
1763+
// be set for custom channels.
1764+
bytes custom_channel_data = 16;
17611765
}
17621766

17631767
enum ResolutionType {

lnrpc/lightning.swagger.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4182,6 +4182,11 @@
41824182
"type": "string",
41834183
"format": "uint64",
41844184
"description": "The confirmed SCID for a zero-conf channel."
4185+
},
4186+
"custom_channel_data": {
4187+
"type": "string",
4188+
"format": "byte",
4189+
"description": "The TLV encoded custom channel data records for this output, which might\nbe set for custom channels."
41854190
}
41864191
}
41874192
},

rpcserver.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4517,6 +4517,16 @@ func (r *rpcServer) ClosedChannels(ctx context.Context,
45174517
resp.Channels = append(resp.Channels, channel)
45184518
}
45194519

4520+
err = fn.MapOptionZ(
4521+
r.server.implCfg.AuxDataParser,
4522+
func(parser AuxDataParser) error {
4523+
return parser.InlineParseCustomData(resp)
4524+
},
4525+
)
4526+
if err != nil {
4527+
return nil, fmt.Errorf("error parsing custom data: %w", err)
4528+
}
4529+
45204530
return resp, nil
45214531
}
45224532

@@ -4990,7 +5000,8 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
49905000
// createRPCClosedChannel creates an *lnrpc.ClosedChannelSummary from a
49915001
// *channeldb.ChannelCloseSummary.
49925002
func (r *rpcServer) createRPCClosedChannel(
4993-
dbChannel *channeldb.ChannelCloseSummary) (*lnrpc.ChannelCloseSummary, error) {
5003+
dbChannel *channeldb.ChannelCloseSummary) (*lnrpc.ChannelCloseSummary,
5004+
error) {
49945005

49955006
nodePub := dbChannel.RemotePub
49965007
nodeID := hex.EncodeToString(nodePub.SerializeCompressed())
@@ -5004,9 +5015,7 @@ func (r *rpcServer) createRPCClosedChannel(
50045015

50055016
// Lookup local and remote cooperative initiators. If these values
50065017
// are not known they will just return unknown.
5007-
openInit, closeInitiator, err = r.getInitiators(
5008-
&dbChannel.ChanPoint,
5009-
)
5018+
openInit, closeInitiator, err = r.getInitiators(&dbChannel.ChanPoint)
50105019
if err != nil {
50115020
return nil, err
50125021
}
@@ -5073,6 +5082,14 @@ func (r *rpcServer) createRPCClosedChannel(
50735082
channel.ZeroConfConfirmedScid = confirmedScid
50745083
}
50755084

5085+
// Finally we'll attempt to encode the custom channel data if
5086+
// any exists.
5087+
channel.CustomChannelData, err = encodeCustomChanData(histChan)
5088+
if err != nil {
5089+
return nil, fmt.Errorf("unable to encode open chan "+
5090+
"data: %w", err)
5091+
}
5092+
50765093
// Non-nil error not due to older versions of lnd.
50775094
default:
50785095
return nil, err

0 commit comments

Comments
 (0)