graphdb: pass context to PruneGraph
This commit is contained in:
6 files changed
+28
-22
No files matched your search
+3
-2
@@ -446,12 +446,13 @@ func (c *ChannelGraph) DisconnectBlockAtHeight(height uint32) (
|
||||
// prune the graph is stored so callers can ensure the graph is fully in sync
|
||||
// with the current UTXO state. A slice of channels that have been closed by
|
||||
// the target block are returned if the function succeeds without error.
|
||||
func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
|
||||
func (c *ChannelGraph) PruneGraph(ctx context.Context,
|
||||
spentOutputs []*wire.OutPoint,
|
||||
blockHash *chainhash.Hash, blockHeight uint32) (
|
||||
[]*models.ChannelEdgeInfo, error) {
|
||||
|
||||
edges, nodes, err := c.db.PruneGraph(
|
||||
spentOutputs, blockHash, blockHeight,
|
||||
ctx, spentOutputs, blockHash, blockHeight,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+12
-9
@@ -863,12 +863,12 @@ func TestDisconnectBlockAtHeight(t *testing.T) {
|
||||
|
||||
// Prune the graph a few times to make sure we have entries in the
|
||||
// prune log.
|
||||
_, err := graph.PruneGraph(spendOutputs, &blockHash, 155)
|
||||
_, err := graph.PruneGraph(ctx, spendOutputs, &blockHash, 155)
|
||||
require.NoError(t, err, "unable to prune graph")
|
||||
var blockHash2 chainhash.Hash
|
||||
copy(blockHash2[:], bytes.Repeat([]byte{2}, 32))
|
||||
|
||||
_, err = graph.PruneGraph(spendOutputs, &blockHash2, 156)
|
||||
_, err = graph.PruneGraph(ctx, spendOutputs, &blockHash2, 156)
|
||||
require.NoError(t, err, "unable to prune graph")
|
||||
|
||||
// We'll create 3 almost identical edges, so first create a helper
|
||||
@@ -2287,7 +2287,9 @@ func TestGraphPruning(t *testing.T) {
|
||||
copy(blockHash[:], bytes.Repeat([]byte{1}, 32))
|
||||
blockHeight := uint32(1)
|
||||
block := channelPoints[:2]
|
||||
prunedChans, err := graph.PruneGraph(block, &blockHash, blockHeight)
|
||||
prunedChans, err := graph.PruneGraph(
|
||||
ctx, block, &blockHash, blockHeight,
|
||||
)
|
||||
require.NoError(t, err, "unable to prune graph")
|
||||
require.Len(t, prunedChans, 2)
|
||||
|
||||
@@ -2313,7 +2315,7 @@ func TestGraphPruning(t *testing.T) {
|
||||
blockHash = sha256.Sum256(blockHash[:])
|
||||
blockHeight = 2
|
||||
prunedChans, err = graph.PruneGraph(
|
||||
[]*wire.OutPoint{nonChannel}, &blockHash, blockHeight,
|
||||
ctx, []*wire.OutPoint{nonChannel}, &blockHash, blockHeight,
|
||||
)
|
||||
require.NoError(t, err, "unable to prune graph")
|
||||
|
||||
@@ -2331,7 +2333,7 @@ func TestGraphPruning(t *testing.T) {
|
||||
blockHash = sha256.Sum256(blockHash[:])
|
||||
blockHeight = 3
|
||||
prunedChans, err = graph.PruneGraph(
|
||||
channelPoints[2:], &blockHash, blockHeight,
|
||||
ctx, channelPoints[2:], &blockHash, blockHeight,
|
||||
)
|
||||
require.NoError(t, err, "unable to prune graph")
|
||||
|
||||
@@ -3383,7 +3385,7 @@ func TestStressTestChannelGraphAPI(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err := graph.PruneGraph(
|
||||
spentOutpoints, &blockHash, 100,
|
||||
ctx, spentOutpoints, &blockHash, 100,
|
||||
)
|
||||
|
||||
return err
|
||||
@@ -3995,7 +3997,8 @@ func TestChannelEdgePruningUpdateIndexDeletion(t *testing.T) {
|
||||
var blockHash chainhash.Hash
|
||||
copy(blockHash[:], bytes.Repeat([]byte{2}, 32))
|
||||
_, err := graph.PruneGraph(
|
||||
[]*wire.OutPoint{&edgeInfo.ChannelPoint}, &blockHash, 101,
|
||||
ctx, []*wire.OutPoint{&edgeInfo.ChannelPoint}, &blockHash,
|
||||
101,
|
||||
)
|
||||
require.NoError(t, err, "unable to prune graph")
|
||||
|
||||
@@ -4762,12 +4765,12 @@ func testBatchedAddChannelEdge(t *testing.T, v lnwire.GossipVersion) {
|
||||
|
||||
// Prune the graph a few times to make sure we have entries in the
|
||||
// prune log.
|
||||
_, err := graph.PruneGraph(spendOutputs, &blockHash, 155)
|
||||
_, err := graph.PruneGraph(ctx, spendOutputs, &blockHash, 155)
|
||||
require.Nil(t, err)
|
||||
var blockHash2 chainhash.Hash
|
||||
copy(blockHash2[:], bytes.Repeat([]byte{2}, 32))
|
||||
|
||||
_, err = graph.PruneGraph(spendOutputs, &blockHash2, 156)
|
||||
_, err = graph.PruneGraph(ctx, spendOutputs, &blockHash2, 156)
|
||||
require.Nil(t, err)
|
||||
|
||||
// We'll create 3 almost identical edges, so first create a helper
|
||||
|
||||
@@ -401,7 +401,7 @@ type Store interface { //nolint:interfacebloat
|
||||
// slice of channels that have been closed by the target block along
|
||||
// with any pruned nodes are returned if the function succeeds without
|
||||
// error.
|
||||
PruneGraph(spentOutputs []*wire.OutPoint,
|
||||
PruneGraph(ctx context.Context, spentOutputs []*wire.OutPoint,
|
||||
blockHash *chainhash.Hash, blockHeight uint32) (
|
||||
[]*models.ChannelEdgeInfo, []route.Vertex, error)
|
||||
|
||||
|
||||
@@ -1492,7 +1492,7 @@ const (
|
||||
// with the current UTXO state. A slice of channels that have been closed by
|
||||
// the target block along with any pruned nodes are returned if the function
|
||||
// succeeds without error.
|
||||
func (c *KVStore) PruneGraph(spentOutputs []*wire.OutPoint,
|
||||
func (c *KVStore) PruneGraph(_ context.Context, spentOutputs []*wire.OutPoint,
|
||||
blockHash *chainhash.Hash, blockHeight uint32) (
|
||||
[]*models.ChannelEdgeInfo, []route.Vertex, error) {
|
||||
|
||||
|
||||
@@ -2831,11 +2831,10 @@ func (s *SQLStore) PruneGraphNodes(ctx context.Context) (
|
||||
// succeeds without error.
|
||||
//
|
||||
// NOTE: part of the Store interface.
|
||||
func (s *SQLStore) PruneGraph(spentOutputs []*wire.OutPoint,
|
||||
blockHash *chainhash.Hash, blockHeight uint32) (
|
||||
[]*models.ChannelEdgeInfo, []route.Vertex, error) {
|
||||
|
||||
ctx := context.TODO()
|
||||
func (s *SQLStore) PruneGraph(ctx context.Context,
|
||||
spentOutputs []*wire.OutPoint, blockHash *chainhash.Hash,
|
||||
blockHeight uint32) ([]*models.ChannelEdgeInfo, []route.Vertex,
|
||||
error) {
|
||||
|
||||
s.cacheMu.Lock()
|
||||
defer s.cacheMu.Unlock()
|
||||
|
||||
Reference in new issue
Block a user