mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 22:25:24 +01:00
lnrpc+rpcserver: add and populate custom channel data
This commit is contained in:
parent
8a0222c347
commit
1b3f386979
5 changed files with 148 additions and 7 deletions
|
@ -4685,6 +4685,8 @@ type Channel struct {
|
|||
// useful information. This is only ever stored locally and in no way impacts
|
||||
// the channel's operation.
|
||||
Memo string `protobuf:"bytes,36,opt,name=memo,proto3" json:"memo,omitempty"`
|
||||
// Custom channel data that might be populated in custom channels.
|
||||
CustomChannelData []byte `protobuf:"bytes,37,opt,name=custom_channel_data,json=customChannelData,proto3" json:"custom_channel_data,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Channel) Reset() {
|
||||
|
@ -4975,6 +4977,13 @@ func (x *Channel) GetMemo() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (x *Channel) GetCustomChannelData() []byte {
|
||||
if x != nil {
|
||||
return x.CustomChannelData
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ListChannelsRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
|
@ -9487,6 +9496,9 @@ type ChannelBalanceResponse struct {
|
|||
PendingOpenLocalBalance *Amount `protobuf:"bytes,7,opt,name=pending_open_local_balance,json=pendingOpenLocalBalance,proto3" json:"pending_open_local_balance,omitempty"`
|
||||
// Sum of channels pending remote balances.
|
||||
PendingOpenRemoteBalance *Amount `protobuf:"bytes,8,opt,name=pending_open_remote_balance,json=pendingOpenRemoteBalance,proto3" json:"pending_open_remote_balance,omitempty"`
|
||||
// Custom channel data that might be populated if there are custom channels
|
||||
// present.
|
||||
CustomChannelData []byte `protobuf:"bytes,9,opt,name=custom_channel_data,json=customChannelData,proto3" json:"custom_channel_data,omitempty"`
|
||||
}
|
||||
|
||||
func (x *ChannelBalanceResponse) Reset() {
|
||||
|
@ -9579,6 +9591,13 @@ func (x *ChannelBalanceResponse) GetPendingOpenRemoteBalance() *Amount {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (x *ChannelBalanceResponse) GetCustomChannelData() []byte {
|
||||
if x != nil {
|
||||
return x.CustomChannelData
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type QueryRoutesRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
|
@ -17408,6 +17427,8 @@ type PendingChannelsResponse_PendingChannel struct {
|
|||
// useful information. This is only ever stored locally and in no way
|
||||
// impacts the channel's operation.
|
||||
Memo string `protobuf:"bytes,13,opt,name=memo,proto3" json:"memo,omitempty"`
|
||||
// Custom channel data that might be populated in custom channels.
|
||||
CustomChannelData []byte `protobuf:"bytes,34,opt,name=custom_channel_data,json=customChannelData,proto3" json:"custom_channel_data,omitempty"`
|
||||
}
|
||||
|
||||
func (x *PendingChannelsResponse_PendingChannel) Reset() {
|
||||
|
@ -17533,6 +17554,13 @@ func (x *PendingChannelsResponse_PendingChannel) GetMemo() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (x *PendingChannelsResponse_PendingChannel) GetCustomChannelData() []byte {
|
||||
if x != nil {
|
||||
return x.CustomChannelData
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type PendingChannelsResponse_PendingOpenChannel struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
|
@ -18415,7 +18443,7 @@ var file_lightning_proto_rawDesc = []byte{
|
|||
0x73, 0x61, 0x74, 0x12, 0x2c, 0x0a, 0x12, 0x6d, 0x61, 0x78, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x70,
|
||||
0x74, 0x65, 0x64, 0x5f, 0x68, 0x74, 0x6c, 0x63, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0d, 0x52,
|
||||
0x10, 0x6d, 0x61, 0x78, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x48, 0x74, 0x6c, 0x63,
|
||||
0x73, 0x22, 0xad, 0x0b, 0x0a, 0x07, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x12, 0x16, 0x0a,
|
||||
0x73, 0x22, 0xdd, 0x0b, 0x0a, 0x07, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x12, 0x16, 0x0a,
|
||||
0x06, 0x61, 0x63, 0x74, 0x69, 0x76, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x61,
|
||||
0x63, 0x74, 0x69, 0x76, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x5f,
|
||||
0x70, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x72, 0x65,
|
||||
|
@ -18506,7 +18534,10 @@ var file_lightning_proto_rawDesc = []byte{
|
|||
0x6c, 0x69, 0x61, 0x73, 0x18, 0x23, 0x20, 0x01, 0x28, 0x04, 0x42, 0x02, 0x30, 0x01, 0x52, 0x0d,
|
||||
0x70, 0x65, 0x65, 0x72, 0x53, 0x63, 0x69, 0x64, 0x41, 0x6c, 0x69, 0x61, 0x73, 0x12, 0x12, 0x0a,
|
||||
0x04, 0x6d, 0x65, 0x6d, 0x6f, 0x18, 0x24, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6d, 0x65, 0x6d,
|
||||
0x6f, 0x22, 0xdf, 0x01, 0x0a, 0x13, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65,
|
||||
0x6f, 0x12, 0x2e, 0x0a, 0x13, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x5f, 0x63, 0x68, 0x61, 0x6e,
|
||||
0x6e, 0x65, 0x6c, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0x25, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x11,
|
||||
0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x44, 0x61, 0x74,
|
||||
0x61, 0x22, 0xdf, 0x01, 0x0a, 0x13, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65,
|
||||
0x6c, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x61, 0x63, 0x74,
|
||||
0x69, 0x76, 0x65, 0x5f, 0x6f, 0x6e, 0x6c, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a,
|
||||
0x61, 0x63, 0x74, 0x69, 0x76, 0x65, 0x4f, 0x6e, 0x6c, 0x79, 0x12, 0x23, 0x0a, 0x0d, 0x69, 0x6e,
|
||||
|
@ -19089,7 +19120,7 @@ var file_lightning_proto_rawDesc = []byte{
|
|||
0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x24,
|
||||
0x0a, 0x0e, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x5f, 0x72, 0x61, 0x77, 0x5f, 0x74, 0x78,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0c, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x52,
|
||||
0x61, 0x77, 0x54, 0x78, 0x22, 0xe1, 0x13, 0x0a, 0x17, 0x50, 0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67,
|
||||
0x61, 0x77, 0x54, 0x78, 0x22, 0x91, 0x14, 0x0a, 0x17, 0x50, 0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67,
|
||||
0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
|
||||
0x12, 0x2e, 0x0a, 0x13, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x6c, 0x69, 0x6d, 0x62, 0x6f, 0x5f,
|
||||
0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x11, 0x74,
|
||||
|
@ -19121,7 +19152,7 @@ var file_lightning_proto_rawDesc = []byte{
|
|||
0x65, 0x6c, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x57, 0x61, 0x69, 0x74,
|
||||
0x69, 0x6e, 0x67, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x52,
|
||||
0x14, 0x77, 0x61, 0x69, 0x74, 0x69, 0x6e, 0x67, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x43, 0x68, 0x61,
|
||||
0x6e, 0x6e, 0x65, 0x6c, 0x73, 0x1a, 0xb3, 0x04, 0x0a, 0x0e, 0x50, 0x65, 0x6e, 0x64, 0x69, 0x6e,
|
||||
0x6e, 0x6e, 0x65, 0x6c, 0x73, 0x1a, 0xe3, 0x04, 0x0a, 0x0e, 0x50, 0x65, 0x6e, 0x64, 0x69, 0x6e,
|
||||
0x67, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x12, 0x26, 0x0a, 0x0f, 0x72, 0x65, 0x6d, 0x6f,
|
||||
0x74, 0x65, 0x5f, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x70, 0x75, 0x62, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x0d, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x50, 0x75, 0x62,
|
||||
|
@ -19156,7 +19187,10 @@ var file_lightning_proto_rawDesc = []byte{
|
|||
0x61, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x46, 0x6c, 0x61, 0x67, 0x73, 0x12, 0x18, 0x0a,
|
||||
0x07, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07,
|
||||
0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6d, 0x65, 0x6d, 0x6f, 0x18,
|
||||
0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6d, 0x65, 0x6d, 0x6f, 0x1a, 0xf9, 0x01, 0x0a, 0x12,
|
||||
0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6d, 0x65, 0x6d, 0x6f, 0x12, 0x2e, 0x0a, 0x13, 0x63,
|
||||
0x75, 0x73, 0x74, 0x6f, 0x6d, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x64, 0x61,
|
||||
0x74, 0x61, 0x18, 0x22, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x11, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d,
|
||||
0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x1a, 0xf9, 0x01, 0x0a, 0x12,
|
||||
0x50, 0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x4f, 0x70, 0x65, 0x6e, 0x43, 0x68, 0x61, 0x6e, 0x6e,
|
||||
0x65, 0x6c, 0x12, 0x47, 0x0a, 0x07, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x18, 0x01, 0x20,
|
||||
0x01, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x6c, 0x6e, 0x72, 0x70, 0x63, 0x2e, 0x50, 0x65, 0x6e, 0x64,
|
||||
|
@ -19334,7 +19368,7 @@ var file_lightning_proto_rawDesc = []byte{
|
|||
0x28, 0x04, 0x52, 0x03, 0x73, 0x61, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6d, 0x73, 0x61, 0x74, 0x18,
|
||||
0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x04, 0x6d, 0x73, 0x61, 0x74, 0x22, 0x17, 0x0a, 0x15, 0x43,
|
||||
0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71,
|
||||
0x75, 0x65, 0x73, 0x74, 0x22, 0x80, 0x04, 0x0a, 0x16, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c,
|
||||
0x75, 0x65, 0x73, 0x74, 0x22, 0xb0, 0x04, 0x0a, 0x16, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c,
|
||||
0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
|
||||
0x1c, 0x0a, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03,
|
||||
0x42, 0x02, 0x18, 0x01, 0x52, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x34, 0x0a,
|
||||
|
@ -19366,7 +19400,10 @@ var file_lightning_proto_rawDesc = []byte{
|
|||
0x5f, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d,
|
||||
0x2e, 0x6c, 0x6e, 0x72, 0x70, 0x63, 0x2e, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x18, 0x70,
|
||||
0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x4f, 0x70, 0x65, 0x6e, 0x52, 0x65, 0x6d, 0x6f, 0x74, 0x65,
|
||||
0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x22, 0x9a, 0x07, 0x0a, 0x12, 0x51, 0x75, 0x65, 0x72,
|
||||
0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x2e, 0x0a, 0x13, 0x63, 0x75, 0x73, 0x74, 0x6f,
|
||||
0x6d, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0x09,
|
||||
0x20, 0x01, 0x28, 0x0c, 0x52, 0x11, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x43, 0x68, 0x61, 0x6e,
|
||||
0x6e, 0x65, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x22, 0x9a, 0x07, 0x0a, 0x12, 0x51, 0x75, 0x65, 0x72,
|
||||
0x79, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17,
|
||||
0x0a, 0x07, 0x70, 0x75, 0x62, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x06, 0x70, 0x75, 0x62, 0x4b, 0x65, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x6d, 0x74, 0x18, 0x02,
|
||||
|
|
|
@ -1590,6 +1590,11 @@ message Channel {
|
|||
the channel's operation.
|
||||
*/
|
||||
string memo = 36;
|
||||
|
||||
/*
|
||||
Custom channel data that might be populated in custom channels.
|
||||
*/
|
||||
bytes custom_channel_data = 37;
|
||||
}
|
||||
|
||||
message ListChannelsRequest {
|
||||
|
@ -2707,6 +2712,11 @@ message PendingChannelsResponse {
|
|||
impacts the channel's operation.
|
||||
*/
|
||||
string memo = 13;
|
||||
|
||||
/*
|
||||
Custom channel data that might be populated in custom channels.
|
||||
*/
|
||||
bytes custom_channel_data = 34;
|
||||
}
|
||||
|
||||
message PendingOpenChannel {
|
||||
|
@ -2966,6 +2976,12 @@ message ChannelBalanceResponse {
|
|||
|
||||
// Sum of channels pending remote balances.
|
||||
Amount pending_open_remote_balance = 8;
|
||||
|
||||
/*
|
||||
Custom channel data that might be populated if there are custom channels
|
||||
present.
|
||||
*/
|
||||
bytes custom_channel_data = 9;
|
||||
}
|
||||
|
||||
message QueryRoutesRequest {
|
||||
|
|
|
@ -3111,6 +3111,11 @@
|
|||
"memo": {
|
||||
"type": "string",
|
||||
"description": "An optional note-to-self to go along with the channel containing some\nuseful information. This is only ever stored locally and in no way\nimpacts the channel's operation."
|
||||
},
|
||||
"custom_channel_data": {
|
||||
"type": "string",
|
||||
"format": "byte",
|
||||
"description": "Custom channel data that might be populated in custom channels."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -3805,6 +3810,11 @@
|
|||
"memo": {
|
||||
"type": "string",
|
||||
"description": "An optional note-to-self to go along with the channel containing some\nuseful information. This is only ever stored locally and in no way impacts\nthe channel's operation."
|
||||
},
|
||||
"custom_channel_data": {
|
||||
"type": "string",
|
||||
"format": "byte",
|
||||
"description": "Custom channel data that might be populated in custom channels."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -4008,6 +4018,11 @@
|
|||
"pending_open_remote_balance": {
|
||||
"$ref": "#/definitions/lnrpcAmount",
|
||||
"description": "Sum of channels pending remote balances."
|
||||
},
|
||||
"custom_channel_data": {
|
||||
"type": "string",
|
||||
"format": "byte",
|
||||
"description": "Custom channel data that might be populated if there are custom channels\npresent."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -958,6 +958,11 @@ func (h *HarnessTest) AssertChannelBalanceResp(hn *node.HarnessNode,
|
|||
expected *lnrpc.ChannelBalanceResponse) {
|
||||
|
||||
resp := hn.RPC.ChannelBalance()
|
||||
|
||||
// Ignore custom channel data of both expected and actual responses.
|
||||
expected.CustomChannelData = nil
|
||||
resp.CustomChannelData = nil
|
||||
|
||||
require.True(h, proto.Equal(expected, resp), "balance is incorrect "+
|
||||
"got: %v, want: %v", resp, expected)
|
||||
}
|
||||
|
|
68
rpcserver.go
68
rpcserver.go
|
@ -3477,6 +3477,7 @@ func (r *rpcServer) ChannelBalance(ctx context.Context,
|
|||
unsettledRemoteBalance lnwire.MilliSatoshi
|
||||
pendingOpenLocalBalance lnwire.MilliSatoshi
|
||||
pendingOpenRemoteBalance lnwire.MilliSatoshi
|
||||
customDataBuf bytes.Buffer
|
||||
)
|
||||
|
||||
openChannels, err := r.server.chanStateDB.FetchAllOpenChannels()
|
||||
|
@ -3484,6 +3485,12 @@ func (r *rpcServer) ChannelBalance(ctx context.Context,
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Encode the number of open channels to the custom data buffer.
|
||||
err = wire.WriteVarInt(&customDataBuf, 0, uint64(len(openChannels)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, channel := range openChannels {
|
||||
c := channel.LocalCommitment
|
||||
localBalance += c.LocalBalance
|
||||
|
@ -3497,6 +3504,13 @@ func (r *rpcServer) ChannelBalance(ctx context.Context,
|
|||
unsettledRemoteBalance += htlc.Amt
|
||||
}
|
||||
}
|
||||
|
||||
// Encode the custom data for this open channel.
|
||||
openChanData := channel.LocalCommitment.CustomBlob.UnwrapOr(nil)
|
||||
err = wire.WriteVarBytes(&customDataBuf, 0, openChanData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
pendingChannels, err := r.server.chanStateDB.FetchPendingChannels()
|
||||
|
@ -3504,10 +3518,23 @@ func (r *rpcServer) ChannelBalance(ctx context.Context,
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Encode the number of pending channels to the custom data buffer.
|
||||
err = wire.WriteVarInt(&customDataBuf, 0, uint64(len(pendingChannels)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, channel := range pendingChannels {
|
||||
c := channel.LocalCommitment
|
||||
pendingOpenLocalBalance += c.LocalBalance
|
||||
pendingOpenRemoteBalance += c.RemoteBalance
|
||||
|
||||
// Encode the custom data for this pending channel.
|
||||
openChanData := channel.LocalCommitment.CustomBlob.UnwrapOr(nil)
|
||||
err = wire.WriteVarBytes(&customDataBuf, 0, openChanData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
rpcsLog.Debugf("[channelbalance] local_balance=%v remote_balance=%v "+
|
||||
|
@ -3542,6 +3569,7 @@ func (r *rpcServer) ChannelBalance(ctx context.Context,
|
|||
Sat: uint64(pendingOpenRemoteBalance.ToSatoshis()),
|
||||
Msat: uint64(pendingOpenRemoteBalance),
|
||||
},
|
||||
CustomChannelData: customDataBuf.Bytes(),
|
||||
|
||||
// Deprecated fields.
|
||||
Balance: int64(localBalance.ToSatoshis()),
|
||||
|
@ -3602,6 +3630,12 @@ func (r *rpcServer) fetchPendingOpenChannels() (pendingOpenChannels, error) {
|
|||
pendingChan.BroadcastHeight()
|
||||
fundingExpiryBlocks := int32(maxFundingHeight) - currentHeight
|
||||
|
||||
customChanBytes, err := encodeCustomChanData(pendingChan)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to encode open chan "+
|
||||
"data: %w", err)
|
||||
}
|
||||
|
||||
result[i] = &lnrpc.PendingChannelsResponse_PendingOpenChannel{
|
||||
Channel: &lnrpc.PendingChannelsResponse_PendingChannel{
|
||||
RemoteNodePub: hex.EncodeToString(pub),
|
||||
|
@ -3615,6 +3649,7 @@ func (r *rpcServer) fetchPendingOpenChannels() (pendingOpenChannels, error) {
|
|||
CommitmentType: rpcCommitmentType(pendingChan.ChanType),
|
||||
Private: isPrivate(pendingChan),
|
||||
Memo: string(pendingChan.Memo),
|
||||
CustomChannelData: customChanBytes,
|
||||
},
|
||||
CommitWeight: commitWeight,
|
||||
CommitFee: int64(localCommitment.CommitFee),
|
||||
|
@ -4345,6 +4380,30 @@ func isPrivate(dbChannel *channeldb.OpenChannel) bool {
|
|||
return dbChannel.ChannelFlags&lnwire.FFAnnounceChannel != 1
|
||||
}
|
||||
|
||||
// encodeCustomChanData encodes the custom channel data for the open channel.
|
||||
// It encodes that data as a pair of var bytes blobs.
|
||||
func encodeCustomChanData(lnChan *channeldb.OpenChannel) ([]byte, error) {
|
||||
customOpenChanData := lnChan.CustomBlob.UnwrapOr(nil)
|
||||
customLocalCommitData := lnChan.LocalCommitment.CustomBlob.UnwrapOr(nil)
|
||||
|
||||
// We'll encode our custom channel data as two blobs. The first is a
|
||||
// set of var bytes encoding of the open chan data, the second is an
|
||||
// encoding of the local commitment data.
|
||||
var customChanDataBuf bytes.Buffer
|
||||
err := wire.WriteVarBytes(&customChanDataBuf, 0, customOpenChanData)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to encode open chan "+
|
||||
"data: %w", err)
|
||||
}
|
||||
err = wire.WriteVarBytes(&customChanDataBuf, 0, customLocalCommitData)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to encode local commit "+
|
||||
"data: %w", err)
|
||||
}
|
||||
|
||||
return customChanDataBuf.Bytes(), nil
|
||||
}
|
||||
|
||||
// createRPCOpenChannel creates an *lnrpc.Channel from the *channeldb.Channel.
|
||||
func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
|
||||
isActive, peerAliasLookup bool) (*lnrpc.Channel, error) {
|
||||
|
@ -4399,6 +4458,14 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
|
|||
// is returned and peerScidAlias will be an empty ShortChannelID.
|
||||
peerScidAlias, _ := r.server.aliasMgr.GetPeerAlias(chanID)
|
||||
|
||||
// Finally we'll attempt to encode the custom channel data if any
|
||||
// exists.
|
||||
customChanBytes, err := encodeCustomChanData(dbChannel)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to encode open chan data: %w",
|
||||
err)
|
||||
}
|
||||
|
||||
channel := &lnrpc.Channel{
|
||||
Active: isActive,
|
||||
Private: isPrivate(dbChannel),
|
||||
|
@ -4431,6 +4498,7 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
|
|||
ZeroConf: dbChannel.IsZeroConf(),
|
||||
ZeroConfConfirmedScid: dbChannel.ZeroConfRealScid().ToUint64(),
|
||||
Memo: string(dbChannel.Memo),
|
||||
CustomChannelData: customChanBytes,
|
||||
// TODO: remove the following deprecated fields
|
||||
CsvDelay: uint32(dbChannel.LocalChanCfg.CsvDelay),
|
||||
LocalChanReserveSat: int64(dbChannel.LocalChanCfg.ChanReserve),
|
||||
|
|
Loading…
Add table
Reference in a new issue