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

lightningnetwork / lnd / 16052816084

03 Jul 2025 02:13PM UTC coverage: 57.771% (-9.8%) from 67.566%
16052816084

Pull #10027

github

web-flow
Merge 8b40fc901 into ffd944e8b
Pull Request #10027: Fix `ExtraData` field and use `BigSize` encodine

0 of 159 new or added lines in 5 files covered. (0.0%)

28276 existing lines in 457 files now uncovered.

98446 of 170408 relevant lines covered (57.77%)

1.79 hits per line

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

36.76
/graph/db/models/channel_edge_info.go
1
package models
2

3
import (
4
        "bytes"
5
        "fmt"
6

7
        "github.com/btcsuite/btcd/btcec/v2"
8
        "github.com/btcsuite/btcd/btcutil"
9
        "github.com/btcsuite/btcd/chaincfg/chainhash"
10
        "github.com/btcsuite/btcd/wire"
11
        "github.com/lightningnetwork/lnd/fn/v2"
12
        "github.com/lightningnetwork/lnd/lnwire"
13
)
14

15
// ChannelEdgeInfo represents a fully authenticated channel along with all its
16
// unique attributes. Once an authenticated channel announcement has been
17
// processed on the network, then an instance of ChannelEdgeInfo encapsulating
18
// the channels attributes is stored. The other portions relevant to routing
19
// policy of a channel are stored within a ChannelEdgePolicy for each direction
20
// of the channel.
21
type ChannelEdgeInfo struct {
22
        // ChannelID is the unique channel ID for the channel. The first 3
23
        // bytes are the block height, the next 3 the index within the block,
24
        // and the last 2 bytes are the output index for the channel.
25
        ChannelID uint64
26

27
        // ChainHash is the hash that uniquely identifies the chain that this
28
        // channel was opened within.
29
        //
30
        // TODO(roasbeef): need to modify db keying for multi-chain
31
        //  * must add chain hash to prefix as well
32
        ChainHash chainhash.Hash
33

34
        // NodeKey1Bytes is the raw public key of the first node.
35
        NodeKey1Bytes [33]byte
36
        nodeKey1      *btcec.PublicKey
37

38
        // NodeKey2Bytes is the raw public key of the first node.
39
        NodeKey2Bytes [33]byte
40
        nodeKey2      *btcec.PublicKey
41

42
        // BitcoinKey1Bytes is the raw public key of the first node.
43
        BitcoinKey1Bytes [33]byte
44
        bitcoinKey1      *btcec.PublicKey
45

46
        // BitcoinKey2Bytes is the raw public key of the first node.
47
        BitcoinKey2Bytes [33]byte
48
        bitcoinKey2      *btcec.PublicKey
49

50
        // Features is the list of protocol features supported by this channel
51
        // edge.
52
        Features *lnwire.FeatureVector
53

54
        // AuthProof is the authentication proof for this channel. This proof
55
        // contains a set of signatures binding four identities, which attests
56
        // to the legitimacy of the advertised channel.
57
        AuthProof *ChannelAuthProof
58

59
        // ChannelPoint is the funding outpoint of the channel. This can be
60
        // used to uniquely identify the channel within the channel graph.
61
        ChannelPoint wire.OutPoint
62

63
        // Capacity is the total capacity of the channel, this is determined by
64
        // the value output in the outpoint that created this channel.
65
        Capacity btcutil.Amount
66

67
        // FundingScript holds the script of the channel's funding transaction.
68
        //
69
        // NOTE: this is not currently persisted and so will not be present if
70
        // the edge object is loaded from the database.
71
        FundingScript fn.Option[[]byte]
72

73
        // ExtraOpaqueData is the set of data that was appended to this
74
        // message, some of which we may not actually know how to iterate or
75
        // parse. By holding onto this data, we ensure that we're able to
76
        // properly validate the set of signatures that cover these new fields,
77
        // and ensure we're able to make upgrades to the network in a forwards
78
        // compatible manner.
79
        ExtraOpaqueData []byte
80
}
81

82
// AddNodeKeys is a setter-like method that can be used to replace the set of
83
// keys for the target ChannelEdgeInfo.
84
func (c *ChannelEdgeInfo) AddNodeKeys(nodeKey1, nodeKey2, bitcoinKey1,
UNCOV
85
        bitcoinKey2 *btcec.PublicKey) {
×
UNCOV
86

×
UNCOV
87
        c.nodeKey1 = nodeKey1
×
UNCOV
88
        copy(c.NodeKey1Bytes[:], c.nodeKey1.SerializeCompressed())
×
UNCOV
89

×
UNCOV
90
        c.nodeKey2 = nodeKey2
×
UNCOV
91
        copy(c.NodeKey2Bytes[:], nodeKey2.SerializeCompressed())
×
UNCOV
92

×
UNCOV
93
        c.bitcoinKey1 = bitcoinKey1
×
UNCOV
94
        copy(c.BitcoinKey1Bytes[:], c.bitcoinKey1.SerializeCompressed())
×
UNCOV
95

×
UNCOV
96
        c.bitcoinKey2 = bitcoinKey2
×
UNCOV
97
        copy(c.BitcoinKey2Bytes[:], bitcoinKey2.SerializeCompressed())
×
UNCOV
98
}
×
99

100
// NodeKey1 is the identity public key of the "first" node that was involved in
101
// the creation of this channel. A node is considered "first" if the
102
// lexicographical ordering the its serialized public key is "smaller" than
103
// that of the other node involved in channel creation.
104
//
105
// NOTE: By having this method to access an attribute, we ensure we only need
106
// to fully deserialize the pubkey if absolutely necessary.
107
func (c *ChannelEdgeInfo) NodeKey1() (*btcec.PublicKey, error) {
3✔
108
        if c.nodeKey1 != nil {
6✔
109
                return c.nodeKey1, nil
3✔
110
        }
3✔
111

112
        key, err := btcec.ParsePubKey(c.NodeKey1Bytes[:])
3✔
113
        if err != nil {
3✔
114
                return nil, err
×
115
        }
×
116
        c.nodeKey1 = key
3✔
117

3✔
118
        return key, nil
3✔
119
}
120

121
// NodeKey2 is the identity public key of the "second" node that was involved in
122
// the creation of this channel. A node is considered "second" if the
123
// lexicographical ordering the its serialized public key is "larger" than that
124
// of the other node involved in channel creation.
125
//
126
// NOTE: By having this method to access an attribute, we ensure we only need
127
// to fully deserialize the pubkey if absolutely necessary.
128
func (c *ChannelEdgeInfo) NodeKey2() (*btcec.PublicKey, error) {
3✔
129
        if c.nodeKey2 != nil {
6✔
130
                return c.nodeKey2, nil
3✔
131
        }
3✔
132

133
        key, err := btcec.ParsePubKey(c.NodeKey2Bytes[:])
3✔
134
        if err != nil {
3✔
135
                return nil, err
×
136
        }
×
137
        c.nodeKey2 = key
3✔
138

3✔
139
        return key, nil
3✔
140
}
141

142
// BitcoinKey1 is the Bitcoin multi-sig key belonging to the first node, that
143
// was involved in the funding transaction that originally created the channel
144
// that this struct represents.
145
//
146
// NOTE: By having this method to access an attribute, we ensure we only need
147
// to fully deserialize the pubkey if absolutely necessary.
148
func (c *ChannelEdgeInfo) BitcoinKey1() (*btcec.PublicKey, error) {
×
149
        if c.bitcoinKey1 != nil {
×
150
                return c.bitcoinKey1, nil
×
151
        }
×
152

153
        key, err := btcec.ParsePubKey(c.BitcoinKey1Bytes[:])
×
154
        if err != nil {
×
155
                return nil, err
×
156
        }
×
157
        c.bitcoinKey1 = key
×
158

×
159
        return key, nil
×
160
}
161

162
// BitcoinKey2 is the Bitcoin multi-sig key belonging to the second node, that
163
// was involved in the funding transaction that originally created the channel
164
// that this struct represents.
165
//
166
// NOTE: By having this method to access an attribute, we ensure we only need
167
// to fully deserialize the pubkey if absolutely necessary.
168
func (c *ChannelEdgeInfo) BitcoinKey2() (*btcec.PublicKey, error) {
×
169
        if c.bitcoinKey2 != nil {
×
170
                return c.bitcoinKey2, nil
×
171
        }
×
172

173
        key, err := btcec.ParsePubKey(c.BitcoinKey2Bytes[:])
×
174
        if err != nil {
×
175
                return nil, err
×
176
        }
×
177
        c.bitcoinKey2 = key
×
178

×
179
        return key, nil
×
180
}
181

182
// OtherNodeKeyBytes returns the node key bytes of the other end of the channel.
183
func (c *ChannelEdgeInfo) OtherNodeKeyBytes(thisNodeKey []byte) (
184
        [33]byte, error) {
3✔
185

3✔
186
        switch {
3✔
187
        case bytes.Equal(c.NodeKey1Bytes[:], thisNodeKey):
3✔
188
                return c.NodeKey2Bytes, nil
3✔
189
        case bytes.Equal(c.NodeKey2Bytes[:], thisNodeKey):
3✔
190
                return c.NodeKey1Bytes, nil
3✔
191
        default:
×
192
                return [33]byte{}, fmt.Errorf("node not participating in " +
×
193
                        "this channel")
×
194
        }
195
}
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