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

lightningnetwork / lnd / 13536249039

26 Feb 2025 03:42AM UTC coverage: 57.462% (-1.4%) from 58.835%
13536249039

Pull #8453

github

Roasbeef
peer: update chooseDeliveryScript to gen script if needed

In this commit, we update `chooseDeliveryScript` to generate a new
script if needed. This allows us to fold in a few other lines that
always followed this function into this expanded function.

The tests have been updated accordingly.
Pull Request #8453: [4/4] - multi: integrate new rbf coop close FSM into the existing peer flow

275 of 1318 new or added lines in 22 files covered. (20.86%)

19521 existing lines in 257 files now uncovered.

103858 of 180741 relevant lines covered (57.46%)

24750.23 hits per line

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

79.37
/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,484✔
69
        if l.pubKey != nil {
1,977✔
70
                return l.pubKey, nil
493✔
71
        }
493✔
72

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

991✔
79
        return key, nil
991✔
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) {
15✔
101

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

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

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

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

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

130
        nodeAnn.Signature = sig
15✔
131

15✔
132
        return nodeAnn, nil
15✔
133
}
134

135
// NodeFromWireAnnouncement creates a LightningNode instance from an
136
// lnwire.NodeAnnouncement message.
137
func NodeFromWireAnnouncement(msg *lnwire.NodeAnnouncement) *LightningNode {
17✔
138
        timestamp := time.Unix(int64(msg.Timestamp), 0)
17✔
139
        features := lnwire.NewFeatureVector(msg.Features, lnwire.Features)
17✔
140

17✔
141
        return &LightningNode{
17✔
142
                HaveNodeAnnouncement: true,
17✔
143
                LastUpdate:           timestamp,
17✔
144
                Addresses:            msg.Addresses,
17✔
145
                PubKeyBytes:          msg.NodeID,
17✔
146
                Alias:                msg.Alias.String(),
17✔
147
                AuthSigBytes:         msg.Signature.ToSignatureBytes(),
17✔
148
                Features:             features,
17✔
149
                Color:                msg.RGBColor,
17✔
150
                ExtraOpaqueData:      msg.ExtraOpaqueData,
17✔
151
        }
17✔
152
}
17✔
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