Merge pull request #9504 from guggero/closedchannels

lnrpc+rpcserver: add custom channel data for closed channels
This commit is contained in:
Oliver Gugger 2025-03-27 12:33:48 -06:00 committed by GitHub
commit eb822a5e11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 86 additions and 16 deletions

View File

@ -189,6 +189,9 @@ close transaction.
RPC method now applies a default timeout of 60 seconds when the
`timeout_seconds` field is not set or is explicitly set to 0.
* [`lnrpc.ClosedChannels` now also includes the `custom_channel_data` used by
custom channels](https://github.com/lightningnetwork/lnd/pull/9504).
## lncli Additions
* [A pre-generated macaroon root key can now be specified in `lncli create` and

View File

@ -5414,6 +5414,9 @@ type ChannelCloseSummary struct {
AliasScids []uint64 `protobuf:"varint,14,rep,packed,name=alias_scids,json=aliasScids,proto3" json:"alias_scids,omitempty"`
// The confirmed SCID for a zero-conf channel.
ZeroConfConfirmedScid uint64 `protobuf:"varint,15,opt,name=zero_conf_confirmed_scid,json=zeroConfConfirmedScid,proto3" json:"zero_conf_confirmed_scid,omitempty"`
// The TLV encoded custom channel data records for this output, which might
// be set for custom channels.
CustomChannelData []byte `protobuf:"bytes,16,opt,name=custom_channel_data,json=customChannelData,proto3" json:"custom_channel_data,omitempty"`
}
func (x *ChannelCloseSummary) Reset() {
@ -5553,6 +5556,13 @@ func (x *ChannelCloseSummary) GetZeroConfConfirmedScid() uint64 {
return 0
}
func (x *ChannelCloseSummary) GetCustomChannelData() []byte {
if x != nil {
return x.CustomChannelData
}
return nil
}
type Resolution struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -19127,7 +19137,7 @@ var file_lightning_proto_rawDesc = []byte{
0x73, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2e, 0x0a, 0x0a, 0x61,
0x6c, 0x69, 0x61, 0x73, 0x5f, 0x6d, 0x61, 0x70, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32,
0x0f, 0x2e, 0x6c, 0x6e, 0x72, 0x70, 0x63, 0x2e, 0x41, 0x6c, 0x69, 0x61, 0x73, 0x4d, 0x61, 0x70,
0x52, 0x09, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x4d, 0x61, 0x70, 0x73, 0x22, 0xb6, 0x06, 0x0a, 0x13,
0x52, 0x09, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x4d, 0x61, 0x70, 0x73, 0x22, 0xe6, 0x06, 0x0a, 0x13,
0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x53, 0x75, 0x6d, 0x6d,
0x61, 0x72, 0x79, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70,
0x6f, 0x69, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x68, 0x61, 0x6e,
@ -19170,7 +19180,10 @@ var file_lightning_proto_rawDesc = []byte{
0x72, 0x6f, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x65,
0x64, 0x5f, 0x73, 0x63, 0x69, 0x64, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x04, 0x42, 0x02, 0x30, 0x01,
0x52, 0x15, 0x7a, 0x65, 0x72, 0x6f, 0x43, 0x6f, 0x6e, 0x66, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72,
0x6d, 0x65, 0x64, 0x53, 0x63, 0x69, 0x64, 0x22, 0x8a, 0x01, 0x0a, 0x0b, 0x43, 0x6c, 0x6f, 0x73,
0x6d, 0x65, 0x64, 0x53, 0x63, 0x69, 0x64, 0x12, 0x2e, 0x0a, 0x13, 0x63, 0x75, 0x73, 0x74, 0x6f,
0x6d, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0x10,
0x20, 0x01, 0x28, 0x0c, 0x52, 0x11, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x43, 0x68, 0x61, 0x6e,
0x6e, 0x65, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x22, 0x8a, 0x01, 0x0a, 0x0b, 0x43, 0x6c, 0x6f, 0x73,
0x75, 0x72, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x15, 0x0a, 0x11, 0x43, 0x4f, 0x4f, 0x50, 0x45,
0x52, 0x41, 0x54, 0x49, 0x56, 0x45, 0x5f, 0x43, 0x4c, 0x4f, 0x53, 0x45, 0x10, 0x00, 0x12, 0x15,
0x0a, 0x11, 0x4c, 0x4f, 0x43, 0x41, 0x4c, 0x5f, 0x46, 0x4f, 0x52, 0x43, 0x45, 0x5f, 0x43, 0x4c,

View File

@ -1758,6 +1758,10 @@ message ChannelCloseSummary {
// The confirmed SCID for a zero-conf channel.
uint64 zero_conf_confirmed_scid = 15 [jstype = JS_STRING];
// The TLV encoded custom channel data records for this output, which might
// be set for custom channels.
bytes custom_channel_data = 16;
}
enum ResolutionType {

View File

@ -4182,6 +4182,11 @@
"type": "string",
"format": "uint64",
"description": "The confirmed SCID for a zero-conf channel."
},
"custom_channel_data": {
"type": "string",
"format": "byte",
"description": "The TLV encoded custom channel data records for this output, which might\nbe set for custom channels."
}
}
},

View File

@ -4028,6 +4028,13 @@ func (r *rpcServer) fetchPendingForceCloseChannels() (pendingForceClose,
historical.LocalCommitment.RemoteBalance.ToSatoshis(),
)
customChanBytes, err := encodeCustomChanData(historical)
if err != nil {
return nil, 0, fmt.Errorf("unable to encode "+
"open chan data: %w", err)
}
channel.CustomChannelData = customChanBytes
channel.Private = isPrivate(historical)
channel.Memo = string(historical.Memo)
@ -4218,20 +4225,41 @@ func (r *rpcServer) fetchWaitingCloseChannels(
return nil, 0, err
}
customChanBytes, err := encodeCustomChanData(waitingClose)
if err != nil {
return nil, 0, fmt.Errorf("unable to encode "+
"open chan data: %w", err)
}
localCommit := waitingClose.LocalCommitment
chanStatus := waitingClose.ChanStatus()
channel := &lnrpc.PendingChannelsResponse_PendingChannel{
RemoteNodePub: hex.EncodeToString(pub),
ChannelPoint: chanPoint.String(),
Capacity: int64(waitingClose.Capacity),
LocalBalance: int64(waitingClose.LocalCommitment.LocalBalance.ToSatoshis()),
RemoteBalance: int64(waitingClose.LocalCommitment.RemoteBalance.ToSatoshis()),
LocalChanReserveSat: int64(waitingClose.LocalChanCfg.ChanReserve),
RemoteChanReserveSat: int64(waitingClose.RemoteChanCfg.ChanReserve),
Initiator: rpcInitiator(waitingClose.IsInitiator),
CommitmentType: rpcCommitmentType(waitingClose.ChanType),
RemoteNodePub: hex.EncodeToString(pub),
ChannelPoint: chanPoint.String(),
Capacity: int64(waitingClose.Capacity),
LocalBalance: int64(
localCommit.LocalBalance.ToSatoshis(),
),
RemoteBalance: int64(
localCommit.RemoteBalance.ToSatoshis(),
),
LocalChanReserveSat: int64(
waitingClose.LocalChanCfg.ChanReserve,
),
RemoteChanReserveSat: int64(
waitingClose.RemoteChanCfg.ChanReserve,
),
Initiator: rpcInitiator(
waitingClose.IsInitiator,
),
CommitmentType: rpcCommitmentType(
waitingClose.ChanType,
),
NumForwardingPackages: int64(len(fwdPkgs)),
ChanStatusFlags: waitingClose.ChanStatus().String(),
ChanStatusFlags: chanStatus.String(),
Private: isPrivate(waitingClose),
Memo: string(waitingClose.Memo),
CustomChannelData: customChanBytes,
}
var closingTxid, closingTxHex string
@ -4517,6 +4545,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 +5028,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 +5043,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 +5110,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