graphdb: pass context to IsClosedScid

This commit is contained in:
Elle Mouton committed 2026-02-25 16:11:46 +02:00
1 parent 4dcaf1c16a
commit 8722a96a4e
9 files changed
+22 -16

No files matched your search

+4 -4
View File
@@ -59,7 +59,7 @@ type GraphCloser interface {
PutClosedScid(context.Context, lnwire.ShortChannelID) error PutClosedScid(context.Context, lnwire.ShortChannelID) error
// IsClosedScid checks if a short channel id is closed. // IsClosedScid checks if a short channel id is closed.
IsClosedScid(lnwire.ShortChannelID) (bool, error) IsClosedScid(context.Context, lnwire.ShortChannelID) (bool, error)
} }
// NodeInfoInquirier handles queries relating to specific nodes and channels // NodeInfoInquirier handles queries relating to specific nodes and channels
@@ -97,10 +97,10 @@ func (s *ScidCloserMan) PutClosedScid(ctx context.Context,
// IsClosedScid checks whether scid is closed so that the gossiper can ignore // IsClosedScid checks whether scid is closed so that the gossiper can ignore
// it. // it.
func (s *ScidCloserMan) IsClosedScid(scid lnwire.ShortChannelID) (bool, func (s *ScidCloserMan) IsClosedScid(ctx context.Context,
error) { scid lnwire.ShortChannelID) (bool, error) {
return s.graph.IsClosedScid(scid) return s.graph.IsClosedScid(ctx, scid)
} }
// IsChannelPeer checks whether we have a channel with the peer. // IsChannelPeer checks whether we have a channel with the peer.
+1 -1
View File
@@ -2724,7 +2724,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
// Check if the channel is already closed in which case we can ignore // Check if the channel is already closed in which case we can ignore
// it. // it.
closed, err := d.cfg.ScidCloser.IsClosedScid(scid) closed, err := d.cfg.ScidCloser.IsClosedScid(ctx, scid)
if err != nil { if err != nil {
log.Errorf("failed to check if scid %v is closed: %v", scid, log.Errorf("failed to check if scid %v is closed: %v", scid,
err) err)
+1 -1
View File
@@ -4793,7 +4793,7 @@ func TestChanAnnBanningNonChanPeer(t *testing.T) {
// Check that the announcement's scid is marked as closed. // Check that the announcement's scid is marked as closed.
isClosed, err := tCtx.gossiper.cfg.ScidCloser.IsClosedScid( isClosed, err := tCtx.gossiper.cfg.ScidCloser.IsClosedScid(
ca.ShortChannelID, ctx, ca.ShortChannelID,
) )
require.Nil(t, err) require.Nil(t, err)
require.True(t, isClosed) require.True(t, isClosed)
+2 -2
View File
@@ -187,8 +187,8 @@ func (m *mockScidCloser) PutClosedScid(_ context.Context,
return nil return nil
} }
func (m *mockScidCloser) IsClosedScid(scid lnwire.ShortChannelID) (bool, func (m *mockScidCloser) IsClosedScid(_ context.Context,
error) { scid lnwire.ShortChannelID) (bool, error) {
m.Lock() m.Lock()
defer m.Unlock() defer m.Unlock()
+4 -2
View File
@@ -779,8 +779,10 @@ func (c *ChannelGraph) PutClosedScid(ctx context.Context,
} }
// IsClosedScid checks whether a channel identified by the scid is closed. // IsClosedScid checks whether a channel identified by the scid is closed.
func (c *ChannelGraph) IsClosedScid(scid lnwire.ShortChannelID) (bool, error) { func (c *ChannelGraph) IsClosedScid(ctx context.Context,
return c.db.IsClosedScid(scid) scid lnwire.ShortChannelID) (bool, error) {
return c.db.IsClosedScid(ctx, scid)
} }
// SetSourceNode sets the source node within the graph database. // SetSourceNode sets the source node within the graph database.
+2 -2
View File
@@ -5086,7 +5086,7 @@ func TestClosedScid(t *testing.T) {
scid := lnwire.ShortChannelID{} scid := lnwire.ShortChannelID{}
// The scid should not exist in the closedScidBucket. // The scid should not exist in the closedScidBucket.
exists, err := graph.IsClosedScid(scid) exists, err := graph.IsClosedScid(t.Context(), scid)
require.Nil(t, err) require.Nil(t, err)
require.False(t, exists) require.False(t, exists)
@@ -5095,7 +5095,7 @@ func TestClosedScid(t *testing.T) {
err = graph.PutClosedScid(t.Context(), scid) err = graph.PutClosedScid(t.Context(), scid)
require.Nil(t, err) require.Nil(t, err)
exists, err = graph.IsClosedScid(scid) exists, err = graph.IsClosedScid(t.Context(), scid)
require.Nil(t, err) require.Nil(t, err)
require.True(t, exists) require.True(t, exists)
} }
+2 -1
View File
@@ -353,7 +353,8 @@ type Store interface { //nolint:interfacebloat
// IsClosedScid checks whether a channel identified by the passed in // IsClosedScid checks whether a channel identified by the passed in
// scid is closed. This helps avoid having to perform expensive // scid is closed. This helps avoid having to perform expensive
// validation checks. // validation checks.
IsClosedScid(scid lnwire.ShortChannelID) (bool, error) IsClosedScid(ctx context.Context,
scid lnwire.ShortChannelID) (bool, error)
// UpdateEdgePolicy updates the edge routing policy for a single // UpdateEdgePolicy updates the edge routing policy for a single
// directed edge within the database for the referenced channel. The // directed edge within the database for the referenced channel. The
+3 -1
View File
@@ -4456,7 +4456,9 @@ func (c *KVStore) PutClosedScid(_ context.Context,
// IsClosedScid checks whether a channel identified by the passed in scid is // IsClosedScid checks whether a channel identified by the passed in scid is
// closed. This helps avoid having to perform expensive validation checks. // closed. This helps avoid having to perform expensive validation checks.
// TODO: Add an LRU cache to cut down on disc reads. // TODO: Add an LRU cache to cut down on disc reads.
func (c *KVStore) IsClosedScid(scid lnwire.ShortChannelID) (bool, error) { func (c *KVStore) IsClosedScid(_ context.Context,
scid lnwire.ShortChannelID) (bool, error) {
var isClosed bool var isClosed bool
err := kvdb.View(c.db, func(tx kvdb.RTx) error { err := kvdb.View(c.db, func(tx kvdb.RTx) error {
closedScids := tx.ReadBucket(closedScidBucket) closedScids := tx.ReadBucket(closedScidBucket)
+3 -2
View File
@@ -3287,9 +3287,10 @@ func (s *SQLStore) PutClosedScid(ctx context.Context,
// closed. This helps avoid having to perform expensive validation checks. // closed. This helps avoid having to perform expensive validation checks.
// //
// NOTE: part of the Store interface. // NOTE: part of the Store interface.
func (s *SQLStore) IsClosedScid(scid lnwire.ShortChannelID) (bool, error) { func (s *SQLStore) IsClosedScid(ctx context.Context,
scid lnwire.ShortChannelID) (bool, error) {
var ( var (
ctx = context.TODO()
isClosed bool isClosed bool
chanIDB = channelIDToBytes(scid.ToUint64()) chanIDB = channelIDToBytes(scid.ToUint64())
) )