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

lightningnetwork / lnd / 19316446305

13 Nov 2025 12:34AM UTC coverage: 65.219% (+8.3%) from 56.89%
19316446305

push

github

web-flow
Merge pull request #10343 from lightningnetwork/0-21-0-staging

Merge branch `0-21-staging`

361 of 5339 new or added lines in 47 files covered. (6.76%)

34 existing lines in 8 files now uncovered.

137571 of 210938 relevant lines covered (65.22%)

20832.75 hits per line

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

0.0
/graph/db/migration1/models/node.go
1
package models
2

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

8
        "github.com/btcsuite/btcd/btcec/v2"
9
        "github.com/lightningnetwork/lnd/fn/v2"
10
        "github.com/lightningnetwork/lnd/lnwire"
11
        "github.com/lightningnetwork/lnd/routing/route"
12
)
13

14
// Node 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 Node struct {
19
        // Version is the gossip version that this node was advertised on.
20
        Version lnwire.GossipVersion
21

22
        // PubKeyBytes is the raw bytes of the public key of the target node.
23
        PubKeyBytes [33]byte
24
        pubKey      *btcec.PublicKey
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.
NEW
90
func NewV1Node(pub route.Vertex, n *NodeV1Fields) *Node {
×
NEW
91
        return &Node{
×
NEW
92
                Version:      lnwire.GossipVersion1,
×
NEW
93
                PubKeyBytes:  pub,
×
NEW
94
                Addresses:    n.Addresses,
×
NEW
95
                AuthSigBytes: n.AuthSigBytes,
×
NEW
96
                Features: lnwire.NewFeatureVector(
×
NEW
97
                        n.Features, lnwire.Features,
×
NEW
98
                ),
×
NEW
99
                Color:           fn.Some(n.Color),
×
NEW
100
                Alias:           fn.Some(n.Alias),
×
NEW
101
                LastUpdate:      n.LastUpdate,
×
NEW
102
                ExtraOpaqueData: n.ExtraOpaqueData,
×
NEW
103
        }
×
NEW
104
}
×
105

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

111
// NewShellNode creates a new shell node with the given gossip version and
112
// public key.
NEW
113
func NewShellNode(v lnwire.GossipVersion, pubKey route.Vertex) *Node {
×
NEW
114
        return &Node{
×
NEW
115
                Version:     v,
×
NEW
116
                PubKeyBytes: pubKey,
×
NEW
117
                Features:    lnwire.EmptyFeatureVector(),
×
NEW
118
                LastUpdate:  time.Unix(0, 0),
×
NEW
119
        }
×
NEW
120
}
×
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.
NEW
125
func (n *Node) HaveAnnouncement() bool {
×
NEW
126
        return len(n.AuthSigBytes) > 0
×
NEW
127
}
×
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
//
132
// NOTE: By having this method to access an attribute, we ensure we only need
133
// to fully deserialize the pubkey if absolutely necessary.
NEW
134
func (n *Node) PubKey() (*btcec.PublicKey, error) {
×
NEW
135
        if n.pubKey != nil {
×
NEW
136
                return n.pubKey, nil
×
NEW
137
        }
×
138

NEW
139
        key, err := btcec.ParsePubKey(n.PubKeyBytes[:])
×
NEW
140
        if err != nil {
×
NEW
141
                return nil, err
×
NEW
142
        }
×
NEW
143
        n.pubKey = key
×
NEW
144

×
NEW
145
        return key, nil
×
146
}
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