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.

93 lines
3.4 KiB

  1. package types
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/tendermint/tendermint/libs/bits"
  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 int32 `json:"round"` // Round peer is at, -1 if unknown.
  14. Step RoundStepType `json:"step"` // Step peer is at
  15. // Estimated start of round 0 at this height
  16. StartTime time.Time `json:"start_time"`
  17. // True if peer has proposal for this round
  18. Proposal bool `json:"proposal"`
  19. ProposalBlockPartSetHeader types.PartSetHeader `json:"proposal_block_part_set_header"`
  20. ProposalBlockParts *bits.BitArray `json:"proposal_block_parts"`
  21. // Proposal's POL round. -1 if none.
  22. ProposalPOLRound int32 `json:"proposal_pol_round"`
  23. // nil until ProposalPOLMessage received.
  24. ProposalPOL *bits.BitArray `json:"proposal_pol"`
  25. Prevotes *bits.BitArray `json:"prevotes"` // All votes peer has for this round
  26. Precommits *bits.BitArray `json:"precommits"` // All precommits peer has for this round
  27. LastCommitRound int32 `json:"last_commit_round"` // Round of commit for last height. -1 if none.
  28. LastCommit *bits.BitArray `json:"last_commit"` // All commit precommits of commit for last height.
  29. // Round that we have commit for. Not necessarily unique. -1 if none.
  30. CatchupCommitRound int32 `json:"catchup_commit_round"`
  31. // All commit precommits peer has for this height & CatchupCommitRound
  32. CatchupCommit *bits.BitArray `json:"catchup_commit"`
  33. }
  34. // String returns a string representation of the PeerRoundState
  35. func (prs PeerRoundState) String() string {
  36. return prs.StringIndented("")
  37. }
  38. // Copy provides a deep copy operation. Because many of the fields in
  39. // the PeerRound struct are pointers, we need an explicit deep copy
  40. // operation to avoid a non-obvious shared data situation.
  41. func (prs PeerRoundState) Copy() PeerRoundState {
  42. // this works because it's not a pointer receiver so it's
  43. // already, effectively a copy.
  44. headerHash := prs.ProposalBlockPartSetHeader.Hash.Bytes()
  45. hashCopy := make([]byte, len(headerHash))
  46. copy(hashCopy, headerHash)
  47. prs.ProposalBlockPartSetHeader = types.PartSetHeader{
  48. Total: prs.ProposalBlockPartSetHeader.Total,
  49. Hash: hashCopy,
  50. }
  51. prs.ProposalBlockParts = prs.ProposalBlockParts.Copy()
  52. prs.ProposalPOL = prs.ProposalPOL.Copy()
  53. prs.Prevotes = prs.Prevotes.Copy()
  54. prs.Precommits = prs.Precommits.Copy()
  55. prs.LastCommit = prs.LastCommit.Copy()
  56. prs.CatchupCommit = prs.CatchupCommit.Copy()
  57. return prs
  58. }
  59. // StringIndented returns a string representation of the PeerRoundState
  60. func (prs PeerRoundState) StringIndented(indent string) string {
  61. return fmt.Sprintf(`PeerRoundState{
  62. %s %v/%v/%v @%v
  63. %s Proposal %v -> %v
  64. %s POL %v (round %v)
  65. %s Prevotes %v
  66. %s Precommits %v
  67. %s LastCommit %v (round %v)
  68. %s Catchup %v (round %v)
  69. %s}`,
  70. indent, prs.Height, prs.Round, prs.Step, prs.StartTime,
  71. indent, prs.ProposalBlockPartSetHeader, prs.ProposalBlockParts,
  72. indent, prs.ProposalPOL, prs.ProposalPOLRound,
  73. indent, prs.Prevotes,
  74. indent, prs.Precommits,
  75. indent, prs.LastCommit, prs.LastCommitRound,
  76. indent, prs.CatchupCommit, prs.CatchupCommitRound,
  77. indent)
  78. }