Skip to content

Commit

Permalink
grpc client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ellemouton committed Nov 15, 2024
1 parent fbe5a6a commit d10f015
Show file tree
Hide file tree
Showing 7 changed files with 1,046 additions and 16 deletions.
12 changes: 6 additions & 6 deletions lnrpc/graphrpc/graph.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lnrpc/graphrpc/graph.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ message BetweennessCentrality {
bytes node = 1;

// The normalized betweenness centrality of the node.
float normalized = 2;
double normalized = 2;

// The non-normalized betweenness centrality of the node.
float non_normalized = 3;
double non_normalized = 3;
}

message BootstrapAddrsReq {
Expand Down
4 changes: 2 additions & 2 deletions lnrpc/graphrpc/graph.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@
},
"normalized": {
"type": "number",
"format": "float",
"format": "double",
"description": "The normalized betweenness centrality of the node."
},
"non_normalized": {
"type": "number",
"format": "float",
"format": "double",
"description": "The non-normalized betweenness centrality of the node."
}
}
Expand Down
23 changes: 17 additions & 6 deletions lnrpc/graphrpc/graph_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import (
)

// Client is a wrapper that implements the sources.GraphSource interface using a
// grpc connection to a grpc GraphClient client.
// grpc connection which it uses to communicate with a grpc GraphClient client
// along with an lnrpc.LightningClient.
type Client struct {
// graphConn is a grpc client that implements the GraphClient service.
graphConn GraphClient
Expand Down Expand Up @@ -65,8 +66,8 @@ func (r *Client) BetweennessCentrality(ctx context.Context) (
var id autopilot.NodeID
copy(id[:], node.Node)
centrality[id] = &models.BetweennessCentrality{
Normalized: float64(node.Normalized),
NonNormalized: float64(node.NonNormalized),
Normalized: node.Normalized,
NonNormalized: node.NonNormalized,
}
}

Expand Down Expand Up @@ -722,15 +723,15 @@ func unmarshalChannelInfo(info *lnrpc.ChannelEdge) (*models.ChannelEdgeInfo,
)
if info.Node1Policy != nil {
policy1, err = unmarshalPolicy(
info.ChannelId, info.Node1Policy, true,
info.ChannelId, info.Node1Policy, true, info.Node2Pub,
)
if err != nil {
return nil, nil, nil, err
}
}
if info.Node2Policy != nil {
policy2, err = unmarshalPolicy(
info.ChannelId, info.Node2Policy, false,
info.ChannelId, info.Node2Policy, false, info.Node1Pub,
)
if err != nil {
return nil, nil, nil, err
Expand All @@ -741,7 +742,7 @@ func unmarshalChannelInfo(info *lnrpc.ChannelEdge) (*models.ChannelEdgeInfo,
}

func unmarshalPolicy(channelID uint64, rpcPolicy *lnrpc.RoutingPolicy,
node1 bool) (*models.ChannelEdgePolicy, error) {
node1 bool, toNodeStr string) (*models.ChannelEdgePolicy, error) {

var chanFlags lnwire.ChanUpdateChanFlags
if !node1 {
Expand All @@ -756,6 +757,15 @@ func unmarshalPolicy(channelID uint64, rpcPolicy *lnrpc.RoutingPolicy,
return nil, err
}

toNodeB, err := hex.DecodeString(toNodeStr)
if err != nil {
return nil, err
}
toNode, err := route.NewVertexFromBytes(toNodeB)
if err != nil {
return nil, err
}

return &models.ChannelEdgePolicy{
ChannelID: channelID,
TimeLockDelta: uint16(rpcPolicy.TimeLockDelta),
Expand All @@ -773,6 +783,7 @@ func unmarshalPolicy(channelID uint64, rpcPolicy *lnrpc.RoutingPolicy,
),
LastUpdate: time.Unix(int64(rpcPolicy.LastUpdate), 0),
ChannelFlags: chanFlags,
ToNode: toNode,
ExtraOpaqueData: extra,
}, nil
}
Expand Down
Loading

0 comments on commit d10f015

Please sign in to comment.