graphdb: pass context to PutClosedScid
This commit is contained in:
8 files changed
+25
-12
No files matched your search
+6
-3
@@ -1,6 +1,7 @@
|
|||||||
package discovery
|
package discovery
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"math"
|
"math"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -55,7 +56,7 @@ type ClosedChannelTracker interface {
|
|||||||
type GraphCloser interface {
|
type GraphCloser interface {
|
||||||
// PutClosedScid marks a channel as closed so that we won't validate
|
// PutClosedScid marks a channel as closed so that we won't validate
|
||||||
// channel announcements for it again.
|
// channel announcements for it again.
|
||||||
PutClosedScid(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(lnwire.ShortChannelID) (bool, error)
|
||||||
@@ -88,8 +89,10 @@ func NewScidCloserMan(graph GraphCloser,
|
|||||||
|
|
||||||
// PutClosedScid marks scid as closed so the gossiper can ignore this channel
|
// PutClosedScid marks scid as closed so the gossiper can ignore this channel
|
||||||
// in the future.
|
// in the future.
|
||||||
func (s *ScidCloserMan) PutClosedScid(scid lnwire.ShortChannelID) error {
|
func (s *ScidCloserMan) PutClosedScid(ctx context.Context,
|
||||||
return s.graph.PutClosedScid(scid)
|
scid lnwire.ShortChannelID) error {
|
||||||
|
|
||||||
|
return s.graph.PutClosedScid(ctx, scid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsClosedScid checks whether scid is closed so that the gossiper can ignore
|
// IsClosedScid checks whether scid is closed so that the gossiper can ignore
|
||||||
|
|||||||
@@ -2877,7 +2877,9 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
|
|||||||
// expensive validation checks on it again.
|
// expensive validation checks on it again.
|
||||||
// TODO: Populate the ScidCloser by using closed
|
// TODO: Populate the ScidCloser by using closed
|
||||||
// channel notifications.
|
// channel notifications.
|
||||||
dbErr := d.cfg.ScidCloser.PutClosedScid(scid)
|
dbErr := d.cfg.ScidCloser.PutClosedScid(
|
||||||
|
ctx, scid,
|
||||||
|
)
|
||||||
if dbErr != nil {
|
if dbErr != nil {
|
||||||
log.Errorf("failed to mark scid(%v) "+
|
log.Errorf("failed to mark scid(%v) "+
|
||||||
"as closed: %v", scid, dbErr)
|
"as closed: %v", scid, dbErr)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package discovery
|
package discovery
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -176,7 +177,9 @@ func newMockScidCloser(channelPeer bool) *mockScidCloser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockScidCloser) PutClosedScid(scid lnwire.ShortChannelID) error {
|
func (m *mockScidCloser) PutClosedScid(_ context.Context,
|
||||||
|
scid lnwire.ShortChannelID) error {
|
||||||
|
|
||||||
m.Lock()
|
m.Lock()
|
||||||
m.m[scid] = struct{}{}
|
m.m[scid] = struct{}{}
|
||||||
m.Unlock()
|
m.Unlock()
|
||||||
|
|||||||
+4
-2
@@ -772,8 +772,10 @@ func (c *ChannelGraph) NumZombies(ctx context.Context) (uint64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PutClosedScid stores a SCID for a closed channel in the database.
|
// PutClosedScid stores a SCID for a closed channel in the database.
|
||||||
func (c *ChannelGraph) PutClosedScid(scid lnwire.ShortChannelID) error {
|
func (c *ChannelGraph) PutClosedScid(ctx context.Context,
|
||||||
return c.db.PutClosedScid(scid)
|
scid lnwire.ShortChannelID) error {
|
||||||
|
|
||||||
|
return c.db.PutClosedScid(ctx, scid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsClosedScid checks whether a channel identified by the scid is closed.
|
// IsClosedScid checks whether a channel identified by the scid is closed.
|
||||||
|
|||||||
@@ -5092,7 +5092,7 @@ func TestClosedScid(t *testing.T) {
|
|||||||
|
|
||||||
// After we call PutClosedScid, the call to IsClosedScid should return
|
// After we call PutClosedScid, the call to IsClosedScid should return
|
||||||
// true.
|
// true.
|
||||||
err = graph.PutClosedScid(scid)
|
err = graph.PutClosedScid(t.Context(), scid)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
exists, err = graph.IsClosedScid(scid)
|
exists, err = graph.IsClosedScid(scid)
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ type Store interface { //nolint:interfacebloat
|
|||||||
// PutClosedScid stores a SCID for a closed channel in the database.
|
// PutClosedScid stores a SCID for a closed channel in the database.
|
||||||
// This is so that we can ignore channel announcements that we know to
|
// This is so that we can ignore channel announcements that we know to
|
||||||
// be closed without having to validate them and fetch a block.
|
// be closed without having to validate them and fetch a block.
|
||||||
PutClosedScid(scid lnwire.ShortChannelID) error
|
PutClosedScid(ctx context.Context, scid lnwire.ShortChannelID) error
|
||||||
|
|
||||||
// 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
|
||||||
|
|||||||
@@ -4437,7 +4437,9 @@ func (c *KVStore) NumZombies(_ context.Context) (uint64, error) {
|
|||||||
// PutClosedScid stores a SCID for a closed channel in the database. This is so
|
// PutClosedScid stores a SCID for a closed channel in the database. This is so
|
||||||
// that we can ignore channel announcements that we know to be closed without
|
// that we can ignore channel announcements that we know to be closed without
|
||||||
// having to validate them and fetch a block.
|
// having to validate them and fetch a block.
|
||||||
func (c *KVStore) PutClosedScid(scid lnwire.ShortChannelID) error {
|
func (c *KVStore) PutClosedScid(_ context.Context,
|
||||||
|
scid lnwire.ShortChannelID) error {
|
||||||
|
|
||||||
return kvdb.Update(c.db, func(tx kvdb.RwTx) error {
|
return kvdb.Update(c.db, func(tx kvdb.RwTx) error {
|
||||||
closedScids, err := tx.CreateTopLevelBucket(closedScidBucket)
|
closedScids, err := tx.CreateTopLevelBucket(closedScidBucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -3271,9 +3271,10 @@ func (s *SQLStore) AddEdgeProof(ctx context.Context,
|
|||||||
// having to validate them and fetch a block.
|
// having to validate them and fetch a block.
|
||||||
//
|
//
|
||||||
// NOTE: part of the Store interface.
|
// NOTE: part of the Store interface.
|
||||||
func (s *SQLStore) PutClosedScid(scid lnwire.ShortChannelID) error {
|
func (s *SQLStore) PutClosedScid(ctx context.Context,
|
||||||
|
scid lnwire.ShortChannelID) error {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ctx = context.TODO()
|
|
||||||
chanIDB = channelIDToBytes(scid.ToUint64())
|
chanIDB = channelIDToBytes(scid.ToUint64())
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user