Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove redundant code from MakeConsumerGenesis (backport #1807) #1856

Merged
merged 1 commit into from
May 2, 2024
Merged
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
2 changes: 1 addition & 1 deletion testutil/keeper/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func GetMocksForMakeConsumerGenesis(ctx sdk.Context, mocks *MockedKeepers,
mocks.MockClientKeeper.EXPECT().GetSelfConsensusState(gomock.Any(),
clienttypes.GetSelfHeight(ctx)).Return(&ibctmtypes.ConsensusState{}, nil).Times(1),

mocks.MockStakingKeeper.EXPECT().IterateLastValidatorPowers(gomock.Any(), gomock.Any()).Times(1),
mocks.MockStakingKeeper.EXPECT().GetLastValidators(gomock.Any()).Times(1),
}
}

Expand Down
26 changes: 2 additions & 24 deletions x/ccv/provider/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

tmtypes "github.com/cometbft/cometbft/types"

Expand Down Expand Up @@ -260,29 +259,8 @@ func (k Keeper) MakeConsumerGenesis(
return gen, nil, errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "error %s getting self consensus state for: %s", err, height)
}

var lastPowers []stakingtypes.LastValidatorPower

k.stakingKeeper.IterateLastValidatorPowers(ctx, func(addr sdk.ValAddress, power int64) (stop bool) {
lastPowers = append(lastPowers, stakingtypes.LastValidatorPower{Address: addr.String(), Power: power})
return false
})

var bondedValidators []stakingtypes.Validator

for _, p := range lastPowers {
addr, err := sdk.ValAddressFromBech32(p.Address)
if err != nil {
return gen, nil, err
}

val, found := k.stakingKeeper.GetValidator(ctx, addr)
if !found {
return gen, nil, errorsmod.Wrapf(stakingtypes.ErrNoValidatorFound, "error getting validator from LastValidatorPowers: %s", err)
}

// gather all the bonded validators in order to construct the consumer validator set for consumer chain `chainID`
bondedValidators = append(bondedValidators, val)
}
// get the bonded validators from the staking module
bondedValidators := k.stakingKeeper.GetLastValidators(ctx)

if topN, found := k.GetTopN(ctx, chainID); found && topN > 0 {
// in a Top-N chain, we automatically opt in all validators that belong to the top N
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/provider/keeper/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestCreateConsumerClient(t *testing.T) {
mocks.MockStakingKeeper.EXPECT().UnbondingTime(gomock.Any()).Times(0)
mocks.MockClientKeeper.EXPECT().CreateClient(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
mocks.MockClientKeeper.EXPECT().GetSelfConsensusState(gomock.Any(), gomock.Any()).Times(0)
mocks.MockStakingKeeper.EXPECT().IterateLastValidatorPowers(gomock.Any(), gomock.Any()).Times(0)
mocks.MockStakingKeeper.EXPECT().GetLastValidators(gomock.Any()).Times(0)
},
expClientCreated: false,
},
Expand Down
Loading