graph/db: add options infrastructure for iterator configuration
What changed, and why it matters
This commit adds a new configuration helper file for controlling how the Lightning Network graph database walks through (iterates over) channel and node records. It introduces tunable batch sizes and a flag to only include publicly announced nodes. There is no change to existing behavior, no bug fix, and no security-sensitive logic visible in the diff.
No security action required. Treat as routine feature/refactoring infrastructure. Review the follow-up commits that consume these options to assess whether batch-size or public-node filtering choices affect resource exhaustion or information-disclosure boundaries.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch creates a functional-options API in graph/db/options.go: IteratorOption, iterConfig, defaultIteratorConfig(), WithChanUpdateIterBatchSize, WithNodeUpdateIterBatchSize, and WithIterPublicNodesOnly. Defaults are 1,000 entries per batch. The options are not yet wired into any call sites in this commit, so existing code paths are unaffected. No validation beyond rejecting non-positive sizes is performed.
Changed components
graph/db/options.goInspect captured patch +54 / −0
diff --git a/graph/db/options.go b/graph/db/options.go
index 3edda66..15ea6f4 100644
--- a/graph/db/options.go
+++ b/graph/db/options.go
@@ -20,6 +20,60 @@ const (
DefaultPreAllocCacheNumNodes = 15000
)
+// IteratorOption is a functional option used to change the per-call
+// configuration for iterators.
+type IteratorOption func(*iterConfig)
+
+// iterConfig holds the configuration for graph operations.
+type iterConfig struct {
+ // chanUpdateIterBatchSize is the batch size to use when reading out
+ // channel updates to send a peer a backlog.
+ chanUpdateIterBatchSize int
+
+ // nodeUpdateIterBatchSize is the batch size to use when reading out
+ // node updates to send to a peer backlog.
+ nodeUpdateIterBatchSize int
+
+ // iterPublicNodes is used to make an iterator that only iterates over
+ // public nodes.
+ iterPublicNodes bool
+}
+
+// defaultIteratorConfig returns the default configuration.
+func defaultIteratorConfig() *iterConfig {
+ return &iterConfig{
+ chanUpdateIterBatchSize: 1_000,
+ nodeUpdateIterBatchSize: 1_000,
+ }
+}
+
+// WithChanUpdateIterBatchSize sets the batch size for channel update
+// iterators.
+func WithChanUpdateIterBatchSize(size int) IteratorOption {
+ return func(cfg *iterConfig) {
+ if size > 0 {
+ cfg.chanUpdateIterBatchSize = size
+ }
+ }
+}
+
+// WithNodeUpdateIterBatchSize set the batch size for node ann iterators.
+func WithNodeUpdateIterBatchSize(size int) IteratorOption {
+ return func(cfg *iterConfig) {
+ if size > 0 {
+ cfg.nodeUpdateIterBatchSize = size
+ }
+ }
+}
+
+// WithIterPublicNodesOnly is used to create an iterator that only iterates over
+// public nodes.
+func WithIterPublicNodesOnly() IteratorOption {
+ return func(cfg *iterConfig) {
+ cfg.iterPublicNodes = true
+ }
+}
+
// chanGraphOptions holds parameters for tuning and customizing the
// ChannelGraph.
type chanGraphOptions struct {
Why this scored 15/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.