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

lightningnetwork / lnd / 13586005509

28 Feb 2025 10:14AM UTC coverage: 68.629% (+9.9%) from 58.77%
13586005509

Pull #9521

github

web-flow
Merge 37d3a70a5 into 8532955b3
Pull Request #9521: unit: remove GOACC, use Go 1.20 native coverage functionality

129950 of 189351 relevant lines covered (68.63%)

23726.46 hits per line

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

84.85
/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
        // LocalNonce is an optional field that is transmitted when accepting
28
        // a dynamic commitment upgrade to Taproot Channels. This nonce will be
29
        // used to verify the first commitment transaction signature. This will
30
        // only be populated if the DynPropose we are responding to specifies
31
        // taproot channels in the ChannelType field.
32
        LocalNonce fn.Option[Musig2Nonce]
33

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

40
// A compile time check to ensure DynAck implements the lnwire.Message
41
// interface.
42
var _ Message = (*DynAck)(nil)
43

44
// Encode serializes the target DynAck into the passed io.Writer. Serialization
45
// will observe the rules defined by the passed protocol version.
46
//
47
// This is a part of the lnwire.Message interface.
48
func (da *DynAck) Encode(w *bytes.Buffer, _ uint32) error {
111✔
49
        if err := WriteChannelID(w, da.ChanID); err != nil {
111✔
50
                return err
×
51
        }
×
52

53
        var tlvRecords []tlv.Record
111✔
54
        da.LocalNonce.WhenSome(func(nonce Musig2Nonce) {
165✔
55
                tlvRecords = append(
54✔
56
                        tlvRecords, tlv.MakeStaticRecord(
54✔
57
                                DALocalMusig2Pubnonce, &nonce,
54✔
58
                                musig2.PubNonceSize, nonceTypeEncoder,
54✔
59
                                nonceTypeDecoder,
54✔
60
                        ),
54✔
61
                )
54✔
62
        })
54✔
63
        tlv.SortRecords(tlvRecords)
111✔
64

111✔
65
        tlvStream, err := tlv.NewStream(tlvRecords...)
111✔
66
        if err != nil {
111✔
67
                return err
×
68
        }
×
69

70
        var extraBytesWriter bytes.Buffer
111✔
71
        if err := tlvStream.Encode(&extraBytesWriter); err != nil {
111✔
72
                return err
×
73
        }
×
74

75
        da.ExtraData = ExtraOpaqueData(extraBytesWriter.Bytes())
111✔
76

111✔
77
        return WriteBytes(w, da.ExtraData)
111✔
78
}
79

80
// Decode deserializes the serialized DynAck stored in the passed io.Reader into
81
// the target DynAck using the deserialization rules defined by the passed
82
// protocol version.
83
//
84
// This is a part of the lnwire.Message interface.
85
func (da *DynAck) Decode(r io.Reader, _ uint32) error {
165✔
86
        // Parse out main message.
165✔
87
        if err := ReadElements(r, &da.ChanID); err != nil {
167✔
88
                return err
2✔
89
        }
2✔
90

91
        // Parse out TLV records.
92
        var tlvRecords ExtraOpaqueData
163✔
93
        if err := ReadElement(r, &tlvRecords); err != nil {
163✔
94
                return err
×
95
        }
×
96

97
        // Prepare receiving buffers to be filled by TLV extraction.
98
        var localNonceScratch Musig2Nonce
163✔
99
        localNonce := tlv.MakeStaticRecord(
163✔
100
                DALocalMusig2Pubnonce, &localNonceScratch, musig2.PubNonceSize,
163✔
101
                nonceTypeEncoder, nonceTypeDecoder,
163✔
102
        )
163✔
103

163✔
104
        // Create set of Records to read TLV bytestream into.
163✔
105
        records := []tlv.Record{localNonce}
163✔
106
        tlv.SortRecords(records)
163✔
107

163✔
108
        // Read TLV stream into record set.
163✔
109
        extraBytesReader := bytes.NewReader(tlvRecords)
163✔
110
        tlvStream, err := tlv.NewStream(records...)
163✔
111
        if err != nil {
163✔
112
                return err
×
113
        }
×
114
        typeMap, err := tlvStream.DecodeWithParsedTypesP2P(extraBytesReader)
163✔
115
        if err != nil {
204✔
116
                return err
41✔
117
        }
41✔
118

119
        // Check the results of the TLV Stream decoding and appropriately set
120
        // message fields.
121
        if val, ok := typeMap[DALocalMusig2Pubnonce]; ok && val == nil {
183✔
122
                da.LocalNonce = fn.Some(localNonceScratch)
61✔
123
        }
61✔
124

125
        if len(tlvRecords) != 0 {
186✔
126
                da.ExtraData = tlvRecords
64✔
127
        }
64✔
128

129
        return nil
122✔
130
}
131

132
// MsgType returns the MessageType code which uniquely identifies this message
133
// as a DynAck on the wire.
134
//
135
// This is part of the lnwire.Message interface.
136
func (da *DynAck) MsgType() MessageType {
111✔
137
        return MsgDynAck
111✔
138
}
111✔
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