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

lightningnetwork / lnd / 16028568263

02 Jul 2025 02:55PM UTC coverage: 67.579% (+0.04%) from 67.54%
16028568263

Pull #10027

github

web-flow
Merge c4f2c13b4 into b5c84eab1
Pull Request #10027: Fix `ExtraData` field and use `BigSize` encodine

137 of 143 new or added lines in 5 files covered. (95.8%)

56 existing lines in 17 files now uncovered.

135172 of 200021 relevant lines covered (67.58%)

21907.18 hits per line

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

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

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

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

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

66
        // Encode ExtraData.
67
        return WriteBytes(w, dc.ExtraData)
101✔
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 {
101✔
76
        // Parse out main message.
101✔
77
        if err := ReadElements(r, &dc.DynPropose.ChanID, &dc.Sig); err != nil {
101✔
78
                return err
×
79
        }
×
80
        dc.DynAck.ChanID = dc.DynPropose.ChanID
101✔
81

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

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

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

107
        // Check the results of the TLV Stream decoding and appropriately set
108
        // message fields.
109
        if _, ok := knownRecords[dc.DustLimit.TlvType()]; ok {
145✔
110
                dc.DustLimit = tlv.SomeRecordT(dustLimit)
44✔
111
        }
44✔
112
        if _, ok := knownRecords[dc.MaxValueInFlight.TlvType()]; ok {
154✔
113
                dc.MaxValueInFlight = tlv.SomeRecordT(maxValue)
53✔
114
        }
53✔
115
        if _, ok := knownRecords[dc.HtlcMinimum.TlvType()]; ok {
102✔
116
                dc.HtlcMinimum = tlv.SomeRecordT(htlcMin)
1✔
117
        }
1✔
118
        if _, ok := knownRecords[dc.ChannelReserve.TlvType()]; ok {
152✔
119
                dc.ChannelReserve = tlv.SomeRecordT(reserve)
51✔
120
        }
51✔
121
        if _, ok := knownRecords[dc.CsvDelay.TlvType()]; ok {
155✔
122
                dc.CsvDelay = tlv.SomeRecordT(csvDelay)
54✔
123
        }
54✔
124
        if _, ok := knownRecords[dc.MaxAcceptedHTLCs.TlvType()]; ok {
153✔
125
                dc.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs)
52✔
126
        }
52✔
127
        if _, ok := knownRecords[dc.ChannelType.TlvType()]; ok {
146✔
128
                dc.ChannelType = tlv.SomeRecordT(chanType)
45✔
129
        }
45✔
130
        if _, ok := knownRecords[dc.LocalNonce.TlvType()]; ok {
153✔
131
                dc.LocalNonce = tlv.SomeRecordT(nonce)
52✔
132
        }
52✔
133

134
        dc.ExtraData = extraData
101✔
135

101✔
136
        return nil
101✔
137
}
138

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

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