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

lightningnetwork / lnd / 13980275562

20 Mar 2025 10:06PM UTC coverage: 58.6% (-10.2%) from 68.789%
13980275562

Pull #9623

github

web-flow
Merge b9b960345 into 09b674508
Pull Request #9623: Size msg test msg

0 of 1518 new or added lines in 42 files covered. (0.0%)

26603 existing lines in 443 files now uncovered.

96807 of 165200 relevant lines covered (58.6%)

1.82 hits per line

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

41.33
/lnwire/funding_created.go
1
package lnwire
2

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

7
        "github.com/btcsuite/btcd/wire"
8
        "github.com/lightningnetwork/lnd/tlv"
9
        "pgregory.net/rapid"
10
)
11

12
// FundingCreated is sent from Alice (the initiator) to Bob (the responder),
13
// once Alice receives Bob's contributions as well as his channel constraints.
14
// Once bob receives this message, he'll gain access to an immediately
15
// broadcastable commitment transaction and will reply with a signature for
16
// Alice's version of the commitment transaction.
17
type FundingCreated struct {
18
        // PendingChannelID serves to uniquely identify the future channel
19
        // created by the initiated single funder workflow.
20
        PendingChannelID [32]byte
21

22
        // FundingPoint is the outpoint of the funding transaction created by
23
        // Alice. With this, Bob is able to generate both his version and
24
        // Alice's version of the commitment transaction.
25
        FundingPoint wire.OutPoint
26

27
        // CommitSig is Alice's signature from Bob's version of the commitment
28
        // transaction.
29
        CommitSig Sig
30

31
        // PartialSig is used to transmit a musig2 extended partial signature
32
        // that also carries along the public nonce of the signer.
33
        //
34
        // NOTE: This field is only populated if a musig2 taproot channel is
35
        // being signed for. In this case, the above Sig type MUST be blank.
36
        PartialSig OptPartialSigWithNonceTLV
37

38
        // ExtraData is the set of data that was appended to this message to
39
        // fill out the full maximum transport message size. These fields can
40
        // be used to specify optional data such as custom TLV fields.
41
        ExtraData ExtraOpaqueData
42
}
43

44
// A compile time check to ensure FundingCreated implements the lnwire.Message
45
// interface.
46
var _ Message = (*FundingCreated)(nil)
47

48
// A compile time check to ensure FundingCreated implements the lnwire.SizeableMessage
49
// interface.
50
var _ SizeableMessage = (*FundingCreated)(nil)
51

52
// Encode serializes the target FundingCreated into the passed io.Writer
53
// implementation. Serialization will observe the rules defined by the passed
54
// protocol version.
55
//
56
// This is part of the lnwire.Message interface.
57
func (f *FundingCreated) Encode(w *bytes.Buffer, pver uint32) error {
3✔
58
        recordProducers := make([]tlv.RecordProducer, 0, 1)
3✔
59
        f.PartialSig.WhenSome(func(sig PartialSigWithNonceTLV) {
6✔
60
                recordProducers = append(recordProducers, &sig)
3✔
61
        })
3✔
62
        err := EncodeMessageExtraData(&f.ExtraData, recordProducers...)
3✔
63
        if err != nil {
3✔
64
                return err
×
65
        }
×
66

67
        if err := WriteBytes(w, f.PendingChannelID[:]); err != nil {
3✔
68
                return err
×
69
        }
×
70

71
        if err := WriteOutPoint(w, f.FundingPoint); err != nil {
3✔
72
                return err
×
73
        }
×
74

75
        if err := WriteSig(w, f.CommitSig); err != nil {
3✔
76
                return err
×
77
        }
×
78

79
        return WriteBytes(w, f.ExtraData)
3✔
80
}
81

82
// Decode deserializes the serialized FundingCreated stored in the passed
83
// io.Reader into the target FundingCreated using the deserialization rules
84
// defined by the passed protocol version.
85
//
86
// This is part of the lnwire.Message interface.
87
func (f *FundingCreated) Decode(r io.Reader, pver uint32) error {
3✔
88
        err := ReadElements(
3✔
89
                r, f.PendingChannelID[:], &f.FundingPoint, &f.CommitSig,
3✔
90
        )
3✔
91
        if err != nil {
3✔
UNCOV
92
                return err
×
UNCOV
93
        }
×
94

95
        var tlvRecords ExtraOpaqueData
3✔
96
        if err := ReadElements(r, &tlvRecords); err != nil {
3✔
97
                return err
×
98
        }
×
99

100
        partialSig := f.PartialSig.Zero()
3✔
101
        typeMap, err := tlvRecords.ExtractRecords(&partialSig)
3✔
102
        if err != nil {
3✔
UNCOV
103
                return err
×
UNCOV
104
        }
×
105

106
        // Set the corresponding TLV types if they were included in the stream.
107
        if val, ok := typeMap[f.PartialSig.TlvType()]; ok && val == nil {
6✔
108
                f.PartialSig = tlv.SomeRecordT(partialSig)
3✔
109
        }
3✔
110

111
        if len(tlvRecords) != 0 {
6✔
112
                f.ExtraData = tlvRecords
3✔
113
        }
3✔
114

115
        return nil
3✔
116
}
117

118
// MsgType returns the uint32 code which uniquely identifies this message as a
119
// FundingCreated on the wire.
120
//
121
// This is part of the lnwire.Message interface.
122
func (f *FundingCreated) MsgType() MessageType {
3✔
123
        return MsgFundingCreated
3✔
124
}
3✔
125

126
// SerializedSize returns the serialized size of the message in bytes.
127
//
128
// This is part of the lnwire.SizeableMessage interface.
NEW
129
func (f *FundingCreated) SerializedSize() (uint32, error) {
×
NEW
130
        return MessageSerializedSize(f)
×
NEW
131
}
×
132

133
// A compile time check to ensure FundingCreated implements the TestMessage interface.
134
var _ TestMessage = (*FundingCreated)(nil)
135

136
// RandTestMessage populates the message with random data suitable for testing.
137
// It uses the rapid testing framework to generate random values.
138
//
139
// This is part of the TestMessage interface.
NEW
140
func (f *FundingCreated) RandTestMessage(t *rapid.T) Message {
×
NEW
141
        var pendingChanID [32]byte
×
NEW
142
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
NEW
143
                t, "pendingChanID",
×
NEW
144
        )
×
NEW
145
        copy(pendingChanID[:], pendingChanIDBytes)
×
NEW
146

×
NEW
147
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
×
NEW
148
        var partialSig OptPartialSigWithNonceTLV
×
NEW
149
        var commitSig Sig
×
NEW
150

×
NEW
151
        if includePartialSig {
×
NEW
152
                sigWithNonce := RandPartialSigWithNonce(t)
×
NEW
153
                partialSig = MaybePartialSigWithNonce(sigWithNonce)
×
NEW
154

×
NEW
155
                // When using partial sig, CommitSig should be empty/blank.
×
NEW
156
                commitSig = Sig{}
×
NEW
157
        } else {
×
NEW
158
                commitSig = RandSignature(t)
×
NEW
159
        }
×
160

NEW
161
        return &FundingCreated{
×
NEW
162
                PendingChannelID: pendingChanID,
×
NEW
163
                FundingPoint:     RandOutPoint(t),
×
NEW
164
                CommitSig:        commitSig,
×
NEW
165
                PartialSig:       partialSig,
×
NEW
166
                ExtraData:        RandExtraOpaqueData(t, nil),
×
NEW
167
        }
×
168
}
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