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

lightningnetwork / lnd / 12313002221

13 Dec 2024 09:25AM UTC coverage: 57.486% (+8.6%) from 48.92%
12313002221

push

github

web-flow
Merge pull request #9343 from ellemouton/contextGuard

fn: expand the ContextGuard and add tests

101902 of 177264 relevant lines covered (57.49%)

24909.26 hits per line

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

44.83
/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
// Options holds parameters for tuning and customizing a graph.DB.
24
type Options struct {
25
        // RejectCacheSize is the maximum number of rejectCacheEntries to hold
26
        // in the rejection cache.
27
        RejectCacheSize int
28

29
        // ChannelCacheSize is the maximum number of ChannelEdges to hold in the
30
        // channel cache.
31
        ChannelCacheSize int
32

33
        // BatchCommitInterval is the maximum duration the batch schedulers will
34
        // wait before attempting to commit a pending set of updates.
35
        BatchCommitInterval time.Duration
36

37
        // PreAllocCacheNumNodes is the number of nodes we expect to be in the
38
        // graph cache, so we can pre-allocate the map accordingly.
39
        PreAllocCacheNumNodes int
40

41
        // UseGraphCache denotes whether the in-memory graph cache should be
42
        // used or a fallback version that uses the underlying database for
43
        // path finding.
44
        UseGraphCache bool
45

46
        // NoMigration specifies that underlying backend was opened in read-only
47
        // mode and migrations shouldn't be performed. This can be useful for
48
        // applications that use the channeldb package as a library.
49
        NoMigration bool
50
}
51

52
// DefaultOptions returns an Options populated with default values.
53
func DefaultOptions() *Options {
212✔
54
        return &Options{
212✔
55
                RejectCacheSize:       DefaultRejectCacheSize,
212✔
56
                ChannelCacheSize:      DefaultChannelCacheSize,
212✔
57
                PreAllocCacheNumNodes: DefaultPreAllocCacheNumNodes,
212✔
58
                UseGraphCache:         true,
212✔
59
                NoMigration:           false,
212✔
60
        }
212✔
61
}
212✔
62

63
// OptionModifier is a function signature for modifying the default Options.
64
type OptionModifier func(*Options)
65

66
// WithRejectCacheSize sets the RejectCacheSize to n.
67
func WithRejectCacheSize(n int) OptionModifier {
×
68
        return func(o *Options) {
×
69
                o.RejectCacheSize = n
×
70
        }
×
71
}
72

73
// WithChannelCacheSize sets the ChannelCacheSize to n.
74
func WithChannelCacheSize(n int) OptionModifier {
×
75
        return func(o *Options) {
×
76
                o.ChannelCacheSize = n
×
77
        }
×
78
}
79

80
// WithPreAllocCacheNumNodes sets the PreAllocCacheNumNodes to n.
81
func WithPreAllocCacheNumNodes(n int) OptionModifier {
×
82
        return func(o *Options) {
×
83
                o.PreAllocCacheNumNodes = n
×
84
        }
×
85
}
86

87
// WithBatchCommitInterval sets the batch commit interval for the interval batch
88
// schedulers.
89
func WithBatchCommitInterval(interval time.Duration) OptionModifier {
×
90
        return func(o *Options) {
×
91
                o.BatchCommitInterval = interval
×
92
        }
×
93
}
94

95
// WithUseGraphCache sets the UseGraphCache option to the given value.
96
func WithUseGraphCache(use bool) OptionModifier {
103✔
97
        return func(o *Options) {
206✔
98
                o.UseGraphCache = use
103✔
99
        }
103✔
100
}
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