You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
3.7 KiB

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