mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-28 06:32:18 +02:00
graph/db: move FilterKnownChanIDs zombie logic up one layer
Here, we move the business logic in FilterKnownChanIDs from the CRUD layer to the ChannelGraph layer. We also add a test for the logic.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package graphdb
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -386,3 +387,55 @@ func (c *ChannelGraph) PruneGraphNodes() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// FilterKnownChanIDs takes a set of channel IDs and return the subset of chan
|
||||
// ID's that we don't know and are not known zombies of the passed set. In other
|
||||
// words, we perform a set difference of our set of chan ID's and the ones
|
||||
// passed in. This method can be used by callers to determine the set of
|
||||
// channels another peer knows of that we don't.
|
||||
func (c *ChannelGraph) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo,
|
||||
isZombieChan func(time.Time, time.Time) bool) ([]uint64, error) {
|
||||
|
||||
unknown, knownZombies, err := c.KVStore.FilterKnownChanIDs(chansInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, info := range knownZombies {
|
||||
// TODO(ziggie): Make sure that for the strict pruning case we
|
||||
// compare the pubkeys and whether the right timestamp is not
|
||||
// older than the `ChannelPruneExpiry`.
|
||||
//
|
||||
// NOTE: The timestamp data has no verification attached to it
|
||||
// in the `ReplyChannelRange` msg so we are trusting this data
|
||||
// at this point. However it is not critical because we are just
|
||||
// removing the channel from the db when the timestamps are more
|
||||
// recent. During the querying of the gossip msg verification
|
||||
// happens as usual. However we should start punishing peers
|
||||
// when they don't provide us honest data ?
|
||||
isStillZombie := isZombieChan(
|
||||
info.Node1UpdateTimestamp, info.Node2UpdateTimestamp,
|
||||
)
|
||||
|
||||
if isStillZombie {
|
||||
continue
|
||||
}
|
||||
|
||||
// If we have marked it as a zombie but the latest update
|
||||
// timestamps could bring it back from the dead, then we mark it
|
||||
// alive, and we let it be added to the set of IDs to query our
|
||||
// peer for.
|
||||
err := c.KVStore.MarkEdgeLive(
|
||||
info.ShortChannelID.ToUint64(),
|
||||
)
|
||||
// Since there is a chance that the edge could have been marked
|
||||
// as "live" between the FilterKnownChanIDs call and the
|
||||
// MarkEdgeLive call, we ignore the error if the edge is already
|
||||
// marked as live.
|
||||
if err != nil && !errors.Is(err, ErrZombieEdgeNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return unknown, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user