• 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_ack.go
1
package lnwire
2

3
import (
4
        "bytes"
5
        "io"
6

7
        "github.com/btcsuite/btcd/btcec/v2/schnorr/musig2"
8
        "github.com/lightningnetwork/lnd/fn/v2"
9
        "github.com/lightningnetwork/lnd/tlv"
10
)
11

12
const (
13
        // DALocalMusig2Pubnonce is the TLV type number that identifies the
14
        // musig2 public nonce that we need to verify the commitment transaction
15
        // signature.
16
        DALocalMusig2Pubnonce tlv.Type = 0
17
)
18

19
// DynAck is the message used to accept the parameters of a dynamic commitment
20
// negotiation. Additional optional parameters will need to be present depending
21
// on the details of the dynamic commitment upgrade.
22
type DynAck struct {
23
        // ChanID is the ChannelID of the channel that is currently undergoing
24
        // a dynamic commitment negotiation
25
        ChanID ChannelID
26

27
        // Sig is a signature that acknowledges and approves the parameters
28
        // that were requested in the DynPropose
29
        Sig Sig
30

31
        // LocalNonce is an optional field that is transmitted when accepting
32
        // a dynamic commitment upgrade to Taproot Channels. This nonce will be
33
        // used to verify the first commitment transaction signature. This will
34
        // only be populated if the DynPropose we are responding to specifies
35
        // taproot channels in the ChannelType field.
36
        LocalNonce fn.Option[Musig2Nonce]
37

38
        // ExtraData is the set of data that was appended to this message to
39
        // fill out the full maximum transport message size. These fields can
40
        // be used to specify optional data such as custom TLV fields.
41
        ExtraData ExtraOpaqueData
42
}
43

44
// A compile time check to ensure DynAck implements the lnwire.Message
45
// interface.
46
var _ Message = (*DynAck)(nil)
47

48
// A compile time check to ensure DynAck implements the lnwire.SizeableMessage
49
// interface.
50
var _ SizeableMessage = (*DynAck)(nil)
51

52
// Encode serializes the target DynAck into the passed io.Writer. Serialization
53
// will observe the rules defined by the passed protocol version.
54
//
55
// This is a part of the lnwire.Message interface.
UNCOV
56
func (da *DynAck) Encode(w *bytes.Buffer, _ uint32) error {
×
UNCOV
57
        if err := WriteChannelID(w, da.ChanID); err != nil {
×
58
                return err
×
59
        }
×
60

UNCOV
61
        if err := WriteSig(w, da.Sig); err != nil {
×
62
                return err
×
63
        }
×
64

UNCOV
65
        var tlvRecords []tlv.Record
×
UNCOV
66
        da.LocalNonce.WhenSome(func(nonce Musig2Nonce) {
×
UNCOV
67
                tlvRecords = append(
×
UNCOV
68
                        tlvRecords, tlv.MakeStaticRecord(
×
UNCOV
69
                                DALocalMusig2Pubnonce, &nonce,
×
UNCOV
70
                                musig2.PubNonceSize, nonceTypeEncoder,
×
UNCOV
71
                                nonceTypeDecoder,
×
UNCOV
72
                        ),
×
UNCOV
73
                )
×
UNCOV
74
        })
×
UNCOV
75
        tlv.SortRecords(tlvRecords)
×
UNCOV
76

×
UNCOV
77
        tlvStream, err := tlv.NewStream(tlvRecords...)
×
UNCOV
78
        if err != nil {
×
79
                return err
×
80
        }
×
81

UNCOV
82
        var extraBytesWriter bytes.Buffer
×
UNCOV
83
        if err := tlvStream.Encode(&extraBytesWriter); err != nil {
×
84
                return err
×
85
        }
×
86

UNCOV
87
        da.ExtraData = ExtraOpaqueData(extraBytesWriter.Bytes())
×
UNCOV
88

×
UNCOV
89
        return WriteBytes(w, da.ExtraData)
×
90
}
91

92
// Decode deserializes the serialized DynAck stored in the passed io.Reader into
93
// the target DynAck using the deserialization rules defined by the passed
94
// protocol version.
95
//
96
// This is a part of the lnwire.Message interface.
UNCOV
97
func (da *DynAck) Decode(r io.Reader, _ uint32) error {
×
UNCOV
98
        // Parse out main message.
×
UNCOV
99
        if err := ReadElements(r, &da.ChanID, &da.Sig); err != nil {
×
UNCOV
100
                return err
×
UNCOV
101
        }
×
102

103
        // Parse out TLV records.
UNCOV
104
        var tlvRecords ExtraOpaqueData
×
UNCOV
105
        if err := ReadElement(r, &tlvRecords); err != nil {
×
106
                return err
×
107
        }
×
108

109
        // Prepare receiving buffers to be filled by TLV extraction.
UNCOV
110
        var localNonceScratch Musig2Nonce
×
UNCOV
111
        localNonce := tlv.MakeStaticRecord(
×
UNCOV
112
                DALocalMusig2Pubnonce, &localNonceScratch, musig2.PubNonceSize,
×
UNCOV
113
                nonceTypeEncoder, nonceTypeDecoder,
×
UNCOV
114
        )
×
UNCOV
115

×
UNCOV
116
        // Create set of Records to read TLV bytestream into.
×
UNCOV
117
        records := []tlv.Record{localNonce}
×
UNCOV
118
        tlv.SortRecords(records)
×
UNCOV
119

×
UNCOV
120
        // Read TLV stream into record set.
×
UNCOV
121
        extraBytesReader := bytes.NewReader(tlvRecords)
×
UNCOV
122
        tlvStream, err := tlv.NewStream(records...)
×
UNCOV
123
        if err != nil {
×
124
                return err
×
125
        }
×
UNCOV
126
        typeMap, err := tlvStream.DecodeWithParsedTypesP2P(extraBytesReader)
×
UNCOV
127
        if err != nil {
×
UNCOV
128
                return err
×
UNCOV
129
        }
×
130

131
        // Check the results of the TLV Stream decoding and appropriately set
132
        // message fields.
UNCOV
133
        if val, ok := typeMap[DALocalMusig2Pubnonce]; ok && val == nil {
×
UNCOV
134
                da.LocalNonce = fn.Some(localNonceScratch)
×
UNCOV
135
        }
×
136

UNCOV
137
        if len(tlvRecords) != 0 {
×
UNCOV
138
                da.ExtraData = tlvRecords
×
UNCOV
139
        }
×
140

UNCOV
141
        return nil
×
142
}
143

144
// MsgType returns the MessageType code which uniquely identifies this message
145
// as a DynAck on the wire.
146
//
147
// This is part of the lnwire.Message interface.
UNCOV
148
func (da *DynAck) MsgType() MessageType {
×
UNCOV
149
        return MsgDynAck
×
UNCOV
150
}
×
151

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