github.com/decred/dcrlnd@v0.7.6/watchtower/wtwire/state_update.go (about) 1 package wtwire 2 3 import "io" 4 5 // StateUpdate transmits an encrypted state update from the client to the 6 // watchtower. Each state update is tied to particular session, identified by 7 // the client's brontine key used to make the request. 8 type StateUpdate struct { 9 // SeqNum is a 1-indexed, monotonically incrementing sequence number. 10 // This number represents to the client's expected sequence number when 11 // sending updates sent to the watchtower. This value must always be 12 // less or equal than the negotiated MaxUpdates for the session, and 13 // greater than the LastApplied sent in the same message. 14 SeqNum uint16 15 16 // LastApplied echos the LastApplied value returned from watchtower, 17 // allowing the tower to detect faulty clients. This allow provides a 18 // feedback mechanism for the tower if updates are allowed to stream in 19 // an async fashion. 20 LastApplied uint16 21 22 // IsComplete is 1 if the watchtower should close the connection after 23 // responding, and 0 otherwise. 24 IsComplete uint8 25 26 // Hint is the 16-byte prefix of the revoked commitment transaction ID 27 // for which the encrypted blob can exact justice. 28 Hint [16]byte 29 30 // EncryptedBlob is the serialized ciphertext containing all necessary 31 // information to sweep the commitment transaction corresponding to the 32 // Hint. The ciphertext is to be encrypted using the full transaction ID 33 // of the revoked commitment transaction. 34 // 35 // The plaintext MUST be encoded using the negotiated Version for 36 // this session. In addition, the signatures must be computed over a 37 // sweep transaction honoring the decided SweepFeeRate, RewardRate, and 38 // (possibly) reward address returned in the SessionInitReply. 39 EncryptedBlob []byte 40 } 41 42 // A compile time check to ensure StateUpdate implements the wtwire.Message 43 // interface. 44 var _ Message = (*StateUpdate)(nil) 45 46 // Decode deserializes a serialized StateUpdate message stored in the passed 47 // io.Reader observing the specified protocol version. 48 // 49 // This is part of the wtwire.Message interface. 50 func (m *StateUpdate) Decode(r io.Reader, pver uint32) error { 51 return ReadElements(r, 52 &m.SeqNum, 53 &m.LastApplied, 54 &m.IsComplete, 55 &m.Hint, 56 &m.EncryptedBlob, 57 ) 58 } 59 60 // Encode serializes the target StateUpdate into the passed io.Writer 61 // observing the protocol version specified. 62 // 63 // This is part of the wtwire.Message interface. 64 func (m *StateUpdate) Encode(w io.Writer, pver uint32) error { 65 return WriteElements(w, 66 m.SeqNum, 67 m.LastApplied, 68 m.IsComplete, 69 m.Hint, 70 m.EncryptedBlob, 71 ) 72 } 73 74 // MsgType returns the integer uniquely identifying this message type on the 75 // wire. 76 // 77 // This is part of the wtwire.Message interface. 78 func (m *StateUpdate) MsgType() MessageType { 79 return MsgStateUpdate 80 } 81 82 // MaxPayloadLength returns the maximum allowed payload size for a StateUpdate 83 // complete message observing the specified protocol version. 84 // 85 // This is part of the wtwire.Message interface. 86 func (m *StateUpdate) MaxPayloadLength(uint32) uint32 { 87 return MaxMessagePayload 88 }