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,
|
// If the graph has never been pruned, or hasn't fully been created yet,
|
||||||
// then we don't treat this as an explicit error.
|
// 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 {
|
switch {
|
||||||
case errors.Is(err, graphdb.ErrGraphNeverPruned):
|
case errors.Is(err, graphdb.ErrGraphNeverPruned):
|
||||||
fallthrough
|
fallthrough
|
||||||
@@ -324,7 +324,7 @@ func (b *Builder) syncGraphWithChain() error {
|
|||||||
}
|
}
|
||||||
b.bestHeight.Store(uint32(bestHeight))
|
b.bestHeight.Store(uint32(bestHeight))
|
||||||
|
|
||||||
pruneHash, pruneHeight, err := b.cfg.Graph.PruneTip()
|
pruneHash, pruneHeight, err := b.cfg.Graph.PruneTip(context.TODO())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch {
|
switch {
|
||||||
// If the graph has never been pruned, or hasn't fully been
|
// If the graph has never been pruned, or hasn't fully been
|
||||||
@@ -371,7 +371,9 @@ func (b *Builder) syncGraphWithChain() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
pruneHash, pruneHeight, err = b.cfg.Graph.PruneTip()
|
pruneHash, pruneHeight, err = b.cfg.Graph.PruneTip(
|
||||||
|
context.TODO(),
|
||||||
|
)
|
||||||
switch {
|
switch {
|
||||||
// If at this point the graph has never been pruned, we can exit
|
// 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
|
// 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.
|
// PruneTip returns the block height and hash of the latest pruning block.
|
||||||
func (c *ChannelGraph) PruneTip() (*chainhash.Hash, uint32, error) {
|
func (c *ChannelGraph) PruneTip(ctx context.Context) (*chainhash.Hash,
|
||||||
return c.db.PruneTip()
|
uint32, error) {
|
||||||
|
|
||||||
|
return c.db.PruneTip(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// VersionedGraph is a wrapper around ChannelGraph that will call underlying
|
// 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
|
// PruneTip should be set to the blockHash we specified for the block
|
||||||
// at height 155.
|
// at height 155.
|
||||||
hash, h, err := graph.PruneTip()
|
hash, h, err := graph.PruneTip(ctx)
|
||||||
require.NoError(t, err, "unable to get prune tip")
|
require.NoError(t, err, "unable to get prune tip")
|
||||||
require.True(t, blockHash.IsEqual(hash))
|
require.True(t, blockHash.IsEqual(hash))
|
||||||
require.Equal(t, h, height-1)
|
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,
|
func assertPruneTip(t *testing.T, graph *ChannelGraph,
|
||||||
blockHash *chainhash.Hash, blockHeight uint32) {
|
blockHash *chainhash.Hash, blockHeight uint32) {
|
||||||
|
|
||||||
pruneHash, pruneHeight, err := graph.PruneTip()
|
pruneHash, pruneHeight, err := graph.PruneTip(t.Context())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, blockHash[:], pruneHash[:])
|
require.Equal(t, blockHash[:], pruneHash[:])
|
||||||
require.Equal(t, blockHeight, pruneHeight)
|
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"
|
// 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
|
// allows callers to tell if the graph is currently in sync with the
|
||||||
// current best known UTXO state.
|
// 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
|
// PruneGraphNodes is a garbage collection method which attempts to
|
||||||
// prune out any nodes from the channel graph that are currently
|
// 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
|
// 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
|
// to tell if the graph is currently in sync with the current best known UTXO
|
||||||
// state.
|
// state.
|
||||||
func (c *KVStore) PruneTip() (*chainhash.Hash, uint32, error) {
|
func (c *KVStore) PruneTip(_ context.Context) (*chainhash.Hash, uint32, error) {
|
||||||
var (
|
var (
|
||||||
tipHash chainhash.Hash
|
tipHash chainhash.Hash
|
||||||
tipHeight uint32
|
tipHeight uint32
|
||||||
|
|||||||
@@ -3049,9 +3049,10 @@ func (s *SQLStore) ChannelView(ctx context.Context) ([]EdgePoint, error) {
|
|||||||
// state.
|
// state.
|
||||||
//
|
//
|
||||||
// NOTE: part of the Store interface.
|
// 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 (
|
var (
|
||||||
ctx = context.TODO()
|
|
||||||
tipHash chainhash.Hash
|
tipHash chainhash.Hash
|
||||||
tipHeight uint32
|
tipHeight uint32
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in new issue
Block a user