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

lightningnetwork / lnd / 12583319996

02 Jan 2025 01:38PM UTC coverage: 57.522% (-1.1%) from 58.598%
12583319996

Pull #9361

github

starius
fn/ContextGuard: use context.AfterFunc to wait

Simplifies context cancellation handling by using context.AfterFunc instead of a
goroutine to wait for context cancellation. This approach avoids the overhead of
a goroutine during the waiting period.

For ctxQuitUnsafe, since g.quit is closed only in the Quit method (which also
cancels all associated contexts), waiting on context cancellation ensures the
same behavior without unnecessary dependency on g.quit.

Added a test to ensure that the Create method does not launch any goroutines.
Pull Request #9361: fn: optimize context guard

102587 of 178344 relevant lines covered (57.52%)

24734.33 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