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.

67 lines
1.8 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. package block
  2. import (
  3. "errors"
  4. "fmt"
  5. "io"
  6. . "github.com/tendermint/tendermint/account"
  7. . "github.com/tendermint/tendermint/binary"
  8. . "github.com/tendermint/tendermint/common"
  9. )
  10. var (
  11. ErrVoteUnexpectedStep = errors.New("Unexpected step")
  12. ErrVoteInvalidAccount = errors.New("Invalid round vote account")
  13. ErrVoteInvalidSignature = errors.New("Invalid round vote signature")
  14. ErrVoteInvalidBlockHash = errors.New("Invalid block hash")
  15. ErrVoteConflictingSignature = errors.New("Conflicting round vote signature")
  16. )
  17. // Represents a prevote, precommit, or commit vote from validators for consensus.
  18. // Commit votes get aggregated into the next block's Validaiton.
  19. // See the whitepaper for details.
  20. type Vote struct {
  21. Height uint
  22. Round uint
  23. Type byte
  24. BlockHash []byte // empty if vote is nil.
  25. BlockParts PartSetHeader // zero if vote is nil.
  26. Signature SignatureEd25519
  27. }
  28. // Types of votes
  29. const (
  30. VoteTypePrevote = byte(0x00)
  31. VoteTypePrecommit = byte(0x01)
  32. VoteTypeCommit = byte(0x02)
  33. )
  34. func (vote *Vote) WriteSignBytes(w io.Writer, n *int64, err *error) {
  35. WriteUvarint(vote.Height, w, n, err)
  36. WriteUvarint(vote.Round, w, n, err)
  37. WriteByte(vote.Type, w, n, err)
  38. WriteByteSlice(vote.BlockHash, w, n, err)
  39. WriteBinary(vote.BlockParts, w, n, err)
  40. }
  41. func (vote *Vote) Copy() *Vote {
  42. voteCopy := *vote
  43. return &voteCopy
  44. }
  45. func (vote *Vote) String() string {
  46. var typeString string
  47. switch vote.Type {
  48. case VoteTypePrevote:
  49. typeString = "Prevote"
  50. case VoteTypePrecommit:
  51. typeString = "Precommit"
  52. case VoteTypeCommit:
  53. typeString = "Commit"
  54. default:
  55. panic("Unknown vote type")
  56. }
  57. return fmt.Sprintf("%v{%v/%v %X#%v %v}", typeString, vote.Height, vote.Round, Fingerprint(vote.BlockHash), vote.BlockParts, vote.Signature)
  58. }