graph/db: thread context through to HighestChanID

This commit is contained in:
Elle Mouton committed 2025-06-19 14:49:32 +02:00
1 parent 004440a86c
commit 9597f01ce3
7 files changed
+21 -14

No files matched your search

+7 -3
View File
@@ -1,6 +1,7 @@
package discovery
import (
"context"
"time"
"github.com/btcsuite/btcd/chaincfg/chainhash"
@@ -22,7 +23,8 @@ type ChannelGraphTimeSeries interface {
// height that's close to the current tip of the main chain as we
// know it. We'll use this to start our QueryChannelRange dance with
// the remote node.
HighestChanID(chain chainhash.Hash) (*lnwire.ShortChannelID, error)
HighestChanID(ctx context.Context,
chain chainhash.Hash) (*lnwire.ShortChannelID, error)
// UpdatesInHorizon returns all known channel and node updates with an
// update timestamp between the start time and end time. We'll use this
@@ -87,8 +89,10 @@ func NewChanSeries(graph *graphdb.ChannelGraph) *ChanSeries {
// this to start our QueryChannelRange dance with the remote node.
//
// NOTE: This is part of the ChannelGraphTimeSeries interface.
func (c *ChanSeries) HighestChanID(chain chainhash.Hash) (*lnwire.ShortChannelID, error) {
chanID, err := c.graph.HighestChanID()
func (c *ChanSeries) HighestChanID(ctx context.Context,
_ chainhash.Hash) (*lnwire.ShortChannelID, error) {
chanID, err := c.graph.HighestChanID(ctx)
if err != nil {
return nil, err
}
+4 -2
View File
@@ -965,12 +965,14 @@ func (g *GossipSyncer) processChanRangeReply(_ context.Context,
// party when we're kicking off the channel graph synchronization upon
// connection. The historicalQuery boolean can be used to generate a query from
// the genesis block of the chain.
func (g *GossipSyncer) genChanRangeQuery(_ context.Context,
func (g *GossipSyncer) genChanRangeQuery(ctx context.Context,
historicalQuery bool) (*lnwire.QueryChannelRange, error) {
// First, we'll query our channel graph time series for its highest
// known channel ID.
newestChan, err := g.cfg.channelSeries.HighestChanID(g.cfg.chainHash)
newestChan, err := g.cfg.channelSeries.HighestChanID(
ctx, g.cfg.chainHash,
)
if err != nil {
return nil, err
}
+4 -1
View File
@@ -79,9 +79,12 @@ func newMockChannelGraphTimeSeries(
}
}
func (m *mockChannelGraphTimeSeries) HighestChanID(chain chainhash.Hash) (*lnwire.ShortChannelID, error) {
func (m *mockChannelGraphTimeSeries) HighestChanID(_ context.Context,
_ chainhash.Hash) (*lnwire.ShortChannelID, error) {
return &m.highestID, nil
}
func (m *mockChannelGraphTimeSeries) UpdatesInHorizon(chain chainhash.Hash,
startTime time.Time, endTime time.Time) ([]lnwire.Message, error) {
+3 -3
View File
@@ -1881,7 +1881,7 @@ func TestHighestChanID(t *testing.T) {
// If we don't yet have any channels in the database, then we should
// get a channel ID of zero if we ask for the highest channel ID.
bestID, err := graph.HighestChanID()
bestID, err := graph.HighestChanID(ctx)
require.NoError(t, err, "unable to get highest ID")
if bestID != 0 {
t.Fatalf("best ID w/ no chan should be zero, is instead: %v",
@@ -1907,7 +1907,7 @@ func TestHighestChanID(t *testing.T) {
// Now that the edges has been inserted, we'll query for the highest
// known channel ID in the database.
bestID, err = graph.HighestChanID()
bestID, err = graph.HighestChanID(ctx)
require.NoError(t, err, "unable to get highest ID")
if bestID != chanID2.ToUint64() {
@@ -1921,7 +1921,7 @@ func TestHighestChanID(t *testing.T) {
if err := graph.AddChannelEdge(ctx, &edge3); err != nil {
t.Fatalf("unable to create channel edge: %v", err)
}
bestID, err = graph.HighestChanID()
bestID, err = graph.HighestChanID(ctx)
require.NoError(t, err, "unable to get highest ID")
if bestID != chanID3.ToUint64() {
+1 -1
View File
@@ -227,7 +227,7 @@ type V1Store interface { //nolint:interfacebloat
// graph. This represents the "newest" channel from the PoV of the
// chain. This method can be used by peers to quickly determine if
// they're graphs are in sync.
HighestChanID() (uint64, error)
HighestChanID(ctx context.Context) (uint64, error)
// ChanUpdatesInHorizon returns all the known channel edges which have
// at least one edge that has an update timestamp within the specified
+1 -1
View File
@@ -1948,7 +1948,7 @@ func getChanID(tx kvdb.RTx, 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 chain. This method
// can be used by peers to quickly determine if they're graphs are in sync.
func (c *KVStore) HighestChanID() (uint64, error) {
func (c *KVStore) HighestChanID(_ context.Context) (uint64, error) {
var cid uint64
err := kvdb.View(c.db, func(tx kvdb.RTx) error {
+1 -3
View File
@@ -543,9 +543,7 @@ func (s *SQLStore) AddChannelEdge(ctx context.Context,
// can be used by peers to quickly determine if their graphs are in sync.
//
// NOTE: This is part of the V1Store interface.
func (s *SQLStore) HighestChanID() (uint64, error) {
ctx := context.TODO()
func (s *SQLStore) HighestChanID(ctx context.Context) (uint64, error) {
var highestChanID uint64
err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
chanID, err := db.HighestSCID(ctx, int16(ProtocolV1))