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

lightningnetwork / lnd / 16811814134

07 Aug 2025 05:46PM UTC coverage: 57.463% (-9.5%) from 66.947%
16811814134

Pull #9844

github

web-flow
Merge 4b08ee16d into 2269859d9
Pull Request #9844: Refactor Payment PR 3

434 of 645 new or added lines in 17 files covered. (67.29%)

28260 existing lines in 457 files now uncovered.

99053 of 172378 relevant lines covered (57.46%)

1.78 hits per line

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

82.22
/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
        // 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 {
3✔
78
        return Options{
3✔
79
                OptionalMiragtionConfig: NewOptionalMiragtionConfig(),
3✔
80
                NoMigration:             false,
3✔
81
                clock:                   clock.NewDefaultClock(),
3✔
82
        }
3✔
83
}
3✔
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 {
3✔
91
        return func(o *Options) {
6✔
92
                o.NoRevLogAmtData = noAmtData
3✔
93
        }
3✔
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.
UNCOV
105
func OptionClock(clock clock.Clock) OptionModifier {
×
UNCOV
106
        return func(o *Options) {
×
UNCOV
107
                o.clock = clock
×
UNCOV
108
        }
×
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 {
3✔
114
        return func(o *Options) {
6✔
115
                o.dryRun = dryRun
3✔
116
        }
3✔
117
}
118

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

3✔
124
        return func(o *Options) {
6✔
125
                o.storeFinalHtlcResolutions = storeFinalHtlcResolutions
3✔
126
        }
3✔
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 {
3✔
132
        return func(o *Options) {
6✔
133
                o.OptionalMiragtionConfig.MigrationFlags[0] = prune
3✔
134
        }
3✔
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 {
3✔
142
        return func(o *Options) {
6✔
143
                o.OptionalMiragtionConfig.DecayedLog = decayedLog
3✔
144
        }
3✔
145
}
146

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