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

feat!: Wire the provider module to return ValidatorUpdates, instead of the staking module #1993

Merged
merged 33 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
39e5060
Refactor validator set storage
p-offtermatt Jun 25, 2024
7441fe0
Add comment for getTotalPower
p-offtermatt Jun 25, 2024
d9a51fb
Add provider consensus validator set storage
p-offtermatt Jun 25, 2024
96a47d7
Add new MaxProviderConsensusValidators param
p-offtermatt Jun 25, 2024
884a356
Add validation for MaxProviderConsensusValidators
p-offtermatt Jun 25, 2024
356e6e8
Add no_valupdates_staking module
p-offtermatt Jun 25, 2024
b0d3ce0
Add function to get MaxProviderConsensusValidators param
p-offtermatt Jun 26, 2024
5f53dc3
Start returning validators in EndBlock
p-offtermatt Jun 26, 2024
463e370
Fix tests
p-offtermatt Jun 26, 2024
23b4c46
Revert cosmetic change
p-offtermatt Jun 26, 2024
8b57495
Revert cosmetic changes
p-offtermatt Jun 26, 2024
b4ed21a
Revert formatting
p-offtermatt Jun 26, 2024
bc69f20
Add genutil replacer module
p-offtermatt Jun 26, 2024
ca84368
Revert formatting
p-offtermatt Jun 26, 2024
eb6f00f
Revert formatting in tests/integration
p-offtermatt Jun 26, 2024
8f8ff96
Revert minor formatting
p-offtermatt Jun 26, 2024
4e8b917
Fix type
p-offtermatt Jun 27, 2024
af1b7d4
Change wrapped staking to conform to EndBlocker interface
p-offtermatt Jun 27, 2024
62dfd1e
Fix typo
p-offtermatt Jun 27, 2024
49a6e04
Revert "Fix typo"
p-offtermatt Jun 27, 2024
cc1185d
Add e2e test for inactive vals
p-offtermatt Jun 27, 2024
732e35d
Start fixing e2e test
p-offtermatt Jun 27, 2024
c07a765
Revert formatting changes
p-offtermatt Jul 2, 2024
1cf874d
Remove more formatting
p-offtermatt Jul 2, 2024
9d0c9b7
Revert extra formatting
p-offtermatt Jul 2, 2024
4a5b80c
Re-wire provider/app.go to use wrapped modules
p-offtermatt Jul 2, 2024
96fbd4e
Remove consumer rewards check
p-offtermatt Jul 2, 2024
0f30ca1
Merge branch 'feat/inactive-vals-v50' into ph/inactive-vals-endblocker
p-offtermatt Jul 2, 2024
2ee5c6d
Add inactive provider vals testcase to nightly
p-offtermatt Jul 3, 2024
ed93ba0
Adjust comment
p-offtermatt Jul 3, 2024
5ff56e8
Address comments
p-offtermatt Jul 3, 2024
9c5028b
Fix nightly test name
p-offtermatt Jul 3, 2024
60e9e7f
feat: Initialize the max validators parameter for existing consumers …
p-offtermatt Jul 15, 2024
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
4 changes: 3 additions & 1 deletion app/provider/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ import (
"github.com/cosmos/cosmos-sdk/testutil/testdata/testpb"
sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"

no_valupdates_staking "github.com/cosmos/interchain-security/v5/x/ccv/no_valupdates_staking"
)

const (
Expand Down Expand Up @@ -552,7 +554,7 @@ func New(
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName), app.interfaceRegistry),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
no_valupdates_staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
upgrade.NewAppModule(&app.UpgradeKeeper, app.AccountKeeper.AddressCodec()),
evidence.NewAppModule(app.EvidenceKeeper),

Expand Down
4 changes: 4 additions & 0 deletions proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ message Params {

// The number of blocks that comprise an epoch.
int64 blocks_per_epoch = 10;

// The maximal number of validators that will be passed
// to the consensus engine on the provider.
int64 max_provider_consensus_validators = 11;
}

// SlashAcks contains cons addresses of consumer chain validators
Expand Down
14 changes: 14 additions & 0 deletions testutil/keeper/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions x/ccv/no_valupdates_staking/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Package staking defines a "wrapper" module around the Cosmos SDK's native
x/staking module. In other words, it provides the exact same functionality as
the native module in that it simply embeds the native module. However, it
overrides `EndBlock` which will return no validator set updates. Instead,
it is assumed that some other module will provide the validator set updates.
*/
package staking
74 changes: 74 additions & 0 deletions x/ccv/no_valupdates_staking/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package staking

import (
"encoding/json"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/staking/exported"
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/cosmos/cosmos-sdk/x/staking/types"

abci "github.com/cometbft/cometbft/abci/types"
)

var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModuleSimulation = AppModule{}
)

// AppModule embeds the Cosmos SDK's x/staking AppModuleBasic.
type AppModuleBasic struct {
staking.AppModuleBasic
}

// AppModule embeds the Cosmos SDK's x/staking AppModule where we only override
// specific methods.
type AppModule struct {
// embed the Cosmos SDK's x/staking AppModule
staking.AppModule

keeper keeper.Keeper
accKeeper types.AccountKeeper
bankKeeper types.BankKeeper
}

// NewAppModule creates a new AppModule object using the native x/staking module
// AppModule constructor.
func NewAppModule(
cdc codec.Codec,
keeper *keeper.Keeper,
ak types.AccountKeeper,
bk types.BankKeeper,
ls exported.Subspace,
) AppModule {
stakingAppMod := staking.NewAppModule(cdc, keeper, ak, bk, ls)
return AppModule{
AppModule: stakingAppMod,
keeper: *keeper,
accKeeper: ak,
bankKeeper: bk,
}
}

// InitGenesis delegates the InitGenesis call to the underlying x/staking module,
// however, it returns no validator updates as validator updates will be provided by the provider module.
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState types.GenesisState

cdc.MustUnmarshalJSON(data, &genesisState)
_ = am.keeper.InitGenesis(ctx, &genesisState)

return []abci.ValidatorUpdate{}
}

// EndBlock delegates the EndBlock call to the underlying x/staking module,
// however, it returns no validator updates as validator updates will be provided by the provider module.
func (am AppModule) EndBlock(ctx sdk.Context) ([]abci.ValidatorUpdate, error) {
_, err := am.keeper.EndBlocker(ctx)
// return the error, but no validator updates
return []abci.ValidatorUpdate{}, err
}
7 changes: 7 additions & 0 deletions x/ccv/provider/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ func (k Keeper) GetBlocksPerEpoch(ctx sdk.Context) int64 {
return params.BlocksPerEpoch
}

// GetMaxProviderConsensusValidators returns the number of validators that will be passed on from the staking module
// to the consensus engine on the provider
func (k Keeper) GetMaxProviderConsensusValidators(ctx sdk.Context) int64 {
params := k.GetParams(ctx)
return params.MaxProviderConsensusValidators
}

// GetParams returns the paramset for the provider module
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
store := ctx.KVStore(k.storeKey)
Expand Down
1 change: 1 addition & 0 deletions x/ccv/provider/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func TestParams(t *testing.T) {
Amount: math.NewInt(10000000),
},
600,
10,
)
providerKeeper.SetParams(ctx, newParams)
params = providerKeeper.GetParams(ctx)
Expand Down
56 changes: 56 additions & 0 deletions x/ccv/provider/keeper/provider_consensus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package keeper

import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/interchain-security/v5/x/ccv/provider/types"
)

// SetLastProviderConsensusValidator sets the given validator to be stored
// as part of the last provider consensus validator set
func (k Keeper) SetLastProviderConsensusValidator(
ctx sdk.Context,
validator types.ConsumerValidator,
) {
k.setValidator(ctx, []byte{types.LastProviderConsensusValsPrefix}, validator)
}

// SetLastProviderConsensusValSet resets the stored last validator set sent to the consensus engine on the provider
// to the provided nextValidators.
func (k Keeper) SetLastProviderConsensusValSet(ctx sdk.Context, nextValidators []types.ConsumerValidator) {
k.setValSet(ctx, []byte{types.LastProviderConsensusValsPrefix}, nextValidators)
}

// DeleteLastProviderConsensusValidator removes the validator with `providerConsAddr` address
// from the stored last provider consensus validator set
func (k Keeper) DeleteLastProviderConsensusValidator(
ctx sdk.Context,
providerConsAddr types.ProviderConsAddress,
) {
k.deleteValidator(ctx, []byte{types.LastProviderConsensusValsPrefix}, providerConsAddr)
}

// DeleteLastProviderConsensusValSet deletes all the stored validators from the
// last provider consensus validator set
func (k Keeper) DeleteLastProviderConsensusValSet(
ctx sdk.Context,
) {
k.deleteValSet(ctx, []byte{types.LastProviderConsensusValsPrefix})
}

// GetLastProviderConsensusValSet returns the last stored
// validator set sent to the consensus engine on the provider
func (k Keeper) GetLastProviderConsensusValSet(
ctx sdk.Context,
) []types.ConsumerValidator {
return k.getValSet(ctx, []byte{types.LastProviderConsensusValsPrefix})
}

// GetLastTotalProviderConsensusPower returns the total power of the last stored
// validator set sent to the consensus engine on the provider
func (k Keeper) GetLastTotalProviderConsensusPower(
ctx sdk.Context,
) math.Int {
return k.getTotalPower(ctx, []byte{types.LastProviderConsensusValsPrefix})
}
102 changes: 102 additions & 0 deletions x/ccv/provider/keeper/provider_consensus_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package keeper_test

import (
"testing"

"github.com/cometbft/cometbft/proto/tendermint/crypto"
"github.com/stretchr/testify/require"

testkeeper "github.com/cosmos/interchain-security/v5/testutil/keeper"
"github.com/cosmos/interchain-security/v5/x/ccv/provider/types"
)

func TestSetLastProviderConsensusValidator(t *testing.T) {
providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()

validator := types.ConsumerValidator{
ProviderConsAddr: []byte("providerConsAddr"),
Power: 2,
ConsumerPublicKey: &crypto.PublicKey{},
}

providerKeeper.SetLastProviderConsensusValidator(ctx, validator)

// Retrieve the stored validator
storedValidator := providerKeeper.GetLastProviderConsensusValSet(ctx)[0]

require.Equal(t, validator, storedValidator, "stored validator does not match")
}

func TestSetLastProviderConsensusValSet(t *testing.T) {
providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()

validator1 := types.ConsumerValidator{
ProviderConsAddr: []byte("providerConsAddr1"),
Power: 2,
ConsumerPublicKey: &crypto.PublicKey{},
}

validator2 := types.ConsumerValidator{
ProviderConsAddr: []byte("providerConsAddr2"),
Power: 3,
ConsumerPublicKey: &crypto.PublicKey{},
}

nextValidators := []types.ConsumerValidator{validator1, validator2}

providerKeeper.SetLastProviderConsensusValSet(ctx, nextValidators)

// Retrieve the stored validator set
storedValidators := providerKeeper.GetLastProviderConsensusValSet(ctx)
require.Equal(t, nextValidators, storedValidators, "stored validator set does not match")
}

func TestDeleteLastProviderConsensusValidator(t *testing.T) {
providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()

validator := types.ConsumerValidator{
ProviderConsAddr: []byte("providerConsAddr"),
Power: 2,
ConsumerPublicKey: &crypto.PublicKey{},
}

providerKeeper.SetLastProviderConsensusValidator(ctx, validator)

// Delete the stored validator
providerKeeper.DeleteLastProviderConsensusValidator(ctx, types.NewProviderConsAddress(validator.ProviderConsAddr))

// Ensure the validator is deleted
storedValidators := providerKeeper.GetLastProviderConsensusValSet(ctx)
require.Empty(t, storedValidators, "validator set should be empty")
}

func TestDeleteLastProviderConsensusValSet(t *testing.T) {
providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()

validator1 := types.ConsumerValidator{
ProviderConsAddr: []byte("providerConsAddr1"),
Power: 2,
ConsumerPublicKey: &crypto.PublicKey{},
}

validator2 := types.ConsumerValidator{
ProviderConsAddr: []byte("providerConsAddr2"),
Power: 3,
ConsumerPublicKey: &crypto.PublicKey{},
}

nextValidators := []types.ConsumerValidator{validator1, validator2}

providerKeeper.SetLastProviderConsensusValSet(ctx, nextValidators)

// Delete the stored validator set
providerKeeper.DeleteLastProviderConsensusValSet(ctx)

// Ensure the validator set is empty
storedValidators := providerKeeper.GetLastProviderConsensusValSet(ctx)
require.Empty(t, storedValidators, "validator set should be empty")
}
Loading
Loading