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

lightningnetwork / lnd / 11170835610

03 Oct 2024 10:41PM UTC coverage: 49.188% (-9.6%) from 58.738%
11170835610

push

github

web-flow
Merge pull request #9154 from ziggie1984/master

multi: bump btcd version.

3 of 6 new or added lines in 6 files covered. (50.0%)

26110 existing lines in 428 files now uncovered.

97359 of 197934 relevant lines covered (49.19%)

1.04 hits per line

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

75.0
/lnwire/channel_ready.go
1
package lnwire
2

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

7
        "github.com/btcsuite/btcd/btcec/v2"
8
        "github.com/lightningnetwork/lnd/tlv"
9
)
10

11
// ChannelReady is the message that both parties to a new channel creation
12
// send once they have observed the funding transaction being confirmed on the
13
// blockchain. ChannelReady contains the signatures necessary for the channel
14
// participants to advertise the existence of the channel to the rest of the
15
// network.
16
type ChannelReady struct {
17
        // ChanID is the outpoint of the channel's funding transaction. This
18
        // can be used to query for the channel in the database.
19
        ChanID ChannelID
20

21
        // NextPerCommitmentPoint is the secret that can be used to revoke the
22
        // next commitment transaction for the channel.
23
        NextPerCommitmentPoint *btcec.PublicKey
24

25
        // AliasScid is an alias ShortChannelID used to refer to the underlying
26
        // channel. It can be used instead of the confirmed on-chain
27
        // ShortChannelID for forwarding.
28
        AliasScid *ShortChannelID
29

30
        // NextLocalNonce is an optional field that stores a local musig2 nonce.
31
        // This will only be populated if the simple taproot channels type was
32
        // negotiated. This is the local nonce that will be used by the sender
33
        // to accept a new commitment state transition.
34
        NextLocalNonce OptMusig2NonceTLV
35

36
        // AnnouncementNodeNonce is an optional field that stores a public
37
        // nonce that will be used along with the node's ID key during signing
38
        // of the ChannelAnnouncement2 message.
39
        AnnouncementNodeNonce tlv.OptionalRecordT[tlv.TlvType0, Musig2Nonce]
40

41
        // AnnouncementBitcoinNonce is an optional field that stores a public
42
        // nonce that will be used along with the node's bitcoin key during
43
        // signing of the ChannelAnnouncement2 message.
44
        AnnouncementBitcoinNonce tlv.OptionalRecordT[tlv.TlvType2, Musig2Nonce]
45

46
        // ExtraData is the set of data that was appended to this message to
47
        // fill out the full maximum transport message size. These fields can
48
        // be used to specify optional data such as custom TLV fields.
49
        ExtraData ExtraOpaqueData
50
}
51

52
// NewChannelReady creates a new ChannelReady message, populating it with the
53
// necessary IDs and revocation secret.
54
func NewChannelReady(cid ChannelID, npcp *btcec.PublicKey) *ChannelReady {
2✔
55
        return &ChannelReady{
2✔
56
                ChanID:                 cid,
2✔
57
                NextPerCommitmentPoint: npcp,
2✔
58
                ExtraData:              nil,
2✔
59
        }
2✔
60
}
2✔
61

62
// A compile time check to ensure ChannelReady implements the lnwire.Message
63
// interface.
64
var _ Message = (*ChannelReady)(nil)
65

66
// Decode deserializes the serialized ChannelReady message stored in the
67
// passed io.Reader into the target ChannelReady using the deserialization
68
// rules defined by the passed protocol version.
69
//
70
// This is part of the lnwire.Message interface.
71
func (c *ChannelReady) Decode(r io.Reader, _ uint32) error {
2✔
72
        // Read all the mandatory fields in the message.
2✔
73
        err := ReadElements(r,
2✔
74
                &c.ChanID,
2✔
75
                &c.NextPerCommitmentPoint,
2✔
76
        )
2✔
77
        if err != nil {
2✔
UNCOV
78
                return err
×
UNCOV
79
        }
×
80

81
        var tlvRecords ExtraOpaqueData
2✔
82
        if err := ReadElements(r, &tlvRecords); err != nil {
2✔
83
                return err
×
84
        }
×
85

86
        // Next we'll parse out the set of known records. For now, this is just
87
        // the AliasScidRecordType.
88
        var (
2✔
89
                aliasScid  ShortChannelID
2✔
90
                localNonce = c.NextLocalNonce.Zero()
2✔
91
                nodeNonce  = tlv.ZeroRecordT[tlv.TlvType0, Musig2Nonce]()
2✔
92
                btcNonce   = tlv.ZeroRecordT[tlv.TlvType2, Musig2Nonce]()
2✔
93
        )
2✔
94
        typeMap, err := tlvRecords.ExtractRecords(
2✔
95
                &btcNonce, &aliasScid, &nodeNonce, &localNonce,
2✔
96
        )
2✔
97
        if err != nil {
2✔
UNCOV
98
                return err
×
UNCOV
99
        }
×
100

101
        // We'll only set AliasScid if the corresponding TLV type was included
102
        // in the stream.
103
        if val, ok := typeMap[AliasScidRecordType]; ok && val == nil {
4✔
104
                c.AliasScid = &aliasScid
2✔
105
        }
2✔
106
        if val, ok := typeMap[c.NextLocalNonce.TlvType()]; ok && val == nil {
4✔
107
                c.NextLocalNonce = tlv.SomeRecordT(localNonce)
2✔
108
        }
2✔
109
        val, ok := typeMap[c.AnnouncementBitcoinNonce.TlvType()]
2✔
110
        if ok && val == nil {
2✔
UNCOV
111
                c.AnnouncementBitcoinNonce = tlv.SomeRecordT(btcNonce)
×
UNCOV
112
        }
×
113
        val, ok = typeMap[c.AnnouncementNodeNonce.TlvType()]
2✔
114
        if ok && val == nil {
2✔
UNCOV
115
                c.AnnouncementNodeNonce = tlv.SomeRecordT(nodeNonce)
×
UNCOV
116
        }
×
117

118
        if len(tlvRecords) != 0 {
4✔
119
                c.ExtraData = tlvRecords
2✔
120
        }
2✔
121

122
        return nil
2✔
123
}
124

125
// Encode serializes the target ChannelReady message into the passed io.Writer
126
// implementation. Serialization will observe the rules defined by the passed
127
// protocol version.
128
//
129
// This is part of the lnwire.Message interface.
130
func (c *ChannelReady) Encode(w *bytes.Buffer, _ uint32) error {
2✔
131
        if err := WriteChannelID(w, c.ChanID); err != nil {
2✔
132
                return err
×
133
        }
×
134

135
        if err := WritePublicKey(w, c.NextPerCommitmentPoint); err != nil {
2✔
136
                return err
×
137
        }
×
138

139
        // We'll only encode the AliasScid in a TLV segment if it exists.
140
        recordProducers := make([]tlv.RecordProducer, 0, 4)
2✔
141
        if c.AliasScid != nil {
4✔
142
                recordProducers = append(recordProducers, c.AliasScid)
2✔
143
        }
2✔
144
        c.NextLocalNonce.WhenSome(func(localNonce Musig2NonceTLV) {
4✔
145
                recordProducers = append(recordProducers, &localNonce)
2✔
146
        })
2✔
147
        c.AnnouncementBitcoinNonce.WhenSome(
2✔
148
                func(nonce tlv.RecordT[tlv.TlvType2, Musig2Nonce]) {
2✔
UNCOV
149
                        recordProducers = append(recordProducers, &nonce)
×
UNCOV
150
                },
×
151
        )
152
        c.AnnouncementNodeNonce.WhenSome(
2✔
153
                func(nonce tlv.RecordT[tlv.TlvType0, Musig2Nonce]) {
2✔
UNCOV
154
                        recordProducers = append(recordProducers, &nonce)
×
UNCOV
155
                },
×
156
        )
157

158
        err := EncodeMessageExtraData(&c.ExtraData, recordProducers...)
2✔
159
        if err != nil {
2✔
160
                return err
×
161
        }
×
162

163
        return WriteBytes(w, c.ExtraData)
2✔
164
}
165

166
// MsgType returns the uint32 code which uniquely identifies this message as a
167
// ChannelReady message on the wire.
168
//
169
// This is part of the lnwire.Message interface.
170
func (c *ChannelReady) MsgType() MessageType {
2✔
171
        return MsgChannelReady
2✔
172
}
2✔
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