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

lightningnetwork / lnd / 16466354971

23 Jul 2025 09:05AM UTC coverage: 57.54% (-9.7%) from 67.201%
16466354971

Pull #9455

github

web-flow
Merge f914ae23c into 90e211684
Pull Request #9455: discovery+lnwire: add support for DNS host name in NodeAnnouncement msg

151 of 291 new or added lines in 7 files covered. (51.89%)

28441 existing lines in 456 files now uncovered.

98864 of 171817 relevant lines covered (57.54%)

1.79 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. 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 {
3✔
46
        return OptionalMiragtionConfig{
3✔
47
                MigrationFlags: make([]bool, len(optionalVersions)),
3✔
48
        }
3✔
49
}
3✔
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
        // keepFailedPaymentAttempts determines whether failed htlc attempts
72
        // are kept on disk or removed to save space.
73
        keepFailedPaymentAttempts bool
74

75
        // storeFinalHtlcResolutions determines whether to persistently store
76
        // the final resolution of incoming htlcs.
77
        storeFinalHtlcResolutions bool
78
}
79

80
// DefaultOptions returns an Options populated with default values.
81
func DefaultOptions() Options {
3✔
82
        return Options{
3✔
83
                OptionalMiragtionConfig: NewOptionalMiragtionConfig(),
3✔
84
                NoMigration:             false,
3✔
85
                clock:                   clock.NewDefaultClock(),
3✔
86
        }
3✔
87
}
3✔
88

89
// OptionModifier is a function signature for modifying the default Options.
90
type OptionModifier func(*Options)
91

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

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

108
// OptionClock sets a non-default clock dependency.
UNCOV
109
func OptionClock(clock clock.Clock) OptionModifier {
×
UNCOV
110
        return func(o *Options) {
×
UNCOV
111
                o.clock = clock
×
UNCOV
112
        }
×
113
}
114

115
// OptionDryRunMigration controls whether or not to intentionally fail to commit a
116
// successful migration that occurs when opening the database.
117
func OptionDryRunMigration(dryRun bool) OptionModifier {
3✔
118
        return func(o *Options) {
6✔
119
                o.dryRun = dryRun
3✔
120
        }
3✔
121
}
122

123
// OptionKeepFailedPaymentAttempts controls whether failed payment attempts are
124
// kept on disk after a payment settles.
125
func OptionKeepFailedPaymentAttempts(keepFailedPaymentAttempts bool) OptionModifier {
3✔
126
        return func(o *Options) {
6✔
127
                o.keepFailedPaymentAttempts = keepFailedPaymentAttempts
3✔
128
        }
3✔
129
}
130

131
// OptionStoreFinalHtlcResolutions controls whether to persistently store the
132
// final resolution of incoming htlcs.
133
func OptionStoreFinalHtlcResolutions(
134
        storeFinalHtlcResolutions bool) OptionModifier {
3✔
135

3✔
136
        return func(o *Options) {
6✔
137
                o.storeFinalHtlcResolutions = storeFinalHtlcResolutions
3✔
138
        }
3✔
139
}
140

141
// OptionPruneRevocationLog specifies whether the migration for pruning
142
// revocation logs needs to be applied or not.
143
func OptionPruneRevocationLog(prune bool) OptionModifier {
3✔
144
        return func(o *Options) {
6✔
145
                o.OptionalMiragtionConfig.MigrationFlags[0] = prune
3✔
146
        }
3✔
147
}
148

149
// OptionWithDecayedLogDB sets the decayed log database reference which might
150
// be used for some migrations because generally we only touch the channeldb
151
// databases in the migrations, this is a way to allow also access to the
152
// decayed log database.
153
func OptionWithDecayedLogDB(decayedLog kvdb.Backend) OptionModifier {
3✔
154
        return func(o *Options) {
6✔
155
                o.OptionalMiragtionConfig.DecayedLog = decayedLog
3✔
156
        }
3✔
157
}
158

159
// OptionGcDecayedLog specifies whether the decayed log migration has to
160
// take place.
161
func OptionGcDecayedLog(noGc bool) OptionModifier {
3✔
162
        return func(o *Options) {
6✔
163
                o.OptionalMiragtionConfig.MigrationFlags[1] = !noGc
3✔
164
        }
3✔
165
}
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