Parts -> PartsHeader; *_parts -> *_parts_header in sign_bytes
This commit is contained in:
parent
afc3e3b6c7
commit
5bf0040f14
|
@ -1177,7 +1177,7 @@ func (cs *ConsensusState) signAddVote(type_ byte, hash []byte, header types.Part
|
||||||
Round: cs.Round,
|
Round: cs.Round,
|
||||||
Type: type_,
|
Type: type_,
|
||||||
BlockHash: hash,
|
BlockHash: hash,
|
||||||
BlockParts: header,
|
BlockPartsHeader: header,
|
||||||
}
|
}
|
||||||
err := cs.privValidator.SignVote(cs.state.ChainID, vote)
|
err := cs.privValidator.SignVote(cs.state.ChainID, vote)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
@ -627,7 +627,7 @@ func TestAddValidator(t *testing.T) {
|
||||||
Round: 0,
|
Round: 0,
|
||||||
Type: types.VoteTypePrecommit,
|
Type: types.VoteTypePrecommit,
|
||||||
BlockHash: block0.Hash(),
|
BlockHash: block0.Hash(),
|
||||||
BlockParts: block0Parts.Header(),
|
BlockPartsHeader: block0Parts.Header(),
|
||||||
}
|
}
|
||||||
privValidators[0].SignVote(s0.ChainID, precommit0)
|
privValidators[0].SignVote(s0.ChainID, precommit0)
|
||||||
|
|
||||||
|
|
|
@ -237,7 +237,7 @@ func (valSet *ValidatorSet) VerifyValidation(chainID string,
|
||||||
if !bytes.Equal(precommit.BlockHash, hash) {
|
if !bytes.Equal(precommit.BlockHash, hash) {
|
||||||
continue // Not an error, but doesn't count
|
continue // Not an error, but doesn't count
|
||||||
}
|
}
|
||||||
if !parts.Equals(precommit.BlockParts) {
|
if !parts.Equals(precommit.BlockPartsHeader) {
|
||||||
continue // Not an error, but doesn't count
|
continue // Not an error, but doesn't count
|
||||||
}
|
}
|
||||||
// Good precommit!
|
// Good precommit!
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/wire"
|
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
|
"github.com/tendermint/tendermint/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -32,7 +32,7 @@ type Vote struct {
|
||||||
Round int `json:"round"`
|
Round int `json:"round"`
|
||||||
Type byte `json:"type"`
|
Type byte `json:"type"`
|
||||||
BlockHash []byte `json:"block_hash"` // empty if vote is nil.
|
BlockHash []byte `json:"block_hash"` // empty if vote is nil.
|
||||||
BlockParts PartSetHeader `json:"block_parts"` // zero if vote is nil.
|
BlockPartsHeader PartSetHeader `json:"block_parts_header"` // zero if vote is nil.
|
||||||
Signature acm.SignatureEd25519 `json:"signature"`
|
Signature acm.SignatureEd25519 `json:"signature"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ const (
|
||||||
|
|
||||||
func (vote *Vote) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
func (vote *Vote) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
||||||
wire.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
|
wire.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
|
||||||
wire.WriteTo([]byte(Fmt(`,"vote":{"block_hash":"%X","block_parts":%v`, vote.BlockHash, vote.BlockParts)), w, n, err)
|
wire.WriteTo([]byte(Fmt(`,"vote":{"block_hash":"%X","block_parts_header":%v`, vote.BlockHash, vote.BlockPartsHeader)), w, n, err)
|
||||||
wire.WriteTo([]byte(Fmt(`,"height":%v,"round":%v,"type":%v}}`, vote.Height, vote.Round, vote.Type)), w, n, err)
|
wire.WriteTo([]byte(Fmt(`,"height":%v,"round":%v,"type":%v}}`, vote.Height, vote.Round, vote.Type)), w, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ func (vote *Vote) String() string {
|
||||||
PanicSanity("Unknown vote type")
|
PanicSanity("Unknown vote type")
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("Vote{%v/%02d/%v(%v) %X#%v %v}", vote.Height, vote.Round, vote.Type, typeString, Fingerprint(vote.BlockHash), vote.BlockParts, vote.Signature)
|
return fmt.Sprintf("Vote{%v/%02d/%v(%v) %X#%v %v}", vote.Height, vote.Round, vote.Type, typeString, Fingerprint(vote.BlockHash), vote.BlockPartsHeader, vote.Signature)
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
|
|
|
@ -28,7 +28,7 @@ type VoteSet struct {
|
||||||
votesByBlock map[string]int64 // string(blockHash)+string(blockParts) -> vote sum.
|
votesByBlock map[string]int64 // string(blockHash)+string(blockParts) -> vote sum.
|
||||||
totalVotes int64
|
totalVotes int64
|
||||||
maj23Hash []byte
|
maj23Hash []byte
|
||||||
maj23Parts PartSetHeader
|
maj23PartsHeader PartSetHeader
|
||||||
maj23Exists bool
|
maj23Exists bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ func (voteSet *VoteSet) addVote(val *Validator, valIndex int, vote *Vote) (bool,
|
||||||
// Add vote.
|
// Add vote.
|
||||||
voteSet.votes[valIndex] = vote
|
voteSet.votes[valIndex] = vote
|
||||||
voteSet.votesBitArray.SetIndex(valIndex, true)
|
voteSet.votesBitArray.SetIndex(valIndex, true)
|
||||||
blockKey := string(vote.BlockHash) + string(wire.BinaryBytes(vote.BlockParts))
|
blockKey := string(vote.BlockHash) + string(wire.BinaryBytes(vote.BlockPartsHeader))
|
||||||
totalBlockHashVotes := voteSet.votesByBlock[blockKey] + val.VotingPower
|
totalBlockHashVotes := voteSet.votesByBlock[blockKey] + val.VotingPower
|
||||||
voteSet.votesByBlock[blockKey] = totalBlockHashVotes
|
voteSet.votesByBlock[blockKey] = totalBlockHashVotes
|
||||||
voteSet.totalVotes += val.VotingPower
|
voteSet.totalVotes += val.VotingPower
|
||||||
|
@ -158,7 +158,7 @@ func (voteSet *VoteSet) addVote(val *Validator, valIndex int, vote *Vote) (bool,
|
||||||
if totalBlockHashVotes > voteSet.valSet.TotalVotingPower()*2/3 &&
|
if totalBlockHashVotes > voteSet.valSet.TotalVotingPower()*2/3 &&
|
||||||
(totalBlockHashVotes-val.VotingPower) <= voteSet.valSet.TotalVotingPower()*2/3 {
|
(totalBlockHashVotes-val.VotingPower) <= voteSet.valSet.TotalVotingPower()*2/3 {
|
||||||
voteSet.maj23Hash = vote.BlockHash
|
voteSet.maj23Hash = vote.BlockHash
|
||||||
voteSet.maj23Parts = vote.BlockParts
|
voteSet.maj23PartsHeader = vote.BlockPartsHeader
|
||||||
voteSet.maj23Exists = true
|
voteSet.maj23Exists = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ func (voteSet *VoteSet) TwoThirdsMajority() (hash []byte, parts PartSetHeader, o
|
||||||
voteSet.mtx.Lock()
|
voteSet.mtx.Lock()
|
||||||
defer voteSet.mtx.Unlock()
|
defer voteSet.mtx.Unlock()
|
||||||
if voteSet.maj23Exists {
|
if voteSet.maj23Exists {
|
||||||
return voteSet.maj23Hash, voteSet.maj23Parts, true
|
return voteSet.maj23Hash, voteSet.maj23PartsHeader, true
|
||||||
} else {
|
} else {
|
||||||
return nil, PartSetHeader{}, false
|
return nil, PartSetHeader{}, false
|
||||||
}
|
}
|
||||||
|
@ -287,7 +287,7 @@ func (voteSet *VoteSet) MakeValidation() *Validation {
|
||||||
if !bytes.Equal(vote.BlockHash, voteSet.maj23Hash) {
|
if !bytes.Equal(vote.BlockHash, voteSet.maj23Hash) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !vote.BlockParts.Equals(voteSet.maj23Parts) {
|
if !vote.BlockPartsHeader.Equals(voteSet.maj23PartsHeader) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
precommits[valIndex] = vote
|
precommits[valIndex] = vote
|
||||||
|
|
|
@ -53,9 +53,9 @@ func withBlockHash(vote *Vote, blockHash []byte) *Vote {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convenience: Return new vote with different blockParts
|
// Convenience: Return new vote with different blockParts
|
||||||
func withBlockParts(vote *Vote, blockParts PartSetHeader) *Vote {
|
func withBlockPartsHeader(vote *Vote, blockPartsHeader PartSetHeader) *Vote {
|
||||||
vote = vote.Copy()
|
vote = vote.Copy()
|
||||||
vote.BlockParts = blockParts
|
vote.BlockPartsHeader = blockPartsHeader
|
||||||
return vote
|
return vote
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,9 +138,9 @@ func Test2_3MajorityRedux(t *testing.T) {
|
||||||
|
|
||||||
blockHash := CRandBytes(32)
|
blockHash := CRandBytes(32)
|
||||||
blockPartsTotal := 123
|
blockPartsTotal := 123
|
||||||
blockParts := PartSetHeader{blockPartsTotal, CRandBytes(32)}
|
blockPartsHeader := PartSetHeader{blockPartsTotal, CRandBytes(32)}
|
||||||
|
|
||||||
vote := &Vote{Height: height, Round: round, Type: VoteTypePrevote, BlockHash: blockHash, BlockParts: blockParts}
|
vote := &Vote{Height: height, Round: round, Type: VoteTypePrevote, BlockHash: blockHash, BlockPartsHeader: blockPartsHeader}
|
||||||
|
|
||||||
// 66 out of 100 voted for nil.
|
// 66 out of 100 voted for nil.
|
||||||
for i := 0; i < 66; i++ {
|
for i := 0; i < 66; i++ {
|
||||||
|
@ -162,8 +162,8 @@ func Test2_3MajorityRedux(t *testing.T) {
|
||||||
|
|
||||||
// 68th validator voted for a different BlockParts PartSetHeader
|
// 68th validator voted for a different BlockParts PartSetHeader
|
||||||
{
|
{
|
||||||
blockParts := PartSetHeader{blockPartsTotal, CRandBytes(32)}
|
blockPartsHeader := PartSetHeader{blockPartsTotal, CRandBytes(32)}
|
||||||
signAddVote(privValidators[67], withBlockParts(vote, blockParts), voteSet)
|
signAddVote(privValidators[67], withBlockPartsHeader(vote, blockPartsHeader), voteSet)
|
||||||
hash, header, ok = voteSet.TwoThirdsMajority()
|
hash, header, ok = voteSet.TwoThirdsMajority()
|
||||||
if hash != nil || !header.IsZero() || ok {
|
if hash != nil || !header.IsZero() || ok {
|
||||||
t.Errorf("There should be no 2/3 majority: last vote added had different PartSetHeader Hash")
|
t.Errorf("There should be no 2/3 majority: last vote added had different PartSetHeader Hash")
|
||||||
|
@ -172,8 +172,8 @@ func Test2_3MajorityRedux(t *testing.T) {
|
||||||
|
|
||||||
// 69th validator voted for different BlockParts Total
|
// 69th validator voted for different BlockParts Total
|
||||||
{
|
{
|
||||||
blockParts := PartSetHeader{blockPartsTotal + 1, blockParts.Hash}
|
blockPartsHeader := PartSetHeader{blockPartsTotal + 1, blockPartsHeader.Hash}
|
||||||
signAddVote(privValidators[68], withBlockParts(vote, blockParts), voteSet)
|
signAddVote(privValidators[68], withBlockPartsHeader(vote, blockPartsHeader), voteSet)
|
||||||
hash, header, ok = voteSet.TwoThirdsMajority()
|
hash, header, ok = voteSet.TwoThirdsMajority()
|
||||||
if hash != nil || !header.IsZero() || ok {
|
if hash != nil || !header.IsZero() || ok {
|
||||||
t.Errorf("There should be no 2/3 majority: last vote added had different PartSetHeader Total")
|
t.Errorf("There should be no 2/3 majority: last vote added had different PartSetHeader Total")
|
||||||
|
@ -189,11 +189,11 @@ func Test2_3MajorityRedux(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 71st validator voted for the right BlockHash & BlockParts
|
// 71st validator voted for the right BlockHash & BlockPartsHeader
|
||||||
{
|
{
|
||||||
signAddVote(privValidators[70], vote, voteSet)
|
signAddVote(privValidators[70], vote, voteSet)
|
||||||
hash, header, ok = voteSet.TwoThirdsMajority()
|
hash, header, ok = voteSet.TwoThirdsMajority()
|
||||||
if !bytes.Equal(hash, blockHash) || !header.Equals(blockParts) || !ok {
|
if !bytes.Equal(hash, blockHash) || !header.Equals(blockPartsHeader) || !ok {
|
||||||
t.Errorf("There should be 2/3 majority")
|
t.Errorf("There should be 2/3 majority")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -238,10 +238,10 @@ func TestBadVotes(t *testing.T) {
|
||||||
func TestMakeValidation(t *testing.T) {
|
func TestMakeValidation(t *testing.T) {
|
||||||
height, round := 1, 0
|
height, round := 1, 0
|
||||||
voteSet, _, privValidators := randVoteSet(height, round, VoteTypePrecommit, 10, 1)
|
voteSet, _, privValidators := randVoteSet(height, round, VoteTypePrecommit, 10, 1)
|
||||||
blockHash, blockParts := CRandBytes(32), PartSetHeader{123, CRandBytes(32)}
|
blockHash, blockPartsHeader := CRandBytes(32), PartSetHeader{123, CRandBytes(32)}
|
||||||
|
|
||||||
vote := &Vote{Height: height, Round: round, Type: VoteTypePrecommit,
|
vote := &Vote{Height: height, Round: round, Type: VoteTypePrecommit,
|
||||||
BlockHash: blockHash, BlockParts: blockParts}
|
BlockHash: blockHash, BlockPartsHeader: blockPartsHeader}
|
||||||
|
|
||||||
// 6 out of 10 voted for some block.
|
// 6 out of 10 voted for some block.
|
||||||
for i := 0; i < 6; i++ {
|
for i := 0; i < 6; i++ {
|
||||||
|
@ -254,7 +254,7 @@ func TestMakeValidation(t *testing.T) {
|
||||||
// 7th voted for some other block.
|
// 7th voted for some other block.
|
||||||
{
|
{
|
||||||
vote := withBlockHash(vote, RandBytes(32))
|
vote := withBlockHash(vote, RandBytes(32))
|
||||||
vote = withBlockParts(vote, PartSetHeader{123, RandBytes(32)})
|
vote = withBlockPartsHeader(vote, PartSetHeader{123, RandBytes(32)})
|
||||||
signAddVote(privValidators[6], vote, voteSet)
|
signAddVote(privValidators[6], vote, voteSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue