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

lightningnetwork / lnd / 16200178152

10 Jul 2025 04:04PM UTC coverage: 57.65% (-9.8%) from 67.417%
16200178152

Pull #10065

github

web-flow
Merge 944c68c38 into 04a2be29d
Pull Request #10065: graph/db: async graph cache population

28 of 38 new or added lines in 3 files covered. (73.68%)

28436 existing lines in 456 files now uncovered.

98585 of 171006 relevant lines covered (57.65%)

1.79 hits per line

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

80.95
/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
        // asyncGraphCachePopulation indicates whether the graph cache
36
        // should be populated asynchronously or if the Start method should
37
        // block until the cache is fully populated.
38
        asyncGraphCachePopulation bool
39
}
40

41
// defaultChanGraphOptions returns a new chanGraphOptions instance populated
42
// with default values.
43
func defaultChanGraphOptions() *chanGraphOptions {
3✔
44
        return &chanGraphOptions{
3✔
45
                useGraphCache:             true,
3✔
46
                asyncGraphCachePopulation: true,
3✔
47
                preAllocCacheNumNodes:     DefaultPreAllocCacheNumNodes,
3✔
48
        }
3✔
49
}
3✔
50

51
// ChanGraphOption describes the signature of a functional option that can be
52
// used to customize a ChannelGraph instance.
53
type ChanGraphOption func(*chanGraphOptions)
54

55
// WithUseGraphCache sets whether the in-memory graph cache should be used.
56
func WithUseGraphCache(use bool) ChanGraphOption {
3✔
57
        return func(o *chanGraphOptions) {
6✔
58
                o.useGraphCache = use
3✔
59
        }
3✔
60
}
61

62
// WithPreAllocCacheNumNodes sets the number of nodes we expect to be in the
63
// graph cache, so we can pre-allocate the map accordingly.
64
func WithPreAllocCacheNumNodes(n int) ChanGraphOption {
×
65
        return func(o *chanGraphOptions) {
×
66
                o.preAllocCacheNumNodes = n
×
67
        }
×
68
}
69

70
// WithAsyncGraphCachePopulation sets whether the graph cache should be
71
// populated asynchronously or if the Start method should block until the
72
// cache is fully populated.
73
func WithAsyncGraphCachePopulation(async bool) ChanGraphOption {
3✔
74
        return func(o *chanGraphOptions) {
6✔
75
                o.asyncGraphCachePopulation = async
3✔
76
        }
3✔
77
}
78

79
// WithSyncGraphCachePopulation will cause the ChannelGraph to block
80
// until the graph cache is fully populated before returning from the Start
81
// method. This is useful for tests that need to ensure the graph cache is
82
// fully populated before proceeding with further operations.
NEW
83
func WithSyncGraphCachePopulation() ChanGraphOption {
×
NEW
84
        return func(o *chanGraphOptions) {
×
NEW
85
                o.asyncGraphCachePopulation = false
×
NEW
86
        }
×
87
}
88

89
// StoreOptions holds parameters for tuning and customizing a graph DB.
90
type StoreOptions struct {
91
        // RejectCacheSize is the maximum number of rejectCacheEntries to hold
92
        // in the rejection cache.
93
        RejectCacheSize int
94

95
        // ChannelCacheSize is the maximum number of ChannelEdges to hold in the
96
        // channel cache.
97
        ChannelCacheSize int
98

99
        // BatchCommitInterval is the maximum duration the batch schedulers will
100
        // wait before attempting to commit a pending set of updates.
101
        BatchCommitInterval time.Duration
102

103
        // NoMigration specifies that underlying backend was opened in read-only
104
        // mode and migrations shouldn't be performed. This can be useful for
105
        // applications that use the channeldb package as a library.
106
        NoMigration bool
107
}
108

109
// DefaultOptions returns a StoreOptions populated with default values.
110
func DefaultOptions() *StoreOptions {
3✔
111
        return &StoreOptions{
3✔
112
                RejectCacheSize:  DefaultRejectCacheSize,
3✔
113
                ChannelCacheSize: DefaultChannelCacheSize,
3✔
114
                NoMigration:      false,
3✔
115
        }
3✔
116
}
3✔
117

118
// StoreOptionModifier is a function signature for modifying the default
119
// StoreOptions.
120
type StoreOptionModifier func(*StoreOptions)
121

122
// WithRejectCacheSize sets the RejectCacheSize to n.
123
func WithRejectCacheSize(n int) StoreOptionModifier {
3✔
124
        return func(o *StoreOptions) {
6✔
125
                o.RejectCacheSize = n
3✔
126
        }
3✔
127
}
128

129
// WithChannelCacheSize sets the ChannelCacheSize to n.
130
func WithChannelCacheSize(n int) StoreOptionModifier {
3✔
131
        return func(o *StoreOptions) {
6✔
132
                o.ChannelCacheSize = n
3✔
133
        }
3✔
134
}
135

136
// WithBatchCommitInterval sets the batch commit interval for the interval batch
137
// schedulers.
138
func WithBatchCommitInterval(interval time.Duration) StoreOptionModifier {
3✔
139
        return func(o *StoreOptions) {
6✔
140
                o.BatchCommitInterval = interval
3✔
141
        }
3✔
142
}
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