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