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