2015-08-10 20:38:45 -07:00
|
|
|
package types
|
2014-09-14 15:37:32 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2014-10-25 14:27:53 -07:00
|
|
|
"fmt"
|
2014-09-14 15:37:32 -07:00
|
|
|
"io"
|
|
|
|
|
2015-11-01 11:34:08 -08:00
|
|
|
"github.com/tendermint/go-crypto"
|
2015-10-22 17:39:06 -07:00
|
|
|
"github.com/tendermint/go-wire"
|
2014-09-14 15:37:32 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ErrInvalidBlockPartSignature = errors.New("Error invalid block part signature")
|
|
|
|
ErrInvalidBlockPartHash = errors.New("Error invalid block part hash")
|
|
|
|
)
|
|
|
|
|
2017-09-22 09:00:37 -07:00
|
|
|
// Proposal defines a block proposal for the consensus.
|
|
|
|
// It refers to the block only by its PartSetHeader.
|
|
|
|
// It must be signed by the correct proposer for the given Height/Round
|
|
|
|
// to be considered valid. It may depend on votes from a previous round,
|
|
|
|
// a so-called Proof-of-Lock (POL) round, as noted in the POLRound and POLBlockID.
|
2014-09-14 15:37:32 -07:00
|
|
|
type Proposal struct {
|
2017-11-30 11:08:38 -08:00
|
|
|
Height uint64 `json:"height"`
|
2016-11-16 15:20:44 -08:00
|
|
|
Round int `json:"round"`
|
|
|
|
BlockPartsHeader PartSetHeader `json:"block_parts_header"`
|
|
|
|
POLRound int `json:"pol_round"` // -1 if null.
|
|
|
|
POLBlockID BlockID `json:"pol_block_id"` // zero if null.
|
|
|
|
Signature crypto.Signature `json:"signature"`
|
2014-09-14 15:37:32 -07:00
|
|
|
}
|
|
|
|
|
2017-09-22 09:00:37 -07:00
|
|
|
// NewProposal returns a new Proposal.
|
|
|
|
// If there is no POLRound, polRound should be -1.
|
2017-11-30 11:08:38 -08:00
|
|
|
func NewProposal(height uint64, round int, blockPartsHeader PartSetHeader, polRound int, polBlockID BlockID) *Proposal {
|
2014-09-14 15:37:32 -07:00
|
|
|
return &Proposal{
|
2015-06-22 19:04:31 -07:00
|
|
|
Height: height,
|
|
|
|
Round: round,
|
|
|
|
BlockPartsHeader: blockPartsHeader,
|
|
|
|
POLRound: polRound,
|
2016-08-20 15:08:26 -07:00
|
|
|
POLBlockID: polBlockID,
|
2014-09-14 15:37:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-22 09:00:37 -07:00
|
|
|
// String returns a string representation of the Proposal.
|
2014-10-25 14:27:53 -07:00
|
|
|
func (p *Proposal) String() string {
|
2016-08-20 15:08:26 -07:00
|
|
|
return fmt.Sprintf("Proposal{%v/%v %v (%v,%v) %v}", p.Height, p.Round,
|
|
|
|
p.BlockPartsHeader, p.POLRound, p.POLBlockID, p.Signature)
|
2014-10-25 14:27:53 -07:00
|
|
|
}
|
2014-12-09 18:49:04 -08:00
|
|
|
|
2017-09-22 09:00:37 -07:00
|
|
|
// WriteSignBytes writes the Proposal bytes for signing
|
2015-11-10 13:10:43 -08:00
|
|
|
func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) {
|
2016-12-02 02:01:47 -08:00
|
|
|
wire.WriteJSON(CanonicalJSONOnceProposal{
|
|
|
|
ChainID: chainID,
|
|
|
|
Proposal: CanonicalProposal(p),
|
|
|
|
}, w, n, err)
|
2014-12-09 18:49:04 -08:00
|
|
|
}
|