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

lightningnetwork / lnd / 12199391122

06 Dec 2024 01:10PM UTC coverage: 49.807% (-9.1%) from 58.933%
12199391122

push

github

web-flow
Merge pull request #9337 from Guayaba221/patch-1

chore: fix typo in ruby.md

100137 of 201051 relevant lines covered (49.81%)

2.07 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 {
4✔
55
        return &ChannelReady{
4✔
56
                ChanID:                 cid,
4✔
57
                NextPerCommitmentPoint: npcp,
4✔
58
                ExtraData:              nil,
4✔
59
        }
4✔
60
}
4✔
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 {
4✔
72
        // Read all the mandatory fields in the message.
4✔
73
        err := ReadElements(r,
4✔
74
                &c.ChanID,
4✔
75
                &c.NextPerCommitmentPoint,
4✔
76
        )
4✔
77
        if err != nil {
4✔
78
                return err
×
79
        }
×
80

81
        var tlvRecords ExtraOpaqueData
4✔
82
        if err := ReadElements(r, &tlvRecords); err != nil {
4✔
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 (
4✔
89
                aliasScid  ShortChannelID
4✔
90
                localNonce = c.NextLocalNonce.Zero()
4✔
91
                nodeNonce  = tlv.ZeroRecordT[tlv.TlvType0, Musig2Nonce]()
4✔
92
                btcNonce   = tlv.ZeroRecordT[tlv.TlvType2, Musig2Nonce]()
4✔
93
        )
4✔
94
        typeMap, err := tlvRecords.ExtractRecords(
4✔
95
                &btcNonce, &aliasScid, &nodeNonce, &localNonce,
4✔
96
        )
4✔
97
        if err != nil {
4✔
98
                return err
×
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 {
8✔
104
                c.AliasScid = &aliasScid
4✔
105
        }
4✔
106
        if val, ok := typeMap[c.NextLocalNonce.TlvType()]; ok && val == nil {
8✔
107
                c.NextLocalNonce = tlv.SomeRecordT(localNonce)
4✔
108
        }
4✔
109
        val, ok := typeMap[c.AnnouncementBitcoinNonce.TlvType()]
4✔
110
        if ok && val == nil {
4✔
111
                c.AnnouncementBitcoinNonce = tlv.SomeRecordT(btcNonce)
×
112
        }
×
113
        val, ok = typeMap[c.AnnouncementNodeNonce.TlvType()]
4✔
114
        if ok && val == nil {
4✔
115
                c.AnnouncementNodeNonce = tlv.SomeRecordT(nodeNonce)
×
116
        }
×
117

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

122
        return nil
4✔
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 {
4✔
131
        if err := WriteChannelID(w, c.ChanID); err != nil {
4✔
132
                return err
×
133
        }
×
134

135
        if err := WritePublicKey(w, c.NextPerCommitmentPoint); err != nil {
4✔
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)
4✔
141
        if c.AliasScid != nil {
8✔
142
                recordProducers = append(recordProducers, c.AliasScid)
4✔
143
        }
4✔
144
        c.NextLocalNonce.WhenSome(func(localNonce Musig2NonceTLV) {
8✔
145
                recordProducers = append(recordProducers, &localNonce)
4✔
146
        })
4✔
147
        c.AnnouncementBitcoinNonce.WhenSome(
4✔
148
                func(nonce tlv.RecordT[tlv.TlvType2, Musig2Nonce]) {
4✔
149
                        recordProducers = append(recordProducers, &nonce)
×
150
                },
×
151
        )
152
        c.AnnouncementNodeNonce.WhenSome(
4✔
153
                func(nonce tlv.RecordT[tlv.TlvType0, Musig2Nonce]) {
4✔
154
                        recordProducers = append(recordProducers, &nonce)
×
155
                },
×
156
        )
157

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

163
        return WriteBytes(w, c.ExtraData)
4✔
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 {
4✔
171
        return MsgChannelReady
4✔
172
}
4✔
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