github.com/decred/dcrlnd@v0.7.6/lnwire/revoke_and_ack.go (about) 1 package lnwire 2 3 import ( 4 "bytes" 5 "io" 6 7 "github.com/decred/dcrd/dcrec/secp256k1/v4" 8 ) 9 10 // RevokeAndAck is sent by either side once a CommitSig message has been 11 // received, and validated. This message serves to revoke the prior commitment 12 // transaction, which was the most up to date version until a CommitSig message 13 // referencing the specified ChannelPoint was received. Additionally, this 14 // message also piggyback's the next revocation hash that Alice should use when 15 // constructing the Bob's version of the next commitment transaction (which 16 // would be done before sending a CommitSig message). This piggybacking allows 17 // Alice to send the next CommitSig message modifying Bob's commitment 18 // transaction without first asking for a revocation hash initially. 19 type RevokeAndAck struct { 20 // ChanID uniquely identifies to which currently active channel this 21 // RevokeAndAck applies to. 22 ChanID ChannelID 23 24 // Revocation is the preimage to the revocation hash of the now prior 25 // commitment transaction. 26 Revocation [32]byte 27 28 // NextRevocationKey is the next commitment point which should be used 29 // for the next commitment transaction the remote peer creates for us. 30 // This, in conjunction with revocation base point will be used to 31 // create the proper revocation key used within the commitment 32 // transaction. 33 NextRevocationKey *secp256k1.PublicKey 34 35 // ExtraData is the set of data that was appended to this message to 36 // fill out the full maximum transport message size. These fields can 37 // be used to specify optional data such as custom TLV fields. 38 ExtraData ExtraOpaqueData 39 } 40 41 // NewRevokeAndAck creates a new RevokeAndAck message. 42 func NewRevokeAndAck() *RevokeAndAck { 43 return &RevokeAndAck{ 44 ExtraData: make([]byte, 0), 45 } 46 } 47 48 // A compile time check to ensure RevokeAndAck implements the lnwire.Message 49 // interface. 50 var _ Message = (*RevokeAndAck)(nil) 51 52 // Decode deserializes a serialized RevokeAndAck message stored in the 53 // passed io.Reader observing the specified protocol version. 54 // 55 // This is part of the lnwire.Message interface. 56 func (c *RevokeAndAck) Decode(r io.Reader, pver uint32) error { 57 return ReadElements(r, 58 &c.ChanID, 59 c.Revocation[:], 60 &c.NextRevocationKey, 61 &c.ExtraData, 62 ) 63 } 64 65 // Encode serializes the target RevokeAndAck into the passed io.Writer 66 // observing the protocol version specified. 67 // 68 // This is part of the lnwire.Message interface. 69 func (c *RevokeAndAck) Encode(w *bytes.Buffer, pver uint32) error { 70 if err := WriteChannelID(w, c.ChanID); err != nil { 71 return err 72 } 73 74 if err := WriteBytes(w, c.Revocation[:]); err != nil { 75 return err 76 } 77 78 if err := WritePublicKey(w, c.NextRevocationKey); err != nil { 79 return err 80 } 81 82 return WriteBytes(w, c.ExtraData) 83 } 84 85 // MsgType returns the integer uniquely identifying this message type on the 86 // wire. 87 // 88 // This is part of the lnwire.Message interface. 89 func (c *RevokeAndAck) MsgType() MessageType { 90 return MsgRevokeAndAck 91 } 92 93 // TargetChanID returns the channel id of the link for which this message is 94 // intended. 95 // 96 // NOTE: Part of peer.LinkUpdater interface. 97 func (c *RevokeAndAck) TargetChanID() ChannelID { 98 return c.ChanID 99 }