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

lightningnetwork / lnd / 13999301927

21 Mar 2025 07:18PM UTC coverage: 68.989% (+9.9%) from 59.126%
13999301927

push

github

web-flow
Merge pull request #9623 from Roasbeef/size-msg-test-msg

Size msg test msg

1461 of 1572 new or added lines in 43 files covered. (92.94%)

28 existing lines in 6 files now uncovered.

132898 of 192637 relevant lines covered (68.99%)

22200.59 hits per line

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

86.75
/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 {
202✔
55
        return &ChannelReady{
202✔
56
                ChanID:                 cid,
202✔
57
                NextPerCommitmentPoint: npcp,
202✔
58
                ExtraData:              nil,
202✔
59
        }
202✔
60
}
202✔
61

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

66
// A compile time check to ensure ChannelReady implements the
67
// lnwire.SizeableMessage interface.
68
var _ SizeableMessage = (*ChannelReady)(nil)
69

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

85
        var tlvRecords ExtraOpaqueData
188✔
86
        if err := ReadElements(r, &tlvRecords); err != nil {
188✔
87
                return err
×
88
        }
×
89

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

105
        // We'll only set AliasScid if the corresponding TLV type was included
106
        // in the stream.
107
        if val, ok := typeMap[AliasScidRecordType]; ok && val == nil {
198✔
108
                c.AliasScid = &aliasScid
55✔
109
        }
55✔
110
        if val, ok := typeMap[c.NextLocalNonce.TlvType()]; ok && val == nil {
203✔
111
                c.NextLocalNonce = tlv.SomeRecordT(localNonce)
60✔
112
        }
60✔
113
        val, ok := typeMap[c.AnnouncementBitcoinNonce.TlvType()]
143✔
114
        if ok && val == nil {
193✔
115
                c.AnnouncementBitcoinNonce = tlv.SomeRecordT(btcNonce)
50✔
116
        }
50✔
117
        val, ok = typeMap[c.AnnouncementNodeNonce.TlvType()]
143✔
118
        if ok && val == nil {
205✔
119
                c.AnnouncementNodeNonce = tlv.SomeRecordT(nodeNonce)
62✔
120
        }
62✔
121

122
        if len(tlvRecords) != 0 {
270✔
123
                c.ExtraData = tlvRecords
127✔
124
        }
127✔
125

126
        return nil
143✔
127
}
128

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

139
        if err := WritePublicKey(w, c.NextPerCommitmentPoint); err != nil {
123✔
140
                return err
×
141
        }
×
142

143
        // We'll only encode the AliasScid in a TLV segment if it exists.
144
        recordProducers := make([]tlv.RecordProducer, 0, 4)
123✔
145
        if c.AliasScid != nil {
172✔
146
                recordProducers = append(recordProducers, c.AliasScid)
49✔
147
        }
49✔
148
        c.NextLocalNonce.WhenSome(func(localNonce Musig2NonceTLV) {
179✔
149
                recordProducers = append(recordProducers, &localNonce)
56✔
150
        })
56✔
151
        c.AnnouncementBitcoinNonce.WhenSome(
123✔
152
                func(nonce tlv.RecordT[tlv.TlvType2, Musig2Nonce]) {
172✔
153
                        recordProducers = append(recordProducers, &nonce)
49✔
154
                },
49✔
155
        )
156
        c.AnnouncementNodeNonce.WhenSome(
123✔
157
                func(nonce tlv.RecordT[tlv.TlvType0, Musig2Nonce]) {
181✔
158
                        recordProducers = append(recordProducers, &nonce)
58✔
159
                },
58✔
160
        )
161

162
        err := EncodeMessageExtraData(&c.ExtraData, recordProducers...)
123✔
163
        if err != nil {
123✔
164
                return err
×
165
        }
×
166

167
        return WriteBytes(w, c.ExtraData)
123✔
168
}
169

170
// MsgType returns the uint32 code which uniquely identifies this message as a
171
// ChannelReady message on the wire.
172
//
173
// This is part of the lnwire.Message interface.
174
func (c *ChannelReady) MsgType() MessageType {
149✔
175
        return MsgChannelReady
149✔
176
}
149✔
177

178
// SerializedSize returns the serialized size of the message in bytes.
179
//
180
// This is part of the lnwire.SizeableMessage interface.
NEW
181
func (c *ChannelReady) SerializedSize() (uint32, error) {
×
NEW
182
        return MessageSerializedSize(c)
×
NEW
183
}
×
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