• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 18137720653

30 Sep 2025 05:06PM UTC coverage: 54.624% (-2.5%) from 57.132%
18137720653

Pull #10251

github

web-flow
Merge b8a855f57 into 90c96c7df
Pull Request #10251: Add release-notes for 0.21.0

109710 of 200846 relevant lines covered (54.62%)

21827.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.04
/graph/db/options.go
1
package graphdb
2

3
import "time"
4

5
const (
6
        // DefaultRejectCacheSize is the default number of rejectCacheEntries to
7
        // cache for use in the rejection cache of incoming gossip traffic. This
8
        // produces a cache size of around 1MB.
9
        DefaultRejectCacheSize = 50000
10

11
        // DefaultChannelCacheSize is the default number of ChannelEdges cached
12
        // in order to reply to gossip queries. This produces a cache size of
13
        // around 40MB.
14
        DefaultChannelCacheSize = 20000
15

16
        // DefaultPreAllocCacheNumNodes is the default number of channels we
17
        // assume for mainnet for pre-allocating the graph cache. As of
18
        // September 2021, there currently are 14k nodes in a strictly pruned
19
        // graph, so we choose a number that is slightly higher.
20
        DefaultPreAllocCacheNumNodes = 15000
21
)
22

23
// IteratorOption is a functional option used to change the per-call
24
// configuration for iterators.
25
type IteratorOption func(*iterConfig)
26

27
// iterConfig holds the configuration for graph operations.
28
type iterConfig struct {
29
        // chanUpdateIterBatchSize is the batch size to use when reading out
30
        // channel updates to send a peer a backlog.
31
        chanUpdateIterBatchSize int
32

33
        // nodeUpdateIterBatchSize is the batch size to use when reading out
34
        // node updates to send to a peer backlog.
35
        nodeUpdateIterBatchSize int
36

37
        // iterPublicNodes is used to make an iterator that only iterates over
38
        // public nodes.
39
        iterPublicNodes bool
40
}
41

42
// defaultIteratorConfig returns the default configuration.
43
func defaultIteratorConfig() *iterConfig {
199✔
44
        return &iterConfig{
199✔
45
                chanUpdateIterBatchSize: 1_000,
199✔
46
                nodeUpdateIterBatchSize: 1_000,
199✔
47
        }
199✔
48
}
199✔
49

50
// WithChanUpdateIterBatchSize sets the batch size for channel update
51
// iterators.
52
func WithChanUpdateIterBatchSize(size int) IteratorOption {
4✔
53
        return func(cfg *iterConfig) {
8✔
54
                if size > 0 {
8✔
55
                        cfg.chanUpdateIterBatchSize = size
4✔
56
                }
4✔
57
        }
58
}
59

60
// WithNodeUpdateIterBatchSize set the batch size for node ann iterators.
61
func WithNodeUpdateIterBatchSize(size int) IteratorOption {
43✔
62
        return func(cfg *iterConfig) {
86✔
63
                if size > 0 {
86✔
64
                        cfg.nodeUpdateIterBatchSize = size
43✔
65
                }
43✔
66
        }
67
}
68

69
// WithIterPublicNodesOnly is used to create an iterator that only iterates over
70
// public nodes.
71
func WithIterPublicNodesOnly() IteratorOption {
×
72
        return func(cfg *iterConfig) {
×
73
                cfg.iterPublicNodes = true
×
74
        }
×
75
}
76

77
// chanGraphOptions holds parameters for tuning and customizing the
78
// ChannelGraph.
79
type chanGraphOptions struct {
80
        // useGraphCache denotes whether the in-memory graph cache should be
81
        // used or a fallback version that uses the underlying database for
82
        // path finding.
83
        useGraphCache bool
84

85
        // preAllocCacheNumNodes is the number of nodes we expect to be in the
86
        // graph cache, so we can pre-allocate the map accordingly.
87
        preAllocCacheNumNodes int
88
}
89

90
// defaultChanGraphOptions returns a new chanGraphOptions instance populated
91
// with default values.
92
func defaultChanGraphOptions() *chanGraphOptions {
182✔
93
        return &chanGraphOptions{
182✔
94
                useGraphCache:         true,
182✔
95
                preAllocCacheNumNodes: DefaultPreAllocCacheNumNodes,
182✔
96
        }
182✔
97
}
182✔
98

99
// ChanGraphOption describes the signature of a functional option that can be
100
// used to customize a ChannelGraph instance.
101
type ChanGraphOption func(*chanGraphOptions)
102

103
// WithUseGraphCache sets whether the in-memory graph cache should be used.
104
func WithUseGraphCache(use bool) ChanGraphOption {
91✔
105
        return func(o *chanGraphOptions) {
182✔
106
                o.useGraphCache = use
91✔
107
        }
91✔
108
}
109

110
// WithPreAllocCacheNumNodes sets the number of nodes we expect to be in the
111
// graph cache, so we can pre-allocate the map accordingly.
112
func WithPreAllocCacheNumNodes(n int) ChanGraphOption {
×
113
        return func(o *chanGraphOptions) {
×
114
                o.preAllocCacheNumNodes = n
×
115
        }
×
116
}
117

118
// StoreOptions holds parameters for tuning and customizing a graph DB.
119
type StoreOptions struct {
120
        // RejectCacheSize is the maximum number of rejectCacheEntries to hold
121
        // in the rejection cache.
122
        RejectCacheSize int
123

124
        // ChannelCacheSize is the maximum number of ChannelEdges to hold in the
125
        // channel cache.
126
        ChannelCacheSize int
127

128
        // BatchCommitInterval is the maximum duration the batch schedulers will
129
        // wait before attempting to commit a pending set of updates.
130
        BatchCommitInterval time.Duration
131

132
        // NoMigration specifies that underlying backend was opened in read-only
133
        // mode and migrations shouldn't be performed. This can be useful for
134
        // applications that use the channeldb package as a library.
135
        NoMigration bool
136
}
137

138
// DefaultOptions returns a StoreOptions populated with default values.
139
func DefaultOptions() *StoreOptions {
181✔
140
        return &StoreOptions{
181✔
141
                RejectCacheSize:  DefaultRejectCacheSize,
181✔
142
                ChannelCacheSize: DefaultChannelCacheSize,
181✔
143
                NoMigration:      false,
181✔
144
        }
181✔
145
}
181✔
146

147
// StoreOptionModifier is a function signature for modifying the default
148
// StoreOptions.
149
type StoreOptionModifier func(*StoreOptions)
150

151
// WithRejectCacheSize sets the RejectCacheSize to n.
152
func WithRejectCacheSize(n int) StoreOptionModifier {
×
153
        return func(o *StoreOptions) {
×
154
                o.RejectCacheSize = n
×
155
        }
×
156
}
157

158
// WithChannelCacheSize sets the ChannelCacheSize to n.
159
func WithChannelCacheSize(n int) StoreOptionModifier {
×
160
        return func(o *StoreOptions) {
×
161
                o.ChannelCacheSize = n
×
162
        }
×
163
}
164

165
// WithBatchCommitInterval sets the batch commit interval for the interval batch
166
// schedulers.
167
func WithBatchCommitInterval(interval time.Duration) StoreOptionModifier {
1✔
168
        return func(o *StoreOptions) {
1✔
169
                o.BatchCommitInterval = interval
×
170
        }
×
171
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc