github.com/evdatsion/aphelion-dpos-bft@v0.32.1/consensus/types/peer_round_state.go (about) 1 package types 2 3 import ( 4 "fmt" 5 "time" 6 7 cmn "github.com/evdatsion/aphelion-dpos-bft/libs/common" 8 "github.com/evdatsion/aphelion-dpos-bft/types" 9 ) 10 11 //----------------------------------------------------------------------------- 12 13 // PeerRoundState contains the known state of a peer. 14 // NOTE: Read-only when returned by PeerState.GetRoundState(). 15 type PeerRoundState struct { 16 Height int64 `json:"height"` // Height peer is at 17 Round int `json:"round"` // Round peer is at, -1 if unknown. 18 Step RoundStepType `json:"step"` // Step peer is at 19 StartTime time.Time `json:"start_time"` // Estimated start of round 0 at this height 20 Proposal bool `json:"proposal"` // True if peer has proposal for this round 21 ProposalBlockPartsHeader types.PartSetHeader `json:"proposal_block_parts_header"` // 22 ProposalBlockParts *cmn.BitArray `json:"proposal_block_parts"` // 23 ProposalPOLRound int `json:"proposal_pol_round"` // Proposal's POL round. -1 if none. 24 ProposalPOL *cmn.BitArray `json:"proposal_pol"` // nil until ProposalPOLMessage received. 25 Prevotes *cmn.BitArray `json:"prevotes"` // All votes peer has for this round 26 Precommits *cmn.BitArray `json:"precommits"` // All precommits peer has for this round 27 LastCommitRound int `json:"last_commit_round"` // Round of commit for last height. -1 if none. 28 LastCommit *cmn.BitArray `json:"last_commit"` // All commit precommits of commit for last height. 29 CatchupCommitRound int `json:"catchup_commit_round"` // Round that we have commit for. Not necessarily unique. -1 if none. 30 CatchupCommit *cmn.BitArray `json:"catchup_commit"` // All commit precommits peer has for this height & CatchupCommitRound 31 } 32 33 // String returns a string representation of the PeerRoundState 34 func (prs PeerRoundState) String() string { 35 return prs.StringIndented("") 36 } 37 38 // StringIndented returns a string representation of the PeerRoundState 39 func (prs PeerRoundState) StringIndented(indent string) string { 40 return fmt.Sprintf(`PeerRoundState{ 41 %s %v/%v/%v @%v 42 %s Proposal %v -> %v 43 %s POL %v (round %v) 44 %s Prevotes %v 45 %s Precommits %v 46 %s LastCommit %v (round %v) 47 %s Catchup %v (round %v) 48 %s}`, 49 indent, prs.Height, prs.Round, prs.Step, prs.StartTime, 50 indent, prs.ProposalBlockPartsHeader, prs.ProposalBlockParts, 51 indent, prs.ProposalPOL, prs.ProposalPOLRound, 52 indent, prs.Prevotes, 53 indent, prs.Precommits, 54 indent, prs.LastCommit, prs.LastCommitRound, 55 indent, prs.CatchupCommit, prs.CatchupCommitRound, 56 indent) 57 } 58 59 //----------------------------------------------------------- 60 // These methods are for Protobuf Compatibility 61 62 // Size returns the size of the amino encoding, in bytes. 63 func (ps *PeerRoundState) Size() int { 64 bs, _ := ps.Marshal() 65 return len(bs) 66 } 67 68 // Marshal returns the amino encoding. 69 func (ps *PeerRoundState) Marshal() ([]byte, error) { 70 return cdc.MarshalBinaryBare(ps) 71 } 72 73 // MarshalTo calls Marshal and copies to the given buffer. 74 func (ps *PeerRoundState) MarshalTo(data []byte) (int, error) { 75 bs, err := ps.Marshal() 76 if err != nil { 77 return -1, err 78 } 79 return copy(data, bs), nil 80 } 81 82 // Unmarshal deserializes from amino encoded form. 83 func (ps *PeerRoundState) Unmarshal(bs []byte) error { 84 return cdc.UnmarshalBinaryBare(bs, ps) 85 }