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.

66 lines
2.0 KiB

  1. package types
  2. import (
  3. "errors"
  4. "fmt"
  5. "time"
  6. cmn "github.com/tendermint/tendermint/libs/common"
  7. tmtime "github.com/tendermint/tendermint/types/time"
  8. )
  9. var (
  10. ErrInvalidBlockPartSignature = errors.New("Error invalid block part signature")
  11. ErrInvalidBlockPartHash = errors.New("Error invalid block part hash")
  12. )
  13. // Proposal defines a block proposal for the consensus.
  14. // It refers to the block only by its PartSetHeader.
  15. // It must be signed by the correct proposer for the given Height/Round
  16. // to be considered valid. It may depend on votes from a previous round,
  17. // a so-called Proof-of-Lock (POL) round, as noted in the POLRound and POLBlockID.
  18. type Proposal struct {
  19. Type SignedMsgType
  20. Height int64 `json:"height"`
  21. Round int `json:"round"`
  22. POLRound int `json:"pol_round"` // -1 if null.
  23. Timestamp time.Time `json:"timestamp"`
  24. BlockPartsHeader PartSetHeader `json:"block_parts_header"`
  25. POLBlockID BlockID `json:"pol_block_id"` // zero if null.
  26. Signature []byte `json:"signature"`
  27. }
  28. // NewProposal returns a new Proposal.
  29. // If there is no POLRound, polRound should be -1.
  30. func NewProposal(height int64, round int, blockPartsHeader PartSetHeader, polRound int, polBlockID BlockID) *Proposal {
  31. return &Proposal{
  32. Type: ProposalType,
  33. Height: height,
  34. Round: round,
  35. POLRound: polRound,
  36. Timestamp: tmtime.Now(),
  37. BlockPartsHeader: blockPartsHeader,
  38. POLBlockID: polBlockID,
  39. }
  40. }
  41. // String returns a string representation of the Proposal.
  42. func (p *Proposal) String() string {
  43. return fmt.Sprintf("Proposal{%v/%v %v (%v,%v) %X @ %s}",
  44. p.Height,
  45. p.Round,
  46. p.BlockPartsHeader,
  47. p.POLRound,
  48. p.POLBlockID,
  49. cmn.Fingerprint(p.Signature),
  50. CanonicalTime(p.Timestamp))
  51. }
  52. // SignBytes returns the Proposal bytes for signing
  53. func (p *Proposal) SignBytes(chainID string) []byte {
  54. bz, err := cdc.MarshalBinaryLengthPrefixed(CanonicalizeProposal(chainID, p))
  55. if err != nil {
  56. panic(err)
  57. }
  58. return bz
  59. }