tendermint/types/proposal.go

56 lines
1.8 KiB
Go
Raw Normal View History

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"
"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 {
2016-11-16 15:20:44 -08: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 09:00:37 -07:00
// NewProposal returns a new Proposal.
// If there is no POLRound, polRound should be -1.
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,
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 {
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
}
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)
}