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

lightningnetwork / lnd / 15736109134

18 Jun 2025 02:46PM UTC coverage: 58.197% (-10.1%) from 68.248%
15736109134

Pull #9752

github

web-flow
Merge d2634a68c into 31c74f20f
Pull Request #9752: routerrpc: reject payment to invoice that don't have payment secret or blinded paths

6 of 13 new or added lines in 2 files covered. (46.15%)

28331 existing lines in 455 files now uncovered.

97860 of 168153 relevant lines covered (58.2%)

1.81 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
        // 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
// A compile time check to ensure DynAck implements the lnwire.SizeableMessage
45
// interface.
46
var _ SizeableMessage = (*DynAck)(nil)
47

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

UNCOV
57
        var tlvRecords []tlv.Record
×
UNCOV
58
        da.LocalNonce.WhenSome(func(nonce Musig2Nonce) {
×
UNCOV
59
                tlvRecords = append(
×
UNCOV
60
                        tlvRecords, tlv.MakeStaticRecord(
×
UNCOV
61
                                DALocalMusig2Pubnonce, &nonce,
×
UNCOV
62
                                musig2.PubNonceSize, nonceTypeEncoder,
×
UNCOV
63
                                nonceTypeDecoder,
×
UNCOV
64
                        ),
×
UNCOV
65
                )
×
UNCOV
66
        })
×
UNCOV
67
        tlv.SortRecords(tlvRecords)
×
UNCOV
68

×
UNCOV
69
        tlvStream, err := tlv.NewStream(tlvRecords...)
×
UNCOV
70
        if err != nil {
×
71
                return err
×
72
        }
×
73

UNCOV
74
        var extraBytesWriter bytes.Buffer
×
UNCOV
75
        if err := tlvStream.Encode(&extraBytesWriter); err != nil {
×
76
                return err
×
77
        }
×
78

UNCOV
79
        da.ExtraData = ExtraOpaqueData(extraBytesWriter.Bytes())
×
UNCOV
80

×
UNCOV
81
        return WriteBytes(w, da.ExtraData)
×
82
}
83

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

95
        // Parse out TLV records.
UNCOV
96
        var tlvRecords ExtraOpaqueData
×
UNCOV
97
        if err := ReadElement(r, &tlvRecords); err != nil {
×
98
                return err
×
99
        }
×
100

101
        // Prepare receiving buffers to be filled by TLV extraction.
UNCOV
102
        var localNonceScratch Musig2Nonce
×
UNCOV
103
        localNonce := tlv.MakeStaticRecord(
×
UNCOV
104
                DALocalMusig2Pubnonce, &localNonceScratch, musig2.PubNonceSize,
×
UNCOV
105
                nonceTypeEncoder, nonceTypeDecoder,
×
UNCOV
106
        )
×
UNCOV
107

×
UNCOV
108
        // Create set of Records to read TLV bytestream into.
×
UNCOV
109
        records := []tlv.Record{localNonce}
×
UNCOV
110
        tlv.SortRecords(records)
×
UNCOV
111

×
UNCOV
112
        // Read TLV stream into record set.
×
UNCOV
113
        extraBytesReader := bytes.NewReader(tlvRecords)
×
UNCOV
114
        tlvStream, err := tlv.NewStream(records...)
×
UNCOV
115
        if err != nil {
×
116
                return err
×
117
        }
×
UNCOV
118
        typeMap, err := tlvStream.DecodeWithParsedTypesP2P(extraBytesReader)
×
UNCOV
119
        if err != nil {
×
UNCOV
120
                return err
×
UNCOV
121
        }
×
122

123
        // Check the results of the TLV Stream decoding and appropriately set
124
        // message fields.
UNCOV
125
        if val, ok := typeMap[DALocalMusig2Pubnonce]; ok && val == nil {
×
UNCOV
126
                da.LocalNonce = fn.Some(localNonceScratch)
×
UNCOV
127
        }
×
128

UNCOV
129
        if len(tlvRecords) != 0 {
×
UNCOV
130
                da.ExtraData = tlvRecords
×
UNCOV
131
        }
×
132

UNCOV
133
        return nil
×
134
}
135

136
// MsgType returns the MessageType code which uniquely identifies this message
137
// as a DynAck on the wire.
138
//
139
// This is part of the lnwire.Message interface.
UNCOV
140
func (da *DynAck) MsgType() MessageType {
×
UNCOV
141
        return MsgDynAck
×
UNCOV
142
}
×
143

144
// SerializedSize returns the serialized size of the message in bytes.
145
//
146
// This is part of the lnwire.SizeableMessage interface.
147
func (da *DynAck) SerializedSize() (uint32, error) {
×
148
        return MessageSerializedSize(da)
×
149
}
×
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