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

lightningnetwork / lnd / 21485572389

29 Jan 2026 04:09PM UTC coverage: 65.247% (+0.2%) from 65.074%
21485572389

Pull #10089

github

web-flow
Merge 22d34d15e into 19b2ad797
Pull Request #10089: Onion message forwarding

1152 of 1448 new or added lines in 23 files covered. (79.56%)

4109 existing lines in 29 files now uncovered.

139515 of 213825 relevant lines covered (65.25%)

20529.09 hits per line

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

25.0
/lncfg/config.go
1
package lncfg
2

3
import (
4
        "os"
5
        "os/user"
6
        "path/filepath"
7
        "strings"
8
        "time"
9
)
10

11
const (
12
        // DefaultConfigFilename is the default configuration file name lnd
13
        // tries to load.
14
        DefaultConfigFilename = "lnd.conf"
15

16
        // DefaultMaxPendingChannels is the default maximum number of incoming
17
        // pending channels permitted per peer.
18
        DefaultMaxPendingChannels = 1
19

20
        // DefaultIncomingBroadcastDelta defines the number of blocks before the
21
        // expiry of an incoming htlc at which we force close the channel. We
22
        // only go to chain if we also have the preimage to actually pull in the
23
        // htlc. BOLT #2 suggests 7 blocks. We use more for extra safety.
24
        //
25
        // The value accounts for:
26
        //   - Up to 6 blocks waiting for close tx confirmation (reorg safety)
27
        //   - Time to broadcast and confirm our sweep/2nd level success tx
28
        //
29
        // Within this window we need to get our sweep confirmed, because after
30
        // that the remote party is also able to claim the htlc using the
31
        // timeout path.
32
        DefaultIncomingBroadcastDelta = 16
33

34
        // DefaultFinalCltvRejectDelta defines the number of blocks before the
35
        // expiry of an incoming exit hop htlc at which we cancel it back
36
        // immediately. It is an extra safety measure over the final cltv
37
        // requirement as it is defined in the invoice. It ensures that we
38
        // cancel back htlcs that, when held on to, may cause us to force close
39
        // the channel because we enter the incoming broadcast window. Bolt #11
40
        // suggests 9 blocks here. We use a few more for additional safety.
41
        //
42
        // There is still a small gap that remains between receiving the
43
        // RevokeAndAck and canceling back. If a new block arrives within that
44
        // window, we may still force close the channel. There is currently no
45
        // way to reject an UpdateAddHtlc of which we already know that it will
46
        // push us in the broadcast window.
47
        DefaultFinalCltvRejectDelta = DefaultIncomingBroadcastDelta + 3
48

49
        // DefaultCltvInterceptDelta defines the number of blocks before the
50
        // expiry of the htlc where we don't intercept anymore. This value must
51
        // be greater than CltvRejectDelta, because we don't want to offer htlcs
52
        // to the interceptor client for which there is no time left to resolve
53
        // them anymore.
54
        DefaultCltvInterceptDelta = DefaultFinalCltvRejectDelta + 3
55

56
        // DefaultOutgoingBroadcastDelta defines the number of blocks before the
57
        // expiry of an outgoing htlc at which we force close the channel. We
58
        // are not in a hurry to force close, because there is nothing to claim
59
        // for us. We do need to time the htlc out, because there may be an
60
        // incoming htlc that will time out too (albeit later). Bolt #2 suggests
61
        // a value of -1 here, but we allow one block less to prevent potential
62
        // confusion around the negative value. It means we force close the
63
        // channel at exactly the htlc expiry height.
64
        DefaultOutgoingBroadcastDelta = 0
65

66
        // DefaultOutgoingCltvRejectDelta defines the number of blocks before
67
        // the expiry of an outgoing htlc at which we don't want to offer it to
68
        // the next peer anymore. If that happens, we cancel back the incoming
69
        // htlc. This is to prevent the situation where we have an outstanding
70
        // htlc that brings or will soon bring us inside the outgoing broadcast
71
        // window and trigger us to force close the channel. Bolt #2 suggests a
72
        // value of 0. We pad it a bit, to prevent a slow round trip to the next
73
        // peer and a block arriving during that round trip to trigger force
74
        // closure.
75
        DefaultOutgoingCltvRejectDelta = DefaultOutgoingBroadcastDelta + 3
76

77
        // DefaultZombieSweeperInterval is the default time interval at which
78
        // unfinished (zombiestate) open channel flows are purged from memory.
79
        DefaultZombieSweeperInterval = 1 * time.Minute
80

81
        // DefaultMaxWaitNumBlocksFundingConf is the maximum number of blocks to
82
        // wait for the funding transaction to confirm before forgetting
83
        // channels that aren't initiated by us. 2016 blocks is ~2 weeks.
84
        DefaultMaxWaitNumBlocksFundingConf = 2016
85
)
86

87
// CleanAndExpandPath expands environment variables and leading ~ in the
88
// passed path, cleans the result, and returns it.
89
// This function is taken from https://github.com/btcsuite/btcd
UNCOV
90
func CleanAndExpandPath(path string) string {
×
91
        if path == "" {
×
92
                return ""
×
93
        }
×
94

95
        // Expand initial ~ to OS specific home directory.
96
        if strings.HasPrefix(path, "~") {
×
97
                var homeDir string
×
98
                u, err := user.Current()
×
UNCOV
99
                if err == nil {
×
100
                        homeDir = u.HomeDir
×
UNCOV
101
                } else {
×
UNCOV
102
                        homeDir = os.Getenv("HOME")
×
UNCOV
103
                }
×
104

105
                path = strings.Replace(path, "~", homeDir, 1)
×
106
        }
107

108
        // NOTE: The os.ExpandEnv doesn't work with Windows-style %VARIABLE%,
109
        // but the variables can still be expanded via POSIX-style $VARIABLE.
UNCOV
110
        return filepath.Clean(os.ExpandEnv(path))
×
111
}
112

113
// NormalizeNetwork returns the common name of a network type used to create
114
// file paths. This allows differently versioned networks to use the same path.
115
func NormalizeNetwork(network string) string {
2✔
116
        // The 4th testnet isn't the "default" yet, so we'll want to explicitly
2✔
117
        // point that to a "testnet4" directory.
2✔
118
        if network == "testnet4" {
2✔
UNCOV
119
                return network
×
120
        }
×
121

122
        // We want to collapse "testnet3" and "testnet" to the same "testnet"
123
        // directory.
124
        if strings.HasPrefix(network, "testnet") {
2✔
UNCOV
125
                return "testnet"
×
UNCOV
126
        }
×
127

128
        return network
2✔
129
}
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

© 2026 Coveralls, Inc