What changed, and why it matters
This change simply threads a context.Context argument through the PruneTip database method so callers can pass cancellation/timeout control. The actual implementation still uses context.TODO() in callers and ignores the context in the KV backend, so it is mostly a plumbing/API cleanup with no immediate security effect.
No security action required; treat as normal refactoring. Review future commits that actually use the passed context for cancellation/timeouts to assess DoS/resilience implications.
Security signals we found
No security-relevant behavioral change in the diff
Context propagation is a code-quality/maintainability improvement, not a vulnerability fix
No input validation, authorization, cryptographic, or resource-limit changes
Evidence from the diff
The commit modifies the Store/ChannelGraph PruneTip signature to accept context.Context. Callers in graph/builder.go pass context.TODO(), the KVStore implementation ignores the context with _, and the SQLStore replaces an internal context.TODO() with the supplied context. No behavioral or security fix is observable in the diff; it is preparatory refactoring for context propagation.
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 +16 / −11
diff --git a/graph/builder.go b/graph/builder.go
index ba3c508..a471e95 100644
--- a/graph/builder.go
+++ b/graph/builder.go
@@ -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
diff --git a/graph/db/graph.go b/graph/db/graph.go
index 38924c8..fd32348 100644
--- a/graph/db/graph.go
+++ b/graph/db/graph.go
@@ -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
diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go
index 7e69e49..4ad0ae3 100644
--- a/graph/db/graph_test.go
+++ b/graph/db/graph_test.go
@@ -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)
diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go
index dec3dba..27dcb04 100644
--- a/graph/db/interfaces.go
+++ b/graph/db/interfaces.go
@@ -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
diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go
index b6e40d8..a5a324d 100644
--- a/graph/db/kv_store.go
+++ b/graph/db/kv_store.go
@@ -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
diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go
index 70fd26c..406b16d 100644
--- a/graph/db/sql_store.go
+++ b/graph/db/sql_store.go
@@ -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
)
Why this scored 18/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.