Skip to content

Commit

Permalink
fix: fix the null node id that is inside the getNode
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
  • Loading branch information
vincenzopalazzo committed Dec 13, 2022
1 parent 3c98782 commit ae34813
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
21 changes: 6 additions & 15 deletions internal/plugin/metrics_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ func (instance *MetricOne) checkChannelInCache(lightning cln4go.Client, channelI
log.GetInstance().Errorf("Error %s:", err)
return nil, err
}
// FIXME: use the plugin encoder
if err := json.Unmarshal(bytes, &nodeInfo); err != nil {
log.GetInstance().Errorf("Error %s", err)
return nil, err
Expand Down Expand Up @@ -534,6 +535,7 @@ func (instance *MetricOne) getChannelDirections(lightning cln4go.Client, channel
return directions, nil
}

// FIXME: make a double check for the direction
for _, channel := range channels {
direction := ChannelDirections[1]
if channel.Source == instance.NodeID {
Expand All @@ -550,7 +552,7 @@ func (instance *MetricOne) collectInfoChannel(lightning cln4go.Client,

shortChannelId := channel.ShortChannelId
timestamp, found := cachePing[channel.PeerId]
// be nicer with the node and do not stress too much by pinging the node too much!
// be nicer with the node and do not stress too much by pinging it!
if !found {
timestamp = 0
// avoid storing the wrong data related to the gossip delay.
Expand Down Expand Up @@ -634,17 +636,6 @@ func (instance *MetricOne) peerConnected(lightning cln4go.Client, nodeId string)
return peer.Connected
}

func NewUnknownChannel() *model.ListChannelsChannel {
return &model.ListChannelsChannel{
LastUpdate: 0,
BaseFeeMillisatoshi: 0,
FeePerMillionth: 0,
// FIXME: check the deprecate API there
HtlcMinimumMsat: 0,
HtlcMaximumMsat: 0,
}
}

// Get the information about the channel that is open with the node id
//
// lightning: Is the Go API for c-lightning
Expand All @@ -660,11 +651,10 @@ func (instance *MetricOne) getChannelInfo(lightning cln4go.Client,
result := make(map[string]*ChannelInfo)

subChannels, err := ln.ListChannels(lightning, channel.ShortChannelId)

// This error should never happen
if err != nil {
log.GetInstance().Errorf("Error: %s", err)
subChannels = []*model.ListChannelsChannel{NewUnknownChannel()}
log.GetInstance().Errorf("error from RPC: %s", err)
return nil, fmt.Errorf("error from RPC: %s", err)
}

for _, subChannel := range subChannels {
Expand Down Expand Up @@ -784,6 +774,7 @@ func (instance *MetricOne) getChannelInfo(lightning cln4go.Client,
return nil, fmt.Errorf("status %s unexpected", forward.Status)
}
}

result[channelInfo.Direction] = channelInfo
}
return result, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ type ListNodesResp struct {
}

type ListNodesNode struct {
Id string `json:"id"`
Id string `json:"nodeid"`
Alias string `json:"alias"`
Color string `json:"color"`
Features *string `json:"features"`
Expand Down

0 comments on commit ae34813

Please sign in to comment.