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

lightningnetwork / lnd / 13156877563

05 Feb 2025 11:55AM UTC coverage: 57.717% (-1.1%) from 58.82%
13156877563

Pull #9447

github

yyforyongyu
sweep: rename methods for clarity

We now rename "third party" to "unknown" as the inputs can be spent via
an older sweeping tx, a third party (anchor), or a remote party (pin).
In fee bumper we don't have the info to distinguish the above cases, and
leave them to be further handled by the sweeper as it has more context.
Pull Request #9447: sweep: start tracking input spending status in the fee bumper

83 of 87 new or added lines in 2 files covered. (95.4%)

19465 existing lines in 252 files now uncovered.

103642 of 179570 relevant lines covered (57.72%)

24914.08 hits per line

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

72.34
/graph/db/models/node.go
1
package models
2

3
import (
4
        "fmt"
5
        "image/color"
6
        "net"
7
        "time"
8

9
        "github.com/btcsuite/btcd/btcec/v2"
10
        "github.com/btcsuite/btcd/btcec/v2/ecdsa"
11
        "github.com/lightningnetwork/lnd/lnwire"
12
)
13

14
// LightningNode represents an individual vertex/node within the channel graph.
15
// A node is connected to other nodes by one or more channel edges emanating
16
// from it. As the graph is directed, a node will also have an incoming edge
17
// attached to it for each outgoing edge.
18
type LightningNode struct {
19
        // PubKeyBytes is the raw bytes of the public key of the target node.
20
        PubKeyBytes [33]byte
21
        pubKey      *btcec.PublicKey
22

23
        // HaveNodeAnnouncement indicates whether we received a node
24
        // announcement for this particular node. If true, the remaining fields
25
        // will be set, if false only the PubKey is known for this node.
26
        HaveNodeAnnouncement bool
27

28
        // LastUpdate is the last time the vertex information for this node has
29
        // been updated.
30
        LastUpdate time.Time
31

32
        // Address is the TCP address this node is reachable over.
33
        Addresses []net.Addr
34

35
        // Color is the selected color for the node.
36
        Color color.RGBA
37

38
        // Alias is a nick-name for the node. The alias can be used to confirm
39
        // a node's identity or to serve as a short ID for an address book.
40
        Alias string
41

42
        // AuthSigBytes is the raw signature under the advertised public key
43
        // which serves to authenticate the attributes announced by this node.
44
        AuthSigBytes []byte
45

46
        // Features is the list of protocol features supported by this node.
47
        Features *lnwire.FeatureVector
48

49
        // ExtraOpaqueData is the set of data that was appended to this
50
        // message, some of which we may not actually know how to iterate or
51
        // parse. By holding onto this data, we ensure that we're able to
52
        // properly validate the set of signatures that cover these new fields,
53
        // and ensure we're able to make upgrades to the network in a forwards
54
        // compatible manner.
55
        ExtraOpaqueData []byte
56

57
        // TODO(roasbeef): discovery will need storage to keep it's last IP
58
        // address and re-announce if interface changes?
59

60
        // TODO(roasbeef): add update method and fetch?
61
}
62

63
// PubKey is the node's long-term identity public key. This key will be used to
64
// authenticated any advertisements/updates sent by the node.
65
//
66
// NOTE: By having this method to access an attribute, we ensure we only need
67
// to fully deserialize the pubkey if absolutely necessary.
68
func (l *LightningNode) PubKey() (*btcec.PublicKey, error) {
1,454✔
69
        if l.pubKey != nil {
1,921✔
70
                return l.pubKey, nil
467✔
71
        }
467✔
72

73
        key, err := btcec.ParsePubKey(l.PubKeyBytes[:])
987✔
74
        if err != nil {
987✔
75
                return nil, err
×
76
        }
×
77
        l.pubKey = key
987✔
78

987✔
79
        return key, nil
987✔
80
}
81

82
// AuthSig is a signature under the advertised public key which serves to
83
// authenticate the attributes announced by this node.
84
//
85
// NOTE: By having this method to access an attribute, we ensure we only need
86
// to fully deserialize the signature if absolutely necessary.
87
func (l *LightningNode) AuthSig() (*ecdsa.Signature, error) {
×
88
        return ecdsa.ParseSignature(l.AuthSigBytes)
×
89
}
×
90

91
// AddPubKey is a setter-link method that can be used to swap out the public
92
// key for a node.
93
func (l *LightningNode) AddPubKey(key *btcec.PublicKey) {
60✔
94
        l.pubKey = key
60✔
95
        copy(l.PubKeyBytes[:], key.SerializeCompressed())
60✔
96
}
60✔
97

98
// NodeAnnouncement retrieves the latest node announcement of the node.
99
func (l *LightningNode) NodeAnnouncement(signed bool) (*lnwire.NodeAnnouncement,
100
        error) {
14✔
101

14✔
102
        if !l.HaveNodeAnnouncement {
14✔
UNCOV
103
                return nil, fmt.Errorf("node does not have node announcement")
×
UNCOV
104
        }
×
105

106
        alias, err := lnwire.NewNodeAlias(l.Alias)
14✔
107
        if err != nil {
14✔
108
                return nil, err
×
109
        }
×
110

111
        nodeAnn := &lnwire.NodeAnnouncement{
14✔
112
                Features:        l.Features.RawFeatureVector,
14✔
113
                NodeID:          l.PubKeyBytes,
14✔
114
                RGBColor:        l.Color,
14✔
115
                Alias:           alias,
14✔
116
                Addresses:       l.Addresses,
14✔
117
                Timestamp:       uint32(l.LastUpdate.Unix()),
14✔
118
                ExtraOpaqueData: l.ExtraOpaqueData,
14✔
119
        }
14✔
120

14✔
121
        if !signed {
14✔
UNCOV
122
                return nodeAnn, nil
×
UNCOV
123
        }
×
124

125
        sig, err := lnwire.NewSigFromECDSARawSignature(l.AuthSigBytes)
14✔
126
        if err != nil {
14✔
127
                return nil, err
×
128
        }
×
129

130
        nodeAnn.Signature = sig
14✔
131

14✔
132
        return nodeAnn, nil
14✔
133
}
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