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.

55 lines
1.8 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
7 years ago
  1. package types
  2. import (
  3. "errors"
  4. "fmt"
  5. "io"
  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 int `json:"height"`
  20. Round int `json:"round"`
  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 crypto.Signature `json:"signature"`
  25. }
  26. // NewProposal returns a new Proposal.
  27. // If there is no POLRound, polRound should be -1.
  28. func NewProposal(height int, round int, blockPartsHeader PartSetHeader, polRound int, polBlockID BlockID) *Proposal {
  29. return &Proposal{
  30. Height: height,
  31. Round: round,
  32. BlockPartsHeader: blockPartsHeader,
  33. POLRound: polRound,
  34. POLBlockID: polBlockID,
  35. }
  36. }
  37. // String returns a string representation of the Proposal.
  38. func (p *Proposal) String() string {
  39. return fmt.Sprintf("Proposal{%v/%v %v (%v,%v) %v}", p.Height, p.Round,
  40. p.BlockPartsHeader, p.POLRound, p.POLBlockID, p.Signature)
  41. }
  42. // WriteSignBytes writes the Proposal bytes for signing
  43. func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) {
  44. wire.WriteJSON(CanonicalJSONOnceProposal{
  45. ChainID: chainID,
  46. Proposal: CanonicalProposal(p),
  47. }, w, n, err)
  48. }