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

lightningnetwork / lnd / 12343072627

15 Dec 2024 11:09PM UTC coverage: 57.504% (-1.1%) from 58.636%
12343072627

Pull #9315

github

yyforyongyu
contractcourt: offer outgoing htlc one block earlier before its expiry

We need to offer the outgoing htlc one block earlier to make sure when
the expiry height hits, the sweeper will not miss sweeping it in the
same block. This also means the outgoing contest resolver now only does
one thing - watch for preimage spend till height expiry-1, which can
easily be moved into the timeout resolver instead in the future.
Pull Request #9315: Implement `blockbeat`

1445 of 2007 new or added lines in 26 files covered. (72.0%)

19246 existing lines in 249 files now uncovered.

102342 of 177975 relevant lines covered (57.5%)

24772.24 hits per line

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

21.74
/build/version.go
1
// Copyright (c) 2013-2017 The btcsuite developers
2
// Copyright (c) 2015-2016 The Decred developers
3
// Heavily inspired by https://github.com/btcsuite/btcd/blob/master/version.go
4
// Copyright (C) 2015-2022 The Lightning Network Developers
5

6
package build
7

8
import (
9
        "context"
10
        "encoding/hex"
11
        "fmt"
12
        "runtime/debug"
13
        "strings"
14

15
        "github.com/btcsuite/btclog/v2"
16
)
17

18
var (
19
        // Commit stores the current commit of this build, which includes the
20
        // most recent tag, the number of commits since that tag (if non-zero),
21
        // the commit hash, and a dirty marker. This should be set using the
22
        // -ldflags during compilation.
23
        Commit string
24

25
        // CommitHash stores the current commit hash of this build.
26
        CommitHash string
27

28
        // RawTags contains the raw set of build tags, separated by commas.
29
        RawTags string
30

31
        // GoVersion stores the go version that the executable was compiled
32
        // with.
33
        GoVersion string
34
)
35

36
// semanticAlphabet is the set of characters that are permitted for use in an
37
// AppPreRelease.
38
const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-."
39

40
// These constants define the application version and follow the semantic
41
// versioning 2.0.0 spec (http://semver.org/).
42
const (
43
        // AppMajor defines the major version of this binary.
44
        AppMajor uint = 0
45

46
        // AppMinor defines the minor version of this binary.
47
        AppMinor uint = 18
48

49
        // AppPatch defines the application patch for this binary.
50
        AppPatch uint = 99
51

52
        // AppPreRelease MUST only contain characters from semanticAlphabet per
53
        // the semantic versioning spec.
54
        AppPreRelease = "beta"
55
)
56

57
func init() {
74✔
58
        // Assert that AppPreRelease is valid according to the semantic
74✔
59
        // versioning guidelines for pre-release version and build metadata
74✔
60
        // strings. In particular it MUST only contain characters in
74✔
61
        // semanticAlphabet.
74✔
62
        for _, r := range AppPreRelease {
370✔
63
                if !strings.ContainsRune(semanticAlphabet, r) {
296✔
64
                        panic(fmt.Errorf("rune: %v is not in the semantic "+
×
65
                                "alphabet", r))
×
66
                }
67
        }
68

69
        // Get build information from the runtime.
70
        if info, ok := debug.ReadBuildInfo(); ok {
148✔
71
                GoVersion = info.GoVersion
74✔
72
                for _, setting := range info.Settings {
74✔
UNCOV
73
                        switch setting.Key {
×
UNCOV
74
                        case "vcs.revision":
×
UNCOV
75
                                CommitHash = setting.Value
×
76

UNCOV
77
                        case "-tags":
×
UNCOV
78
                                RawTags = setting.Value
×
79
                        }
80
                }
81
        }
82
}
83

84
// Version returns the application version as a properly formed string per the
85
// semantic versioning 2.0.0 spec (http://semver.org/).
UNCOV
86
func Version() string {
×
UNCOV
87
        // Start with the major, minor, and patch versions.
×
UNCOV
88
        version := fmt.Sprintf("%d.%d.%d", AppMajor, AppMinor, AppPatch)
×
UNCOV
89

×
UNCOV
90
        // Append pre-release version if there is one. The hyphen called for by
×
UNCOV
91
        // the semantic versioning spec is automatically appended and should not
×
UNCOV
92
        // be contained in the pre-release string.
×
UNCOV
93
        if AppPreRelease != "" {
×
UNCOV
94
                version = fmt.Sprintf("%s-%s", version, AppPreRelease)
×
UNCOV
95
        }
×
96

UNCOV
97
        return version
×
98
}
99

100
// Tags returns the list of build tags that were compiled into the executable.
UNCOV
101
func Tags() []string {
×
UNCOV
102
        if len(RawTags) == 0 {
×
103
                return nil
×
104
        }
×
105

UNCOV
106
        return strings.Split(RawTags, ",")
×
107
}
108

109
// WithBuildInfo derives a child context with the build information attached as
110
// attributes. At the moment, this only includes the current build's commit
111
// hash.
112
func WithBuildInfo(ctx context.Context, cfg *LogConfig) (context.Context,
UNCOV
113
        error) {
×
UNCOV
114

×
UNCOV
115
        if cfg.NoCommitHash {
×
UNCOV
116
                return ctx, nil
×
UNCOV
117
        }
×
118

119
        // Convert the commit hash to a byte slice.
120
        commitHash, err := hex.DecodeString(CommitHash)
×
121
        if err != nil {
×
122
                return nil, fmt.Errorf("unable to decode commit hash: %w", err)
×
123
        }
×
124

125
        // Include the first 3 bytes of the commit hash in the context as an
126
        // slog attribute.
127
        if len(commitHash) > 3 {
×
128
                commitHash = commitHash[:3]
×
129
        }
×
130

131
        return btclog.WithCtx(ctx, btclog.Hex("rev", commitHash)), nil
×
132
}
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