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

update getParams for consumerkeeper and add SlashWithInfractionReason #6

Merged
merged 1 commit into from
Apr 24, 2023
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ require (
require github.com/confio/ics23/go v0.9.0 // indirect

replace (
github.com/cosmos/cosmos-sdk => github.com/notional-labs/cosmos-sdk v0.47.2-0.20230414131805-781d3665d7a0
github.com/cosmos/cosmos-sdk => github.com/notional-labs/cosmos-sdk v0.47.2-0.20230424022356-49c2e39f3fe6
github.com/cosmos/ibc-go/v7 => github.com/notional-labs/ibc-go/v7 v7.0.0-rc0.0.20230417042817-8072b1e9aabc

// following versions might cause unexpected behavior
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -919,8 +919,8 @@ github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/neilotoole/errgroup v0.1.6/go.mod h1:Q2nLGf+594h0CLBs/Mbg6qOr7GtqDK7C2S41udRnToE=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/notional-labs/cosmos-sdk v0.47.2-0.20230414131805-781d3665d7a0 h1:SsOek50tnVAUTHaH65bNwbg5UzPf5soh5x2j/DPGGTY=
github.com/notional-labs/cosmos-sdk v0.47.2-0.20230414131805-781d3665d7a0/go.mod h1:14tO5KQaTrl2q3OxBnDRfue7TRN9zkXS0cLutrSqkOo=
github.com/notional-labs/cosmos-sdk v0.47.2-0.20230424022356-49c2e39f3fe6 h1:/66obfC6FRb8phL73iqj1N7yrKw/7vfwdTkaJ9AO4/o=
github.com/notional-labs/cosmos-sdk v0.47.2-0.20230424022356-49c2e39f3fe6/go.mod h1:14tO5KQaTrl2q3OxBnDRfue7TRN9zkXS0cLutrSqkOo=
github.com/notional-labs/ibc-go/v7 v7.0.0-rc0.0.20230417042817-8072b1e9aabc h1:2qZf+B37YnoHcmXnB87VfcrVC50I+LZWeWu4ZEAddsc=
github.com/notional-labs/ibc-go/v7 v7.0.0-rc0.0.20230417042817-8072b1e9aabc/go.mod h1:BFh8nKWjr5zeR2OZfhkzdgDzj1+KjRn3aJLpwapStj8=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand Down
2 changes: 2 additions & 0 deletions legacy_ibc_testing/testing/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func SetupWithGenesisValSet(t *testing.T, appIniter AppIniter, valSet *tmtypes.V
t.Helper()
app, genesisState := appIniter()

baseapp.SetChainID(chainID)(app.GetBaseApp())

// set genesis accounts
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis)
Expand Down
3 changes: 3 additions & 0 deletions tests/difference/core/driver/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
abci "github.com/cometbft/cometbft/abci/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/baseapp"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cosmosEd25519 "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
Expand Down Expand Up @@ -244,6 +245,8 @@ func (b *Builder) newChain(
) *ibctesting.TestChain {
app, genesis := appInit()

baseapp.SetChainID(chainID)(app.GetBaseApp())

stateBytes, senderAccounts := b.getAppBytesAndSenders(chainID, app, genesis, validators)

app.InitChain(
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/consumer/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state *consumertypes.GenesisState)

// ExportGenesis returns the CCV consumer module's exported genesis
func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *consumertypes.GenesisState) {
params := k.GetParams(ctx)
params := k.GetConsumerParams(ctx)
if !params.Enabled {
return consumertypes.DefaultGenesisState()
}
Expand Down
6 changes: 3 additions & 3 deletions x/ccv/consumer/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestInitGenesis(t *testing.T) {
assertHeightValsetUpdateIDs(t, ctx, &ck, defaultHeightValsetUpdateIDs)

require.Equal(t, validator.Address.Bytes(), ck.GetAllCCValidator(ctx)[0].Address)
require.Equal(t, gs.Params, ck.GetParams(ctx))
require.Equal(t, gs.Params, ck.GetConsumerParams(ctx))
},
}, {
"restart a chain without an established CCV channel",
Expand All @@ -150,7 +150,7 @@ func TestInitGenesis(t *testing.T) {
assertHeightValsetUpdateIDs(t, ctx, &ck, defaultHeightValsetUpdateIDs)
assertProviderClientID(t, ctx, &ck, provClientID)
require.Equal(t, validator.Address.Bytes(), ck.GetAllCCValidator(ctx)[0].Address)
require.Equal(t, gs.Params, ck.GetParams(ctx))
require.Equal(t, gs.Params, ck.GetConsumerParams(ctx))
},
}, {
"restart a chain with an established CCV channel",
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestInitGenesis(t *testing.T) {
assertHeightValsetUpdateIDs(t, ctx, &ck, updatedHeightValsetUpdateIDs)
assertProviderClientID(t, ctx, &ck, provClientID)

require.Equal(t, gs.Params, ck.GetParams(ctx))
require.Equal(t, gs.Params, ck.GetConsumerParams(ctx))
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/consumer/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (k Keeper) QueryParams(c context.Context,
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}

p := k.GetParams(ctx)
p := k.GetConsumerParams(ctx)

return &types.QueryParamsResponse{Params: p}, nil
}
8 changes: 7 additions & 1 deletion x/ccv/consumer/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"time"

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

"github.com/cosmos/interchain-security/x/ccv/consumer/types"
ccvtypes "github.com/cosmos/interchain-security/x/ccv/types"
)

// GetParams returns the params for the consumer ccv module
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
func (k Keeper) GetConsumerParams(ctx sdk.Context) types.Params {
return types.NewParams(
k.GetEnabled(ctx),
k.GetBlocksPerDistributionTransmission(ctx),
Expand All @@ -30,6 +31,11 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramStore.SetParamSet(ctx, &params)
}

// GetParams implement from staking keeper
func (k Keeper) GetParams(ctx sdk.Context) stakingtypes.Params {
return stakingtypes.DefaultParams()
}

// GetEnabled returns the enabled flag for the consumer module
func (k Keeper) GetEnabled(ctx sdk.Context) bool {
var enabled bool
Expand Down
4 changes: 2 additions & 2 deletions x/ccv/consumer/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ func TestParams(t *testing.T) {
types.DefaultSoftOptOutThreshold,
) // these are the default params, IBC suite independently sets enabled=true

params := consumerKeeper.GetParams(ctx)
params := consumerKeeper.GetConsumerParams(ctx)
require.Equal(t, expParams, params)

newParams := types.NewParams(false, 1000,
"channel-2", "cosmos19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddwhu7lm",
7*24*time.Hour, 25*time.Hour, "0.5", 500, 24*21*time.Hour, "0.05")
consumerKeeper.SetParams(ctx, newParams)
params = consumerKeeper.GetParams(ctx)
params = consumerKeeper.GetConsumerParams(ctx)
require.Equal(t, newParams, params)

consumerKeeper.SetBlocksPerDistributionTransmission(ctx, 10)
Expand Down
8 changes: 8 additions & 0 deletions x/ccv/consumer/keeper/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"time"

"cosmossdk.io/math"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"

abci "github.com/cometbft/cometbft/abci/types"
Expand Down Expand Up @@ -149,6 +150,13 @@ func (k Keeper) Slash(ctx sdk.Context, addr sdk.ConsAddress, infractionHeight, p
)
}

// implement for stakingkeeper Interface
func (k Keeper) SlashWithInfractionReason(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeight, power int64, slashFactor sdk.Dec, infractionType stakingtypes.Infraction) math.Int {
k.Slash(ctx, consAddr, infractionHeight, power, slashFactor, infractionType)
// Only return to comply with the interface restriction
return math.ZeroInt()
}

// Jail - unimplemented on CCV keeper
//
// This method should be a no-op even during a standalone to consumer changeover.
Expand Down