• 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

46.67
/lnwire/funding_signed.go
1
package lnwire
2

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

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

11
// FundingSigned is sent from Bob (the responder) to Alice (the initiator)
12
// after receiving the funding outpoint and her signature for Bob's version of
13
// the commitment transaction.
14
type FundingSigned struct {
15
        // ChannelPoint is the particular active channel that this
16
        // FundingSigned is bound to.
17
        ChanID ChannelID
18

19
        // CommitSig is Bob's signature for Alice's version of the commitment
20
        // transaction.
21
        CommitSig Sig
22

23
        // PartialSig is used to transmit a musig2 extended partial signature
24
        // that also carries along the public nonce of the signer.
25
        //
26
        // NOTE: This field is only populated if a musig2 taproot channel is
27
        // being signed for. In this case, the above Sig type MUST be blank.
28
        PartialSig OptPartialSigWithNonceTLV
29

30
        // ExtraData is the set of data that was appended to this message to
31
        // fill out the full maximum transport message size. These fields can
32
        // be used to specify optional data such as custom TLV fields.
33
        ExtraData ExtraOpaqueData
34
}
35

36
// A compile time check to ensure FundingSigned implements the lnwire.Message
37
// interface.
38
var _ Message = (*FundingSigned)(nil)
39

40
// A compile time check to ensure FundingSigned implements the lnwire.SizeableMessage
41
// interface.
42
var _ SizeableMessage = (*FundingSigned)(nil)
43

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

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

63
        if err := WriteChannelID(w, f.ChanID); err != nil {
3✔
64
                return err
×
65
        }
×
66

67
        if err := WriteSig(w, f.CommitSig); err != nil {
3✔
68
                return err
×
69
        }
×
70

71
        return WriteBytes(w, f.ExtraData)
3✔
72
}
73

74
// Decode deserializes the serialized FundingSigned stored in the passed
75
// io.Reader into the target FundingSigned using the deserialization rules
76
// defined by the passed protocol version.
77
//
78
// This is part of the lnwire.Message interface.
79
func (f *FundingSigned) Decode(r io.Reader, pver uint32) error {
3✔
80
        err := ReadElements(r, &f.ChanID, &f.CommitSig)
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
        partialSig := f.PartialSig.Zero()
3✔
91
        typeMap, err := tlvRecords.ExtractRecords(&partialSig)
3✔
92
        if err != nil {
3✔
UNCOV
93
                return err
×
UNCOV
94
        }
×
95

96
        // Set the corresponding TLV types if they were included in the stream.
97
        if val, ok := typeMap[f.PartialSig.TlvType()]; ok && val == nil {
6✔
98
                f.PartialSig = tlv.SomeRecordT(partialSig)
3✔
99
        }
3✔
100

101
        if len(tlvRecords) != 0 {
6✔
102
                f.ExtraData = tlvRecords
3✔
103
        }
3✔
104

105
        return nil
3✔
106
}
107

108
// MsgType returns the uint32 code which uniquely identifies this message as a
109
// FundingSigned on the wire.
110
//
111
// This is part of the lnwire.Message interface.
112
func (f *FundingSigned) MsgType() MessageType {
3✔
113
        return MsgFundingSigned
3✔
114
}
3✔
115

116
// SerializedSize returns the serialized size of the message in bytes.
117
//
118
// This is part of the lnwire.SizeableMessage interface.
NEW
119
func (f *FundingSigned) SerializedSize() (uint32, error) {
×
NEW
120
        return MessageSerializedSize(f)
×
NEW
121
}
×
122

123
// RandTestMessage populates the message with random data suitable for testing.
124
// It uses the rapid testing framework to generate random values.
125
//
126
// This is part of the TestMessage interface.
NEW
127
func (f *FundingSigned) RandTestMessage(t *rapid.T) Message {
×
NEW
128
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
×
NEW
129

×
NEW
130
        msg := &FundingSigned{
×
NEW
131
                ChanID:    RandChannelID(t),
×
NEW
132
                ExtraData: RandExtraOpaqueData(t, nil),
×
NEW
133
        }
×
NEW
134

×
NEW
135
        if usePartialSig {
×
NEW
136
                sigWithNonce := RandPartialSigWithNonce(t)
×
NEW
137
                msg.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
×
NEW
138

×
NEW
139
                msg.CommitSig = Sig{}
×
NEW
140
        } else {
×
NEW
141
                msg.CommitSig = RandSignature(t)
×
NEW
142
        }
×
143

NEW
144
        return msg
×
145
}
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