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

lightningnetwork / lnd / 16948521526

13 Aug 2025 08:27PM UTC coverage: 54.877% (-12.1%) from 66.929%
16948521526

Pull #10155

github

web-flow
Merge 61c0fecf6 into c6a9116e3
Pull Request #10155: Add missing invoice index for native sql

108941 of 198518 relevant lines covered (54.88%)

22023.66 hits per line

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

55.56
/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. The channeldb
35
        // is inherently part of the optional migration flow so there is no need
36
        // to specify it here. The DecayedLog is a separate database in case the
37
        // kvdb backend is set to `bbolt`. And also for the kvdb SQL backend
38
        // case it is a separate table therefore we need to reference it here
39
        // as well to use the right query to access the decayed log.
40
        DecayedLog kvdb.Backend
41
}
42

43
// NewOptionalMiragtionConfig creates a new OptionalMiragtionConfig with the
44
// default migration flags.
45
func NewOptionalMiragtionConfig() OptionalMiragtionConfig {
1,760✔
46
        return OptionalMiragtionConfig{
1,760✔
47
                MigrationFlags: make([]bool, len(optionalVersions)),
1,760✔
48
        }
1,760✔
49
}
1,760✔
50

51
// Options holds parameters for tuning and customizing a channeldb.DB.
52
type Options struct {
53
        OptionalMiragtionConfig
54

55
        // NoMigration specifies that underlying backend was opened in read-only
56
        // mode and migrations shouldn't be performed. This can be useful for
57
        // applications that use the channeldb package as a library.
58
        NoMigration bool
59

60
        // NoRevLogAmtData when set to true, indicates that amount data should
61
        // not be stored in the revocation log.
62
        NoRevLogAmtData bool
63

64
        // clock is the time source used by the database.
65
        clock clock.Clock
66

67
        // dryRun will fail to commit a successful migration when opening the
68
        // database if set to true.
69
        dryRun bool
70

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

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

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

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

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

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

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

119
// OptionStoreFinalHtlcResolutions controls whether to persistently store the
120
// final resolution of incoming htlcs.
121
func OptionStoreFinalHtlcResolutions(
122
        storeFinalHtlcResolutions bool) OptionModifier {
7✔
123

7✔
124
        return func(o *Options) {
20✔
125
                o.storeFinalHtlcResolutions = storeFinalHtlcResolutions
13✔
126
        }
13✔
127
}
128

129
// OptionPruneRevocationLog specifies whether the migration for pruning
130
// revocation logs needs to be applied or not.
131
func OptionPruneRevocationLog(prune bool) OptionModifier {
×
132
        return func(o *Options) {
×
133
                o.OptionalMiragtionConfig.MigrationFlags[0] = prune
×
134
        }
×
135
}
136

137
// OptionWithDecayedLogDB sets the decayed log database reference which might
138
// be used for some migrations because generally we only touch the channeldb
139
// databases in the migrations, this is a way to allow also access to the
140
// decayed log database.
141
func OptionWithDecayedLogDB(decayedLog kvdb.Backend) OptionModifier {
×
142
        return func(o *Options) {
×
143
                o.OptionalMiragtionConfig.DecayedLog = decayedLog
×
144
        }
×
145
}
146

147
// OptionGcDecayedLog specifies whether the decayed log migration has to
148
// take place.
149
func OptionGcDecayedLog(noGc bool) OptionModifier {
×
150
        return func(o *Options) {
×
151
                o.OptionalMiragtionConfig.MigrationFlags[1] = !noGc
×
152
        }
×
153
}
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