Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions state/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func TestFinalizeBlockMisbehavior(t *testing.T) {
// we don't need to worry about validating the evidence as long as they pass validate basic
dve, err := types.NewMockDuplicateVoteEvidenceWithValidator(3, defaultEvidenceTime, privVal, state.ChainID)
require.NoError(t, err)
dve.ValidatorPower = 1000
dve.ValidatorPower = state.Validators.Validators[0].VotingPower
lcae := &types.LightClientAttackEvidence{
ConflictingBlock: &types.LightBlock{
SignedHeader: &types.SignedHeader{
Expand Down Expand Up @@ -317,7 +317,7 @@ func TestFinalizeBlockMisbehavior(t *testing.T) {
Height: 3,
Time: defaultEvidenceTime,
Validator: types.TM2PB.Validator(state.Validators.Validators[0]),
TotalVotingPower: 10,
TotalVotingPower: dve.TotalVotingPower,
},
{
Type: abci.MisbehaviorType_LIGHT_CLIENT_ATTACK,
Expand Down Expand Up @@ -415,7 +415,7 @@ func TestProcessProposal(t *testing.T) {
BlockIdFlag: cmtproto.BlockIDFlagCommit,
Validator: abci.Validator{
Address: addr,
Power: 1000,
Power: testValidatorPower(0),
},
})
lastCommitSig = append(lastCommitSig, vote.CommitSig())
Expand Down
46 changes: 21 additions & 25 deletions state/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func makeState(nVals, height int) (sm.State, dbm.DB, map[string]types.PrivValida
vals[i] = types.GenesisValidator{
Address: valAddr,
PubKey: pk.PubKey(),
Power: 1000,
Power: testValidatorPower(i),
Name: fmt.Sprintf("test%d", i),
}
privVals[valAddr.String()] = types.NewMockPVWithParams(pk, false, false)
Expand Down Expand Up @@ -165,11 +165,18 @@ func makeState(nVals, height int) (sm.State, dbm.DB, map[string]types.PrivValida
func genValSet(size int) *types.ValidatorSet {
vals := make([]*types.Validator, size)
for i := 0; i < size; i++ {
vals[i] = types.NewValidator(ed25519.GenPrivKey().PubKey(), 10)
vals[i] = types.NewValidator(ed25519.GenPrivKey().PubKey(), testValidatorPower(i))
}
return types.NewValidatorSet(vals)
}

func testValidatorPower(index int) int64 {
if index == 0 {
return types.SequencerVotingPower
}
return types.AttestorVotingPower
}

func makeHeaderPartsResponsesValPubKeyChange(
state sm.State,
pubkey crypto.PubKey,
Expand All @@ -180,32 +187,11 @@ func makeHeaderPartsResponsesValPubKeyChange(
}
abciResponses := &abci.ResponseFinalizeBlock{}
// If the pubkey is new, remove the old and add the new.
_, val := state.NextValidators.GetByIndex(0)
val := getSequencer(state.NextValidators)
if !bytes.Equal(pubkey.Bytes(), val.PubKey.Bytes()) {
abciResponses.ValidatorUpdates = []abci.ValidatorUpdate{
types.TM2PB.NewValidatorUpdate(val.PubKey, 0),
types.TM2PB.NewValidatorUpdate(pubkey, 10),
}
}

return block.Header, types.BlockID{Hash: block.Hash(), PartSetHeader: types.PartSetHeader{}}, abciResponses
}

func makeHeaderPartsResponsesValPowerChange(
state sm.State,
power int64,
) (types.Header, types.BlockID, *abci.ResponseFinalizeBlock) {
block, err := makeBlock(state, state.LastBlockHeight+1, new(types.Commit))
if err != nil {
return types.Header{}, types.BlockID{}, nil
}
abciResponses := &abci.ResponseFinalizeBlock{}

// If the pubkey is new, remove the old and add the new.
_, val := state.NextValidators.GetByIndex(0)
if val.VotingPower != power {
abciResponses.ValidatorUpdates = []abci.ValidatorUpdate{
types.TM2PB.NewValidatorUpdate(val.PubKey, power),
types.TM2PB.NewValidatorUpdate(pubkey, val.VotingPower),
}
}

Expand All @@ -226,6 +212,16 @@ func makeHeaderPartsResponsesParams(
return block.Header, types.BlockID{Hash: block.Hash(), PartSetHeader: types.PartSetHeader{}}, abciResponses
}

func getSequencer(vals *types.ValidatorSet) *types.Validator {
for i := 0; i < vals.Size(); i++ {
_, val := vals.GetByIndex(int32(i))
if val.VotingPower == types.SequencerVotingPower {
return val
}
}
return nil
}

func randomGenesisDoc() *types.GenesisDoc {
pubkey := ed25519.GenPrivKey().PubKey()
return &types.GenesisDoc{
Expand Down
5 changes: 3 additions & 2 deletions state/rollback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestRollbackHard(t *testing.T) {
blockStore := store.NewBlockStore(dbm.NewMemDB())
stateStore := state.NewStore(dbm.NewMemDB(), state.StoreOptions{DiscardABCIResponses: false})

valSet, _ := types.RandValidatorSet(5, 10)
valSet := genValSet(5)

params := types.DefaultConsensusParams()
params.Version.App = 10
Expand Down Expand Up @@ -240,7 +240,7 @@ func TestRollbackDifferentStateHeight(t *testing.T) {

func setupStateStore(t *testing.T, height int64) state.Store {
stateStore := state.NewStore(dbm.NewMemDB(), state.StoreOptions{DiscardABCIResponses: false})
valSet, _ := types.RandValidatorSet(5, 10)
valSet := genValSet(5)

params := types.DefaultConsensusParams()
params.Version.App = 10
Expand Down Expand Up @@ -347,6 +347,7 @@ func TestRollback_To(t *testing.T) {
}

// rollback the state
blockStore.On("DeleteBlocksFromHeight", nextHeight).Return(nil)
rollbackHeight, rollbackHash, err := state.RollbackTo(blockStore, stateStore, height, false)
require.NoError(t, err)
require.EqualValues(t, height, rollbackHeight)
Expand Down
Loading