graphdb: pass context to PruneTip
This commit is contained in:
6 files changed
+16
-11
No files matched your search
+5
-3
@@ -175,7 +175,7 @@ func (b *Builder) Start() error {
|
||||
|
||||
// If the graph has never been pruned, or hasn't fully been created yet,
|
||||
// then we don't treat this as an explicit error.
|
||||
if _, _, err := b.cfg.Graph.PruneTip(); err != nil {
|
||||
if _, _, err := b.cfg.Graph.PruneTip(context.TODO()); err != nil {
|
||||
switch {
|
||||
case errors.Is(err, graphdb.ErrGraphNeverPruned):
|
||||
fallthrough
|
||||
@@ -324,7 +324,7 @@ func (b *Builder) syncGraphWithChain() error {
|
||||
}
|
||||
b.bestHeight.Store(uint32(bestHeight))
|
||||
|
||||
pruneHash, pruneHeight, err := b.cfg.Graph.PruneTip()
|
||||
pruneHash, pruneHeight, err := b.cfg.Graph.PruneTip(context.TODO())
|
||||
if err != nil {
|
||||
switch {
|
||||
// If the graph has never been pruned, or hasn't fully been
|
||||
@@ -371,7 +371,9 @@ func (b *Builder) syncGraphWithChain() error {
|
||||
return err
|
||||
}
|
||||
|
||||
pruneHash, pruneHeight, err = b.cfg.Graph.PruneTip()
|
||||
pruneHash, pruneHeight, err = b.cfg.Graph.PruneTip(
|
||||
context.TODO(),
|
||||
)
|
||||
switch {
|
||||
// If at this point the graph has never been pruned, we can exit
|
||||
// as this entails we are back to the point where it hasn't seen
|
||||
|
||||
+4
-2
@@ -789,8 +789,10 @@ func (c *ChannelGraph) SetSourceNode(ctx context.Context,
|
||||
}
|
||||
|
||||
// PruneTip returns the block height and hash of the latest pruning block.
|
||||
func (c *ChannelGraph) PruneTip() (*chainhash.Hash, uint32, error) {
|
||||
return c.db.PruneTip()
|
||||
func (c *ChannelGraph) PruneTip(ctx context.Context) (*chainhash.Hash,
|
||||
uint32, error) {
|
||||
|
||||
return c.db.PruneTip(ctx)
|
||||
}
|
||||
|
||||
// VersionedGraph is a wrapper around ChannelGraph that will call underlying
|
||||
|
||||
@@ -940,7 +940,7 @@ func TestDisconnectBlockAtHeight(t *testing.T) {
|
||||
|
||||
// PruneTip should be set to the blockHash we specified for the block
|
||||
// at height 155.
|
||||
hash, h, err := graph.PruneTip()
|
||||
hash, h, err := graph.PruneTip(ctx)
|
||||
require.NoError(t, err, "unable to get prune tip")
|
||||
require.True(t, blockHash.IsEqual(hash))
|
||||
require.Equal(t, h, height-1)
|
||||
@@ -2122,7 +2122,7 @@ func fillTestGraph(t testing.TB, graph *ChannelGraph, numNodes,
|
||||
func assertPruneTip(t *testing.T, graph *ChannelGraph,
|
||||
blockHash *chainhash.Hash, blockHeight uint32) {
|
||||
|
||||
pruneHash, pruneHeight, err := graph.PruneTip()
|
||||
pruneHash, pruneHeight, err := graph.PruneTip(t.Context())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, blockHash[:], pruneHash[:])
|
||||
require.Equal(t, blockHeight, pruneHeight)
|
||||
|
||||
@@ -383,7 +383,7 @@ type Store interface { //nolint:interfacebloat
|
||||
// has been used to prune channels in the graph. Knowing the "prune tip"
|
||||
// allows callers to tell if the graph is currently in sync with the
|
||||
// current best known UTXO state.
|
||||
PruneTip() (*chainhash.Hash, uint32, error)
|
||||
PruneTip(ctx context.Context) (*chainhash.Hash, uint32, error)
|
||||
|
||||
// PruneGraphNodes is a garbage collection method which attempts to
|
||||
// prune out any nodes from the channel graph that are currently
|
||||
|
||||
@@ -1887,7 +1887,7 @@ func (c *KVStore) DisconnectBlockAtHeight(height uint32) (
|
||||
// used to prune channels in the graph. Knowing the "prune tip" allows callers
|
||||
// to tell if the graph is currently in sync with the current best known UTXO
|
||||
// state.
|
||||
func (c *KVStore) PruneTip() (*chainhash.Hash, uint32, error) {
|
||||
func (c *KVStore) PruneTip(_ context.Context) (*chainhash.Hash, uint32, error) {
|
||||
var (
|
||||
tipHash chainhash.Hash
|
||||
tipHeight uint32
|
||||
|
||||
@@ -3049,9 +3049,10 @@ func (s *SQLStore) ChannelView(ctx context.Context) ([]EdgePoint, error) {
|
||||
// state.
|
||||
//
|
||||
// NOTE: part of the Store interface.
|
||||
func (s *SQLStore) PruneTip() (*chainhash.Hash, uint32, error) {
|
||||
func (s *SQLStore) PruneTip(ctx context.Context) (*chainhash.Hash, uint32,
|
||||
error) {
|
||||
|
||||
var (
|
||||
ctx = context.TODO()
|
||||
tipHash chainhash.Hash
|
||||
tipHeight uint32
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user