rpcserver: expose graph tlv data

This commit is contained in:
Joost Jager 2022-10-25 15:34:28 +02:00
parent 0663a92bff
commit 6e073cb213
No known key found for this signature in database
GPG key ID: B9A26449A5528325
6 changed files with 1749 additions and 1594 deletions

View file

@ -46,6 +46,10 @@
skipped by specifying `skip_peer_alias_lookup`. `lncli fwdinghistory` also
adds a flag `skip_peer_alias_lookup` to skip the lookup.
* The graph lookups method `DescribeGraph`, `GetNodeInfo` and `GetChanInfo` now
[expose tlv data](https://github.com/lightningnetwork/lnd/pull/7085) that is
broadcast over the gossip network.
## Wallet
* [Allows Taproot public keys and tap scripts to be imported as watch-only

View file

@ -84,6 +84,14 @@
},
"node2_policy": {
"$ref": "#/definitions/lnrpcRoutingPolicy"
},
"custom_records": {
"type": "object",
"additionalProperties": {
"type": "string",
"format": "byte"
},
"description": "Custom channel announcement tlv records."
}
},
"description": "A fully authenticated channel along with all its unique attributes.\nOnce an authenticated channel announcement has been processed on the network,\nthen an instance of ChannelEdgeInfo encapsulating the channels attributes is\nstored. The other portions relevant to routing policy of a channel are stored\nwithin a ChannelEdgePolicy for each direction of the channel."
@ -149,6 +157,14 @@
"additionalProperties": {
"$ref": "#/definitions/lnrpcFeature"
}
},
"custom_records": {
"type": "object",
"additionalProperties": {
"type": "string",
"format": "byte"
},
"description": "Custom node announcement tlv records."
}
},
"description": "An individual vertex/node within the channel graph. A node is\nconnected to other nodes by one or more channel edges emanating from it. As the\ngraph is directed, a node will also have an incoming edge attached to it for\neach outgoing edge."
@ -193,6 +209,14 @@
"last_update": {
"type": "integer",
"format": "int64"
},
"custom_records": {
"type": "object",
"additionalProperties": {
"type": "string",
"format": "byte"
},
"description": "Custom channel update tlv records."
}
}
},

File diff suppressed because it is too large Load diff

View file

@ -3054,6 +3054,9 @@ message LightningNode {
repeated NodeAddress addresses = 4;
string color = 5;
map<uint32, Feature> features = 6;
// Custom node announcement tlv records.
map<uint64, bytes> custom_records = 7;
}
message NodeAddress {
@ -3069,6 +3072,9 @@ message RoutingPolicy {
bool disabled = 5;
uint64 max_htlc_msat = 6;
uint32 last_update = 7;
// Custom channel update tlv records.
map<uint64, bytes> custom_records = 8;
}
/*
@ -3096,6 +3102,9 @@ message ChannelEdge {
RoutingPolicy node1_policy = 7;
RoutingPolicy node2_policy = 8;
// Custom channel announcement tlv records.
map<uint64, bytes> custom_records = 9;
}
message ChannelGraphRequest {

View file

@ -3845,6 +3845,14 @@
},
"node2_policy": {
"$ref": "#/definitions/lnrpcRoutingPolicy"
},
"custom_records": {
"type": "object",
"additionalProperties": {
"type": "string",
"format": "byte"
},
"description": "Custom channel announcement tlv records."
}
},
"description": "A fully authenticated channel along with all its unique attributes.\nOnce an authenticated channel announcement has been processed on the network,\nthen an instance of ChannelEdgeInfo encapsulating the channels attributes is\nstored. The other portions relevant to routing policy of a channel are stored\nwithin a ChannelEdgePolicy for each direction of the channel."
@ -5210,6 +5218,14 @@
"additionalProperties": {
"$ref": "#/definitions/lnrpcFeature"
}
},
"custom_records": {
"type": "object",
"additionalProperties": {
"type": "string",
"format": "byte"
},
"description": "Custom node announcement tlv records."
}
},
"description": "An individual vertex/node within the channel graph. A node is\nconnected to other nodes by one or more channel edges emanating from it. As the\ngraph is directed, a node will also have an incoming edge attached to it for\neach outgoing edge."
@ -6443,6 +6459,14 @@
"last_update": {
"type": "integer",
"format": "int64"
},
"custom_records": {
"type": "object",
"additionalProperties": {
"type": "string",
"format": "byte"
},
"description": "Custom channel update tlv records."
}
}
},

View file

@ -71,6 +71,7 @@ import (
"github.com/lightningnetwork/lnd/rpcperms"
"github.com/lightningnetwork/lnd/signal"
"github.com/lightningnetwork/lnd/sweep"
"github.com/lightningnetwork/lnd/tlv"
"github.com/lightningnetwork/lnd/watchtower"
"github.com/lightningnetwork/lnd/zpay32"
"github.com/tv42/zbase32"
@ -5716,6 +5717,30 @@ func (r *rpcServer) DescribeGraph(ctx context.Context,
return resp, nil
}
// marshalExtraOpaqueData marshals the given tlv data. If the tlv stream is
// malformed or empty, an empty map is returned. This makes the method safe to
// use on unvalidated data.
func marshalExtraOpaqueData(data []byte) map[uint64][]byte {
r := bytes.NewReader(data)
tlvStream, err := tlv.NewStream()
if err != nil {
return nil
}
parsedTypes, err := tlvStream.DecodeWithParsedTypes(r)
if err != nil || len(parsedTypes) == 0 {
return nil
}
records := make(map[uint64][]byte)
for k, v := range parsedTypes {
records[uint64(k)] = v
}
return records
}
func marshalDbEdge(edgeInfo *channeldb.ChannelEdgeInfo,
c1, c2 *channeldb.ChannelEdgePolicy) *lnrpc.ChannelEdge {
@ -5735,14 +5760,17 @@ func marshalDbEdge(edgeInfo *channeldb.ChannelEdgeInfo,
lastUpdate = c2.LastUpdate.Unix()
}
customRecords := marshalExtraOpaqueData(edgeInfo.ExtraOpaqueData)
edge := &lnrpc.ChannelEdge{
ChannelId: edgeInfo.ChannelID,
ChanPoint: edgeInfo.ChannelPoint.String(),
// TODO(roasbeef): update should be on edge info itself
LastUpdate: uint32(lastUpdate),
Node1Pub: hex.EncodeToString(edgeInfo.NodeKey1Bytes[:]),
Node2Pub: hex.EncodeToString(edgeInfo.NodeKey2Bytes[:]),
Capacity: int64(edgeInfo.Capacity),
LastUpdate: uint32(lastUpdate),
Node1Pub: hex.EncodeToString(edgeInfo.NodeKey1Bytes[:]),
Node2Pub: hex.EncodeToString(edgeInfo.NodeKey2Bytes[:]),
Capacity: int64(edgeInfo.Capacity),
CustomRecords: customRecords,
}
if c1 != nil {
@ -5761,6 +5789,8 @@ func marshalDBRoutingPolicy(
disabled := policy.ChannelFlags&lnwire.ChanUpdateDisabled != 0
customRecords := marshalExtraOpaqueData(policy.ExtraOpaqueData)
return &lnrpc.RoutingPolicy{
TimeLockDelta: uint32(policy.TimeLockDelta),
MinHtlc: int64(policy.MinHTLC),
@ -5769,6 +5799,7 @@ func marshalDBRoutingPolicy(
FeeRateMilliMsat: int64(policy.FeeProportionalMillionths),
Disabled: disabled,
LastUpdate: uint32(policy.LastUpdate.Unix()),
CustomRecords: customRecords,
}
}
@ -5931,13 +5962,16 @@ func marshalNode(node *channeldb.LightningNode) *lnrpc.LightningNode {
features := invoicesrpc.CreateRPCFeatures(node.Features)
customRecords := marshalExtraOpaqueData(node.ExtraOpaqueData)
return &lnrpc.LightningNode{
LastUpdate: uint32(node.LastUpdate.Unix()),
PubKey: hex.EncodeToString(node.PubKeyBytes[:]),
Addresses: nodeAddrs,
Alias: node.Alias,
Color: routing.EncodeHexColor(node.Color),
Features: features,
LastUpdate: uint32(node.LastUpdate.Unix()),
PubKey: hex.EncodeToString(node.PubKeyBytes[:]),
Addresses: nodeAddrs,
Alias: node.Alias,
Color: routing.EncodeHexColor(node.Color),
Features: features,
CustomRecords: customRecords,
}
}