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

lightningnetwork / lnd / 15106427751

19 May 2025 07:00AM UTC coverage: 57.417%. First build
15106427751

Pull #9823

github

web-flow
Merge 78203ac47 into b857ae5e6
Pull Request #9823: graph/db: final test preparation before SQL impl

6 of 30 new or added lines in 3 files covered. (20.0%)

95519 of 166359 relevant lines covered (57.42%)

0.61 hits per line

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

61.7
/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
// chanGraphOptions holds parameters for tuning and customizing the
24
// ChannelGraph.
25
type chanGraphOptions struct {
26
        // useGraphCache denotes whether the in-memory graph cache should be
27
        // used or a fallback version that uses the underlying database for
28
        // path finding.
29
        useGraphCache bool
30

31
        // preAllocCacheNumNodes is the number of nodes we expect to be in the
32
        // graph cache, so we can pre-allocate the map accordingly.
33
        preAllocCacheNumNodes int
34
}
35

36
// defaultChanGraphOptions returns a new chanGraphOptions instance populated
37
// with default values.
38
func defaultChanGraphOptions() *chanGraphOptions {
1✔
39
        return &chanGraphOptions{
1✔
40
                useGraphCache:         true,
1✔
41
                preAllocCacheNumNodes: DefaultPreAllocCacheNumNodes,
1✔
42
        }
1✔
43
}
1✔
44

45
// ChanGraphOption describes the signature of a functional option that can be
46
// used to customize a ChannelGraph instance.
47
type ChanGraphOption func(*chanGraphOptions)
48

49
// WithUseGraphCache sets whether the in-memory graph cache should be used.
50
func WithUseGraphCache(use bool) ChanGraphOption {
1✔
51
        return func(o *chanGraphOptions) {
2✔
52
                o.useGraphCache = use
1✔
53
        }
1✔
54
}
55

56
// WithPreAllocCacheNumNodes sets the number of nodes we expect to be in the
57
// graph cache, so we can pre-allocate the map accordingly.
58
func WithPreAllocCacheNumNodes(n int) ChanGraphOption {
×
59
        return func(o *chanGraphOptions) {
×
60
                o.preAllocCacheNumNodes = n
×
61
        }
×
62
}
63

64
// SQLStoreOptions holds parameters for tuning and customizing a SQLStore
65
// instance.
66
type SQLStoreOptions struct {
67
        // RejectCacheSize is the maximum number of rejectCacheEntries to hold
68
        // in the rejection cache.
69
        RejectCacheSize int
70

71
        // ChannelCacheSize is the maximum number of ChannelEdges to hold in the
72
        // channel cache.
73
        ChannelCacheSize int
74
}
75

76
// DefaultSQLOptions returns a SQLStoreOptions populated with default values.
NEW
77
func DefaultSQLOptions() *SQLStoreOptions {
×
NEW
78
        return &SQLStoreOptions{
×
NEW
79
                RejectCacheSize:  DefaultRejectCacheSize,
×
NEW
80
                ChannelCacheSize: DefaultChannelCacheSize,
×
NEW
81
        }
×
NEW
82
}
×
83

84
// SQLStoreOption defines the function signature for a functional option
85
// that can be used to customize a SQLStoreOptions instance.
86
type SQLStoreOption func(*SQLStoreOptions)
87

88
// WithSQLStoreRejectCacheSize sets the RejectCacheSize to n.
NEW
89
func WithSQLStoreRejectCacheSize(n int) SQLStoreOption {
×
NEW
90
        return func(o *SQLStoreOptions) {
×
NEW
91
                o.RejectCacheSize = n
×
NEW
92
        }
×
93
}
94

95
// WithSQLStoreChannelCacheSize sets the ChannelCacheSize to n.
NEW
96
func WithSQLStoreChannelCacheSize(n int) SQLStoreOption {
×
NEW
97
        return func(o *SQLStoreOptions) {
×
NEW
98
                o.ChannelCacheSize = n
×
NEW
99
        }
×
100
}
101

102
// KVStoreOptions holds parameters for tuning and customizing a graph.DB.
103
type KVStoreOptions struct {
104
        // RejectCacheSize is the maximum number of rejectCacheEntries to hold
105
        // in the rejection cache.
106
        RejectCacheSize int
107

108
        // ChannelCacheSize is the maximum number of ChannelEdges to hold in the
109
        // channel cache.
110
        ChannelCacheSize int
111

112
        // BatchCommitInterval is the maximum duration the batch schedulers will
113
        // wait before attempting to commit a pending set of updates.
114
        BatchCommitInterval time.Duration
115

116
        // NoMigration specifies that underlying backend was opened in read-only
117
        // mode and migrations shouldn't be performed. This can be useful for
118
        // applications that use the channeldb package as a library.
119
        NoMigration bool
120
}
121

122
// DefaultOptions returns a KVStoreOptions populated with default values.
123
func DefaultOptions() *KVStoreOptions {
1✔
124
        return &KVStoreOptions{
1✔
125
                RejectCacheSize:  DefaultRejectCacheSize,
1✔
126
                ChannelCacheSize: DefaultChannelCacheSize,
1✔
127
                NoMigration:      false,
1✔
128
        }
1✔
129
}
1✔
130

131
// KVStoreOptionModifier is a function signature for modifying the default
132
// KVStoreOptions.
133
type KVStoreOptionModifier func(*KVStoreOptions)
134

135
// WithRejectCacheSize sets the RejectCacheSize to n.
136
func WithRejectCacheSize(n int) KVStoreOptionModifier {
1✔
137
        return func(o *KVStoreOptions) {
2✔
138
                o.RejectCacheSize = n
1✔
139
        }
1✔
140
}
141

142
// WithChannelCacheSize sets the ChannelCacheSize to n.
143
func WithChannelCacheSize(n int) KVStoreOptionModifier {
1✔
144
        return func(o *KVStoreOptions) {
2✔
145
                o.ChannelCacheSize = n
1✔
146
        }
1✔
147
}
148

149
// WithBatchCommitInterval sets the batch commit interval for the interval batch
150
// schedulers.
151
func WithBatchCommitInterval(interval time.Duration) KVStoreOptionModifier {
1✔
152
        return func(o *KVStoreOptions) {
2✔
153
                o.BatchCommitInterval = interval
1✔
154
        }
1✔
155
}
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