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

lightningnetwork / lnd / 12312390362

13 Dec 2024 08:44AM UTC coverage: 57.458% (+8.5%) from 48.92%
12312390362

Pull #9343

github

ellemouton
fn: rework the ContextGuard and add tests

In this commit, the ContextGuard struct is re-worked such that the
context that its new main WithCtx method provides is cancelled in sync
with a parent context being cancelled or with it's quit channel being
cancelled. Tests are added to assert the behaviour. In order for the
close of the quit channel to be consistent with the cancelling of the
derived context, the quit channel _must_ be contained internal to the
ContextGuard so that callers are only able to close the channel via the
exposed Quit method which will then take care to first cancel any
derived context that depend on the quit channel before returning.
Pull Request #9343: fn: expand the ContextGuard and add tests

101853 of 177264 relevant lines covered (57.46%)

24972.93 hits per line

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

66.67
/channeldb/options.go
1
package channeldb
2

3
import (
4
        "github.com/lightningnetwork/lnd/clock"
5
)
6

7
const (
8
        // DefaultRejectCacheSize is the default number of rejectCacheEntries to
9
        // cache for use in the rejection cache of incoming gossip traffic. This
10
        // produces a cache size of around 1MB.
11
        DefaultRejectCacheSize = 50000
12

13
        // DefaultChannelCacheSize is the default number of ChannelEdges cached
14
        // in order to reply to gossip queries. This produces a cache size of
15
        // around 40MB.
16
        DefaultChannelCacheSize = 20000
17

18
        // DefaultPreAllocCacheNumNodes is the default number of channels we
19
        // assume for mainnet for pre-allocating the graph cache. As of
20
        // September 2021, there currently are 14k nodes in a strictly pruned
21
        // graph, so we choose a number that is slightly higher.
22
        DefaultPreAllocCacheNumNodes = 15000
23
)
24

25
// OptionalMiragtionConfig defines the flags used to signal whether a
26
// particular migration needs to be applied.
27
type OptionalMiragtionConfig struct {
28
        // PruneRevocationLog specifies that the revocation log migration needs
29
        // to be applied.
30
        PruneRevocationLog bool
31
}
32

33
// Options holds parameters for tuning and customizing a channeldb.DB.
34
type Options struct {
35
        OptionalMiragtionConfig
36

37
        // NoMigration specifies that underlying backend was opened in read-only
38
        // mode and migrations shouldn't be performed. This can be useful for
39
        // applications that use the channeldb package as a library.
40
        NoMigration bool
41

42
        // NoRevLogAmtData when set to true, indicates that amount data should
43
        // not be stored in the revocation log.
44
        NoRevLogAmtData bool
45

46
        // clock is the time source used by the database.
47
        clock clock.Clock
48

49
        // dryRun will fail to commit a successful migration when opening the
50
        // database if set to true.
51
        dryRun bool
52

53
        // keepFailedPaymentAttempts determines whether failed htlc attempts
54
        // are kept on disk or removed to save space.
55
        keepFailedPaymentAttempts bool
56

57
        // storeFinalHtlcResolutions determines whether to persistently store
58
        // the final resolution of incoming htlcs.
59
        storeFinalHtlcResolutions bool
60
}
61

62
// DefaultOptions returns an Options populated with default values.
63
func DefaultOptions() Options {
1,737✔
64
        return Options{
1,737✔
65
                OptionalMiragtionConfig: OptionalMiragtionConfig{},
1,737✔
66
                NoMigration:             false,
1,737✔
67
                clock:                   clock.NewDefaultClock(),
1,737✔
68
        }
1,737✔
69
}
1,737✔
70

71
// OptionModifier is a function signature for modifying the default Options.
72
type OptionModifier func(*Options)
73

74
// OptionNoRevLogAmtData sets the NoRevLogAmtData option to the given value. If
75
// it is set to true then amount data will not be stored in the revocation log.
76
func OptionNoRevLogAmtData(noAmtData bool) OptionModifier {
×
77
        return func(o *Options) {
×
78
                o.NoRevLogAmtData = noAmtData
×
79
        }
×
80
}
81

82
// OptionNoMigration allows the database to be opened in read only mode by
83
// disabling migrations.
84
func OptionNoMigration(b bool) OptionModifier {
×
85
        return func(o *Options) {
×
86
                o.NoMigration = b
×
87
        }
×
88
}
89

90
// OptionClock sets a non-default clock dependency.
91
func OptionClock(clock clock.Clock) OptionModifier {
151✔
92
        return func(o *Options) {
302✔
93
                o.clock = clock
151✔
94
        }
151✔
95
}
96

97
// OptionDryRunMigration controls whether or not to intentionally fail to commit a
98
// successful migration that occurs when opening the database.
99
func OptionDryRunMigration(dryRun bool) OptionModifier {
1✔
100
        return func(o *Options) {
2✔
101
                o.dryRun = dryRun
1✔
102
        }
1✔
103
}
104

105
// OptionKeepFailedPaymentAttempts controls whether failed payment attempts are
106
// kept on disk after a payment settles.
107
func OptionKeepFailedPaymentAttempts(keepFailedPaymentAttempts bool) OptionModifier {
9✔
108
        return func(o *Options) {
18✔
109
                o.keepFailedPaymentAttempts = keepFailedPaymentAttempts
9✔
110
        }
9✔
111
}
112

113
// OptionStoreFinalHtlcResolutions controls whether to persistently store the
114
// final resolution of incoming htlcs.
115
func OptionStoreFinalHtlcResolutions(
116
        storeFinalHtlcResolutions bool) OptionModifier {
7✔
117

7✔
118
        return func(o *Options) {
20✔
119
                o.storeFinalHtlcResolutions = storeFinalHtlcResolutions
13✔
120
        }
13✔
121
}
122

123
// OptionPruneRevocationLog specifies whether the migration for pruning
124
// revocation logs needs to be applied or not.
125
func OptionPruneRevocationLog(prune bool) OptionModifier {
×
126
        return func(o *Options) {
×
127
                o.OptionalMiragtionConfig.PruneRevocationLog = prune
×
128
        }
×
129
}
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