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

lightningnetwork / lnd / 17101605539

20 Aug 2025 02:35PM UTC coverage: 57.321% (-9.4%) from 66.68%
17101605539

push

github

web-flow
Merge pull request #10102 from yyforyongyu/fix-UpdatesInHorizon

Catch bad gossip peer and fix `UpdatesInHorizon`

28 of 89 new or added lines in 4 files covered. (31.46%)

29163 existing lines in 459 files now uncovered.

99187 of 173038 relevant lines covered (57.32%)

1.78 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/lightningnetwork/lnd/tlv"
8
)
9

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

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

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

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

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

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

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

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

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

63
        // Create extra data records.
UNCOV
64
        producers, err := da.ExtraData.RecordProducers()
×
UNCOV
65
        if err != nil {
×
66
                return err
×
67
        }
×
68

69
        // Append the known records.
UNCOV
70
        da.LocalNonce.WhenSome(
×
UNCOV
71
                func(rec tlv.RecordT[tlv.TlvType14, Musig2Nonce]) {
×
UNCOV
72
                        producers = append(producers, &rec)
×
UNCOV
73
                },
×
74
        )
75

76
        // Encode all records.
UNCOV
77
        var tlvData ExtraOpaqueData
×
UNCOV
78
        err = tlvData.PackRecords(producers...)
×
UNCOV
79
        if err != nil {
×
80
                return err
×
81
        }
×
82

UNCOV
83
        return WriteBytes(w, tlvData)
×
84
}
85

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

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

103
        // Parse all known records and extra data.
UNCOV
104
        nonce := da.LocalNonce.Zero()
×
UNCOV
105
        knownRecords, extraData, err := ParseAndExtractExtraData(
×
UNCOV
106
                tlvRecords, &nonce,
×
UNCOV
107
        )
×
UNCOV
108
        if err != nil {
×
UNCOV
109
                return err
×
UNCOV
110
        }
×
111

112
        // Check the results of the TLV Stream decoding and appropriately set
113
        // message fields.
UNCOV
114
        if _, ok := knownRecords[da.LocalNonce.TlvType()]; ok {
×
UNCOV
115
                da.LocalNonce = tlv.SomeRecordT(nonce)
×
UNCOV
116
        }
×
117

UNCOV
118
        da.ExtraData = extraData
×
UNCOV
119

×
UNCOV
120
        return nil
×
121
}
122

123
// MsgType returns the MessageType code which uniquely identifies this message
124
// as a DynAck on the wire.
125
//
126
// This is part of the lnwire.Message interface.
UNCOV
127
func (da *DynAck) MsgType() MessageType {
×
UNCOV
128
        return MsgDynAck
×
UNCOV
129
}
×
130

131
// SerializedSize returns the serialized size of the message in bytes.
132
//
133
// This is part of the lnwire.SizeableMessage interface.
134
func (da *DynAck) SerializedSize() (uint32, error) {
×
135
        return MessageSerializedSize(da)
×
136
}
×
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