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

lightningnetwork / lnd / 14358372723

09 Apr 2025 01:26PM UTC coverage: 56.696% (-12.3%) from 69.037%
14358372723

Pull #9696

github

web-flow
Merge e2837e400 into 867d27d68
Pull Request #9696: Add `development_guidelines.md` for both human and machine

107055 of 188823 relevant lines covered (56.7%)

22721.56 hits per line

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

72.41
/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
)
10

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

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

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

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

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

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

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

58
// A compile time check to ensure RevokeAndAck implements the
59
// 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 {
163✔
67
        err := ReadElements(r,
163✔
68
                &c.ChanID,
163✔
69
                c.Revocation[:],
163✔
70
                &c.NextRevocationKey,
163✔
71
        )
163✔
72
        if err != nil {
171✔
73
                return err
8✔
74
        }
8✔
75

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

81
        localNonce := c.LocalNonce.Zero()
155✔
82
        typeMap, err := tlvRecords.ExtractRecords(&localNonce)
155✔
83
        if err != nil {
196✔
84
                return err
41✔
85
        }
41✔
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 {
169✔
89
                c.LocalNonce = tlv.SomeRecordT(localNonce)
55✔
90
        }
55✔
91

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

96
        return nil
114✔
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 {
107✔
104
        recordProducers := make([]tlv.RecordProducer, 0, 1)
107✔
105
        c.LocalNonce.WhenSome(func(localNonce Musig2NonceTLV) {
161✔
106
                recordProducers = append(recordProducers, &localNonce)
54✔
107
        })
54✔
108
        err := EncodeMessageExtraData(&c.ExtraData, recordProducers...)
107✔
109
        if err != nil {
107✔
110
                return err
×
111
        }
×
112

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

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

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

125
        return WriteBytes(w, c.ExtraData)
107✔
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,688✔
133
        return MsgRevokeAndAck
3,688✔
134
}
3,688✔
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 {
×
141
        return c.ChanID
×
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 (c *RevokeAndAck) SerializedSize() (uint32, error) {
×
148
        return MessageSerializedSize(c)
×
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