github.com/decred/dcrlnd@v0.7.6/watchtower/wtwire/create_session.go (about) 1 package wtwire 2 3 import ( 4 "io" 5 6 "github.com/decred/dcrlnd/lnwallet/chainfee" 7 "github.com/decred/dcrlnd/watchtower/blob" 8 ) 9 10 // CreateSession is sent from a client to tower when to negotiate a session, which 11 // specifies the total number of updates that can be made, as well as fee rates. 12 // An update is consumed by uploading an encrypted blob that contains 13 // information required to sweep a revoked commitment transaction. 14 type CreateSession struct { 15 // BlobType specifies the blob format that must be used by all updates sent 16 // under the session key used to negotiate this session. 17 BlobType blob.Type 18 19 // MaxUpdates is the maximum number of updates the watchtower will honor 20 // for this session. 21 MaxUpdates uint16 22 23 // RewardBase is the fixed amount allocated to the tower when the 24 // policy's blob type specifies a reward for the tower. This is taken 25 // before adding the proportional reward. 26 RewardBase uint32 27 28 // RewardRate is the fraction of the total balance of the revoked 29 // commitment that the watchtower is entitled to. This value is 30 // expressed in millionths of the total balance. 31 RewardRate uint32 32 33 // SweepFeeRate expresses the intended fee rate to be used when 34 // constructing the justice transaction. All sweep transactions created 35 // for this session must use this value during construction, and the 36 // signatures must implicitly commit to the resulting output values. 37 SweepFeeRate chainfee.AtomPerKByte 38 } 39 40 // A compile time check to ensure CreateSession implements the wtwire.Message 41 // interface. 42 var _ Message = (*CreateSession)(nil) 43 44 // Decode deserializes a serialized CreateSession message stored in the passed 45 // io.Reader observing the specified protocol version. 46 // 47 // This is part of the wtwire.Message interface. 48 func (m *CreateSession) Decode(r io.Reader, pver uint32) error { 49 return ReadElements(r, 50 &m.BlobType, 51 &m.MaxUpdates, 52 &m.RewardBase, 53 &m.RewardRate, 54 &m.SweepFeeRate, 55 ) 56 } 57 58 // Encode serializes the target CreateSession into the passed io.Writer 59 // observing the protocol version specified. 60 // 61 // This is part of the wtwire.Message interface. 62 func (m *CreateSession) Encode(w io.Writer, pver uint32) error { 63 return WriteElements(w, 64 m.BlobType, 65 m.MaxUpdates, 66 m.RewardBase, 67 m.RewardRate, 68 m.SweepFeeRate, 69 ) 70 } 71 72 // MsgType returns the integer uniquely identifying this message type on the 73 // wire. 74 // 75 // This is part of the wtwire.Message interface. 76 func (m *CreateSession) MsgType() MessageType { 77 return MsgCreateSession 78 } 79 80 // MaxPayloadLength returns the maximum allowed payload size for a CreateSession 81 // complete message observing the specified protocol version. 82 // 83 // This is part of the wtwire.Message interface. 84 func (m *CreateSession) MaxPayloadLength(uint32) uint32 { 85 return 2 + 2 + 4 + 4 + 8 // 20 86 }