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

lightningnetwork / lnd / 11216766535

07 Oct 2024 01:37PM UTC coverage: 57.817% (-1.0%) from 58.817%
11216766535

Pull #9148

github

ProofOfKeags
lnwire: remove kickoff feerate from propose/commit
Pull Request #9148: DynComms [2/n]: lnwire: add authenticated wire messages for Dyn*

571 of 879 new or added lines in 16 files covered. (64.96%)

23253 existing lines in 251 files now uncovered.

99022 of 171268 relevant lines covered (57.82%)

38420.67 hits per line

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

43.59
/channeldb/options.go
1
package channeldb
2

3
import (
4
        "time"
5

6
        "github.com/lightningnetwork/lnd/clock"
7
        "github.com/lightningnetwork/lnd/kvdb"
8
)
9

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

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

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

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

36
// Options holds parameters for tuning and customizing a channeldb.DB.
37
type Options struct {
38
        kvdb.BoltBackendConfig
39
        OptionalMiragtionConfig
40

41
        // RejectCacheSize is the maximum number of rejectCacheEntries to hold
42
        // in the rejection cache.
43
        RejectCacheSize int
44

45
        // ChannelCacheSize is the maximum number of ChannelEdges to hold in the
46
        // channel cache.
47
        ChannelCacheSize int
48

49
        // BatchCommitInterval is the maximum duration the batch schedulers will
50
        // wait before attempting to commit a pending set of updates.
51
        BatchCommitInterval time.Duration
52

53
        // PreAllocCacheNumNodes is the number of nodes we expect to be in the
54
        // graph cache, so we can pre-allocate the map accordingly.
55
        PreAllocCacheNumNodes int
56

57
        // UseGraphCache denotes whether the in-memory graph cache should be
58
        // used or a fallback version that uses the underlying database for
59
        // path finding.
60
        UseGraphCache bool
61

62
        // NoMigration specifies that underlying backend was opened in read-only
63
        // mode and migrations shouldn't be performed. This can be useful for
64
        // applications that use the channeldb package as a library.
65
        NoMigration bool
66

67
        // NoRevLogAmtData when set to true, indicates that amount data should
68
        // not be stored in the revocation log.
69
        NoRevLogAmtData bool
70

71
        // clock is the time source used by the database.
72
        clock clock.Clock
73

74
        // dryRun will fail to commit a successful migration when opening the
75
        // database if set to true.
76
        dryRun bool
77

78
        // keepFailedPaymentAttempts determines whether failed htlc attempts
79
        // are kept on disk or removed to save space.
80
        keepFailedPaymentAttempts bool
81

82
        // storeFinalHtlcResolutions determines whether to persistently store
83
        // the final resolution of incoming htlcs.
84
        storeFinalHtlcResolutions bool
85
}
86

87
// DefaultOptions returns an Options populated with default values.
88
func DefaultOptions() Options {
3,327✔
89
        return Options{
3,327✔
90
                BoltBackendConfig: kvdb.BoltBackendConfig{
3,327✔
91
                        NoFreelistSync:    true,
3,327✔
92
                        AutoCompact:       false,
3,327✔
93
                        AutoCompactMinAge: kvdb.DefaultBoltAutoCompactMinAge,
3,327✔
94
                        DBTimeout:         kvdb.DefaultDBTimeout,
3,327✔
95
                },
3,327✔
96
                OptionalMiragtionConfig: OptionalMiragtionConfig{},
3,327✔
97
                RejectCacheSize:         DefaultRejectCacheSize,
3,327✔
98
                ChannelCacheSize:        DefaultChannelCacheSize,
3,327✔
99
                PreAllocCacheNumNodes:   DefaultPreAllocCacheNumNodes,
3,327✔
100
                UseGraphCache:           true,
3,327✔
101
                NoMigration:             false,
3,327✔
102
                clock:                   clock.NewDefaultClock(),
3,327✔
103
        }
3,327✔
104
}
3,327✔
105

106
// OptionModifier is a function signature for modifying the default Options.
107
type OptionModifier func(*Options)
108

109
// OptionSetRejectCacheSize sets the RejectCacheSize to n.
UNCOV
110
func OptionSetRejectCacheSize(n int) OptionModifier {
×
UNCOV
111
        return func(o *Options) {
×
UNCOV
112
                o.RejectCacheSize = n
×
UNCOV
113
        }
×
114
}
115

116
// OptionSetChannelCacheSize sets the ChannelCacheSize to n.
UNCOV
117
func OptionSetChannelCacheSize(n int) OptionModifier {
×
UNCOV
118
        return func(o *Options) {
×
UNCOV
119
                o.ChannelCacheSize = n
×
UNCOV
120
        }
×
121
}
122

123
// OptionSetPreAllocCacheNumNodes sets the PreAllocCacheNumNodes to n.
124
func OptionSetPreAllocCacheNumNodes(n int) OptionModifier {
×
125
        return func(o *Options) {
×
126
                o.PreAllocCacheNumNodes = n
×
127
        }
×
128
}
129

130
// OptionSetUseGraphCache sets the UseGraphCache option to the given value.
UNCOV
131
func OptionSetUseGraphCache(use bool) OptionModifier {
×
UNCOV
132
        return func(o *Options) {
×
UNCOV
133
                o.UseGraphCache = use
×
UNCOV
134
        }
×
135
}
136

137
// OptionNoRevLogAmtData sets the NoRevLogAmtData option to the given value. If
138
// it is set to true then amount data will not be stored in the revocation log.
UNCOV
139
func OptionNoRevLogAmtData(noAmtData bool) OptionModifier {
×
UNCOV
140
        return func(o *Options) {
×
UNCOV
141
                o.NoRevLogAmtData = noAmtData
×
UNCOV
142
        }
×
143
}
144

145
// OptionSetSyncFreelist allows the database to sync its freelist.
146
func OptionSetSyncFreelist(b bool) OptionModifier {
×
147
        return func(o *Options) {
×
148
                o.NoFreelistSync = !b
×
149
        }
×
150
}
151

152
// OptionAutoCompact turns on automatic database compaction on startup.
153
func OptionAutoCompact() OptionModifier {
×
154
        return func(o *Options) {
×
155
                o.AutoCompact = true
×
156
        }
×
157
}
158

159
// OptionAutoCompactMinAge sets the minimum age for automatic database
160
// compaction.
161
func OptionAutoCompactMinAge(minAge time.Duration) OptionModifier {
×
162
        return func(o *Options) {
×
163
                o.AutoCompactMinAge = minAge
×
164
        }
×
165
}
166

167
// OptionSetBatchCommitInterval sets the batch commit interval for the internval
168
// batch schedulers.
UNCOV
169
func OptionSetBatchCommitInterval(interval time.Duration) OptionModifier {
×
UNCOV
170
        return func(o *Options) {
×
UNCOV
171
                o.BatchCommitInterval = interval
×
UNCOV
172
        }
×
173
}
174

175
// OptionNoMigration allows the database to be opened in read only mode by
176
// disabling migrations.
177
func OptionNoMigration(b bool) OptionModifier {
×
178
        return func(o *Options) {
×
179
                o.NoMigration = b
×
180
        }
×
181
}
182

183
// OptionClock sets a non-default clock dependency.
184
func OptionClock(clock clock.Clock) OptionModifier {
151✔
185
        return func(o *Options) {
302✔
186
                o.clock = clock
151✔
187
        }
151✔
188
}
189

190
// OptionDryRunMigration controls whether or not to intentionally fail to commit a
191
// successful migration that occurs when opening the database.
192
func OptionDryRunMigration(dryRun bool) OptionModifier {
1✔
193
        return func(o *Options) {
3✔
194
                o.dryRun = dryRun
2✔
195
        }
2✔
196
}
197

198
// OptionKeepFailedPaymentAttempts controls whether failed payment attempts are
199
// kept on disk after a payment settles.
200
func OptionKeepFailedPaymentAttempts(keepFailedPaymentAttempts bool) OptionModifier {
9✔
201
        return func(o *Options) {
27✔
202
                o.keepFailedPaymentAttempts = keepFailedPaymentAttempts
18✔
203
        }
18✔
204
}
205

206
// OptionStoreFinalHtlcResolutions controls whether to persistently store the
207
// final resolution of incoming htlcs.
208
func OptionStoreFinalHtlcResolutions(
209
        storeFinalHtlcResolutions bool) OptionModifier {
7✔
210

7✔
211
        return func(o *Options) {
32✔
212
                o.storeFinalHtlcResolutions = storeFinalHtlcResolutions
25✔
213
        }
25✔
214
}
215

216
// OptionPruneRevocationLog specifies whether the migration for pruning
217
// revocation logs needs to be applied or not.
UNCOV
218
func OptionPruneRevocationLog(prune bool) OptionModifier {
×
UNCOV
219
        return func(o *Options) {
×
UNCOV
220
                o.OptionalMiragtionConfig.PruneRevocationLog = prune
×
UNCOV
221
        }
×
222
}
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