• 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

73.33
/labels/labels.go
1
// Package labels contains labels used to label transactions broadcast by lnd.
2
// These labels are used across packages, so they are declared in a separate
3
// package to avoid dependency issues.
4
//
5
// Labels for transactions broadcast by lnd have two set fields followed by an
6
// optional set labelled data values, all separated by colons.
7
//   - Label version: an integer that indicates the version lnd used
8
//   - Label type: the type of transaction we are labelling
9
//   - {field name}-{value}: a named field followed by its value, these items are
10
//     optional, and there may be more than field present.
11
//
12
// For version 0 we have the following optional data fields defined:
13
//   - shortchanid: the short channel ID that a transaction is associated with,
14
//     with its value set to the uint64 short channel id.
15
package labels
16

17
import (
18
        "fmt"
19

20
        "github.com/btcsuite/btcwallet/wtxmgr"
21
        "github.com/lightningnetwork/lnd/lnwire"
22
)
23

24
// External labels a transaction as user initiated via the api. This
25
// label is only used when a custom user provided label is not given.
26
const External = "external"
27

28
// ValidateAPI returns the generic api label if the label provided is empty.
29
// This allows us to label all transactions published by the api, even if
30
// no label is provided. If a label is provided, it is validated against
31
// the known restrictions.
32
func ValidateAPI(label string) (string, error) {
4✔
33
        if len(label) > wtxmgr.TxLabelLimit {
4✔
34
                return "", fmt.Errorf("label length: %v exceeds "+
×
35
                        "limit of %v", len(label), wtxmgr.TxLabelLimit)
×
36
        }
×
37

38
        // If no label was provided by the user, add the generic user
39
        // send label.
40
        if len(label) == 0 {
8✔
41
                return External, nil
4✔
42
        }
4✔
43

UNCOV
44
        return label, nil
×
45
}
46

47
// LabelVersion versions our labels so they can be easily update to contain
48
// new data while still easily string matched.
49
type LabelVersion uint8
50

51
// LabelVersionZero is the label version for labels that contain label type and
52
// channel ID (where available).
53
const LabelVersionZero LabelVersion = iota
54

55
// LabelType indicates the type of label we are creating. It is a string rather
56
// than an int for easy string matching and human-readability.
57
type LabelType string
58

59
const (
60
        // LabelTypeChannelOpen is used to label channel opens.
61
        LabelTypeChannelOpen LabelType = "openchannel"
62

63
        // LabelTypeChannelClose is used to label channel closes.
64
        LabelTypeChannelClose LabelType = "closechannel"
65

66
        // LabelTypeJusticeTransaction is used to label justice transactions.
67
        LabelTypeJusticeTransaction LabelType = "justicetx"
68

69
        // LabelTypeSweepTransaction is used to label sweeps.
70
        LabelTypeSweepTransaction LabelType = "sweep"
71
)
72

73
// LabelField is used to tag a value within a label.
74
type LabelField string
75

76
const (
77
        // ShortChanID is used to tag short channel id values in our labels.
78
        ShortChanID LabelField = "shortchanid"
79
)
80

81
// MakeLabel creates a label with the provided type and short channel id. If
82
// our short channel ID is not known, we simply return version:label_type. If
83
// we do have a short channel ID set, the label will also contain its value:
84
// shortchanid-{int64 chan ID}.
85
func MakeLabel(labelType LabelType, channelID *lnwire.ShortChannelID) string {
128✔
86
        if channelID == nil {
199✔
87
                return fmt.Sprintf("%v:%v", LabelVersionZero, labelType)
71✔
88
        }
71✔
89

90
        return fmt.Sprintf("%v:%v:%v-%v", LabelVersionZero, labelType,
57✔
91
                ShortChanID, channelID.ToUint64())
57✔
92
}
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