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

lightningnetwork / lnd / 15561477203

10 Jun 2025 01:54PM UTC coverage: 58.351% (-10.1%) from 68.487%
15561477203

Pull #9356

github

web-flow
Merge 6440b25db into c6d6d4c0b
Pull Request #9356: lnrpc: add incoming/outgoing channel ids filter to forwarding history request

33 of 36 new or added lines in 2 files covered. (91.67%)

28366 existing lines in 455 files now uncovered.

97715 of 167461 relevant lines covered (58.35%)

1.81 hits per line

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

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

85
        var tlvRecords ExtraOpaqueData
3✔
86
        if err := ReadElements(r, &tlvRecords); err != nil {
3✔
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 (
3✔
93
                aliasScid  ShortChannelID
3✔
94
                localNonce = c.NextLocalNonce.Zero()
3✔
95
                nodeNonce  = tlv.ZeroRecordT[tlv.TlvType0, Musig2Nonce]()
3✔
96
                btcNonce   = tlv.ZeroRecordT[tlv.TlvType2, Musig2Nonce]()
3✔
97
        )
3✔
98
        typeMap, err := tlvRecords.ExtractRecords(
3✔
99
                &btcNonce, &aliasScid, &nodeNonce, &localNonce,
3✔
100
        )
3✔
101
        if err != nil {
3✔
UNCOV
102
                return err
×
UNCOV
103
        }
×
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 {
6✔
108
                c.AliasScid = &aliasScid
3✔
109
        }
3✔
110
        if val, ok := typeMap[c.NextLocalNonce.TlvType()]; ok && val == nil {
6✔
111
                c.NextLocalNonce = tlv.SomeRecordT(localNonce)
3✔
112
        }
3✔
113
        val, ok := typeMap[c.AnnouncementBitcoinNonce.TlvType()]
3✔
114
        if ok && val == nil {
3✔
UNCOV
115
                c.AnnouncementBitcoinNonce = tlv.SomeRecordT(btcNonce)
×
UNCOV
116
        }
×
117
        val, ok = typeMap[c.AnnouncementNodeNonce.TlvType()]
3✔
118
        if ok && val == nil {
3✔
UNCOV
119
                c.AnnouncementNodeNonce = tlv.SomeRecordT(nodeNonce)
×
UNCOV
120
        }
×
121

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

126
        return nil
3✔
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 {
3✔
135
        if err := WriteChannelID(w, c.ChanID); err != nil {
3✔
136
                return err
×
137
        }
×
138

139
        if err := WritePublicKey(w, c.NextPerCommitmentPoint); err != nil {
3✔
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)
3✔
145
        if c.AliasScid != nil {
6✔
146
                recordProducers = append(recordProducers, c.AliasScid)
3✔
147
        }
3✔
148
        c.NextLocalNonce.WhenSome(func(localNonce Musig2NonceTLV) {
6✔
149
                recordProducers = append(recordProducers, &localNonce)
3✔
150
        })
3✔
151
        c.AnnouncementBitcoinNonce.WhenSome(
3✔
152
                func(nonce tlv.RecordT[tlv.TlvType2, Musig2Nonce]) {
3✔
UNCOV
153
                        recordProducers = append(recordProducers, &nonce)
×
UNCOV
154
                },
×
155
        )
156
        c.AnnouncementNodeNonce.WhenSome(
3✔
157
                func(nonce tlv.RecordT[tlv.TlvType0, Musig2Nonce]) {
3✔
UNCOV
158
                        recordProducers = append(recordProducers, &nonce)
×
UNCOV
159
                },
×
160
        )
161

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

167
        return WriteBytes(w, c.ExtraData)
3✔
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 {
3✔
175
        return MsgChannelReady
3✔
176
}
3✔
177

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