graph/db: parameterize forEachChanInSCIDList with gossip version
What changed, and why it matters
This is a small internal code cleanup in LND's channel graph database code. It replaces a hardcoded gossip version number with a parameter so the same helper function can be reused for both old and new channel gossip formats. The only visible behavior change is that zombie-channel checks now use the version carried in each channel's own metadata rather than always assuming the old version. There is no obvious security vulnerability here; it looks like a correctness/refactoring change.
Treat as a normal refactoring/correctness commit. Review the full PR context to confirm that all callers of forEachChanInSCIDList pass a sensible gossip version and that chanInfo.Version is validated before reaching the database. No immediate security action is indicated by this diff alone.
Security signals we found
Hardcoded protocol version replaced by parameterized version
Database query version field now derived from caller-supplied channel metadata
No input validation changes visible in the diff
No mention of security, vulnerability, CVE, or bug bounty in commit message
Evidence from the diff
The commit parameterizes forEachChanInSCIDList in graph/db/sql_store.go so it accepts a lnwire.GossipVersion argument instead of hardcoding GossipVersion1. FilterKnownChanIDs now passes the version through when calling the helper. Additionally, the IsZombieChannel query now uses chanInfo.Version instead of lnwire.GossipVersion1. This enables v2 gossip channel lookups and makes zombie checks consistent with the channel’s actual gossip version. No references to security issues, CVEs, or external reports are present in the commit or supplied materials.
Changed components
graph/db/sql_store.goFilterKnownChanIDsforEachChanInSCIDListIsZombieChannel SQL queryInspect captured patch +23 / −15
diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go
index 34c36d6..874f512 100644
--- a/graph/db/sql_store.go
+++ b/graph/db/sql_store.go
@@ -3141,7 +3141,8 @@ func (s *SQLStore) FilterKnownChanIDs(ctx context.Context,
err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
// The call-back function deletes known channels from
// infoLookup, so that we can later check which channels are
- // zombies by only looking at the remaining channels in the set.
+ // zombies by only looking at the remaining channels in the
+ // set.
cb := func(ctx context.Context,
channel sqlc.GraphChannel) error {
@@ -3150,16 +3151,18 @@ func (s *SQLStore) FilterKnownChanIDs(ctx context.Context,
return nil
}
- err := s.forEachChanInSCIDList(ctx, db, cb, chansInfo)
+ err := s.forEachChanInSCIDList(
+ ctx, db, lnwire.GossipVersion1, cb, chansInfo,
+ )
if err != nil {
- return fmt.Errorf("unable to iterate through "+
+ return fmt.Errorf("unable to iterate "+
"channels: %w", err)
}
// We want to ensure that we deal with the channels in the
- // same order that they were passed in, so we iterate over the
- // original chansInfo slice and then check if that channel is
- // still in the infoLookup map.
+ // same order that they were passed in, so we iterate over
+ // the original chansInfo slice and then check if that
+ // channel is still in the infoLookup map.
for _, chanInfo := range chansInfo {
channelID := chanInfo.ShortChannelID.ToUint64()
if _, ok := infoLookup[channelID]; !ok {
@@ -3168,17 +3171,21 @@ func (s *SQLStore) FilterKnownChanIDs(ctx context.Context,
isZombie, err := db.IsZombieChannel(
ctx, sqlc.IsZombieChannelParams{
- Scid: channelIDToBytes(channelID),
- Version: int16(lnwire.GossipVersion1),
+ Scid: channelIDToBytes(channelID),
+ Version: int16(
+ chanInfo.Version,
+ ),
},
)
if err != nil {
- return fmt.Errorf("unable to fetch zombie "+
- "channel: %w", err)
+ return fmt.Errorf("unable to fetch "+
+ "zombie channel: %w", err)
}
if isZombie {
- knownZombies = append(knownZombies, chanInfo)
+ knownZombies = append(
+ knownZombies, chanInfo,
+ )
continue
}
@@ -3204,10 +3211,11 @@ func (s *SQLStore) FilterKnownChanIDs(ctx context.Context,
}
// forEachChanInSCIDList is a helper method that executes a paged query
-// against the database to fetch all channels that match the passed
-// ChannelUpdateInfo slice. The callback function is called for each channel
-// that is found.
+// against the database to fetch all channels of the given gossip version that
+// match the passed ChannelUpdateInfo slice. The callback function is called
+// for each channel that is found.
func (s *SQLStore) forEachChanInSCIDList(ctx context.Context, db SQLQueries,
+ v lnwire.GossipVersion,
cb func(ctx context.Context, channel sqlc.GraphChannel) error,
chansInfo []ChannelUpdateInfo) error {
@@ -3216,7 +3224,7 @@ func (s *SQLStore) forEachChanInSCIDList(ctx context.Context, db SQLQueries,
return db.GetChannelsBySCIDs(
ctx, sqlc.GetChannelsBySCIDsParams{
- Version: int16(lnwire.GossipVersion1),
+ Version: int16(v),
Scids: scids,
},
)
Why this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.