graph/db+sqldb: impl PutClosedScid and IsClosedScid
This commit is contained in:
5 files changed
+101
-1
No files matched your search
@@ -4325,7 +4325,7 @@ func TestGraphLoading(t *testing.T) {
|
||||
func TestClosedScid(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
graph := MakeTestGraph(t)
|
||||
graph := MakeTestGraphNew(t)
|
||||
|
||||
scid := lnwire.ShortChannelID{}
|
||||
|
||||
|
||||
@@ -137,6 +137,12 @@ type SQLQueries interface {
|
||||
GetPruneTip(ctx context.Context) (sqlc.PruneLog, error)
|
||||
UpsertPruneLogEntry(ctx context.Context, arg sqlc.UpsertPruneLogEntryParams) error
|
||||
DeletePruneLogEntriesInRange(ctx context.Context, arg sqlc.DeletePruneLogEntriesInRangeParams) error
|
||||
|
||||
/*
|
||||
Closed SCID table queries.
|
||||
*/
|
||||
InsertClosedChannel(ctx context.Context, scid []byte) error
|
||||
IsClosedChannel(ctx context.Context, scid []byte) (bool, error)
|
||||
}
|
||||
|
||||
// BatchedSQLQueries is a version of SQLQueries that's capable of batched
|
||||
@@ -2624,6 +2630,50 @@ func (s *SQLStore) AddEdgeProof(scid lnwire.ShortChannelID,
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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
|
||||
// having to validate them and fetch a block.
|
||||
//
|
||||
// NOTE: part of the V1Store interface.
|
||||
func (s *SQLStore) PutClosedScid(scid lnwire.ShortChannelID) error {
|
||||
var (
|
||||
ctx = context.TODO()
|
||||
chanIDB = channelIDToBytes(scid.ToUint64())
|
||||
)
|
||||
|
||||
return s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error {
|
||||
return db.InsertClosedChannel(ctx, chanIDB[:])
|
||||
}, sqldb.NoOpReset)
|
||||
}
|
||||
|
||||
// IsClosedScid checks whether a channel identified by the passed in scid is
|
||||
// closed. This helps avoid having to perform expensive validation checks.
|
||||
//
|
||||
// NOTE: part of the V1Store interface.
|
||||
func (s *SQLStore) IsClosedScid(scid lnwire.ShortChannelID) (bool, error) {
|
||||
var (
|
||||
ctx = context.TODO()
|
||||
isClosed bool
|
||||
chanIDB = channelIDToBytes(scid.ToUint64())
|
||||
)
|
||||
err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
||||
var err error
|
||||
isClosed, err = db.IsClosedChannel(ctx, chanIDB[:])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to fetch closed channel: %w",
|
||||
err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}, sqldb.NoOpReset)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("unable to fetch closed channel: %w",
|
||||
err)
|
||||
}
|
||||
|
||||
return isClosed, nil
|
||||
}
|
||||
|
||||
// forEachNodeDirectedChannel iterates through all channels of a given
|
||||
// node, executing the passed callback on the directed edge representing the
|
||||
// channel and its incoming policy. If the node is not found, no error is
|
||||
|
||||
Reference in new issue
Block a user