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

lightningnetwork / lnd / 20239727253

15 Dec 2025 04:31PM UTC coverage: 53.405% (-11.8%) from 65.173%
20239727253

Pull #10363

github

web-flow
Merge f9078e552 into 06cc0f3aa
Pull Request #10363: graphdb: add caching for isPublicNode query

4 of 61 new or added lines in 4 files covered. (6.56%)

24136 existing lines in 286 files now uncovered.

110522 of 206950 relevant lines covered (53.41%)

21143.83 hits per line

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

89.87
/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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

129
// PubKey is the node's long-term identity public key. This key will be used to
130
// authenticated any advertisements/updates sent by the node.
131
func (n *Node) PubKey() (*btcec.PublicKey, error) {
2,897✔
132
        return btcec.ParsePubKey(n.PubKeyBytes[:])
2,897✔
133
}
2,897✔
134

135
// NodeAnnouncement retrieves the latest node announcement of the node.
136
func (n *Node) NodeAnnouncement(signed bool) (*lnwire.NodeAnnouncement1,
137
        error) {
15✔
138

15✔
139
        // Error out if we request the signed announcement, but we don't have
15✔
140
        // a signature for this announcement.
15✔
141
        if !n.HaveAnnouncement() && signed {
15✔
UNCOV
142
                return nil, fmt.Errorf("node does not have node announcement")
×
UNCOV
143
        }
×
144

145
        alias, err := lnwire.NewNodeAlias(n.Alias.UnwrapOr(""))
15✔
146
        if err != nil {
15✔
147
                return nil, err
×
148
        }
×
149

150
        nodeAnn := &lnwire.NodeAnnouncement1{
15✔
151
                Features:        n.Features.RawFeatureVector,
15✔
152
                NodeID:          n.PubKeyBytes,
15✔
153
                RGBColor:        n.Color.UnwrapOr(color.RGBA{}),
15✔
154
                Alias:           alias,
15✔
155
                Addresses:       n.Addresses,
15✔
156
                Timestamp:       uint32(n.LastUpdate.Unix()),
15✔
157
                ExtraOpaqueData: n.ExtraOpaqueData,
15✔
158
        }
15✔
159

15✔
160
        if !signed {
15✔
UNCOV
161
                return nodeAnn, nil
×
UNCOV
162
        }
×
163

164
        sig, err := lnwire.NewSigFromECDSARawSignature(n.AuthSigBytes)
15✔
165
        if err != nil {
15✔
166
                return nil, err
×
167
        }
×
168

169
        nodeAnn.Signature = sig
15✔
170

15✔
171
        return nodeAnn, nil
15✔
172
}
173

174
// NodeFromWireAnnouncement creates a Node instance from an
175
// lnwire.NodeAnnouncement1 message.
176
func NodeFromWireAnnouncement(msg *lnwire.NodeAnnouncement1) *Node {
17✔
177
        timestamp := time.Unix(int64(msg.Timestamp), 0)
17✔
178

17✔
179
        return NewV1Node(
17✔
180
                msg.NodeID,
17✔
181
                &NodeV1Fields{
17✔
182
                        LastUpdate:      timestamp,
17✔
183
                        Addresses:       msg.Addresses,
17✔
184
                        Alias:           msg.Alias.String(),
17✔
185
                        AuthSigBytes:    msg.Signature.ToSignatureBytes(),
17✔
186
                        Features:        msg.Features,
17✔
187
                        Color:           msg.RGBColor,
17✔
188
                        ExtraOpaqueData: msg.ExtraOpaqueData,
17✔
189
                },
17✔
190
        )
17✔
191
}
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