@@ -1990,6 +1990,76 @@ func (s *SQLStore) ChannelID(chanPoint *wire.OutPoint) (uint64, error) {
1990
1990
return channelID , nil
1991
1991
}
1992
1992
1993
+ // FilterKnownChanIDs takes a set of channel IDs and return the subset of chan
1994
+ // ID's that we don't know and are not known zombies of the passed set. In other
1995
+ // words, we perform a set difference of our set of chan ID's and the ones
1996
+ // passed in. This method can be used by callers to determine the set of
1997
+ // channels another peer knows of that we don't. The ChannelUpdateInfos for the
1998
+ // known zombies is also returned.
1999
+ //
2000
+ // NOTE: part of the V1Store interface.
2001
+ func (s * SQLStore ) FilterKnownChanIDs (chansInfo []ChannelUpdateInfo ) ([]uint64 ,
2002
+ []ChannelUpdateInfo , error ) {
2003
+
2004
+ var (
2005
+ ctx = context .TODO ()
2006
+ newChanIDs []uint64
2007
+ knownZombies []ChannelUpdateInfo
2008
+ )
2009
+ err := s .db .ExecTx (ctx , sqldb .ReadTxOpt (), func (db SQLQueries ) error {
2010
+ for _ , chanInfo := range chansInfo {
2011
+ channelID := chanInfo .ShortChannelID .ToUint64 ()
2012
+ var chanIDB [8 ]byte
2013
+ byteOrder .PutUint64 (chanIDB [:], channelID )
2014
+
2015
+ // TODO(elle): potentially optimize this by using
2016
+ // sqlc.slice() once that works for both SQLite and
2017
+ // Postgres.
2018
+ _ , err := db .GetChannelBySCID (
2019
+ ctx , sqlc.GetChannelBySCIDParams {
2020
+ Version : int16 (ProtocolV1 ),
2021
+ Scid : chanIDB [:],
2022
+ },
2023
+ )
2024
+ if err == nil {
2025
+ continue
2026
+ } else if ! errors .Is (err , sql .ErrNoRows ) {
2027
+ return fmt .Errorf ("unable to fetch channel: %w" ,
2028
+ err )
2029
+ }
2030
+
2031
+ isZombie , err := db .IsZombieChannel (
2032
+ ctx , sqlc.IsZombieChannelParams {
2033
+ Scid : chanIDB [:],
2034
+ Version : int16 (ProtocolV1 ),
2035
+ },
2036
+ )
2037
+ if err != nil {
2038
+ return fmt .Errorf ("unable to fetch zombie " +
2039
+ "channel: %w" , err )
2040
+ }
2041
+
2042
+ if isZombie {
2043
+ knownZombies = append (knownZombies , chanInfo )
2044
+
2045
+ continue
2046
+ }
2047
+
2048
+ newChanIDs = append (newChanIDs , channelID )
2049
+ }
2050
+
2051
+ return nil
2052
+ }, func () {
2053
+ newChanIDs = nil
2054
+ knownZombies = nil
2055
+ })
2056
+ if err != nil {
2057
+ return nil , nil , fmt .Errorf ("unable to fetch channels: %w" , err )
2058
+ }
2059
+
2060
+ return newChanIDs , knownZombies , nil
2061
+ }
2062
+
1993
2063
// forEachNodeDirectedChannel iterates through all channels of a given
1994
2064
// node, executing the passed callback on the directed edge representing the
1995
2065
// channel and its incoming policy. If the node is not found, no error is
0 commit comments