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

lightningnetwork / lnd / 9915780197

13 Jul 2024 12:30AM UTC coverage: 49.268% (-9.1%) from 58.413%
9915780197

push

github

web-flow
Merge pull request #8653 from ProofOfKeags/fn-prim

DynComms [0/n]: `fn` package additions

92837 of 188433 relevant lines covered (49.27%)

1.55 hits per line

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

36.76
/channeldb/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
)
12

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

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

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

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

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

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

48
        // Features is an opaque byte slice that encodes the set of channel
49
        // specific features that this channel edge supports.
50
        Features []byte
51

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

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

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

65
        // ExtraOpaqueData is the set of data that was appended to this
66
        // message, some of which we may not actually know how to iterate or
67
        // parse. By holding onto this data, we ensure that we're able to
68
        // properly validate the set of signatures that cover these new fields,
69
        // and ensure we're able to make upgrades to the network in a forwards
70
        // compatible manner.
71
        ExtraOpaqueData []byte
72
}
73

74
// AddNodeKeys is a setter-like method that can be used to replace the set of
75
// keys for the target ChannelEdgeInfo.
76
func (c *ChannelEdgeInfo) AddNodeKeys(nodeKey1, nodeKey2, bitcoinKey1,
77
        bitcoinKey2 *btcec.PublicKey) {
×
78

×
79
        c.nodeKey1 = nodeKey1
×
80
        copy(c.NodeKey1Bytes[:], c.nodeKey1.SerializeCompressed())
×
81

×
82
        c.nodeKey2 = nodeKey2
×
83
        copy(c.NodeKey2Bytes[:], nodeKey2.SerializeCompressed())
×
84

×
85
        c.bitcoinKey1 = bitcoinKey1
×
86
        copy(c.BitcoinKey1Bytes[:], c.bitcoinKey1.SerializeCompressed())
×
87

×
88
        c.bitcoinKey2 = bitcoinKey2
×
89
        copy(c.BitcoinKey2Bytes[:], bitcoinKey2.SerializeCompressed())
×
90
}
×
91

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

104
        key, err := btcec.ParsePubKey(c.NodeKey1Bytes[:])
3✔
105
        if err != nil {
3✔
106
                return nil, err
×
107
        }
×
108
        c.nodeKey1 = key
3✔
109

3✔
110
        return key, nil
3✔
111
}
112

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

125
        key, err := btcec.ParsePubKey(c.NodeKey2Bytes[:])
3✔
126
        if err != nil {
3✔
127
                return nil, err
×
128
        }
×
129
        c.nodeKey2 = key
3✔
130

3✔
131
        return key, nil
3✔
132
}
133

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

145
        key, err := btcec.ParsePubKey(c.BitcoinKey1Bytes[:])
×
146
        if err != nil {
×
147
                return nil, err
×
148
        }
×
149
        c.bitcoinKey1 = key
×
150

×
151
        return key, nil
×
152
}
153

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

165
        key, err := btcec.ParsePubKey(c.BitcoinKey2Bytes[:])
×
166
        if err != nil {
×
167
                return nil, err
×
168
        }
×
169
        c.bitcoinKey2 = key
×
170

×
171
        return key, nil
×
172
}
173

174
// OtherNodeKeyBytes returns the node key bytes of the other end of the channel.
175
func (c *ChannelEdgeInfo) OtherNodeKeyBytes(thisNodeKey []byte) (
176
        [33]byte, error) {
3✔
177

3✔
178
        switch {
3✔
179
        case bytes.Equal(c.NodeKey1Bytes[:], thisNodeKey):
3✔
180
                return c.NodeKey2Bytes, nil
3✔
181
        case bytes.Equal(c.NodeKey2Bytes[:], thisNodeKey):
3✔
182
                return c.NodeKey1Bytes, nil
3✔
183
        default:
×
184
                return [33]byte{}, fmt.Errorf("node not participating in " +
×
185
                        "this channel")
×
186
        }
187
}
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