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

lightningnetwork / lnd / 13980275562

20 Mar 2025 10:06PM UTC coverage: 58.6% (-10.2%) from 68.789%
13980275562

Pull #9623

github

web-flow
Merge b9b960345 into 09b674508
Pull Request #9623: Size msg test msg

0 of 1518 new or added lines in 42 files covered. (0.0%)

26603 existing lines in 443 files now uncovered.

96807 of 165200 relevant lines covered (58.6%)

1.82 hits per line

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

43.37
/lnwire/revoke_and_ack.go
1
package lnwire
2

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

7
        "github.com/btcsuite/btcd/btcec/v2"
8
        "github.com/lightningnetwork/lnd/tlv"
9
        "pgregory.net/rapid"
10
)
11

12
// RevokeAndAck is sent by either side once a CommitSig message has been
13
// received, and validated. This message serves to revoke the prior commitment
14
// transaction, which was the most up to date version until a CommitSig message
15
// referencing the specified ChannelPoint was received.  Additionally, this
16
// message also piggyback's the next revocation hash that Alice should use when
17
// constructing the Bob's version of the next commitment transaction (which
18
// would be done before sending a CommitSig message).  This piggybacking allows
19
// Alice to send the next CommitSig message modifying Bob's commitment
20
// transaction without first asking for a revocation hash initially.
21
type RevokeAndAck struct {
22
        // ChanID uniquely identifies to which currently active channel this
23
        // RevokeAndAck applies to.
24
        ChanID ChannelID
25

26
        // Revocation is the preimage to the revocation hash of the now prior
27
        // commitment transaction.
28
        Revocation [32]byte
29

30
        // NextRevocationKey is the next commitment point which should be used
31
        // for the next commitment transaction the remote peer creates for us.
32
        // This, in conjunction with revocation base point will be used to
33
        // create the proper revocation key used within the commitment
34
        // transaction.
35
        NextRevocationKey *btcec.PublicKey
36

37
        // LocalNonce is the next _local_ nonce for the sending party. This
38
        // allows the receiving party to propose a new commitment using their
39
        // remote nonce and the sender's local nonce.
40
        LocalNonce OptMusig2NonceTLV
41

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

48
// NewRevokeAndAck creates a new RevokeAndAck message.
UNCOV
49
func NewRevokeAndAck() *RevokeAndAck {
×
UNCOV
50
        return &RevokeAndAck{
×
UNCOV
51
                ExtraData: make([]byte, 0),
×
UNCOV
52
        }
×
UNCOV
53
}
×
54

55
// A compile time check to ensure RevokeAndAck implements the lnwire.Message
56
// interface.
57
var _ Message = (*RevokeAndAck)(nil)
58

59
// A compile time check to ensure RevokeAndAck implements the lnwire.SizeableMessage interface.
60
var _ SizeableMessage = (*RevokeAndAck)(nil)
61

62
// Decode deserializes a serialized RevokeAndAck message stored in the
63
// passed io.Reader observing the specified protocol version.
64
//
65
// This is part of the lnwire.Message interface.
66
func (c *RevokeAndAck) Decode(r io.Reader, pver uint32) error {
3✔
67
        err := ReadElements(r,
3✔
68
                &c.ChanID,
3✔
69
                c.Revocation[:],
3✔
70
                &c.NextRevocationKey,
3✔
71
        )
3✔
72
        if err != nil {
3✔
UNCOV
73
                return err
×
UNCOV
74
        }
×
75

76
        var tlvRecords ExtraOpaqueData
3✔
77
        if err := ReadElements(r, &tlvRecords); err != nil {
3✔
UNCOV
78
                return err
×
79
        }
×
80

81
        localNonce := c.LocalNonce.Zero()
3✔
82
        typeMap, err := tlvRecords.ExtractRecords(&localNonce)
3✔
83
        if err != nil {
3✔
UNCOV
84
                return err
×
UNCOV
85
        }
×
86

87
        // Set the corresponding TLV types if they were included in the stream.
88
        if val, ok := typeMap[c.LocalNonce.TlvType()]; ok && val == nil {
6✔
89
                c.LocalNonce = tlv.SomeRecordT(localNonce)
3✔
90
        }
3✔
91

92
        if len(tlvRecords) != 0 {
6✔
93
                c.ExtraData = tlvRecords
3✔
94
        }
3✔
95

96
        return nil
3✔
97
}
98

99
// Encode serializes the target RevokeAndAck into the passed io.Writer
100
// observing the protocol version specified.
101
//
102
// This is part of the lnwire.Message interface.
103
func (c *RevokeAndAck) Encode(w *bytes.Buffer, pver uint32) error {
3✔
104
        recordProducers := make([]tlv.RecordProducer, 0, 1)
3✔
105
        c.LocalNonce.WhenSome(func(localNonce Musig2NonceTLV) {
6✔
106
                recordProducers = append(recordProducers, &localNonce)
3✔
107
        })
3✔
108
        err := EncodeMessageExtraData(&c.ExtraData, recordProducers...)
3✔
109
        if err != nil {
3✔
UNCOV
110
                return err
×
111
        }
×
112

113
        if err := WriteChannelID(w, c.ChanID); err != nil {
3✔
UNCOV
114
                return err
×
115
        }
×
116

117
        if err := WriteBytes(w, c.Revocation[:]); err != nil {
3✔
UNCOV
118
                return err
×
119
        }
×
120

121
        if err := WritePublicKey(w, c.NextRevocationKey); err != nil {
3✔
UNCOV
122
                return err
×
123
        }
×
124

125
        return WriteBytes(w, c.ExtraData)
3✔
126
}
127

128
// MsgType returns the integer uniquely identifying this message type on the
129
// wire.
130
//
131
// This is part of the lnwire.Message interface.
132
func (c *RevokeAndAck) MsgType() MessageType {
3✔
133
        return MsgRevokeAndAck
3✔
134
}
3✔
135

136
// TargetChanID returns the channel id of the link for which this message is
137
// intended.
138
//
139
// NOTE: Part of peer.LinkUpdater interface.
140
func (c *RevokeAndAck) TargetChanID() ChannelID {
3✔
141
        return c.ChanID
3✔
142
}
3✔
143

144
// SerializedSize returns the serialized size of the message in bytes.
145
//
146
// This is part of the lnwire.SizeableMessage interface.
NEW
147
func (c *RevokeAndAck) SerializedSize() (uint32, error) {
×
NEW
148
        return MessageSerializedSize(c)
×
NEW
149
}
×
150

151
// RandTestMessage returns a RevokeAndAck message populated with random data.
152
//
153
// This is part of the TestMessage interface.
NEW
154
func (c *RevokeAndAck) RandTestMessage(t *rapid.T) Message {
×
NEW
155
        msg := NewRevokeAndAck()
×
NEW
156

×
NEW
157
        var chanID ChannelID
×
NEW
158
        bytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "channelID")
×
NEW
159
        copy(chanID[:], bytes)
×
NEW
160
        msg.ChanID = chanID
×
NEW
161

×
NEW
162
        revBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "revocation")
×
NEW
163
        copy(msg.Revocation[:], revBytes)
×
NEW
164

×
NEW
165
        msg.NextRevocationKey = RandPubKey(t)
×
NEW
166

×
NEW
167
        if rapid.Bool().Draw(t, "includeLocalNonce") {
×
NEW
168
                var nonce Musig2Nonce
×
NEW
169
                nonceBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
NEW
170
                        t, "nonce",
×
NEW
171
                )
×
NEW
172
                copy(nonce[:], nonceBytes)
×
NEW
173

×
NEW
174
                msg.LocalNonce = tlv.SomeRecordT(
×
NEW
175
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
×
NEW
176
                )
×
NEW
177
        }
×
178

NEW
179
        return msg
×
180
}
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