Skip to content

Commit

Permalink
feat!: Allow inactive provider chain validators to validate on consum…
Browse files Browse the repository at this point in the history
…er chains (#2079)

* refactor!: Refactor the validator set storage and add provider consensus validator storage (#1990)

* Refactor validator set storage

* Add comment for getTotalPower

* Add provider consensus validator set storage

* Add key to key test

* Add unit test for LastTotalProviderConsensusPower

* Address comments

* feat!: Introduce the MaxProviderConsensusValidators param (#1992)

* Refactor validator set storage

* Add comment for getTotalPower

* Add provider consensus validator set storage

* Add new MaxProviderConsensusValidators param

* Add validation for MaxProviderConsensusValidators

* Add function to get MaxProviderConsensusValidators param

* refactor!: Refactor the validator set storage and add provider consensus validator storage (#1990)

* Refactor validator set storage

* Add comment for getTotalPower

* Add provider consensus validator set storage

* Add key to key test

* Add unit test for LastTotalProviderConsensusPower

* Address comments

* feat!: Wire the provider module to return ValidatorUpdates, instead of 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

* test: enable the simulator for the provider module (#2005)

* 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 simulator test

* Add randomly generated parameters for provider in sim

* Add invariant

* Add simulation to Makefile and github workflow

* Use simcli instead of just passing true

* feat!: Let consumer chains choose a minimum stake and validator rank (#2035)

* Add minimum stake key

* Add MinValidatorRank prefix

* Add keeper and tests for new parameters

* Utilize MinStake and MaxRank parameters in computing next validators

* Mention MinStake and MaxRank in adr

* Add test for FulfillsMinStake

* Handle multiple validators with same power

* Add min stake and max rank to docs

* Add minStake and maxRank to proposals

* Check for untyped equality

* Handle minStake and maxRank in Msgs

* Add integration test for min stake and max rank

* Rename test and testfile

* Update docs/docs/adrs/adr-017-allowing-inactive-validators.md

* Add changelog entries for maxrank and minstake

* Address comments

* Clarify which feature is disabled by setting maxrank

* Test validator powers cap and validator set cap into int param testing function

* feat!: Rewire dependencies on the staking module (#2056)

* Change wiring for mint and gov to use ProviderKeeper instead of StakingKeeper

* Add test for IterateBondedValidatorsByPower

* Rewire GovKeeper

* Fix docstrings

* Test other modified functions

* Start writing some testing scenarios

* Add TotalBondedTokens to expected staking keeper interface

* feat: Calculate Top N based on active validators only (#2070)

* Add test for inactive vals with top N

* Add test case to predefined tests

* Fix bonded/active validator distinction

* Fix relay test to set max provider consensus vals correctly

* feat!: Add a parameter that determines whether consumer chains allow inactive validators to validate them (#2066)

* Introduce new AllowInactiveValidators param for consumer chains

* Add AllowInactiveValidators param to tests

* Set MaxProviderConsensusValidators in tests

* Add migration to initialize inactive vals

* Add changelog entries for inactive vals param

* Add property-based test for inactive vals

* Add docs for inactive vals param

* Set AllowInactiveVals parameter in e2e test

* test: Add e2e tests for inactive vals (#2064)

* Start adding e2e test for governance

* Debug gov with inactive vals test

* Outline for test scenarios where they are tested

* Add MaxRank steps

* Add e2e tests for min stake and max rank

* Revert formatting change

* Refactor stepsOptIn

* Use adjusted config for e2e tests

* Write for more scenarios where they are tested

* Add test for mint

* Add docstrings for e2e steps

* Delete hanging changelog entry

* Address comments

* Address more comments

* Add migration for param

* Fix allow inactive validators param test

* Fix tests

* Add LastProviderConsensusValidatorKey to fully defined keys

* Fix key for validator set updates

* Add info about genesis/endblock ordering

* Add unit test for ProviderValidatorUpdates

* Add example to proto definition of max_rank

* Remove max rank

* Remove references to max rank

* Start adding an extension to the simulator

* Make invariant fail early when param is 0

* Reorder InitGenesis to put Crisis last

* Remove canary

* Swap equals for not equals

* Disable invariant check when max validators != max provider consensus validators

* Make the simulator use a random seed

* Remove TODO

* Remove decoder

* Run go mod tidy

* Add migration in UPGRADING.md

* Fix tests

* Put random seed generation into golang code

* Rename simulation jobs

* Update UPGRADING.md

Co-authored-by: Marius Poke <[email protected]>

* Update UPGRADING.md

Co-authored-by: Marius Poke <[email protected]>

* Update x/ccv/provider/keeper/genesis.go

Co-authored-by: Marius Poke <[email protected]>

* Mention simulation tests in testing.md

* Address some comments

* Remake protos

* Panic when LastActiveBondedValidators fails

* Address some comments

* Address comments

* Reorder tests

* Adjust stake_multiplier to stakeMultiplier

* Address comments

* Add error logging

* Fix reference to bank blocked addrs in simulation

* Change hasToValidate to only take into account active validators

* Update docs/docs/adrs/adr-017-allowing-inactive-validators.md

Co-authored-by: insumity <[email protected]>

* Clarify: Slash happens on provider

Co-authored-by: insumity <[email protected]>

---------

Co-authored-by: Marius Poke <[email protected]>
Co-authored-by: insumity <[email protected]>
  • Loading branch information
3 people authored Aug 5, 2024
1 parent 50d602f commit 2fb67d1
Show file tree
Hide file tree
Showing 86 changed files with 4,575 additions and 726 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add minimum stake requirement to let consumer chains
determine requirements for validators that validate their chain. ([\#2035](https://github.com/cosmos/interchain-security/pull/2035))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add the `allow_inactive_vals` parameter for consumer chains to choose whether inactive validators can validate their chain ([\#2066](https://github.com/cosmos/interchain-security/pull/2066))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add minimum stake requirement to let consumer chains
determine requirements for validators that validate their chain. ([\#2035](https://github.com/cosmos/interchain-security/pull/2035))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add the `allow_inactive_vals` parameter for consumer chains to choose whether inactive validators can validate their chain ([\#2066](https://github.com/cosmos/interchain-security/pull/2066))
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
69 changes: 69 additions & 0 deletions .github/workflows/simulation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Simulation
on:
workflow_call:
pull_request:
merge_group:
push:
branches:
- main
- release/v*
- feat/*

permissions:
contents: read

concurrency:
group: ci-${{ github.ref }}-tests
cancel-in-progress: true

jobs:
simulation-full:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
check-latest: true
cache: true
cache-dependency-path: go.sum
- uses: technote-space/[email protected]
id: git_diff
with:
PATTERNS: |
**/*.go
go.mod
go.sum
**/go.mod
**/go.sum
**/Makefile
Makefile
- name: full simulation test
if: env.GIT_DIFF
run: |
make sim-full
simulation-no-inactive:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
check-latest: true
cache: true
cache-dependency-path: go.sum
- uses: technote-space/[email protected]
id: git_diff
with:
PATTERNS: |
**/*.go
go.mod
go.sum
**/go.mod
**/go.sum
**/Makefile
Makefile
- name: simulation test without inactive validators
if: env.GIT_DIFF
run: |
make sim-full-no-inactive-vals
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ verify-models:
../run_invariants.sh


###############################################################################
### Simulation tests ###

# Run a full simulation test
sim-full:
cd app/provider;\
go test -mod=readonly . -run=^TestFullAppSimulation$ -Enabled=true -NumBlocks=500 -BlockSize=200 -Commit=true -timeout 24h -v

# Run full simulation without any inactive validators
sim-full-no-inactive-vals:
cd app/provider;\
go test -mod=readonly . -run=^TestFullAppSimulation$ -Enabled=true -NumBlocks=500 -BlockSize=200 -Commit=true -timeout 24h -Params=no_inactive_vals_params.json -v


###############################################################################
### Linting ###
Expand Down
13 changes: 13 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ To run integration tests against your own consumer/provider implementations, use

[E2E tests](tests/e2e/) run true consumer and provider chain binaries within a docker container and are relevant to the highest level of functionality. E2E tests use queries/transactions invoked from CLI to drive and validate the code.

## Simulation Tests

[Simulation tests](app/provider/sim_test.go) are used to test the full application via the SDK's simulation framework. This framework generates random inputs and checks that certain user-defined invariants hold.
Notably, as-of-now simulation tests do not include any multi-chain testing, so can only test the provider chain on its own, without consumer chains.

## Compatibility Tests

To test compatibility between different provider and consumer versions the [E2E tests](tests/e2e/) were extended by compatibility tests. The test cases perform basic sanity tests against the selected provider and consumer versions. A selected combination of provider and consumer versions are tested on a nightly bases and can be run locally with the
Expand Down Expand Up @@ -57,6 +62,12 @@ make test-no-cache

# run E2E compatibility tests for selected provider and consumer versions
make test-e2e-compatibility-tests-latest

# run full simulation tests
make sim-full

#run simulation tests where providerModule.max_provider_consensus_validators=stakingModule.max_validators=100
make sim-full-no-inactive-vals
```

Alternatively you can run tests using `go test`:
Expand All @@ -83,6 +94,8 @@ go run ./tests/e2e/... --local-sdk-path "/Users/bob/Documents/cosmos-sdk/"
go test -fuzz=<regex-to-match-test-name>
# run verbose E2E tests
go run ./tests/e2e/... --local-sdk-path "/Users/bob/Documents/cosmos-sdk/" --verbose
# run simulation tests; should be run from the 0app/provider directory
go test -mod=readonly . -run=^TestFullAppSimulation$ -Enabled=true -NumBlocks=500 -BlockSize=200 -Commit=true -timeout 24h -v
```

### Testing with Gaia as the provider
Expand Down
27 changes: 27 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# Upgrading Replicated Security

## Unreleased

### Provider

Upgrading a provider from v5.1.x requires state migrations. The following migrators should be added to the upgrade handler of the provider chain:

```go
// InitializeMaxValidatorsForExistingConsumers initializes the max validators
// parameter for existing consumers to the MaxProviderConsensusValidators parameter.
// This is necessary to avoid those consumer chains having an excessive amount of validators.
func InitializeMaxValidatorsForExistingConsumers(ctx sdk.Context, providerKeeper providerkeeper.Keeper) {
maxVals := providerKeeper.GetParams(ctx).MaxProviderConsensusValidators
for _, chainID := range providerKeeper.GetAllRegisteredConsumerChainIDs(ctx) {
providerKeeper.SetValidatorSetCap(ctx, chainID, uint32(maxVals))
}
}

// InitializeMaxProviderConsensusParam initializes the MaxProviderConsensusValidators parameter.
func InitializeMaxProviderConsensusParam(ctx sdk.Context, providerKeeper providerkeeper.Keeper) {
params := providerKeeper.GetParams(ctx)
if params.MaxProviderConsensusValidators == 0 {
params.MaxProviderConsensusValidators = 180
providerKeeper.SetParams(ctx, params)
}
}
```

## [v5.1.x](https://github.com/cosmos/interchain-security/releases/tag/v5.1.0)

### Provider
Expand Down
Loading

0 comments on commit 2fb67d1

Please sign in to comment.