discovery: avoid always validating ECDSA sigs by asking router if item is fresh
In this commit, we reduce the amount of unnecessary work that the gossiper can carry out. When CPU profiling some nodes, I noticed that we’d spend a lot of time validating the signatures for an announcement, only to realize that the router already had it. To remedy this, we’ll use the new methods added to the channel router in order to avoid unnecessarily validating an announcement that is actually stale. This should reduce memory usage (since it uses big int’s under the scenes), and also idle CPU usage.
This commit is contained in:
2 files changed
+75
-3
No files matched your search
@@ -199,6 +199,49 @@ func (r *mockGraphSource) GetChannelByID(chanID lnwire.ShortChannelID) (
|
||||
return chanInfo, edges[0], edges[1], nil
|
||||
}
|
||||
|
||||
// IsStaleNode returns true if the graph source has a node announcement for the
|
||||
// target node with a more recent timestamp.
|
||||
func (r *mockGraphSource) IsStaleNode(nodePub routing.Vertex, timestamp time.Time) bool {
|
||||
for _, node := range r.nodes {
|
||||
if node.PubKeyBytes == nodePub {
|
||||
return node.LastUpdate.After(timestamp) ||
|
||||
node.LastUpdate.Equal(timestamp)
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// IsKnownEdge returns true if the graph source already knows of the passed
|
||||
// channel ID.
|
||||
func (r *mockGraphSource) IsKnownEdge(chanID lnwire.ShortChannelID) bool {
|
||||
_, ok := r.infos[chanID.ToUint64()]
|
||||
return ok
|
||||
}
|
||||
|
||||
// IsStaleEdgePolicy returns true if the graph source has a channel edge for
|
||||
// the passed channel ID (and flags) that have a more recent timestamp.
|
||||
func (r *mockGraphSource) IsStaleEdgePolicy(chanID lnwire.ShortChannelID,
|
||||
timestamp time.Time, flags lnwire.ChanUpdateFlag) bool {
|
||||
|
||||
edges, ok := r.edges[chanID.ToUint64()]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
switch {
|
||||
|
||||
case len(edges) >= 1 && edges[0].Flags == flags:
|
||||
return !edges[0].LastUpdate.Before(timestamp)
|
||||
|
||||
case len(edges) >= 2 && edges[1].Flags == flags:
|
||||
return !edges[1].LastUpdate.Before(timestamp)
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type mockNotifier struct {
|
||||
clientCounter uint32
|
||||
epochClients map[uint32]chan *chainntnfs.BlockEpoch
|
||||
|
||||
Reference in new issue
Block a user