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

lightningnetwork / lnd / 20088220763

10 Dec 2025 05:19AM UTC coverage: 65.185% (+0.009%) from 65.176%
20088220763

Pull #10436

github

web-flow
Merge a7b61f3ec into 456d7dcf0
Pull Request #10436: multi: add `CombinedNonce` functionality to Musig2 Signers

66 of 199 new or added lines in 8 files covered. (33.17%)

29408 existing lines in 461 files now uncovered.

137799 of 211398 relevant lines covered (65.18%)

20752.71 hits per line

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

84.52
/lnwire/dyn_commit.go
1
package lnwire
2

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

7
        "github.com/btcsuite/btcd/btcutil"
8
        "github.com/lightningnetwork/lnd/tlv"
9
)
10

11
// DynCommit is a composite message that is used to irrefutably execute a
12
// dynamic commitment update.
13
type DynCommit struct {
14
        // DynPropose is an embedded version of the original DynPropose message
15
        // that initiated this negotiation.
16
        DynPropose
17

18
        // DynAck is an embedded version of the original DynAck message that
19
        // countersigned this negotiation.
20
        DynAck
21

22
        // ExtraData is the set of data that was appended to this message to
23
        // fill out the full maximum transport message size. These fields can
24
        // be used to specify optional data such as custom TLV fields.
25
        ExtraData ExtraOpaqueData
26
}
27

28
// A compile time check to ensure DynCommit implements the lnwire.Message
29
// interface.
30
var _ Message = (*DynCommit)(nil)
31

32
// A compile time check to ensure DynCommit implements the
33
// lnwire.SizeableMessage interface.
34
var _ SizeableMessage = (*DynCommit)(nil)
35

36
// Encode serializes the target DynAck into the passed io.Writer. Serialization
37
// will observe the rules defined by the passed protocol version.
38
//
39
// This is a part of the lnwire.Message interface.
UNCOV
40
func (dc *DynCommit) Encode(w *bytes.Buffer, _ uint32) error {
133✔
UNCOV
41
        if err := WriteChannelID(w, dc.DynPropose.ChanID); err != nil {
133✔
42
                return err
×
43
        }
×
44

UNCOV
45
        if err := WriteSig(w, dc.Sig); err != nil {
133✔
46
                return err
×
47
        }
×
48

49
        // Create extra data records.
UNCOV
50
        producers, err := dc.ExtraData.RecordProducers()
133✔
UNCOV
51
        if err != nil {
133✔
52
                return err
×
53
        }
×
54

55
        // Append the known records.
UNCOV
56
        producers = append(producers, dynProposeRecords(&dc.DynPropose)...)
133✔
UNCOV
57
        dc.LocalNonce.WhenSome(
133✔
UNCOV
58
                func(rec tlv.RecordT[tlv.TlvType14, Musig2Nonce]) {
186✔
UNCOV
59
                        producers = append(producers, &rec)
53✔
UNCOV
60
                },
53✔
61
        )
62

63
        // Encode all known records.
UNCOV
64
        var tlvData ExtraOpaqueData
133✔
UNCOV
65
        err = tlvData.PackRecords(producers...)
133✔
UNCOV
66
        if err != nil {
133✔
67
                return err
×
68
        }
×
69

UNCOV
70
        return WriteBytes(w, tlvData)
133✔
71
}
72

73
// Decode deserializes the serialized DynCommit stored in the passed io.Reader
74
// into the target DynAck using the deserialization rules defined by the passed
75
// protocol version.
76
//
77
// This is a part of the lnwire.Message interface.
UNCOV
78
func (dc *DynCommit) Decode(r io.Reader, _ uint32) error {
187✔
UNCOV
79
        // Parse out main message.
187✔
UNCOV
80
        if err := ReadElements(r, &dc.DynPropose.ChanID, &dc.Sig); err != nil {
190✔
UNCOV
81
                return err
3✔
UNCOV
82
        }
3✔
UNCOV
83
        dc.DynAck.ChanID = dc.DynPropose.ChanID
184✔
UNCOV
84

184✔
UNCOV
85
        // Parse out TLV records.
184✔
UNCOV
86
        var tlvRecords ExtraOpaqueData
184✔
UNCOV
87
        if err := ReadElement(r, &tlvRecords); err != nil {
184✔
88
                return err
×
89
        }
×
90

91
        // Prepare receiving buffers to be filled by TLV extraction.
UNCOV
92
        var dustLimit tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]]
184✔
UNCOV
93
        var maxValue tlv.RecordT[tlv.TlvType2, MilliSatoshi]
184✔
UNCOV
94
        var htlcMin tlv.RecordT[tlv.TlvType4, MilliSatoshi]
184✔
UNCOV
95
        var reserve tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]]
184✔
UNCOV
96
        csvDelay := dc.CsvDelay.Zero()
184✔
UNCOV
97
        maxHtlcs := dc.MaxAcceptedHTLCs.Zero()
184✔
UNCOV
98
        chanType := dc.ChannelType.Zero()
184✔
UNCOV
99
        nonce := dc.LocalNonce.Zero()
184✔
UNCOV
100

184✔
UNCOV
101
        // Parse all known records and extra data.
184✔
UNCOV
102
        knownRecords, extraData, err := ParseAndExtractExtraData(
184✔
UNCOV
103
                tlvRecords, &dustLimit, &maxValue, &htlcMin, &reserve,
184✔
UNCOV
104
                &csvDelay, &maxHtlcs, &chanType, &nonce,
184✔
UNCOV
105
        )
184✔
UNCOV
106
        if err != nil {
203✔
UNCOV
107
                return err
19✔
UNCOV
108
        }
19✔
109

110
        // Check the results of the TLV Stream decoding and appropriately set
111
        // message fields.
UNCOV
112
        if _, ok := knownRecords[dc.DustLimit.TlvType()]; ok {
222✔
UNCOV
113
                dc.DustLimit = tlv.SomeRecordT(dustLimit)
57✔
UNCOV
114
        }
57✔
UNCOV
115
        if _, ok := knownRecords[dc.MaxValueInFlight.TlvType()]; ok {
230✔
UNCOV
116
                dc.MaxValueInFlight = tlv.SomeRecordT(maxValue)
65✔
UNCOV
117
        }
65✔
UNCOV
118
        if _, ok := knownRecords[dc.HtlcMinimum.TlvType()]; ok {
174✔
UNCOV
119
                dc.HtlcMinimum = tlv.SomeRecordT(htlcMin)
9✔
UNCOV
120
        }
9✔
UNCOV
121
        if _, ok := knownRecords[dc.ChannelReserve.TlvType()]; ok {
226✔
UNCOV
122
                dc.ChannelReserve = tlv.SomeRecordT(reserve)
61✔
UNCOV
123
        }
61✔
UNCOV
124
        if _, ok := knownRecords[dc.CsvDelay.TlvType()]; ok {
213✔
UNCOV
125
                dc.CsvDelay = tlv.SomeRecordT(csvDelay)
48✔
UNCOV
126
        }
48✔
UNCOV
127
        if _, ok := knownRecords[dc.MaxAcceptedHTLCs.TlvType()]; ok {
210✔
UNCOV
128
                dc.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs)
45✔
UNCOV
129
        }
45✔
UNCOV
130
        if _, ok := knownRecords[dc.ChannelType.TlvType()]; ok {
226✔
UNCOV
131
                dc.ChannelType = tlv.SomeRecordT(chanType)
61✔
UNCOV
132
        }
61✔
UNCOV
133
        if _, ok := knownRecords[dc.LocalNonce.TlvType()]; ok {
218✔
UNCOV
134
                dc.LocalNonce = tlv.SomeRecordT(nonce)
53✔
UNCOV
135
        }
53✔
136

UNCOV
137
        dc.ExtraData = extraData
165✔
UNCOV
138

165✔
UNCOV
139
        return nil
165✔
140
}
141

142
// MsgType returns the MessageType code which uniquely identifies this message
143
// as a DynCommit on the wire.
144
//
145
// This is part of the lnwire.Message interface.
UNCOV
146
func (dc *DynCommit) MsgType() MessageType {
132✔
UNCOV
147
        return MsgDynCommit
132✔
UNCOV
148
}
132✔
149

150
// SerializedSize returns the serialized size of the message in bytes.
151
//
152
// This is part of the lnwire.SizeableMessage interface.
153
func (dc *DynCommit) SerializedSize() (uint32, error) {
×
154
        return MessageSerializedSize(dc)
×
155
}
×
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