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.

59 lines
1.9 KiB

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