What changed, and why it matters
This change simply threads a cancellation context through the graph-pruning code paths so the database layer can respect timeouts and cancellation. It is a routine code-quality/refactoring patch with no obvious security flaw or fix. The context is passed as context.TODO() at the call sites, meaning callers are not yet supplying real deadlines, so the immediate practical effect is limited.
No immediate action required. Treat as normal maintenance. If reviewing, verify that follow-up commits replace context.TODO() with a properly scoped, cancellable context in production call sites and that the KVStore backend eventually respects the context.
Security signals we found
No security-relevant behavior change: the new context parameter is not used to enforce timeouts or cancellation at the call sites.
Context propagation is a defensive hygiene improvement, but the patch is partial (callers still use context.TODO()).
No input validation, authorization, cryptographic, or resource-control changes are present in the diff.
Evidence from the diff
The commit updates the PruneGraph method signature across the graph database interfaces and implementations (ChannelGraph, KVStore, SQLStore) to accept a context.Context. The SQL implementation previously created context.TODO() internally; now it receives the context from callers. The KVStore implementation ignores the context (named _). Call sites in graph/builder.go pass context.TODO(). Tests are updated to pass an existing ctx. This is preparatory work for proper context propagation and cancellation support, not a security patch.
Changed components
graph/builder.gograph/db/graph.gograph/db/interfaces.gograph/db/kv_store.gograph/db/sql_store.gograph/db/graph_test.goInspect captured patch +28 / −22
diff --git a/graph/builder.go b/graph/builder.go
index 8e2aba1..7e1910c 100644
--- a/graph/builder.go
+++ b/graph/builder.go
@@ -185,7 +185,8 @@ func (b *Builder) Start() error {
// the prune height to the current best height of the
// chain backend.
_, err = b.cfg.Graph.PruneGraph(
- nil, bestHash, uint32(bestHeight),
+ context.TODO(), nil, bestHash,
+ uint32(bestHeight),
)
if err != nil {
return err
@@ -443,7 +444,7 @@ func (b *Builder) syncGraphWithChain() error {
// With the spent outputs gathered, attempt to prune the channel graph,
// also passing in the best hash+height so the prune tip can be updated.
closedChans, err := b.cfg.Graph.PruneGraph(
- spentOutputs, bestHash, uint32(bestHeight),
+ context.TODO(), spentOutputs, bestHash, uint32(bestHeight),
)
if err != nil {
return err
@@ -857,8 +858,10 @@ func (b *Builder) updateGraphWithClosedChannels(
// With the spent outputs gathered, attempt to prune the channel graph,
// also passing in the hash+height of the block being pruned so the
// prune tip can be updated.
- chansClosed, err := b.cfg.Graph.PruneGraph(spentOutputs,
- &chainUpdate.Hash, chainUpdate.Height)
+ chansClosed, err := b.cfg.Graph.PruneGraph(
+ context.TODO(), spentOutputs, &chainUpdate.Hash,
+ chainUpdate.Height,
+ )
if err != nil {
log.Errorf("unable to prune routing table: %v", err)
return err
diff --git a/graph/db/graph.go b/graph/db/graph.go
index 8ad85aa..e7e2027 100644
--- a/graph/db/graph.go
+++ b/graph/db/graph.go
@@ -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
diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go
index cd9f7d7..d0d4501 100644
--- a/graph/db/graph_test.go
+++ b/graph/db/graph_test.go
@@ -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
diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go
index 95651fa..923bc8e 100644
--- a/graph/db/interfaces.go
+++ b/graph/db/interfaces.go
@@ -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)
diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go
index 38920ca..280a4cb 100644
--- a/graph/db/kv_store.go
+++ b/graph/db/kv_store.go
@@ -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) {
diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go
index acc1da9..9156f0f 100644
--- a/graph/db/sql_store.go
+++ b/graph/db/sql_store.go
@@ -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()
Why this scored 17/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.