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

lightningnetwork / lnd / 15248061147

26 May 2025 06:45AM UTC coverage: 56.774% (-1.8%) from 58.596%
15248061147

Pull #9807

github

web-flow
Merge c65cf7ffd into dc946ae7e
Pull Request #9807: make: allow skipping the vendor and source packaging

107749 of 189787 relevant lines covered (56.77%)

22587.19 hits per line

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

51.52
/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 {
170✔
39
        return &chanGraphOptions{
170✔
40
                useGraphCache:         true,
170✔
41
                preAllocCacheNumNodes: DefaultPreAllocCacheNumNodes,
170✔
42
        }
170✔
43
}
170✔
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 {
91✔
51
        return func(o *chanGraphOptions) {
182✔
52
                o.useGraphCache = use
91✔
53
        }
91✔
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
// KVStoreOptions holds parameters for tuning and customizing a graph.DB.
65
type KVStoreOptions struct {
66
        // RejectCacheSize is the maximum number of rejectCacheEntries to hold
67
        // in the rejection cache.
68
        RejectCacheSize int
69

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

74
        // BatchCommitInterval is the maximum duration the batch schedulers will
75
        // wait before attempting to commit a pending set of updates.
76
        BatchCommitInterval time.Duration
77

78
        // NoMigration specifies that underlying backend was opened in read-only
79
        // mode and migrations shouldn't be performed. This can be useful for
80
        // applications that use the channeldb package as a library.
81
        NoMigration bool
82
}
83

84
// DefaultOptions returns a KVStoreOptions populated with default values.
85
func DefaultOptions() *KVStoreOptions {
169✔
86
        return &KVStoreOptions{
169✔
87
                RejectCacheSize:  DefaultRejectCacheSize,
169✔
88
                ChannelCacheSize: DefaultChannelCacheSize,
169✔
89
                NoMigration:      false,
169✔
90
        }
169✔
91
}
169✔
92

93
// KVStoreOptionModifier is a function signature for modifying the default
94
// KVStoreOptions.
95
type KVStoreOptionModifier func(*KVStoreOptions)
96

97
// WithRejectCacheSize sets the RejectCacheSize to n.
98
func WithRejectCacheSize(n int) KVStoreOptionModifier {
×
99
        return func(o *KVStoreOptions) {
×
100
                o.RejectCacheSize = n
×
101
        }
×
102
}
103

104
// WithChannelCacheSize sets the ChannelCacheSize to n.
105
func WithChannelCacheSize(n int) KVStoreOptionModifier {
×
106
        return func(o *KVStoreOptions) {
×
107
                o.ChannelCacheSize = n
×
108
        }
×
109
}
110

111
// WithBatchCommitInterval sets the batch commit interval for the interval batch
112
// schedulers.
113
func WithBatchCommitInterval(interval time.Duration) KVStoreOptionModifier {
×
114
        return func(o *KVStoreOptions) {
×
115
                o.BatchCommitInterval = interval
×
116
        }
×
117
}
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