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

lightningnetwork / lnd / 16152866413

08 Jul 2025 07:44PM UTC coverage: 57.72% (-9.8%) from 67.503%
16152866413

Pull #10015

github

web-flow
Merge f6affb695 into 47dce0894
Pull Request #10015: graph/db: add zombie channels cleanup routine

32 of 63 new or added lines in 2 files covered. (50.79%)

28432 existing lines in 455 files now uncovered.

98528 of 170699 relevant lines covered (57.72%)

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

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

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

×
UNCOV
56
        return WriteBytes(w, dc.ExtraData)
×
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.
UNCOV
64
func (dc *DynCommit) Decode(r io.Reader, _ uint32) error {
×
UNCOV
65
        // Parse out main message.
×
UNCOV
66
        if err := ReadElements(r, &dc.DynPropose.ChanID, &dc.Sig); err != nil {
×
67
                return err
×
68
        }
×
UNCOV
69
        dc.DynAck.ChanID = dc.DynPropose.ChanID
×
UNCOV
70

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

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

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

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

UNCOV
126
        if len(tlvRecords) != 0 {
×
UNCOV
127
                dc.ExtraData = tlvRecords
×
UNCOV
128
        }
×
129

UNCOV
130
        return nil
×
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.
UNCOV
137
func (dc *DynCommit) MsgType() MessageType {
×
UNCOV
138
        return MsgDynCommit
×
UNCOV
139
}
×
140

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