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

lightningnetwork / lnd / 16025893053

02 Jul 2025 01:03PM UTC coverage: 57.783% (-0.02%) from 57.803%
16025893053

Pull #10027

github

web-flow
Merge c74b17c9e into 1d2e5472b
Pull Request #10027: Fix `ExtraData` field and use `BigSize` encodine

0 of 155 new or added lines in 5 files covered. (0.0%)

49 existing lines in 10 files now uncovered.

98479 of 170428 relevant lines covered (57.78%)

1.79 hits per line

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

0.0
/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.
40
func (dc *DynCommit) Encode(w *bytes.Buffer, _ uint32) error {
×
41
        if err := WriteChannelID(w, dc.DynPropose.ChanID); err != nil {
×
42
                return err
×
43
        }
×
44

45
        if err := WriteSig(w, dc.Sig); err != nil {
×
46
                return err
×
47
        }
×
NEW
48
        producers := dynProposeRecords(&dc.DynPropose)
×
NEW
49
        dc.LocalNonce.WhenSome(
×
NEW
50
                func(rec tlv.RecordT[tlv.TlvType14, Musig2Nonce]) {
×
NEW
51
                        producers = append(producers, &rec)
×
NEW
52
                })
×
53

54
        // Encode all known records.
NEW
55
        var tlvData ExtraOpaqueData
×
NEW
56
        err := tlvData.PackRecords(producers...)
×
57
        if err != nil {
×
58
                return err
×
59
        }
×
60

61
        // Write the known records.
NEW
62
        if err := WriteBytes(w, tlvData); err != nil {
×
NEW
63
                return err
×
NEW
64
        }
×
65

66
        // Encode ExtraData.
UNCOV
67
        return WriteBytes(w, dc.ExtraData)
×
68
}
69

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

×
82
        // Parse out TLV records.
×
83
        var tlvRecords ExtraOpaqueData
×
84
        if err := ReadElement(r, &tlvRecords); err != nil {
×
85
                return err
×
86
        }
×
87

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

×
NEW
98
        // Parse all known records and extra data.
×
NEW
99
        knownRecords, extraData, err := ParseAndExtractExtraData(
×
NEW
100
                tlvRecords, &dustLimit, &maxValue, &htlcMin, &reserve,
×
NEW
101
                &csvDelay, &maxHtlcs, &chanType, &nonce,
×
102
        )
×
103
        if err != nil {
×
104
                return err
×
105
        }
×
106

107
        // Check the results of the TLV Stream decoding and appropriately set
108
        // message fields.
NEW
109
        if _, ok := knownRecords[dc.DustLimit.TlvType()]; ok {
×
NEW
110
                var rec tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]]
×
NEW
111
                rec.Val = tlv.NewBigSizeT(btcutil.Amount(dustLimit.Val.Int()))
×
112
                dc.DustLimit = tlv.SomeRecordT(rec)
×
113
        }
×
NEW
114
        if _, ok := knownRecords[dc.MaxValueInFlight.TlvType()]; ok {
×
115
                var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi]
×
116
                rec.Val = MilliSatoshi(maxValue.Val)
×
117
                dc.MaxValueInFlight = tlv.SomeRecordT(rec)
×
118
        }
×
NEW
119
        if _, ok := knownRecords[dc.HtlcMinimum.TlvType()]; ok {
×
120
                var rec tlv.RecordT[tlv.TlvType4, MilliSatoshi]
×
121
                rec.Val = MilliSatoshi(htlcMin.Val)
×
122
                dc.HtlcMinimum = tlv.SomeRecordT(rec)
×
123
        }
×
NEW
124
        if _, ok := knownRecords[dc.ChannelReserve.TlvType()]; ok {
×
NEW
125
                var rec tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]]
×
NEW
126
                rec.Val = tlv.NewBigSizeT(btcutil.Amount(reserve.Val.Int()))
×
127
                dc.ChannelReserve = tlv.SomeRecordT(rec)
×
128
        }
×
NEW
129
        if _, ok := knownRecords[dc.CsvDelay.TlvType()]; ok {
×
130
                dc.CsvDelay = tlv.SomeRecordT(csvDelay)
×
131
        }
×
NEW
132
        if _, ok := knownRecords[dc.MaxAcceptedHTLCs.TlvType()]; ok {
×
133
                dc.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs)
×
134
        }
×
NEW
135
        if _, ok := knownRecords[dc.ChannelType.TlvType()]; ok {
×
136
                dc.ChannelType = tlv.SomeRecordT(chanType)
×
137
        }
×
NEW
138
        if _, ok := knownRecords[dc.LocalNonce.TlvType()]; ok {
×
NEW
139
                dc.LocalNonce = tlv.SomeRecordT(nonce)
×
UNCOV
140
        }
×
141

NEW
142
        dc.ExtraData = extraData
×
NEW
143

×
UNCOV
144
        return nil
×
145
}
146

147
// MsgType returns the MessageType code which uniquely identifies this message
148
// as a DynCommit on the wire.
149
//
150
// This is part of the lnwire.Message interface.
151
func (dc *DynCommit) MsgType() MessageType {
×
152
        return MsgDynCommit
×
153
}
×
154

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

© 2026 Coveralls, Inc