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

lightningnetwork / lnd / 15628278788

13 Jun 2025 06:45AM UTC coverage: 68.511% (+10.2%) from 58.333%
15628278788

Pull #9945

github

web-flow
Merge e78253ccc into 35102e7c3
Pull Request #9945: Decayed log optional migration

104 of 128 new or added lines in 10 files covered. (81.25%)

42 existing lines in 10 files now uncovered.

134495 of 196311 relevant lines covered (68.51%)

22245.95 hits per line

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

83.67
/channeldb/options.go
1
package channeldb
2

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

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

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

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

26
// OptionalMiragtionConfig defines the flags used to signal whether a
27
// particular migration needs to be applied.
28
type OptionalMiragtionConfig struct {
29
        // MigrationFlags is an array of booleans indicating which optional
30
        // migrations should be run. The index in the array corresponds to the
31
        // migration number in optionalVersions.
32
        MigrationFlags []bool
33

34
        // DecayedLog is a reference to the decayed log database.
35
        DecayedLog kvdb.Backend
36
}
37

38
// NewOptionalMiragtionConfig creates a new OptionalMiragtionConfig with the
39
// default migration flags.
40
func NewOptionalMiragtionConfig() OptionalMiragtionConfig {
1,754✔
41
        return OptionalMiragtionConfig{
1,754✔
42
                MigrationFlags: make([]bool, len(optionalVersions)),
1,754✔
43
        }
1,754✔
44
}
1,754✔
45

46
// Options holds parameters for tuning and customizing a channeldb.DB.
47
type Options struct {
48
        OptionalMiragtionConfig
49

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

55
        // NoRevLogAmtData when set to true, indicates that amount data should
56
        // not be stored in the revocation log.
57
        NoRevLogAmtData bool
58

59
        // clock is the time source used by the database.
60
        clock clock.Clock
61

62
        // dryRun will fail to commit a successful migration when opening the
63
        // database if set to true.
64
        dryRun bool
65

66
        // keepFailedPaymentAttempts determines whether failed htlc attempts
67
        // are kept on disk or removed to save space.
68
        keepFailedPaymentAttempts bool
69

70
        // storeFinalHtlcResolutions determines whether to persistently store
71
        // the final resolution of incoming htlcs.
72
        storeFinalHtlcResolutions bool
73
}
74

75
// DefaultOptions returns an Options populated with default values.
76
func DefaultOptions() Options {
1,753✔
77
        return Options{
1,753✔
78
                OptionalMiragtionConfig: NewOptionalMiragtionConfig(),
1,753✔
79
                NoMigration:             false,
1,753✔
80
                clock:                   clock.NewDefaultClock(),
1,753✔
81
        }
1,753✔
82
}
1,753✔
83

84
// OptionModifier is a function signature for modifying the default Options.
85
type OptionModifier func(*Options)
86

87
// OptionNoRevLogAmtData sets the NoRevLogAmtData option to the given value. If
88
// it is set to true then amount data will not be stored in the revocation log.
89
func OptionNoRevLogAmtData(noAmtData bool) OptionModifier {
3✔
90
        return func(o *Options) {
6✔
91
                o.NoRevLogAmtData = noAmtData
3✔
92
        }
3✔
93
}
94

95
// OptionNoMigration allows the database to be opened in read only mode by
96
// disabling migrations.
97
func OptionNoMigration(b bool) OptionModifier {
×
98
        return func(o *Options) {
×
99
                o.NoMigration = b
×
100
        }
×
101
}
102

103
// OptionClock sets a non-default clock dependency.
104
func OptionClock(clock clock.Clock) OptionModifier {
154✔
105
        return func(o *Options) {
308✔
106
                o.clock = clock
154✔
107
        }
154✔
108
}
109

110
// OptionDryRunMigration controls whether or not to intentionally fail to commit a
111
// successful migration that occurs when opening the database.
112
func OptionDryRunMigration(dryRun bool) OptionModifier {
4✔
113
        return func(o *Options) {
8✔
114
                o.dryRun = dryRun
4✔
115
        }
4✔
116
}
117

118
// OptionKeepFailedPaymentAttempts controls whether failed payment attempts are
119
// kept on disk after a payment settles.
120
func OptionKeepFailedPaymentAttempts(keepFailedPaymentAttempts bool) OptionModifier {
12✔
121
        return func(o *Options) {
24✔
122
                o.keepFailedPaymentAttempts = keepFailedPaymentAttempts
12✔
123
        }
12✔
124
}
125

126
// OptionStoreFinalHtlcResolutions controls whether to persistently store the
127
// final resolution of incoming htlcs.
128
func OptionStoreFinalHtlcResolutions(
129
        storeFinalHtlcResolutions bool) OptionModifier {
10✔
130

10✔
131
        return func(o *Options) {
26✔
132
                o.storeFinalHtlcResolutions = storeFinalHtlcResolutions
16✔
133
        }
16✔
134
}
135

136
// OptionPruneRevocationLog specifies whether the migration for pruning
137
// revocation logs needs to be applied or not.
UNCOV
138
func OptionPruneRevocationLog(prune bool) OptionModifier {
×
UNCOV
139
        return func(o *Options) {
×
NEW
140
                o.OptionalMiragtionConfig.MigrationFlags[0] = prune
×
NEW
141
        }
×
142
}
143

144
// OptionWithDecayedLog sets the decayed log database reference which might be
145
// used for some migrations because generally we only touch the channeldb
146
// database.
147
func OptionWithDecayedLog(decayedLog kvdb.Backend) OptionModifier {
3✔
148
        return func(o *Options) {
6✔
149
                o.OptionalMiragtionConfig.DecayedLog = decayedLog
3✔
150
        }
3✔
151
}
152

153
// OptionGcDecayedLog specifies whether the decayed log migration has to
154
// take place.
155
func OptionGcDecayedLog(noGc bool) OptionModifier {
3✔
156
        return func(o *Options) {
6✔
157
                o.OptionalMiragtionConfig.MigrationFlags[1] = !noGc
3✔
158
        }
3✔
159
}
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