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.

60 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. Height int64 `json:"height"`
  20. Round int `json:"round"`
  21. Timestamp time.Time `json:"timestamp"`
  22. BlockPartsHeader PartSetHeader `json:"block_parts_header"`
  23. POLRound int `json:"pol_round"` // -1 if null.
  24. POLBlockID BlockID `json:"pol_block_id"` // zero if null.
  25. Signature []byte `json:"signature"`
  26. }
  27. // NewProposal returns a new Proposal.
  28. // If there is no POLRound, polRound should be -1.
  29. func NewProposal(height int64, round int, blockPartsHeader PartSetHeader, polRound int, polBlockID BlockID) *Proposal {
  30. return &Proposal{
  31. Height: height,
  32. Round: round,
  33. Timestamp: tmtime.Now(),
  34. BlockPartsHeader: blockPartsHeader,
  35. POLRound: polRound,
  36. POLBlockID: polBlockID,
  37. }
  38. }
  39. // String returns a string representation of the Proposal.
  40. func (p *Proposal) String() string {
  41. return fmt.Sprintf("Proposal{%v/%v %v (%v,%v) %X @ %s}",
  42. p.Height, p.Round, p.BlockPartsHeader, p.POLRound,
  43. p.POLBlockID,
  44. cmn.Fingerprint(p.Signature), CanonicalTime(p.Timestamp))
  45. }
  46. // SignBytes returns the Proposal bytes for signing
  47. func (p *Proposal) SignBytes(chainID string) []byte {
  48. bz, err := cdc.MarshalJSON(CanonicalProposal(chainID, p))
  49. if err != nil {
  50. panic(err)
  51. }
  52. return bz
  53. }