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.

62 lines
2.0 KiB

10 years ago
10 years ago
10 years ago
10 years ago
7 years ago
10 years ago
10 years ago
7 years ago
10 years ago
10 years ago
7 years ago
10 years ago
10 years ago
  1. package types
  2. import (
  3. "errors"
  4. "fmt"
  5. "time"
  6. "github.com/tendermint/go-crypto"
  7. "github.com/tendermint/go-wire"
  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 crypto.Signature `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: time.Now().UTC(),
  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) %v @ %s}",
  42. p.Height, p.Round, p.BlockPartsHeader, p.POLRound,
  43. p.POLBlockID, 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 := wire.MarshalJSON(CanonicalJSONOnceProposal{
  48. ChainID: chainID,
  49. Proposal: CanonicalProposal(p),
  50. })
  51. if err != nil {
  52. panic(err)
  53. }
  54. return bz
  55. }