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

lightningnetwork / lnd / 14358372723

09 Apr 2025 01:26PM UTC coverage: 56.696% (-12.3%) from 69.037%
14358372723

Pull #9696

github

web-flow
Merge e2837e400 into 867d27d68
Pull Request #9696: Add `development_guidelines.md` for both human and machine

107055 of 188823 relevant lines covered (56.7%)

22721.56 hits per line

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

0.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 a few more for extra safety.
24
        // Within this window we need to get our sweep or 2nd level success tx
25
        // confirmed, because after that the remote party is also able to claim
26
        // the htlc using the timeout path.
27
        DefaultIncomingBroadcastDelta = 10
28

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

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

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

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

72
        // DefaultZombieSweeperInterval is the default time interval at which
73
        // unfinished (zombiestate) open channel flows are purged from memory.
74
        DefaultZombieSweeperInterval = 1 * time.Minute
75

76
        // DefaultMaxWaitNumBlocksFundingConf is the maximum number of blocks to
77
        // wait for the funding transaction to confirm before forgetting
78
        // channels that aren't initiated by us. 2016 blocks is ~2 weeks.
79
        DefaultMaxWaitNumBlocksFundingConf = 2016
80
)
81

82
// CleanAndExpandPath expands environment variables and leading ~ in the
83
// passed path, cleans the result, and returns it.
84
// This function is taken from https://github.com/btcsuite/btcd
85
func CleanAndExpandPath(path string) string {
×
86
        if path == "" {
×
87
                return ""
×
88
        }
×
89

90
        // Expand initial ~ to OS specific home directory.
91
        if strings.HasPrefix(path, "~") {
×
92
                var homeDir string
×
93
                u, err := user.Current()
×
94
                if err == nil {
×
95
                        homeDir = u.HomeDir
×
96
                } else {
×
97
                        homeDir = os.Getenv("HOME")
×
98
                }
×
99

100
                path = strings.Replace(path, "~", homeDir, 1)
×
101
        }
102

103
        // NOTE: The os.ExpandEnv doesn't work with Windows-style %VARIABLE%,
104
        // but the variables can still be expanded via POSIX-style $VARIABLE.
105
        return filepath.Clean(os.ExpandEnv(path))
×
106
}
107

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

117
        // We want to collapse "testnet3" and "testnet" to the same "testnet"
118
        // directory.
119
        if strings.HasPrefix(network, "testnet") {
×
120
                return "testnet"
×
121
        }
×
122

123
        return network
×
124
}
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