Skip to content

Commit

Permalink
feat!: Wire the provider module to return ValidatorUpdates, instead o…
Browse files Browse the repository at this point in the history
…f the staking module (#1993)

* Refactor validator set storage

* Add comment for getTotalPower

* Add provider consensus validator set storage

* Add new MaxProviderConsensusValidators param

* Add validation for MaxProviderConsensusValidators

* Add no_valupdates_staking module

* Add function to get MaxProviderConsensusValidators param

* Start returning validators in EndBlock

* Fix tests

* Revert cosmetic change

* Revert cosmetic changes

* Revert formatting

* Add genutil replacer module

* Revert formatting

* Revert formatting in tests/integration

* Revert minor formatting

* Fix type

* Change wrapped staking to conform to EndBlocker interface

* Fix typo

* Revert "Fix typo"

This reverts commit 62dfd1e.

* Add e2e test for inactive vals

* Start fixing e2e test

* Revert formatting changes

* Remove more formatting

* Revert extra formatting

* Re-wire provider/app.go to use wrapped modules

* Remove consumer rewards check

* Add inactive provider vals testcase to nightly

* Adjust comment

* Address comments

* Fix nightly test name

* feat: Initialize the max validators parameter for existing consumers (#2012)

* Add initialization for validator cap

* Remove migration test

* Fix inconsistent naming
  • Loading branch information
p-offtermatt authored Jul 15, 2024
1 parent 8ba4e6e commit 757680b
Show file tree
Hide file tree
Showing 48 changed files with 1,527 additions and 498 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/nightly-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,23 @@ jobs:
- name: E2E active set changes
run: go run ./tests/e2e/... --tc active-set-changes

inactive-provider-validators-on-consumer-test:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- uses: actions/checkout@v4
- name: Checkout LFS objects
run: git lfs checkout
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.22" # The Go version to download (if necessary) and use.
- name: E2E inactive provider validators on consumer
run: go run ./tests/e2e/... --tc inactive-provider-validators-on-consumer

nightly-test-fail:
needs:
- happy-path-test
Expand Down
2 changes: 1 addition & 1 deletion app/consumer-democracy/proposals_whitelisting.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type legacyParamChangeKey struct {
// these parameters don't exist in the consumer app -- keeping them as an
var LegacyWhitelistedParams = map[legacyParamChangeKey]struct{}{
// add whitlisted legacy parameters here [cosmos-sdk <= 0.47]
// commented parameters are just an example - most params have been moved to their respecitve modules
// commented parameters are just an example - most params have been moved to their respective modules
// and they cannot be changed through legacy governance proposals
{Subspace: banktypes.ModuleName, Key: "SendEnabled"}: {},
}
Expand Down
28 changes: 14 additions & 14 deletions app/provider/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import (
"os"
"path/filepath"

dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/gogoproto/proto"
"github.com/cosmos/ibc-go/modules/capability"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
"github.com/cosmos/ibc-go/v8/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
Expand All @@ -26,7 +30,7 @@ import (
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/core/appmodule"

"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
"cosmossdk.io/x/evidence"
evidencekeeper "cosmossdk.io/x/evidence/keeper"
Expand All @@ -35,6 +39,7 @@ import (
"cosmossdk.io/x/upgrade"
upgradekeeper "cosmossdk.io/x/upgrade/keeper"
upgradetypes "cosmossdk.io/x/upgrade/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand All @@ -50,16 +55,19 @@ import (
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/testutil/testdata/testpb"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/types/msgservice"
sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
"github.com/cosmos/cosmos-sdk/x/auth/posthandler"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
Expand Down Expand Up @@ -93,29 +101,21 @@ import (
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/ibc-go/modules/capability"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"

"cosmossdk.io/log"
abci "github.com/cometbft/cometbft/abci/types"
tmjson "github.com/cometbft/cometbft/libs/json"
tmos "github.com/cometbft/cometbft/libs/os"
dbm "github.com/cosmos/cosmos-db"

appencoding "github.com/cosmos/interchain-security/v5/app/encoding"
testutil "github.com/cosmos/interchain-security/v5/testutil/integration"
no_valupdates_genutil "github.com/cosmos/interchain-security/v5/x/ccv/no_valupdates_genutil"
no_valupdates_staking "github.com/cosmos/interchain-security/v5/x/ccv/no_valupdates_staking"
ibcprovider "github.com/cosmos/interchain-security/v5/x/ccv/provider"
ibcproviderclient "github.com/cosmos/interchain-security/v5/x/ccv/provider/client"
ibcproviderkeeper "github.com/cosmos/interchain-security/v5/x/ccv/provider/keeper"
providertypes "github.com/cosmos/interchain-security/v5/x/ccv/provider/types"

"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"
)

const (
Expand Down Expand Up @@ -152,7 +152,7 @@ var (
mint.AppModuleBasic{},
slashing.AppModuleBasic{},
distr.AppModuleBasic{},
staking.AppModuleBasic{},
no_valupdates_staking.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},

Expand Down Expand Up @@ -536,7 +536,7 @@ func New(
// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.
app.MM = module.NewManager(
genutil.NewAppModule(
no_valupdates_genutil.NewAppModule(
app.AccountKeeper,
app.StakingKeeper,
app,
Expand All @@ -552,7 +552,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
1 change: 0 additions & 1 deletion app/sovereign/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
// withdraw all validator commission
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
valBz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())

if err != nil {
panic(err)
}
Expand Down
3 changes: 3 additions & 0 deletions proto/interchain_security/ccv/provider/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ message GenesisState {

repeated interchain_security.ccv.provider.v1.ExportedVscSendTimestamp exported_vsc_send_timestamps = 13
[ (gogoproto.nullable) = false ];

repeated ConsensusValidator last_provider_consensus_validators = 14
[ (gogoproto.nullable) = false ];
}

// The provider CCV module's knowledge of consumer state.
Expand Down
13 changes: 8 additions & 5 deletions proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,18 @@ message ConsumerAddrsToPrune {
AddressList consumer_addrs = 3;
}

// ConsumerValidator is used to facilitate epoch-based transitions. It contains relevant info for
// a validator that is expected to validate on a consumer chain during an epoch.
message ConsumerValidator {
// ConsensusValidator is used to express a validator that
// should be validating on a chain.
// It contains relevant info for
// a validator that is expected to validate on
// either the provider or a consumer chain.
message ConsensusValidator {
// validator's consensus address on the provider chain
bytes provider_cons_addr = 1;
// voting power the validator has during this epoch
int64 power = 2;
// public key the validator uses on the consumer chain during this epoch
tendermint.crypto.PublicKey consumer_public_key = 3;
// public key the validator uses on the chain it is validating on
tendermint.crypto.PublicKey public_key = 3;
}
// ConsumerRewardsAllocation stores the rewards allocated by a consumer chain
// to the consumer rewards pool. It is used to allocate the tokens to the consumer
Expand Down
26 changes: 25 additions & 1 deletion tests/e2e/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const (
ConsumerMisbehaviourTestCfg TestConfigType = "consumer-misbehaviour"
CompatibilityTestCfg TestConfigType = "compatibility"
SmallMaxValidatorsTestCfg TestConfigType = "small-max-validators"
InactiveProviderValsTestCfg TestConfigType = "inactive-provider-vals"
)

type TestConfig struct {
Expand Down Expand Up @@ -180,6 +181,8 @@ func GetTestConfig(cfgType TestConfigType, providerVersion, consumerVersion stri
testCfg = CompatibilityTestConfig(pv, cv)
case SmallMaxValidatorsTestCfg:
testCfg = SmallMaxValidatorsTestConfig()
case InactiveProviderValsTestCfg:
testCfg = InactiveProviderValsTestConfig()
default:
panic(fmt.Sprintf("Invalid test config: %s", cfgType))
}
Expand Down Expand Up @@ -417,7 +420,7 @@ func CompatibilityTestConfig(providerVersion, consumerVersion string) TestConfig
".app_state.provider.params.slash_meter_replenish_fraction = \"1.0\" | " + // This disables slash packet throttling
".app_state.provider.params.slash_meter_replenish_period = \"3s\"",
}
} else if semver.Compare(providerVersion, "v5.0.0-alpha1") < 0 { //TODO: MOV THIS BACK TO "v5.0.0"
} else if semver.Compare(providerVersion, "v5.0.0-alpha1") < 0 { // TODO: MOV THIS BACK TO "v5.0.0"
fmt.Println("Using provider chain config for v4.1.x")
providerConfig = ChainConfig{
ChainId: ChainID("provi"),
Expand Down Expand Up @@ -557,6 +560,27 @@ func DemocracyTestConfig(allowReward bool) TestConfig {
return tr
}

func InactiveProviderValsTestConfig() TestConfig {
tr := DefaultTestConfig()
tr.name = "InactiveValsConfig"
// set the MaxProviderConsensusValidators param to 2
proviConfig := tr.chainConfigs[ChainID("provi")]
proviConfig.GenesisChanges += " | .app_state.provider.params.max_provider_consensus_validators = \"2\""

consuConfig := tr.chainConfigs[ChainID("consu")]
// set the soft_opt_out threshold to 0% to make sure all validators are slashed for downtime
consuConfig.GenesisChanges += " | .app_state.ccvconsumer.params.soft_opt_out_threshold = \"0.0\""
tr.chainConfigs[ChainID("provi")] = proviConfig
tr.chainConfigs[ChainID("consu")] = consuConfig

// make is to that carol does not use a consumer key
carolConfig := tr.validatorConfigs[ValidatorID("carol")]
carolConfig.UseConsumerKey = false
tr.validatorConfigs[ValidatorID("carol")] = carolConfig

return tr
}

func SmallMaxValidatorsTestConfig() TestConfig {
cfg := DefaultTestConfig()

Expand Down
6 changes: 6 additions & 0 deletions tests/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ var stepChoices = map[string]StepChoice{
description: "This is a regression test related to the issue discussed here: https://forum.cosmos.network/t/cosmos-hub-v17-1-chain-halt-post-mortem/13899. The test ensures that the protocol works as expected when MaxValidators is smaller than the number of potential validators.",
testConfig: SmallMaxValidatorsTestCfg,
},
"inactive-provider-validators-on-consumer": {
name: "inactive-provider-validators-on-consumer",
steps: stepsInactiveProviderValidators(),
description: "test inactive validators on consumer",
testConfig: InactiveProviderValsTestCfg,
},
}

func getTestCaseUsageString() string {
Expand Down
12 changes: 8 additions & 4 deletions tests/e2e/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,19 @@ func (tr Commands) GetReward(chain ChainID, validator ValidatorID, blockHeight u

binaryName := tr.chainConfigs[chain].BinaryName
cmd := tr.target.ExecCommand(binaryName,
"query", "distribution", "delegation-total-rewards",
"--delegator-address", delAddresss,
"query", "distribution", "rewards",
delAddresss,
`--height`, fmt.Sprint(blockHeight),
`--node`, tr.GetQueryNode(chain),
`-o`, `json`,
)

bz, err := cmd.CombinedOutput()
if *verbose {
log.Println("getting rewards for chain: ", chain, " validator: ", validator, " blockHeight: ", blockHeight)
log.Println(cmd)
}

bz, err := cmd.CombinedOutput()
if err != nil {
log.Fatal("failed getting rewards: ", err, "\n", string(bz))
}
Expand All @@ -380,7 +384,7 @@ func (tr Commands) GetReward(chain ChainID, validator ValidatorID, blockHeight u

// interchain-securityd query gov proposals
func (tr Commands) GetProposal(chain ChainID, proposal uint) Proposal {
var noProposalRegex = regexp.MustCompile(`doesn't exist: key not found`)
noProposalRegex := regexp.MustCompile(`doesn't exist: key not found`)

binaryName := tr.chainConfigs[chain].BinaryName
bz, err := tr.target.ExecCommand(binaryName,
Expand Down
Loading

0 comments on commit 757680b

Please sign in to comment.