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 12:00:37 -04: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 {
|
2016-11-16 17:20:44 -06:00
|
|
|
Height int `json:"height"`
|
|
|
|
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 12:00:37 -04:00
|
|
|
// NewProposal returns a new Proposal.
|
|
|
|
// If there is no POLRound, polRound should be -1.
|
2016-08-20 15:08:26 -07:00
|
|
|
func NewProposal(height int, 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 12:00:37 -04: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 12:00:37 -04: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 05:01:47 -05:00
|
|
|
wire.WriteJSON(CanonicalJSONOnceProposal{
|
|
|
|
ChainID: chainID,
|
|
|
|
Proposal: CanonicalProposal(p),
|
|
|
|
}, w, n, err)
|
2014-12-09 18:49:04 -08:00
|
|
|
}
|