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

lightningnetwork / lnd / 19155841408

07 Nov 2025 02:03AM UTC coverage: 66.675% (-0.04%) from 66.712%
19155841408

Pull #10352

github

web-flow
Merge e4313eba8 into 096ab65b1
Pull Request #10352: [WIP] chainrpc: return Unavailable while notifier starts

137328 of 205965 relevant lines covered (66.68%)

21333.36 hits per line

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

92.45
/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 {
197✔
44
        return &iterConfig{
197✔
45
                chanUpdateIterBatchSize: 1_000,
197✔
46
                nodeUpdateIterBatchSize: 1_000,
197✔
47
        }
197✔
48
}
197✔
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 {
3✔
72
        return func(cfg *iterConfig) {
6✔
73
                cfg.iterPublicNodes = true
3✔
74
        }
3✔
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 {
185✔
93
        return &chanGraphOptions{
185✔
94
                useGraphCache:         true,
185✔
95
                preAllocCacheNumNodes: DefaultPreAllocCacheNumNodes,
185✔
96
        }
185✔
97
}
185✔
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 {
94✔
105
        return func(o *chanGraphOptions) {
188✔
106
                o.useGraphCache = use
94✔
107
        }
94✔
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 {
184✔
140
        return &StoreOptions{
184✔
141
                RejectCacheSize:  DefaultRejectCacheSize,
184✔
142
                ChannelCacheSize: DefaultChannelCacheSize,
184✔
143
                NoMigration:      false,
184✔
144
        }
184✔
145
}
184✔
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 {
3✔
153
        return func(o *StoreOptions) {
6✔
154
                o.RejectCacheSize = n
3✔
155
        }
3✔
156
}
157

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

165
// WithBatchCommitInterval sets the batch commit interval for the interval batch
166
// schedulers.
167
func WithBatchCommitInterval(interval time.Duration) StoreOptionModifier {
4✔
168
        return func(o *StoreOptions) {
7✔
169
                o.BatchCommitInterval = interval
3✔
170
        }
3✔
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