routing+discovery: extend ChannelGraphSource with zombie index methods
This commit is contained in:
parent
174645fcba
commit
23796d3247
@ -1793,7 +1793,6 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(
|
||||
if d.cfg.Router.IsStaleEdgePolicy(
|
||||
msg.ShortChannelID, timestamp, msg.ChannelFlags,
|
||||
) {
|
||||
|
||||
nMsg.err <- nil
|
||||
return nil
|
||||
}
|
||||
|
@ -114,6 +114,7 @@ type mockGraphSource struct {
|
||||
nodes []channeldb.LightningNode
|
||||
infos map[uint64]channeldb.ChannelEdgeInfo
|
||||
edges map[uint64][]channeldb.ChannelEdgePolicy
|
||||
zombies map[uint64][][33]byte
|
||||
}
|
||||
|
||||
func newMockRouter(height uint32) *mockGraphSource {
|
||||
@ -121,6 +122,7 @@ func newMockRouter(height uint32) *mockGraphSource {
|
||||
bestHeight: height,
|
||||
infos: make(map[uint64]channeldb.ChannelEdgeInfo),
|
||||
edges: make(map[uint64][]channeldb.ChannelEdgePolicy),
|
||||
zombies: make(map[uint64][][33]byte),
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,11 +207,20 @@ func (r *mockGraphSource) GetChannelByID(chanID lnwire.ShortChannelID) (
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
chanInfo, ok := r.infos[chanID.ToUint64()]
|
||||
chanIDInt := chanID.ToUint64()
|
||||
chanInfo, ok := r.infos[chanIDInt]
|
||||
if !ok {
|
||||
pubKeys, isZombie := r.zombies[chanIDInt]
|
||||
if !isZombie {
|
||||
return nil, nil, nil, channeldb.ErrEdgeNotFound
|
||||
}
|
||||
|
||||
return &channeldb.ChannelEdgeInfo{
|
||||
NodeKey1Bytes: pubKeys[0],
|
||||
NodeKey2Bytes: pubKeys[1],
|
||||
}, nil, nil, channeldb.ErrZombieEdge
|
||||
}
|
||||
|
||||
edges := r.edges[chanID.ToUint64()]
|
||||
if len(edges) == 0 {
|
||||
return &chanInfo, nil, nil, nil
|
||||
@ -280,13 +291,15 @@ func (r *mockGraphSource) IsPublicNode(node routing.Vertex) (bool, error) {
|
||||
}
|
||||
|
||||
// IsKnownEdge returns true if the graph source already knows of the passed
|
||||
// channel ID.
|
||||
// channel ID either as a live or zombie channel.
|
||||
func (r *mockGraphSource) IsKnownEdge(chanID lnwire.ShortChannelID) bool {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
_, ok := r.infos[chanID.ToUint64()]
|
||||
return ok
|
||||
chanIDInt := chanID.ToUint64()
|
||||
_, exists := r.infos[chanIDInt]
|
||||
_, isZombie := r.zombies[chanIDInt]
|
||||
return exists || isZombie
|
||||
}
|
||||
|
||||
// IsStaleEdgePolicy returns true if the graph source has a channel edge for
|
||||
@ -297,13 +310,23 @@ func (r *mockGraphSource) IsStaleEdgePolicy(chanID lnwire.ShortChannelID,
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
edges, ok := r.edges[chanID.ToUint64()]
|
||||
chanIDInt := chanID.ToUint64()
|
||||
edges, ok := r.edges[chanIDInt]
|
||||
if !ok {
|
||||
// Since the edge doesn't exist, we'll check our zombie index as
|
||||
// well.
|
||||
_, isZombie := r.zombies[chanIDInt]
|
||||
if !isZombie {
|
||||
return false
|
||||
}
|
||||
|
||||
switch {
|
||||
// Since it exists within our zombie index, we'll check that it
|
||||
// respects the router's live edge horizon to determine whether
|
||||
// it is stale or not.
|
||||
return time.Since(timestamp) > routing.DefaultChannelPruneExpiry
|
||||
}
|
||||
|
||||
switch {
|
||||
case len(edges) >= 1 && edges[0].ChannelFlags == flags:
|
||||
return !edges[0].LastUpdate.Before(timestamp)
|
||||
|
||||
@ -315,6 +338,26 @@ func (r *mockGraphSource) IsStaleEdgePolicy(chanID lnwire.ShortChannelID,
|
||||
}
|
||||
}
|
||||
|
||||
// MarkEdgeLive clears an edge from our zombie index, deeming it as live.
|
||||
//
|
||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||
func (r *mockGraphSource) MarkEdgeLive(chanID lnwire.ShortChannelID) error {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
delete(r.zombies, chanID.ToUint64())
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarkEdgeZombie marks an edge as a zombie within our zombie index.
|
||||
func (r *mockGraphSource) MarkEdgeZombie(chanID lnwire.ShortChannelID, pubKey1,
|
||||
pubKey2 [33]byte) error {
|
||||
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
r.zombies[chanID.ToUint64()] = [][33]byte{pubKey1, pubKey2}
|
||||
return nil
|
||||
}
|
||||
|
||||
type mockNotifier struct {
|
||||
clientCounter uint32
|
||||
epochClients map[uint32]chan *chainntnfs.BlockEpoch
|
||||
|
@ -89,6 +89,10 @@ type ChannelGraphSource interface {
|
||||
IsStaleEdgePolicy(chanID lnwire.ShortChannelID, timestamp time.Time,
|
||||
flags lnwire.ChanUpdateChanFlags) bool
|
||||
|
||||
// MarkEdgeLive clears an edge from our zombie index, deeming it as
|
||||
// live.
|
||||
MarkEdgeLive(chanID lnwire.ShortChannelID) error
|
||||
|
||||
// ForAllOutgoingChannels is used to iterate over all channels
|
||||
// emanating from the "source" node which is the center of the
|
||||
// star-graph.
|
||||
@ -2314,3 +2318,10 @@ func (r *ChannelRouter) IsStaleEdgePolicy(chanID lnwire.ShortChannelID,
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// MarkEdgeLive clears an edge from our zombie index, deeming it as live.
|
||||
//
|
||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||
func (r *ChannelRouter) MarkEdgeLive(chanID lnwire.ShortChannelID) error {
|
||||
return r.cfg.Graph.MarkEdgeLive(chanID.ToUint64())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user