github.com/fiagdao/tendermint@v0.32.11-0.20220824195748-2087fcc480c1/consensus/types/peer_round_state.go (about) 1 package types 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/tendermint/tendermint/libs/bits" 8 "github.com/tendermint/tendermint/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 20 // Estimated start of round 0 at this height 21 StartTime time.Time `json:"start_time"` 22 23 // True if peer has proposal for this round 24 Proposal bool `json:"proposal"` 25 ProposalBlockPartsHeader types.PartSetHeader `json:"proposal_block_parts_header"` // 26 ProposalBlockParts *bits.BitArray `json:"proposal_block_parts"` // 27 ProposalPOLRound int `json:"proposal_pol_round"` // Proposal's POL round. -1 if none. 28 29 // nil until ProposalPOLMessage received. 30 ProposalPOL *bits.BitArray `json:"proposal_pol"` 31 Prevotes *bits.BitArray `json:"prevotes"` // All votes peer has for this round 32 Precommits *bits.BitArray `json:"precommits"` // All precommits peer has for this round 33 LastCommitRound int `json:"last_commit_round"` // Round of commit for last height. -1 if none. 34 LastCommit *bits.BitArray `json:"last_commit"` // All commit precommits of commit for last height. 35 36 // Round that we have commit for. Not necessarily unique. -1 if none. 37 CatchupCommitRound int `json:"catchup_commit_round"` 38 39 // All commit precommits peer has for this height & CatchupCommitRound 40 CatchupCommit *bits.BitArray `json:"catchup_commit"` 41 } 42 43 // String returns a string representation of the PeerRoundState 44 func (prs PeerRoundState) String() string { 45 return prs.StringIndented("") 46 } 47 48 // StringIndented returns a string representation of the PeerRoundState 49 func (prs PeerRoundState) StringIndented(indent string) string { 50 return fmt.Sprintf(`PeerRoundState{ 51 %s %v/%v/%v @%v 52 %s Proposal %v -> %v 53 %s POL %v (round %v) 54 %s Prevotes %v 55 %s Precommits %v 56 %s LastCommit %v (round %v) 57 %s Catchup %v (round %v) 58 %s}`, 59 indent, prs.Height, prs.Round, prs.Step, prs.StartTime, 60 indent, prs.ProposalBlockPartsHeader, prs.ProposalBlockParts, 61 indent, prs.ProposalPOL, prs.ProposalPOLRound, 62 indent, prs.Prevotes, 63 indent, prs.Precommits, 64 indent, prs.LastCommit, prs.LastCommitRound, 65 indent, prs.CatchupCommit, prs.CatchupCommitRound, 66 indent) 67 } 68 69 //----------------------------------------------------------- 70 // These methods are for Protobuf Compatibility 71 72 // Size returns the size of the amino encoding, in bytes. 73 func (prs *PeerRoundState) Size() int { 74 bs, _ := prs.Marshal() 75 return len(bs) 76 } 77 78 // Marshal returns the amino encoding. 79 func (prs *PeerRoundState) Marshal() ([]byte, error) { 80 return cdc.MarshalBinaryBare(prs) 81 } 82 83 // MarshalTo calls Marshal and copies to the given buffer. 84 func (prs *PeerRoundState) MarshalTo(data []byte) (int, error) { 85 bs, err := prs.Marshal() 86 if err != nil { 87 return -1, err 88 } 89 return copy(data, bs), nil 90 } 91 92 // Unmarshal deserializes from amino encoded form. 93 func (prs *PeerRoundState) Unmarshal(bs []byte) error { 94 return cdc.UnmarshalBinaryBare(bs, prs) 95 }