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

fix!: drop chain proposals with empty validator set at spawn time #1888

Merged
merged 3 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 0 additions & 2 deletions testutil/keeper/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ 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().GetLastValidators(gomock.Any()).Times(1),
}
}

Expand Down
1 change: 1 addition & 0 deletions testutil/keeper/unit_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func SetupForStoppingConsumerChain(t *testing.T, ctx sdk.Context,
providerKeeper *providerkeeper.Keeper, mocks MockedKeepers,
) {
t.Helper()
mocks.MockStakingKeeper.EXPECT().GetLastValidators(gomock.Any()).Times(1)
expectations := GetMocksForCreateConsumerClient(ctx, &mocks,
"chainID", clienttypes.NewHeight(4, 5))
expectations = append(expectations, GetMocksForSetConsumerChain(ctx, &mocks, "chainID")...)
Expand Down
13 changes: 13 additions & 0 deletions x/ccv/provider/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,19 @@ func (k Keeper) BeginBlockInit(ctx sdk.Context) {
continue
}

consumerGenesis, found := k.GetConsumerGenesis(cachedCtx, prop.ChainId)
if !found {
// drop the proposal
ctx.Logger().Info("consumer genesis could not be created")
continue
}
MSalopek marked this conversation as resolved.
Show resolved Hide resolved

if len(consumerGenesis.Provider.InitialValSet) == 0 {
// drop the proposal
ctx.Logger().Info("consumer genesis initial validator set is empty - no validators opted in")
continue
}

// The cached context is created with a new EventManager so we merge the event
// into the original context
ctx.EventManager().EmitEvents(cachedCtx.EventManager().Events())
Expand Down
7 changes: 7 additions & 0 deletions x/ccv/provider/keeper/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper_test
import (
"bytes"
"encoding/json"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"sort"
"testing"
"time"
Expand Down Expand Up @@ -115,6 +116,7 @@ func TestHandleConsumerAdditionProposal(t *testing.T) {

if tc.expAppendProp {
// Mock calls are only asserted if we expect a client to be created.
mocks.MockStakingKeeper.EXPECT().GetLastValidators(gomock.Any()).Times(1)
gomock.InOrder(
testkeeper.GetMocksForCreateConsumerClient(ctx, &mocks, tc.prop.ChainId, clienttypes.NewHeight(2, 3))...,
)
Expand Down Expand Up @@ -158,6 +160,7 @@ func TestCreateConsumerClient(t *testing.T) {
description: "No state mutation, new client should be created",
setup: func(providerKeeper *providerkeeper.Keeper, ctx sdk.Context, mocks *testkeeper.MockedKeepers) {
// Valid client creation is asserted with mock expectations here
mocks.MockStakingKeeper.EXPECT().GetLastValidators(gomock.Any()).Times(1)
gomock.InOrder(
testkeeper.GetMocksForCreateConsumerClient(ctx, mocks, "chainID", clienttypes.NewHeight(4, 5))...,
)
Expand Down Expand Up @@ -796,6 +799,7 @@ func TestMakeConsumerGenesis(t *testing.T) {
//
ctx = ctx.WithChainID("testchain1") // chainID is obtained from ctx
ctx = ctx.WithBlockHeight(5) // RevisionHeight obtained from ctx
mocks.MockStakingKeeper.EXPECT().GetLastValidators(gomock.Any()).Times(1)
gomock.InOrder(testkeeper.GetMocksForMakeConsumerGenesis(ctx, &mocks, 1814400000000000)...)

// matches params from jsonString
Expand Down Expand Up @@ -1021,6 +1025,8 @@ func TestBeginBlockInit(t *testing.T) {
// opt in a sample validator so the chain's proposal can successfully execute
validator := cryptotestutil.NewCryptoIdentityFromIntSeed(0).SDKStakingValidator()
consAddr, _ := validator.GetConsAddr()
mocks.MockStakingKeeper.EXPECT().GetLastValidators(gomock.Any()).Return([]stakingtypes.Validator{validator}).AnyTimes()
mocks.MockStakingKeeper.EXPECT().GetLastValidatorPower(gomock.Any(), validator.GetOperator()).Return(int64(1)).AnyTimes()
providerKeeper.SetOptedIn(ctx, pendingProps[4].ChainId, providertypes.NewProviderConsAddress(consAddr))

providerKeeper.BeginBlockInit(ctx)
Expand Down Expand Up @@ -1104,6 +1110,7 @@ func TestBeginBlockCCR(t *testing.T) {
expectations := []*gomock.Call{}
for _, prop := range pendingProps {
// A consumer chain is setup corresponding to each prop, making these mocks necessary
mocks.MockStakingKeeper.EXPECT().GetLastValidators(gomock.Any()).Times(1)
expectations = append(expectations, testkeeper.GetMocksForCreateConsumerClient(ctx, &mocks,
prop.ChainId, clienttypes.NewHeight(2, 3))...)
expectations = append(expectations, testkeeper.GetMocksForSetConsumerChain(ctx, &mocks, prop.ChainId)...)
Expand Down
1 change: 1 addition & 0 deletions x/ccv/provider/proposal_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func TestProviderProposalHandler(t *testing.T) {
// Mock expectations depending on expected outcome
switch {
case tc.expValidConsumerAddition:
mocks.MockStakingKeeper.EXPECT().GetLastValidators(gomock.Any()).Times(1)
gomock.InOrder(testkeeper.GetMocksForCreateConsumerClient(
ctx, &mocks, "chainID", clienttypes.NewHeight(2, 3),
)...)
Expand Down
Loading