Skip to content

Commit 9597f01

Browse files
committed
graph/db: thread context through to HighestChanID
1 parent 004440a commit 9597f01

File tree

7 files changed

+21
-14
lines changed

7 files changed

+21
-14
lines changed

discovery/chan_series.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package discovery
22

33
import (
4+
"context"
45
"time"
56

67
"github.com/btcsuite/btcd/chaincfg/chainhash"
@@ -22,7 +23,8 @@ type ChannelGraphTimeSeries interface {
2223
// height that's close to the current tip of the main chain as we
2324
// know it. We'll use this to start our QueryChannelRange dance with
2425
// the remote node.
25-
HighestChanID(chain chainhash.Hash) (*lnwire.ShortChannelID, error)
26+
HighestChanID(ctx context.Context,
27+
chain chainhash.Hash) (*lnwire.ShortChannelID, error)
2628

2729
// UpdatesInHorizon returns all known channel and node updates with an
2830
// update timestamp between the start time and end time. We'll use this
@@ -87,8 +89,10 @@ func NewChanSeries(graph *graphdb.ChannelGraph) *ChanSeries {
8789
// this to start our QueryChannelRange dance with the remote node.
8890
//
8991
// NOTE: This is part of the ChannelGraphTimeSeries interface.
90-
func (c *ChanSeries) HighestChanID(chain chainhash.Hash) (*lnwire.ShortChannelID, error) {
91-
chanID, err := c.graph.HighestChanID()
92+
func (c *ChanSeries) HighestChanID(ctx context.Context,
93+
_ chainhash.Hash) (*lnwire.ShortChannelID, error) {
94+
95+
chanID, err := c.graph.HighestChanID(ctx)
9296
if err != nil {
9397
return nil, err
9498
}

discovery/syncer.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,12 +965,14 @@ func (g *GossipSyncer) processChanRangeReply(_ context.Context,
965965
// party when we're kicking off the channel graph synchronization upon
966966
// connection. The historicalQuery boolean can be used to generate a query from
967967
// the genesis block of the chain.
968-
func (g *GossipSyncer) genChanRangeQuery(_ context.Context,
968+
func (g *GossipSyncer) genChanRangeQuery(ctx context.Context,
969969
historicalQuery bool) (*lnwire.QueryChannelRange, error) {
970970

971971
// First, we'll query our channel graph time series for its highest
972972
// known channel ID.
973-
newestChan, err := g.cfg.channelSeries.HighestChanID(g.cfg.chainHash)
973+
newestChan, err := g.cfg.channelSeries.HighestChanID(
974+
ctx, g.cfg.chainHash,
975+
)
974976
if err != nil {
975977
return nil, err
976978
}

discovery/syncer_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,12 @@ func newMockChannelGraphTimeSeries(
7979
}
8080
}
8181

82-
func (m *mockChannelGraphTimeSeries) HighestChanID(chain chainhash.Hash) (*lnwire.ShortChannelID, error) {
82+
func (m *mockChannelGraphTimeSeries) HighestChanID(_ context.Context,
83+
_ chainhash.Hash) (*lnwire.ShortChannelID, error) {
84+
8385
return &m.highestID, nil
8486
}
87+
8588
func (m *mockChannelGraphTimeSeries) UpdatesInHorizon(chain chainhash.Hash,
8689
startTime time.Time, endTime time.Time) ([]lnwire.Message, error) {
8790

graph/db/graph_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,7 +1881,7 @@ func TestHighestChanID(t *testing.T) {
18811881

18821882
// If we don't yet have any channels in the database, then we should
18831883
// get a channel ID of zero if we ask for the highest channel ID.
1884-
bestID, err := graph.HighestChanID()
1884+
bestID, err := graph.HighestChanID(ctx)
18851885
require.NoError(t, err, "unable to get highest ID")
18861886
if bestID != 0 {
18871887
t.Fatalf("best ID w/ no chan should be zero, is instead: %v",
@@ -1907,7 +1907,7 @@ func TestHighestChanID(t *testing.T) {
19071907

19081908
// Now that the edges has been inserted, we'll query for the highest
19091909
// known channel ID in the database.
1910-
bestID, err = graph.HighestChanID()
1910+
bestID, err = graph.HighestChanID(ctx)
19111911
require.NoError(t, err, "unable to get highest ID")
19121912

19131913
if bestID != chanID2.ToUint64() {
@@ -1921,7 +1921,7 @@ func TestHighestChanID(t *testing.T) {
19211921
if err := graph.AddChannelEdge(ctx, &edge3); err != nil {
19221922
t.Fatalf("unable to create channel edge: %v", err)
19231923
}
1924-
bestID, err = graph.HighestChanID()
1924+
bestID, err = graph.HighestChanID(ctx)
19251925
require.NoError(t, err, "unable to get highest ID")
19261926

19271927
if bestID != chanID3.ToUint64() {

graph/db/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ type V1Store interface { //nolint:interfacebloat
227227
// graph. This represents the "newest" channel from the PoV of the
228228
// chain. This method can be used by peers to quickly determine if
229229
// they're graphs are in sync.
230-
HighestChanID() (uint64, error)
230+
HighestChanID(ctx context.Context) (uint64, error)
231231

232232
// ChanUpdatesInHorizon returns all the known channel edges which have
233233
// at least one edge that has an update timestamp within the specified

graph/db/kv_store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,7 @@ func getChanID(tx kvdb.RTx, chanPoint *wire.OutPoint) (uint64, error) {
19481948
// HighestChanID returns the "highest" known channel ID in the channel graph.
19491949
// This represents the "newest" channel from the PoV of the chain. This method
19501950
// can be used by peers to quickly determine if they're graphs are in sync.
1951-
func (c *KVStore) HighestChanID() (uint64, error) {
1951+
func (c *KVStore) HighestChanID(_ context.Context) (uint64, error) {
19521952
var cid uint64
19531953

19541954
err := kvdb.View(c.db, func(tx kvdb.RTx) error {

graph/db/sql_store.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,7 @@ func (s *SQLStore) AddChannelEdge(ctx context.Context,
543543
// can be used by peers to quickly determine if their graphs are in sync.
544544
//
545545
// NOTE: This is part of the V1Store interface.
546-
func (s *SQLStore) HighestChanID() (uint64, error) {
547-
ctx := context.TODO()
548-
546+
func (s *SQLStore) HighestChanID(ctx context.Context) (uint64, error) {
549547
var highestChanID uint64
550548
err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
551549
chanID, err := db.HighestSCID(ctx, int16(ProtocolV1))

0 commit comments

Comments
 (0)