@@ -137,6 +137,12 @@ type SQLQueries interface {
137137 GetPruneTip (ctx context.Context ) (sqlc.PruneLog , error )
138138 UpsertPruneLogEntry (ctx context.Context , arg sqlc.UpsertPruneLogEntryParams ) error
139139 DeletePruneLogEntriesInRange (ctx context.Context , arg sqlc.DeletePruneLogEntriesInRangeParams ) error
140+
141+ /*
142+ Closed SCID table queries.
143+ */
144+ InsertClosedChannel (ctx context.Context , scid []byte ) error
145+ IsClosedChannel (ctx context.Context , scid []byte ) (bool , error )
140146}
141147
142148// BatchedSQLQueries is a version of SQLQueries that's capable of batched
@@ -2624,6 +2630,50 @@ func (s *SQLStore) AddEdgeProof(scid lnwire.ShortChannelID,
26242630 return nil
26252631}
26262632
2633+ // PutClosedScid stores a SCID for a closed channel in the database. This is so
2634+ // that we can ignore channel announcements that we know to be closed without
2635+ // having to validate them and fetch a block.
2636+ //
2637+ // NOTE: part of the V1Store interface.
2638+ func (s * SQLStore ) PutClosedScid (scid lnwire.ShortChannelID ) error {
2639+ var (
2640+ ctx = context .TODO ()
2641+ chanIDB = channelIDToBytes (scid .ToUint64 ())
2642+ )
2643+
2644+ return s .db .ExecTx (ctx , sqldb .WriteTxOpt (), func (db SQLQueries ) error {
2645+ return db .InsertClosedChannel (ctx , chanIDB [:])
2646+ }, sqldb .NoOpReset )
2647+ }
2648+
2649+ // IsClosedScid checks whether a channel identified by the passed in scid is
2650+ // closed. This helps avoid having to perform expensive validation checks.
2651+ //
2652+ // NOTE: part of the V1Store interface.
2653+ func (s * SQLStore ) IsClosedScid (scid lnwire.ShortChannelID ) (bool , error ) {
2654+ var (
2655+ ctx = context .TODO ()
2656+ isClosed bool
2657+ chanIDB = channelIDToBytes (scid .ToUint64 ())
2658+ )
2659+ err := s .db .ExecTx (ctx , sqldb .ReadTxOpt (), func (db SQLQueries ) error {
2660+ var err error
2661+ isClosed , err = db .IsClosedChannel (ctx , chanIDB [:])
2662+ if err != nil {
2663+ return fmt .Errorf ("unable to fetch closed channel: %w" ,
2664+ err )
2665+ }
2666+
2667+ return nil
2668+ }, sqldb .NoOpReset )
2669+ if err != nil {
2670+ return false , fmt .Errorf ("unable to fetch closed channel: %w" ,
2671+ err )
2672+ }
2673+
2674+ return isClosed , nil
2675+ }
2676+
26272677// forEachNodeDirectedChannel iterates through all channels of a given
26282678// node, executing the passed callback on the directed edge representing the
26292679// channel and its incoming policy. If the node is not found, no error is
0 commit comments