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.

56 lines
1.9 KiB

10 years ago
10 years ago
10 years ago
8 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/tmlibs/common"
  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 int `json:"height"`
  21. Round int `json:"round"`
  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 int, round int, blockPartsHeader PartSetHeader, polRound int, polBlockID BlockID) *Proposal {
  30. return &Proposal{
  31. Height: height,
  32. Round: round,
  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) %v}", p.Height, p.Round,
  41. p.BlockPartsHeader, p.POLRound, p.POLBlockID, p.Signature)
  42. }
  43. // WriteSignBytes writes the Proposal bytes for signing
  44. func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) {
  45. wire.WriteJSON(CanonicalJSONOnceProposal{
  46. ChainID: chainID,
  47. Proposal: CanonicalProposal(p),
  48. }, w, n, err)
  49. }