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

lightningnetwork / lnd / 15858991938

24 Jun 2025 06:51PM UTC coverage: 55.808% (-2.4%) from 58.173%
15858991938

Pull #9148

github

web-flow
Merge 0e921d6a5 into 29ff13d83
Pull Request #9148: DynComms [2/n]: lnwire: add authenticated wire messages for Dyn*

232 of 267 new or added lines in 5 files covered. (86.89%)

24606 existing lines in 281 files now uncovered.

108380 of 194201 relevant lines covered (55.81%)

22488.12 hits per line

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

79.49
/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 DynAck implements the lnwire.Message
29
// interface.
30
var _ Message = (*DynCommit)(nil)
31

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

41
        if err := WriteSig(w, dc.Sig); err != nil {
100✔
NEW
42
                return err
×
NEW
43
        }
×
44

45
        var extra ExtraOpaqueData
100✔
46
        err := extra.PackRecords(dynProposeRecords(&dc.DynPropose)...)
100✔
47
        if err != nil {
100✔
NEW
48
                return err
×
NEW
49
        }
×
50
        dc.ExtraData = extra
100✔
51

100✔
52
        return WriteBytes(w, dc.ExtraData)
100✔
53
}
54

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

100✔
67
        // Parse out TLV records.
100✔
68
        var tlvRecords ExtraOpaqueData
100✔
69
        if err := ReadElement(r, &tlvRecords); err != nil {
100✔
NEW
70
                return err
×
NEW
71
        }
×
72

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

100✔
82
        typeMap, err := tlvRecords.ExtractRecords(
100✔
83
                &dustLimit, &maxValue, &htlcMin, &reserve, &csvDelay, &maxHtlcs,
100✔
84
                &chanType,
100✔
85
        )
100✔
86
        if err != nil {
100✔
NEW
87
                return err
×
NEW
88
        }
×
89

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

122
        if len(tlvRecords) != 0 {
198✔
123
                dc.ExtraData = tlvRecords
98✔
124
        }
98✔
125

126
        return nil
100✔
127
}
128

129
// MsgType returns the MessageType code which uniquely identifies this message
130
// as a DynCommit on the wire.
131
//
132
// This is part of the lnwire.Message interface.
133
func (dc *DynCommit) MsgType() MessageType {
100✔
134
        return MsgDynCommit
100✔
135
}
100✔
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