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:
3 files changed
+140
-44
No files matched your search
+17
-44
@@ -2155,16 +2155,20 @@ func (c *KVStore) NodeUpdatesInHorizon(startTime,
|
||||
// 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 *KVStore) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo,
|
||||
isZombieChan func(time.Time, time.Time) bool) ([]uint64, error) {
|
||||
// channels another peer knows of that we don't. The ChannelUpdateInfos for the
|
||||
// known zombies is also returned.
|
||||
func (c *KVStore) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo) ([]uint64,
|
||||
[]ChannelUpdateInfo, error) {
|
||||
|
||||
var newChanIDs []uint64
|
||||
var (
|
||||
newChanIDs []uint64
|
||||
knownZombies []ChannelUpdateInfo
|
||||
)
|
||||
|
||||
c.cacheMu.Lock()
|
||||
defer c.cacheMu.Unlock()
|
||||
|
||||
err := kvdb.Update(c.db, func(tx kvdb.RwTx) error {
|
||||
err := kvdb.View(c.db, func(tx kvdb.RTx) error {
|
||||
edges := tx.ReadBucket(edgeBucket)
|
||||
if edges == nil {
|
||||
return ErrGraphNoEdgesFound
|
||||
@@ -2197,44 +2201,12 @@ func (c *KVStore) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo,
|
||||
zombieIndex, scid,
|
||||
)
|
||||
|
||||
// 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 isZombie {
|
||||
knownZombies = append(
|
||||
knownZombies, info,
|
||||
)
|
||||
|
||||
switch {
|
||||
// If the edge is a known zombie and if we
|
||||
// would still consider it a zombie given the
|
||||
// latest update timestamps, then we skip this
|
||||
// channel.
|
||||
case isZombie && isStillZombie:
|
||||
continue
|
||||
|
||||
// Otherwise, 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.
|
||||
case isZombie && !isStillZombie:
|
||||
err := c.markEdgeLiveUnsafe(tx, scid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2244,6 +2216,7 @@ func (c *KVStore) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo,
|
||||
return nil
|
||||
}, func() {
|
||||
newChanIDs = nil
|
||||
knownZombies = nil
|
||||
})
|
||||
switch {
|
||||
// If we don't know of any edges yet, then we'll return the entire set
|
||||
@@ -2254,13 +2227,13 @@ func (c *KVStore) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo,
|
||||
ogChanIDs[i] = info.ShortChannelID.ToUint64()
|
||||
}
|
||||
|
||||
return ogChanIDs, nil
|
||||
return ogChanIDs, nil, nil
|
||||
|
||||
case err != nil:
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return newChanIDs, nil
|
||||
return newChanIDs, knownZombies, nil
|
||||
}
|
||||
|
||||
// ChannelUpdateInfo couples the SCID of a channel with the timestamps of the
|
||||
|
||||
Reference in new issue
Block a user