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

lightningnetwork / lnd / 16048076081

03 Jul 2025 10:31AM UTC coverage: 67.53% (-0.06%) from 67.589%
16048076081

Pull #10018

github

web-flow
Merge b10bc9e36 into 8a0341419
Pull Request #10018: Refactor link's long methods

530 of 808 new or added lines in 1 file covered. (65.59%)

140 existing lines in 29 files now uncovered.

135096 of 200052 relevant lines covered (67.53%)

21807.17 hits per line

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

76.54
/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 {
100✔
41
        if err := WriteChannelID(w, dc.DynPropose.ChanID); err != nil {
100✔
42
                return err
×
43
        }
×
44

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

49
        var extra ExtraOpaqueData
100✔
50
        err := extra.PackRecords(dynProposeRecords(&dc.DynPropose)...)
100✔
51
        if err != nil {
100✔
52
                return err
×
53
        }
×
54
        dc.ExtraData = extra
100✔
55

100✔
56
        return WriteBytes(w, dc.ExtraData)
100✔
57
}
58

59
// Decode deserializes the serialized DynCommit stored in the passed io.Reader
60
// into the target DynAck using the deserialization rules defined by the passed
61
// protocol version.
62
//
63
// This is a part of the lnwire.Message interface.
64
func (dc *DynCommit) Decode(r io.Reader, _ uint32) error {
100✔
65
        // Parse out main message.
100✔
66
        if err := ReadElements(r, &dc.DynPropose.ChanID, &dc.Sig); err != nil {
100✔
67
                return err
×
68
        }
×
69
        dc.DynAck.ChanID = dc.DynPropose.ChanID
100✔
70

100✔
71
        // Parse out TLV records.
100✔
72
        var tlvRecords ExtraOpaqueData
100✔
73
        if err := ReadElement(r, &tlvRecords); err != nil {
100✔
74
                return err
×
75
        }
×
76

77
        // Prepare receiving buffers to be filled by TLV extraction.
78
        var dustLimit tlv.RecordT[tlv.TlvType0, uint64]
100✔
79
        var maxValue tlv.RecordT[tlv.TlvType2, uint64]
100✔
80
        var htlcMin tlv.RecordT[tlv.TlvType4, uint64]
100✔
81
        var reserve tlv.RecordT[tlv.TlvType6, uint64]
100✔
82
        csvDelay := dc.CsvDelay.Zero()
100✔
83
        maxHtlcs := dc.MaxAcceptedHTLCs.Zero()
100✔
84
        chanType := dc.ChannelType.Zero()
100✔
85

100✔
86
        typeMap, err := tlvRecords.ExtractRecords(
100✔
87
                &dustLimit, &maxValue, &htlcMin, &reserve, &csvDelay, &maxHtlcs,
100✔
88
                &chanType,
100✔
89
        )
100✔
90
        if err != nil {
100✔
91
                return err
×
92
        }
×
93

94
        // Check the results of the TLV Stream decoding and appropriately set
95
        // message fields.
96
        if val, ok := typeMap[dc.DustLimit.TlvType()]; ok && val == nil {
155✔
97
                var rec tlv.RecordT[tlv.TlvType0, btcutil.Amount]
55✔
98
                rec.Val = btcutil.Amount(dustLimit.Val)
55✔
99
                dc.DustLimit = tlv.SomeRecordT(rec)
55✔
100
        }
55✔
101
        if val, ok := typeMap[dc.MaxValueInFlight.TlvType()]; ok && val == nil {
149✔
102
                var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi]
49✔
103
                rec.Val = MilliSatoshi(maxValue.Val)
49✔
104
                dc.MaxValueInFlight = tlv.SomeRecordT(rec)
49✔
105
        }
49✔
106
        if val, ok := typeMap[dc.HtlcMinimum.TlvType()]; ok && val == nil {
100✔
107
                var rec tlv.RecordT[tlv.TlvType4, MilliSatoshi]
×
108
                rec.Val = MilliSatoshi(htlcMin.Val)
×
109
                dc.HtlcMinimum = tlv.SomeRecordT(rec)
×
110
        }
×
111
        if val, ok := typeMap[dc.ChannelReserve.TlvType()]; ok && val == nil {
154✔
112
                var rec tlv.RecordT[tlv.TlvType6, btcutil.Amount]
54✔
113
                rec.Val = btcutil.Amount(reserve.Val)
54✔
114
                dc.ChannelReserve = tlv.SomeRecordT(rec)
54✔
115
        }
54✔
116
        if val, ok := typeMap[dc.CsvDelay.TlvType()]; ok && val == nil {
149✔
117
                dc.CsvDelay = tlv.SomeRecordT(csvDelay)
49✔
118
        }
49✔
119
        if val, ok := typeMap[dc.MaxAcceptedHTLCs.TlvType()]; ok && val == nil {
150✔
120
                dc.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs)
50✔
121
        }
50✔
122
        if val, ok := typeMap[dc.ChannelType.TlvType()]; ok && val == nil {
154✔
123
                dc.ChannelType = tlv.SomeRecordT(chanType)
54✔
124
        }
54✔
125

126
        if len(tlvRecords) != 0 {
199✔
127
                dc.ExtraData = tlvRecords
99✔
128
        }
99✔
129

130
        return nil
100✔
131
}
132

133
// MsgType returns the MessageType code which uniquely identifies this message
134
// as a DynCommit on the wire.
135
//
136
// This is part of the lnwire.Message interface.
137
func (dc *DynCommit) MsgType() MessageType {
100✔
138
        return MsgDynCommit
100✔
139
}
100✔
140

141
// SerializedSize returns the serialized size of the message in bytes.
142
//
143
// This is part of the lnwire.SizeableMessage interface.
UNCOV
144
func (dc *DynCommit) SerializedSize() (uint32, error) {
×
UNCOV
145
        return MessageSerializedSize(dc)
×
UNCOV
146
}
×
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