github.com/bigzoro/my_simplechain@v0.0.0-20240315012955-8ad0a2a29bb9/consensus/hotstuff/hotsptcl/protocol.go (about) 1 package hotstuffprotocol 2 3 import ( 4 "encoding/json" 5 6 "github.com/bigzoro/my_simplechain/common" 7 ) 8 9 const ( 10 // hotsutff events message code 11 status uint64 = iota 12 propose 13 vote 14 timeout 15 16 // Maximum cap on the size of a protocol message 17 protocolMaxMsgSize = 10 * 1024 * 1024 18 ) 19 20 type handshakeData struct { 21 Random []byte 22 Signature []byte 23 } 24 25 func (msg *handshakeData) MarshalJSON() ([]byte, error) { 26 return json.Marshal(msg) 27 } 28 29 func (msg *handshakeData) UnmarshalJSON(input []byte) error { 30 return json.Unmarshal(input, msg) 31 } 32 33 type voteMsg struct { 34 View uint64 35 Hash common.Hash 36 Signature []byte 37 } 38 39 func (msg *voteMsg) MarshalJSON() ([]byte, error) { 40 return json.Marshal(msg) 41 } 42 43 func (msg *voteMsg) UnmarshalJSON(input []byte) error { 44 return json.Unmarshal(input, msg) 45 } 46 47 type timeoutMsg struct { 48 View uint64 49 // Hash *common.Hash 50 } 51 52 func (msg *timeoutMsg) MarshalJSON() ([]byte, error) { 53 return json.Marshal(msg) 54 } 55 56 func (msg *timeoutMsg) UnmarshalJSON(input []byte) error { 57 return json.Unmarshal(input, msg) 58 }