Skip to content

Commit 6009cf4

Browse files
committed
graph/db: thread context through to HighestChanID
1 parent 4e91563 commit 6009cf4

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
@@ -1880,7 +1880,7 @@ func TestHighestChanID(t *testing.T) {
18801880

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

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

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

19261926
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
@@ -526,9 +526,7 @@ func (s *SQLStore) AddChannelEdge(ctx context.Context,
526526
// can be used by peers to quickly determine if their graphs are in sync.
527527
//
528528
// NOTE: This is part of the V1Store interface.
529-
func (s *SQLStore) HighestChanID() (uint64, error) {
530-
ctx := context.TODO()
531-
529+
func (s *SQLStore) HighestChanID(ctx context.Context) (uint64, error) {
532530
var highestChanID uint64
533531
err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
534532
chanID, err := db.HighestSCID(ctx, int16(ProtocolV1))

0 commit comments

Comments
 (0)