|
@ -333,6 +333,7 @@ func TestSimulateValidatorsChange(t *testing.T) { |
|
|
vss[i] = newValidatorStub(css[i].privValidator, i) |
|
|
vss[i] = newValidatorStub(css[i].privValidator, i) |
|
|
} |
|
|
} |
|
|
height, round := css[0].Height, css[0].Round |
|
|
height, round := css[0].Height, css[0].Round |
|
|
|
|
|
|
|
|
// start the machine
|
|
|
// start the machine
|
|
|
startTestRound(css[0], height, round) |
|
|
startTestRound(css[0], height, round) |
|
|
incrementHeight(vss...) |
|
|
incrementHeight(vss...) |
|
@ -342,7 +343,9 @@ func TestSimulateValidatorsChange(t *testing.T) { |
|
|
signAddVotes(css[0], types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...) |
|
|
signAddVotes(css[0], types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...) |
|
|
ensureNewRound(newRoundCh, height+1, 0) |
|
|
ensureNewRound(newRoundCh, height+1, 0) |
|
|
|
|
|
|
|
|
//height 2
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
// HEIGHT 2
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
height++ |
|
|
height++ |
|
|
incrementHeight(vss...) |
|
|
incrementHeight(vss...) |
|
|
newValidatorPubKey1, err := css[nVals].privValidator.GetPubKey() |
|
|
newValidatorPubKey1, err := css[nVals].privValidator.GetPubKey() |
|
@ -368,7 +371,9 @@ func TestSimulateValidatorsChange(t *testing.T) { |
|
|
signAddVotes(css[0], types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...) |
|
|
signAddVotes(css[0], types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...) |
|
|
ensureNewRound(newRoundCh, height+1, 0) |
|
|
ensureNewRound(newRoundCh, height+1, 0) |
|
|
|
|
|
|
|
|
//height 3
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
// HEIGHT 3
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
height++ |
|
|
height++ |
|
|
incrementHeight(vss...) |
|
|
incrementHeight(vss...) |
|
|
updateValidatorPubKey1, err := css[nVals].privValidator.GetPubKey() |
|
|
updateValidatorPubKey1, err := css[nVals].privValidator.GetPubKey() |
|
@ -394,7 +399,9 @@ func TestSimulateValidatorsChange(t *testing.T) { |
|
|
signAddVotes(css[0], types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...) |
|
|
signAddVotes(css[0], types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...) |
|
|
ensureNewRound(newRoundCh, height+1, 0) |
|
|
ensureNewRound(newRoundCh, height+1, 0) |
|
|
|
|
|
|
|
|
//height 4
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
// HEIGHT 4
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
height++ |
|
|
height++ |
|
|
incrementHeight(vss...) |
|
|
incrementHeight(vss...) |
|
|
newValidatorPubKey2, err := css[nVals+1].privValidator.GetPubKey() |
|
|
newValidatorPubKey2, err := css[nVals+1].privValidator.GetPubKey() |
|
@ -414,21 +421,25 @@ func TestSimulateValidatorsChange(t *testing.T) { |
|
|
blockID = types.BlockID{Hash: propBlock.Hash(), PartsHeader: propBlockParts.Header()} |
|
|
blockID = types.BlockID{Hash: propBlock.Hash(), PartsHeader: propBlockParts.Header()} |
|
|
newVss := make([]*validatorStub, nVals+1) |
|
|
newVss := make([]*validatorStub, nVals+1) |
|
|
copy(newVss, vss[:nVals+1]) |
|
|
copy(newVss, vss[:nVals+1]) |
|
|
sort.Sort(ValidatorStubsByAddress(newVss)) |
|
|
|
|
|
selfIndex := 0 |
|
|
|
|
|
for i, vs := range newVss { |
|
|
|
|
|
vsPubKey, err := vs.GetPubKey() |
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
sort.Sort(ValidatorStubsByPower(newVss)) |
|
|
|
|
|
|
|
|
css0PubKey, err := css[0].privValidator.GetPubKey() |
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
valIndexFn := func(cssIdx int) int { |
|
|
|
|
|
for i, vs := range newVss { |
|
|
|
|
|
vsPubKey, err := vs.GetPubKey() |
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
if vsPubKey.Equals(css0PubKey) { |
|
|
|
|
|
selfIndex = i |
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
cssPubKey, err := css[cssIdx].privValidator.GetPubKey() |
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
|
|
if vsPubKey.Equals(cssPubKey) { |
|
|
|
|
|
return i |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
panic(fmt.Sprintf("validator css[%d] not found in newVss", cssIdx)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
selfIndex := valIndexFn(0) |
|
|
|
|
|
|
|
|
proposal = types.NewProposal(vss[3].Height, round, -1, blockID) |
|
|
proposal = types.NewProposal(vss[3].Height, round, -1, blockID) |
|
|
if err := vss[3].SignProposal(config.ChainID(), proposal); err != nil { |
|
|
if err := vss[3].SignProposal(config.ChainID(), proposal); err != nil { |
|
|
t.Fatal("failed to sign bad proposal", err) |
|
|
t.Fatal("failed to sign bad proposal", err) |
|
@ -454,9 +465,16 @@ func TestSimulateValidatorsChange(t *testing.T) { |
|
|
|
|
|
|
|
|
ensureNewRound(newRoundCh, height+1, 0) |
|
|
ensureNewRound(newRoundCh, height+1, 0) |
|
|
|
|
|
|
|
|
//height 5
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
// HEIGHT 5
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
height++ |
|
|
height++ |
|
|
incrementHeight(vss...) |
|
|
incrementHeight(vss...) |
|
|
|
|
|
// Reflect the changes to vss[nVals] at height 3 and resort newVss.
|
|
|
|
|
|
newVssIdx := valIndexFn(nVals) |
|
|
|
|
|
newVss[newVssIdx].VotingPower = 25 |
|
|
|
|
|
sort.Sort(ValidatorStubsByPower(newVss)) |
|
|
|
|
|
selfIndex = valIndexFn(0) |
|
|
ensureNewProposal(proposalCh, height, round) |
|
|
ensureNewProposal(proposalCh, height, round) |
|
|
rs = css[0].GetRoundState() |
|
|
rs = css[0].GetRoundState() |
|
|
for i := 0; i < nVals+1; i++ { |
|
|
for i := 0; i < nVals+1; i++ { |
|
@ -467,7 +485,9 @@ func TestSimulateValidatorsChange(t *testing.T) { |
|
|
} |
|
|
} |
|
|
ensureNewRound(newRoundCh, height+1, 0) |
|
|
ensureNewRound(newRoundCh, height+1, 0) |
|
|
|
|
|
|
|
|
//height 6
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
// HEIGHT 6
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
height++ |
|
|
height++ |
|
|
incrementHeight(vss...) |
|
|
incrementHeight(vss...) |
|
|
removeValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, 0) |
|
|
removeValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, 0) |
|
@ -478,19 +498,9 @@ func TestSimulateValidatorsChange(t *testing.T) { |
|
|
blockID = types.BlockID{Hash: propBlock.Hash(), PartsHeader: propBlockParts.Header()} |
|
|
blockID = types.BlockID{Hash: propBlock.Hash(), PartsHeader: propBlockParts.Header()} |
|
|
newVss = make([]*validatorStub, nVals+3) |
|
|
newVss = make([]*validatorStub, nVals+3) |
|
|
copy(newVss, vss[:nVals+3]) |
|
|
copy(newVss, vss[:nVals+3]) |
|
|
sort.Sort(ValidatorStubsByAddress(newVss)) |
|
|
|
|
|
for i, vs := range newVss { |
|
|
|
|
|
vsKeyKey, err := vs.GetPubKey() |
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
|
|
css0PubKey, err := css[0].privValidator.GetPubKey() |
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
sort.Sort(ValidatorStubsByPower(newVss)) |
|
|
|
|
|
|
|
|
if vsKeyKey.Equals(css0PubKey) { |
|
|
|
|
|
selfIndex = i |
|
|
|
|
|
break |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
selfIndex = valIndexFn(0) |
|
|
proposal = types.NewProposal(vss[1].Height, round, -1, blockID) |
|
|
proposal = types.NewProposal(vss[1].Height, round, -1, blockID) |
|
|
if err := vss[1].SignProposal(config.ChainID(), proposal); err != nil { |
|
|
if err := vss[1].SignProposal(config.ChainID(), proposal); err != nil { |
|
|
t.Fatal("failed to sign bad proposal", err) |
|
|
t.Fatal("failed to sign bad proposal", err) |
|
|