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
2.0 KiB

10 years ago
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
7 years ago
  1. package types
  2. import (
  3. "errors"
  4. "fmt"
  5. "io"
  6. "time"
  7. "github.com/tendermint/go-crypto"
  8. "github.com/tendermint/go-wire"
  9. )
  10. var (
  11. ErrInvalidBlockPartSignature = errors.New("Error invalid block part signature")
  12. ErrInvalidBlockPartHash = errors.New("Error invalid block part hash")
  13. )
  14. // Proposal defines a block proposal for the consensus.
  15. // It refers to the block only by its PartSetHeader.
  16. // It must be signed by the correct proposer for the given Height/Round
  17. // to be considered valid. It may depend on votes from a previous round,
  18. // a so-called Proof-of-Lock (POL) round, as noted in the POLRound and POLBlockID.
  19. type Proposal struct {
  20. Height int64 `json:"height"`
  21. Round int `json:"round"`
  22. Timestamp time.Time `json:"timestamp"`
  23. BlockPartsHeader PartSetHeader `json:"block_parts_header"`
  24. POLRound int `json:"pol_round"` // -1 if null.
  25. POLBlockID BlockID `json:"pol_block_id"` // zero if null.
  26. Signature crypto.Signature `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. Height: height,
  33. Round: round,
  34. Timestamp: time.Now().UTC(),
  35. BlockPartsHeader: blockPartsHeader,
  36. POLRound: polRound,
  37. POLBlockID: polBlockID,
  38. }
  39. }
  40. // String returns a string representation of the Proposal.
  41. func (p *Proposal) String() string {
  42. return fmt.Sprintf("Proposal{%v/%v %v (%v,%v) %v @ %s}",
  43. p.Height, p.Round, p.BlockPartsHeader, p.POLRound,
  44. p.POLBlockID, p.Signature, CanonicalTime(p.Timestamp))
  45. }
  46. // WriteSignBytes writes the Proposal bytes for signing
  47. func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) {
  48. wire.WriteJSON(CanonicalJSONOnceProposal{
  49. ChainID: chainID,
  50. Proposal: CanonicalProposal(p),
  51. }, w, n, err)
  52. }