graph/db: add gossip version parameter to ForEachNodeChannel
Update ForEachNodeChannel to accept a gossip version parameter, allowing callers to specify which gossip version's channels should be iterated. This change mirrors the approach taken in ForEachChannel and prepares the graph database for supporting multiple gossip versions while maintaining backward compatibility. The Store interface is updated to include the version parameter, and both KVStore and SQLStore implementations are updated accordingly: - KVStore validates that only GossipVersion1 is requested, returning ErrVersionNotSupportedForKVDB for other versions. - SQLStore passes the version through to the underlying node query, enabling version-specific channel iteration. The ChannelGraph wrapper is updated to accept and pass through the version parameter. VersionedGraph gains a ForEachNodeChannel method that automatically uses its configured gossip version, providing a clean interface for version-specific operations. Update all call sites to explicitly pass lnwire.GossipVersion1, except for the local channel manager in server.go which now uses the v1Graph directly (matching the pattern used in other parts of the codebase).
This commit is contained in:
7 files changed
+68
-66
No files matched your search
@@ -913,7 +913,7 @@ func (s *SQLStore) ForEachSourceNodeChannel(ctx context.Context,
|
||||
}
|
||||
|
||||
return forEachNodeChannel(
|
||||
ctx, db, s.cfg, nodeID,
|
||||
ctx, db, s.cfg, lnwire.GossipVersion1, nodeID,
|
||||
func(info *models.ChannelEdgeInfo,
|
||||
outPolicy *models.ChannelEdgePolicy,
|
||||
_ *models.ChannelEdgePolicy) error {
|
||||
@@ -1027,14 +1027,15 @@ func (s *SQLStore) ForEachNodeCacheable(ctx context.Context,
|
||||
// Unknown policies are passed into the callback as nil values.
|
||||
//
|
||||
// NOTE: part of the Store interface.
|
||||
func (s *SQLStore) ForEachNodeChannel(ctx context.Context, nodePub route.Vertex,
|
||||
func (s *SQLStore) ForEachNodeChannel(ctx context.Context,
|
||||
v lnwire.GossipVersion, nodePub route.Vertex,
|
||||
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy) error, reset func()) error {
|
||||
|
||||
return s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
||||
dbNode, err := db.GetNodeByPubKey(
|
||||
ctx, sqlc.GetNodeByPubKeyParams{
|
||||
Version: int16(lnwire.GossipVersion1),
|
||||
Version: int16(v),
|
||||
PubKey: nodePub[:],
|
||||
},
|
||||
)
|
||||
@@ -1044,7 +1045,7 @@ func (s *SQLStore) ForEachNodeChannel(ctx context.Context, nodePub route.Vertex,
|
||||
return fmt.Errorf("unable to fetch node: %w", err)
|
||||
}
|
||||
|
||||
return forEachNodeChannel(ctx, db, s.cfg, dbNode.ID, cb)
|
||||
return forEachNodeChannel(ctx, db, s.cfg, v, dbNode.ID, cb)
|
||||
}, reset)
|
||||
}
|
||||
|
||||
@@ -3524,14 +3525,15 @@ func forEachNodeCacheable(ctx context.Context, cfg *sqldb.QueryConfig,
|
||||
// edge information, the outgoing policy and the incoming policy for the
|
||||
// channel and node combo.
|
||||
func forEachNodeChannel(ctx context.Context, db SQLQueries,
|
||||
cfg *SQLStoreConfig, id int64, cb func(*models.ChannelEdgeInfo,
|
||||
cfg *SQLStoreConfig, v lnwire.GossipVersion, id int64,
|
||||
cb func(*models.ChannelEdgeInfo,
|
||||
*models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy) error) error {
|
||||
|
||||
// Get all the V1 channels for this node.
|
||||
// Get all the channels for this node.
|
||||
rows, err := db.ListChannelsByNodeID(
|
||||
ctx, sqlc.ListChannelsByNodeIDParams{
|
||||
Version: int16(lnwire.GossipVersion1),
|
||||
Version: int16(v),
|
||||
NodeID1: id,
|
||||
},
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user