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

lightningnetwork / lnd / 19398014578

16 Nov 2025 12:53AM UTC coverage: 65.213% (+8.4%) from 56.858%
19398014578

Pull #10323

github

web-flow
Merge c98812e55 into 841a29118
Pull Request #10323: walletrpc: add raw_tx field to BumpFee response

29 of 50 new or added lines in 2 files covered. (58.0%)

6215 existing lines in 35 files now uncovered.

137591 of 210988 relevant lines covered (65.21%)

20814.78 hits per line

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

93.1
/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/lightningnetwork/lnd/fn/v2"
11
        "github.com/lightningnetwork/lnd/lnwire"
12
        "github.com/lightningnetwork/lnd/routing/route"
13
)
14

15
// Node represents an individual vertex/node within the channel graph.
16
// A node is connected to other nodes by one or more channel edges emanating
17
// from it. As the graph is directed, a node will also have an incoming edge
18
// attached to it for each outgoing edge.
19
type Node struct {
20
        // Version is the gossip version that this node was advertised on.
21
        Version lnwire.GossipVersion
22

23
        // PubKeyBytes is the raw bytes of the public key of the target node.
24
        PubKeyBytes [33]byte
25
        pubKey      *btcec.PublicKey
26

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

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

34
        // Color is the selected color for the node.
35
        Color fn.Option[color.RGBA]
36

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

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

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

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

57
// NodeV1Fields houses the fields that are specific to a version 1 node
58
// announcement.
59
type NodeV1Fields struct {
60
        // Address is the TCP address this node is reachable over.
61
        Addresses []net.Addr
62

63
        // AuthSigBytes is the raw signature under the advertised public key
64
        // which serves to authenticate the attributes announced by this node.
65
        AuthSigBytes []byte
66

67
        // Features is the list of protocol features supported by this node.
68
        Features *lnwire.RawFeatureVector
69

70
        // Color is the selected color for the node.
71
        Color color.RGBA
72

73
        // Alias is a nick-name for the node. The alias can be used to confirm
74
        // a node's identity or to serve as a short ID for an address book.
75
        Alias string
76

77
        // LastUpdate is the last time the vertex information for this node has
78
        // been updated.
79
        LastUpdate time.Time
80

81
        // ExtraOpaqueData is the set of data that was appended to this
82
        // message, some of which we may not actually know how to iterate or
83
        // parse. By holding onto this data, we ensure that we're able to
84
        // properly validate the set of signatures that cover these new fields,
85
        // and ensure we're able to make upgrades to the network in a forwards
86
        // compatible manner.
87
        ExtraOpaqueData []byte
88
}
89

90
// NewV1Node creates a new version 1 node from the passed fields.
91
func NewV1Node(pub route.Vertex, n *NodeV1Fields) *Node {
1,131✔
92
        return &Node{
1,131✔
93
                Version:      lnwire.GossipVersion1,
1,131✔
94
                PubKeyBytes:  pub,
1,131✔
95
                Addresses:    n.Addresses,
1,131✔
96
                AuthSigBytes: n.AuthSigBytes,
1,131✔
97
                Features: lnwire.NewFeatureVector(
1,131✔
98
                        n.Features, lnwire.Features,
1,131✔
99
                ),
1,131✔
100
                Color:           fn.Some(n.Color),
1,131✔
101
                Alias:           fn.Some(n.Alias),
1,131✔
102
                LastUpdate:      n.LastUpdate,
1,131✔
103
                ExtraOpaqueData: n.ExtraOpaqueData,
1,131✔
104
        }
1,131✔
105
}
1,131✔
106

107
// NewV1ShellNode creates a new shell version 1 node.
108
func NewV1ShellNode(pubKey route.Vertex) *Node {
9,567✔
109
        return NewShellNode(lnwire.GossipVersion1, pubKey)
9,567✔
110
}
9,567✔
111

112
// NewShellNode creates a new shell node with the given gossip version and
113
// public key.
114
func NewShellNode(v lnwire.GossipVersion, pubKey route.Vertex) *Node {
9,567✔
115
        return &Node{
9,567✔
116
                Version:     v,
9,567✔
117
                PubKeyBytes: pubKey,
9,567✔
118
                Features:    lnwire.EmptyFeatureVector(),
9,567✔
119
                LastUpdate:  time.Unix(0, 0),
9,567✔
120
        }
9,567✔
121
}
9,567✔
122

123
// HaveAnnouncement returns true if we have received a node announcement for
124
// this node. We determine this by checking if we have a signature for the
125
// announcement.
126
func (n *Node) HaveAnnouncement() bool {
1,191✔
127
        return len(n.AuthSigBytes) > 0
1,191✔
128
}
1,191✔
129

130
// PubKey is the node's long-term identity public key. This key will be used to
131
// authenticated any advertisements/updates sent by the node.
132
//
133
// NOTE: By having this method to access an attribute, we ensure we only need
134
// to fully deserialize the pubkey if absolutely necessary.
135
func (n *Node) PubKey() (*btcec.PublicKey, error) {
2,888✔
136
        if n.pubKey != nil {
4,414✔
137
                return n.pubKey, nil
1,526✔
138
        }
1,526✔
139

140
        key, err := btcec.ParsePubKey(n.PubKeyBytes[:])
1,365✔
141
        if err != nil {
1,365✔
UNCOV
142
                return nil, err
×
UNCOV
143
        }
×
144
        n.pubKey = key
1,365✔
145

1,365✔
146
        return key, nil
1,365✔
147
}
148

149
// NodeAnnouncement retrieves the latest node announcement of the node.
150
func (n *Node) NodeAnnouncement(signed bool) (*lnwire.NodeAnnouncement1,
151
        error) {
18✔
152

18✔
153
        // Error out if we request the signed announcement, but we don't have
18✔
154
        // a signature for this announcement.
18✔
155
        if !n.HaveAnnouncement() && signed {
21✔
156
                return nil, fmt.Errorf("node does not have node announcement")
3✔
157
        }
3✔
158

159
        alias, err := lnwire.NewNodeAlias(n.Alias.UnwrapOr(""))
18✔
160
        if err != nil {
18✔
UNCOV
161
                return nil, err
×
UNCOV
162
        }
×
163

164
        nodeAnn := &lnwire.NodeAnnouncement1{
18✔
165
                Features:        n.Features.RawFeatureVector,
18✔
166
                NodeID:          n.PubKeyBytes,
18✔
167
                RGBColor:        n.Color.UnwrapOr(color.RGBA{}),
18✔
168
                Alias:           alias,
18✔
169
                Addresses:       n.Addresses,
18✔
170
                Timestamp:       uint32(n.LastUpdate.Unix()),
18✔
171
                ExtraOpaqueData: n.ExtraOpaqueData,
18✔
172
        }
18✔
173

18✔
174
        if !signed {
21✔
175
                return nodeAnn, nil
3✔
176
        }
3✔
177

178
        sig, err := lnwire.NewSigFromECDSARawSignature(n.AuthSigBytes)
18✔
179
        if err != nil {
18✔
UNCOV
180
                return nil, err
×
UNCOV
181
        }
×
182

183
        nodeAnn.Signature = sig
18✔
184

18✔
185
        return nodeAnn, nil
18✔
186
}
187

188
// NodeFromWireAnnouncement creates a Node instance from an
189
// lnwire.NodeAnnouncement1 message.
190
func NodeFromWireAnnouncement(msg *lnwire.NodeAnnouncement1) *Node {
20✔
191
        timestamp := time.Unix(int64(msg.Timestamp), 0)
20✔
192

20✔
193
        return NewV1Node(
20✔
194
                msg.NodeID,
20✔
195
                &NodeV1Fields{
20✔
196
                        LastUpdate:      timestamp,
20✔
197
                        Addresses:       msg.Addresses,
20✔
198
                        Alias:           msg.Alias.String(),
20✔
199
                        AuthSigBytes:    msg.Signature.ToSignatureBytes(),
20✔
200
                        Features:        msg.Features,
20✔
201
                        Color:           msg.RGBColor,
20✔
202
                        ExtraOpaqueData: msg.ExtraOpaqueData,
20✔
203
                },
20✔
204
        )
20✔
205
}
20✔
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