|
|
@ -49,14 +49,14 @@ func withType(vote *Vote, type_ byte) *Vote { |
|
|
|
// Convenience: Return new vote with different blockHash
|
|
|
|
func withBlockHash(vote *Vote, blockHash []byte) *Vote { |
|
|
|
vote = vote.Copy() |
|
|
|
vote.BlockHash = blockHash |
|
|
|
vote.BlockID.Hash = blockHash |
|
|
|
return vote |
|
|
|
} |
|
|
|
|
|
|
|
// Convenience: Return new vote with different blockParts
|
|
|
|
func withBlockPartsHeader(vote *Vote, blockPartsHeader PartSetHeader) *Vote { |
|
|
|
vote = vote.Copy() |
|
|
|
vote.BlockPartsHeader = blockPartsHeader |
|
|
|
vote.BlockID.PartsHeader = blockPartsHeader |
|
|
|
return vote |
|
|
|
} |
|
|
|
|
|
|
@ -79,8 +79,8 @@ func TestAddVote(t *testing.T) { |
|
|
|
if voteSet.BitArray().GetIndex(0) { |
|
|
|
t.Errorf("Expected BitArray.GetIndex(0) to be false") |
|
|
|
} |
|
|
|
hash, header, ok := voteSet.TwoThirdsMajority() |
|
|
|
if hash != nil || !header.IsZero() || ok { |
|
|
|
blockID, ok := voteSet.TwoThirdsMajority() |
|
|
|
if ok || !blockID.IsZero() { |
|
|
|
t.Errorf("There should be no 2/3 majority") |
|
|
|
} |
|
|
|
|
|
|
@ -90,7 +90,7 @@ func TestAddVote(t *testing.T) { |
|
|
|
Height: height, |
|
|
|
Round: round, |
|
|
|
Type: VoteTypePrevote, |
|
|
|
BlockHash: nil, |
|
|
|
BlockID: BlockID{nil, PartSetHeader{}}, |
|
|
|
} |
|
|
|
signAddVote(val0, vote, voteSet) |
|
|
|
|
|
|
@ -100,8 +100,8 @@ func TestAddVote(t *testing.T) { |
|
|
|
if !voteSet.BitArray().GetIndex(0) { |
|
|
|
t.Errorf("Expected BitArray.GetIndex(0) to be true") |
|
|
|
} |
|
|
|
hash, header, ok = voteSet.TwoThirdsMajority() |
|
|
|
if hash != nil || !header.IsZero() || ok { |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
if ok || !blockID.IsZero() { |
|
|
|
t.Errorf("There should be no 2/3 majority") |
|
|
|
} |
|
|
|
} |
|
|
@ -116,15 +116,15 @@ func Test2_3Majority(t *testing.T) { |
|
|
|
Height: height, |
|
|
|
Round: round, |
|
|
|
Type: VoteTypePrevote, |
|
|
|
BlockHash: nil, |
|
|
|
BlockID: BlockID{nil, PartSetHeader{}}, |
|
|
|
} |
|
|
|
// 6 out of 10 voted for nil.
|
|
|
|
for i := 0; i < 6; i++ { |
|
|
|
vote := withValidator(voteProto, privValidators[i].Address, i) |
|
|
|
signAddVote(privValidators[i], vote, voteSet) |
|
|
|
} |
|
|
|
hash, header, ok := voteSet.TwoThirdsMajority() |
|
|
|
if hash != nil || !header.IsZero() || ok { |
|
|
|
blockID, ok := voteSet.TwoThirdsMajority() |
|
|
|
if ok || !blockID.IsZero() { |
|
|
|
t.Errorf("There should be no 2/3 majority") |
|
|
|
} |
|
|
|
|
|
|
@ -132,8 +132,8 @@ func Test2_3Majority(t *testing.T) { |
|
|
|
{ |
|
|
|
vote := withValidator(voteProto, privValidators[6].Address, 6) |
|
|
|
signAddVote(privValidators[6], withBlockHash(vote, RandBytes(32)), voteSet) |
|
|
|
hash, header, ok = voteSet.TwoThirdsMajority() |
|
|
|
if hash != nil || !header.IsZero() || ok { |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
if ok || !blockID.IsZero() { |
|
|
|
t.Errorf("There should be no 2/3 majority") |
|
|
|
} |
|
|
|
} |
|
|
@ -142,8 +142,8 @@ func Test2_3Majority(t *testing.T) { |
|
|
|
{ |
|
|
|
vote := withValidator(voteProto, privValidators[7].Address, 7) |
|
|
|
signAddVote(privValidators[7], vote, voteSet) |
|
|
|
hash, header, ok = voteSet.TwoThirdsMajority() |
|
|
|
if hash != nil || !header.IsZero() || !ok { |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
if !ok || !blockID.IsZero() { |
|
|
|
t.Errorf("There should be 2/3 majority for nil") |
|
|
|
} |
|
|
|
} |
|
|
@ -163,8 +163,7 @@ func Test2_3MajorityRedux(t *testing.T) { |
|
|
|
Height: height, |
|
|
|
Round: round, |
|
|
|
Type: VoteTypePrevote, |
|
|
|
BlockHash: blockHash, |
|
|
|
BlockPartsHeader: blockPartsHeader, |
|
|
|
BlockID: BlockID{blockHash, blockPartsHeader}, |
|
|
|
} |
|
|
|
|
|
|
|
// 66 out of 100 voted for nil.
|
|
|
@ -172,8 +171,8 @@ func Test2_3MajorityRedux(t *testing.T) { |
|
|
|
vote := withValidator(voteProto, privValidators[i].Address, i) |
|
|
|
signAddVote(privValidators[i], vote, voteSet) |
|
|
|
} |
|
|
|
hash, header, ok := voteSet.TwoThirdsMajority() |
|
|
|
if hash != nil || !header.IsZero() || ok { |
|
|
|
blockID, ok := voteSet.TwoThirdsMajority() |
|
|
|
if ok || !blockID.IsZero() { |
|
|
|
t.Errorf("There should be no 2/3 majority") |
|
|
|
} |
|
|
|
|
|
|
@ -181,8 +180,8 @@ func Test2_3MajorityRedux(t *testing.T) { |
|
|
|
{ |
|
|
|
vote := withValidator(voteProto, privValidators[66].Address, 66) |
|
|
|
signAddVote(privValidators[66], withBlockHash(vote, nil), voteSet) |
|
|
|
hash, header, ok = voteSet.TwoThirdsMajority() |
|
|
|
if hash != nil || !header.IsZero() || ok { |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
if ok || !blockID.IsZero() { |
|
|
|
t.Errorf("There should be no 2/3 majority: last vote added was nil") |
|
|
|
} |
|
|
|
} |
|
|
@ -192,8 +191,8 @@ func Test2_3MajorityRedux(t *testing.T) { |
|
|
|
vote := withValidator(voteProto, privValidators[67].Address, 67) |
|
|
|
blockPartsHeader := PartSetHeader{blockPartsTotal, crypto.CRandBytes(32)} |
|
|
|
signAddVote(privValidators[67], withBlockPartsHeader(vote, blockPartsHeader), voteSet) |
|
|
|
hash, header, ok = voteSet.TwoThirdsMajority() |
|
|
|
if hash != nil || !header.IsZero() || ok { |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
if ok || !blockID.IsZero() { |
|
|
|
t.Errorf("There should be no 2/3 majority: last vote added had different PartSetHeader Hash") |
|
|
|
} |
|
|
|
} |
|
|
@ -203,8 +202,8 @@ func Test2_3MajorityRedux(t *testing.T) { |
|
|
|
vote := withValidator(voteProto, privValidators[68].Address, 68) |
|
|
|
blockPartsHeader := PartSetHeader{blockPartsTotal + 1, blockPartsHeader.Hash} |
|
|
|
signAddVote(privValidators[68], withBlockPartsHeader(vote, blockPartsHeader), voteSet) |
|
|
|
hash, header, ok = voteSet.TwoThirdsMajority() |
|
|
|
if hash != nil || !header.IsZero() || ok { |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
if ok || !blockID.IsZero() { |
|
|
|
t.Errorf("There should be no 2/3 majority: last vote added had different PartSetHeader Total") |
|
|
|
} |
|
|
|
} |
|
|
@ -213,8 +212,8 @@ func Test2_3MajorityRedux(t *testing.T) { |
|
|
|
{ |
|
|
|
vote := withValidator(voteProto, privValidators[69].Address, 69) |
|
|
|
signAddVote(privValidators[69], withBlockHash(vote, RandBytes(32)), voteSet) |
|
|
|
hash, header, ok = voteSet.TwoThirdsMajority() |
|
|
|
if hash != nil || !header.IsZero() || ok { |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
if ok || !blockID.IsZero() { |
|
|
|
t.Errorf("There should be no 2/3 majority: last vote added had different BlockHash") |
|
|
|
} |
|
|
|
} |
|
|
@ -223,8 +222,8 @@ func Test2_3MajorityRedux(t *testing.T) { |
|
|
|
{ |
|
|
|
vote := withValidator(voteProto, privValidators[70].Address, 70) |
|
|
|
signAddVote(privValidators[70], vote, voteSet) |
|
|
|
hash, header, ok = voteSet.TwoThirdsMajority() |
|
|
|
if !bytes.Equal(hash, blockHash) || !header.Equals(blockPartsHeader) || !ok { |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
if !ok || !blockID.Equals(BlockID{blockHash, blockPartsHeader}) { |
|
|
|
t.Errorf("There should be 2/3 majority") |
|
|
|
} |
|
|
|
} |
|
|
@ -240,7 +239,7 @@ func TestBadVotes(t *testing.T) { |
|
|
|
Height: height, |
|
|
|
Round: round, |
|
|
|
Type: VoteTypePrevote, |
|
|
|
BlockHash: nil, |
|
|
|
BlockID: BlockID{nil, PartSetHeader{}}, |
|
|
|
} |
|
|
|
|
|
|
|
// val0 votes for nil.
|
|
|
@ -301,7 +300,7 @@ func TestConflicts(t *testing.T) { |
|
|
|
Height: height, |
|
|
|
Round: round, |
|
|
|
Type: VoteTypePrevote, |
|
|
|
BlockHash: nil, |
|
|
|
BlockID: BlockID{nil, PartSetHeader{}}, |
|
|
|
} |
|
|
|
|
|
|
|
// val0 votes for nil.
|
|
|
@ -326,7 +325,7 @@ func TestConflicts(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
// start tracking blockHash1
|
|
|
|
voteSet.SetPeerMaj23("peerA", blockHash1, PartSetHeader{}) |
|
|
|
voteSet.SetPeerMaj23("peerA", BlockID{blockHash1, PartSetHeader{}}) |
|
|
|
|
|
|
|
// val0 votes again for blockHash1.
|
|
|
|
{ |
|
|
@ -341,7 +340,7 @@ func TestConflicts(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
// attempt tracking blockHash2, should fail because already set for peerA.
|
|
|
|
voteSet.SetPeerMaj23("peerA", blockHash2, PartSetHeader{}) |
|
|
|
voteSet.SetPeerMaj23("peerA", BlockID{blockHash2, PartSetHeader{}}) |
|
|
|
|
|
|
|
// val0 votes again for blockHash1.
|
|
|
|
{ |
|
|
@ -390,7 +389,7 @@ func TestConflicts(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
// now attempt tracking blockHash1
|
|
|
|
voteSet.SetPeerMaj23("peerB", blockHash1, PartSetHeader{}) |
|
|
|
voteSet.SetPeerMaj23("peerB", BlockID{blockHash1, PartSetHeader{}}) |
|
|
|
|
|
|
|
// val2 votes for blockHash1.
|
|
|
|
{ |
|
|
@ -408,8 +407,8 @@ func TestConflicts(t *testing.T) { |
|
|
|
if !voteSet.HasTwoThirdsMajority() { |
|
|
|
t.Errorf("We should have 2/3 majority for blockHash1") |
|
|
|
} |
|
|
|
blockHash23maj, _, _ := voteSet.TwoThirdsMajority() |
|
|
|
if !bytes.Equal(blockHash23maj, blockHash1) { |
|
|
|
blockIDMaj23, _ := voteSet.TwoThirdsMajority() |
|
|
|
if !bytes.Equal(blockIDMaj23.Hash, blockHash1) { |
|
|
|
t.Errorf("Got the wrong 2/3 majority blockhash") |
|
|
|
} |
|
|
|
if !voteSet.HasTwoThirdsAny() { |
|
|
@ -429,8 +428,7 @@ func TestMakeCommit(t *testing.T) { |
|
|
|
Height: height, |
|
|
|
Round: round, |
|
|
|
Type: VoteTypePrecommit, |
|
|
|
BlockHash: blockHash, |
|
|
|
BlockPartsHeader: blockPartsHeader, |
|
|
|
BlockID: BlockID{blockHash, blockPartsHeader}, |
|
|
|
} |
|
|
|
|
|
|
|
// 6 out of 10 voted for some block.
|
|
|
|