graph/db: version ChannelID lookup
Add a gossip version parameter to the ChannelID method (outpoint to short channel ID lookup) in the Store interface and both KV/SQL implementations. Update the VersionedGraph wrapper and tests.
This commit is contained in:
5 files changed
+26
-9
No files matched your search
+12
-4
@@ -177,8 +177,9 @@ func (c *ChannelGraph) populateCache(ctx context.Context) error {
|
||||
return nil
|
||||
}, func() {},
|
||||
)
|
||||
if err != nil &&
|
||||
!errors.Is(err, ErrVersionNotSupportedForKVDB) {
|
||||
if err != nil && !errors.Is(
|
||||
err, ErrVersionNotSupportedForKVDB,
|
||||
) {
|
||||
|
||||
return err
|
||||
}
|
||||
@@ -685,8 +686,10 @@ func (c *ChannelGraph) AddEdgeProof(chanID lnwire.ShortChannelID,
|
||||
}
|
||||
|
||||
// ChannelID attempts to lookup the 8-byte compact channel ID.
|
||||
func (c *ChannelGraph) ChannelID(chanPoint *wire.OutPoint) (uint64, error) {
|
||||
return c.db.ChannelID(chanPoint)
|
||||
func (c *ChannelGraph) ChannelID(v lnwire.GossipVersion,
|
||||
chanPoint *wire.OutPoint) (uint64, error) {
|
||||
|
||||
return c.db.ChannelID(v, chanPoint)
|
||||
}
|
||||
|
||||
// HighestChanID returns the "highest" known channel ID in the channel graph.
|
||||
@@ -947,6 +950,11 @@ func (c *VersionedGraph) ForEachChannelCacheable(
|
||||
return c.db.ForEachChannelCacheable(c.v, cb, reset)
|
||||
}
|
||||
|
||||
// ChannelID attempts to lookup the 8-byte compact channel ID.
|
||||
func (c *VersionedGraph) ChannelID(chanPoint *wire.OutPoint) (uint64, error) {
|
||||
return c.db.ChannelID(c.v, chanPoint)
|
||||
}
|
||||
|
||||
// IsPublicNode determines whether the node is seen as public in the graph.
|
||||
func (c *VersionedGraph) IsPublicNode(pubKey [33]byte) (bool, error) {
|
||||
return c.db.IsPublicNode(c.v, pubKey)
|
||||
|
||||
@@ -1238,7 +1238,7 @@ func TestEdgeInfoUpdates(t *testing.T) {
|
||||
|
||||
// We should also be able to retrieve the channelID only knowing the
|
||||
// channel point of the channel.
|
||||
dbChanID, err := graph.ChannelID(&outpoint)
|
||||
dbChanID, err := graph.ChannelID(lnwire.GossipVersion1, &outpoint)
|
||||
require.NoError(t, err, "unable to retrieve channel ID")
|
||||
if dbChanID != chanID {
|
||||
t.Fatalf("chan ID's mismatch, expected %v got %v", dbChanID,
|
||||
|
||||
@@ -239,7 +239,8 @@ type Store interface { //nolint:interfacebloat
|
||||
// ChannelID attempt to lookup the 8-byte compact channel ID which maps
|
||||
// to the passed channel point (outpoint). If the passed channel doesn't
|
||||
// exist within the database, then ErrEdgeNotFound is returned.
|
||||
ChannelID(chanPoint *wire.OutPoint) (uint64, error)
|
||||
ChannelID(v lnwire.GossipVersion,
|
||||
chanPoint *wire.OutPoint) (uint64, error)
|
||||
|
||||
// HighestChanID returns the "highest" known channel ID in the channel
|
||||
// graph. This represents the "newest" channel from the PoV of the
|
||||
|
||||
@@ -1998,7 +1998,13 @@ func (c *KVStore) DeleteChannelEdges(v lnwire.GossipVersion,
|
||||
// ChannelID attempt to lookup the 8-byte compact channel ID which maps to the
|
||||
// passed channel point (outpoint). If the passed channel doesn't exist within
|
||||
// the database, then ErrEdgeNotFound is returned.
|
||||
func (c *KVStore) ChannelID(chanPoint *wire.OutPoint) (uint64, error) {
|
||||
func (c *KVStore) ChannelID(v lnwire.GossipVersion,
|
||||
chanPoint *wire.OutPoint) (uint64, error) {
|
||||
|
||||
if v != lnwire.GossipVersion1 {
|
||||
return 0, ErrVersionNotSupportedForKVDB
|
||||
}
|
||||
|
||||
var chanID uint64
|
||||
if err := kvdb.View(c.db, func(tx kvdb.RTx) error {
|
||||
var err error
|
||||
|
||||
@@ -2507,7 +2507,9 @@ func (s *SQLStore) HasChannelEdge(v lnwire.GossipVersion,
|
||||
// the database, then ErrEdgeNotFound is returned.
|
||||
//
|
||||
// NOTE: part of the Store interface.
|
||||
func (s *SQLStore) ChannelID(chanPoint *wire.OutPoint) (uint64, error) {
|
||||
func (s *SQLStore) ChannelID(v lnwire.GossipVersion,
|
||||
chanPoint *wire.OutPoint) (uint64, error) {
|
||||
|
||||
var (
|
||||
ctx = context.TODO()
|
||||
channelID uint64
|
||||
@@ -2516,7 +2518,7 @@ func (s *SQLStore) ChannelID(chanPoint *wire.OutPoint) (uint64, error) {
|
||||
chanID, err := db.GetSCIDByOutpoint(
|
||||
ctx, sqlc.GetSCIDByOutpointParams{
|
||||
Outpoint: chanPoint.String(),
|
||||
Version: int16(lnwire.GossipVersion1),
|
||||
Version: int16(v),
|
||||
},
|
||||
)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
|
||||
Reference in new issue
Block a user