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

lightningnetwork / lnd / 14358372723

09 Apr 2025 01:26PM UTC coverage: 56.696% (-12.3%) from 69.037%
14358372723

Pull #9696

github

web-flow
Merge e2837e400 into 867d27d68
Pull Request #9696: Add `development_guidelines.md` for both human and machine

107055 of 188823 relevant lines covered (56.7%)

22721.56 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 {
174✔
39
        return &chanGraphOptions{
174✔
40
                useGraphCache:         true,
174✔
41
                preAllocCacheNumNodes: DefaultPreAllocCacheNumNodes,
174✔
42
        }
174✔
43
}
174✔
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 {
102✔
51
        return func(o *chanGraphOptions) {
204✔
52
                o.useGraphCache = use
102✔
53
        }
102✔
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 {
215✔
86
        return &KVStoreOptions{
215✔
87
                RejectCacheSize:  DefaultRejectCacheSize,
215✔
88
                ChannelCacheSize: DefaultChannelCacheSize,
215✔
89
                NoMigration:      false,
215✔
90
        }
215✔
91
}
215✔
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