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: standalone to consumer changeover part 1 #757

Merged
merged 60 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
40f3fdd
on-chain upgrade to consumer chain wip
jstr1121 Dec 19, 2022
aa566c9
add preCCV store and use it on democracy staking
jstr1121 Dec 19, 2022
dc9768d
add TODOs and one more packet possibility
jstr1121 Dec 19, 2022
473e467
status update
jstr1121 Dec 28, 2022
c6803f1
Resolve hermes start issue for trusted validator set by changing revi…
jstr1121 Jan 5, 2023
15265ad
remove intermediary logs
jstr1121 Jan 6, 2023
2806d6f
remove further unused codebase
jstr1121 Jan 6, 2023
c3ae9a4
updates for endblocker test, existing test fixes, get last validators
jstr1121 Jan 18, 2023
67aa39b
update for slashing sovereign validators for the fault made before co…
jstr1121 Jan 19, 2023
09f7b61
resolve comments on github and slack communication
jstr1121 Jan 31, 2023
d7b5a7f
Merge branch 'main' of github.com:Stride-Labs/interchain-security int…
jstr1121 Feb 21, 2023
8aea5bf
update sovereign app to use v4 ibc from v3 & resolve consumer module …
jstr1121 Feb 21, 2023
62da0d2
Update app/sovereign/upgrades/v3/upgrades.go
jstr1121 Feb 21, 2023
1cbd9d8
Merge branch 'main' into feature/onchain_upgrade_to_consumer_chain_840
shaspitz Mar 9, 2023
d46d6ef
rm sovereign chain and tests. Will be replaced by simapp and integrat…
shaspitz Mar 9, 2023
a8e8f4f
duplicate module name
shaspitz Mar 9, 2023
85b7be5
add comment
shaspitz Mar 10, 2023
a651abc
small rename
shaspitz Mar 10, 2023
1269163
remove democracy staking changes
shaspitz Mar 10, 2023
68515d9
consumer ccv beginblock, endblock, and initgenesis order shouldn't ma…
shaspitz Mar 11, 2023
48d64f4
add mock calls to compile
shaspitz Mar 13, 2023
95d11e7
adjust tests for new keeper field
shaspitz Mar 13, 2023
be3fda8
add registerDemocConsumer method
shaspitz Mar 13, 2023
e3a35ce
Merge branch 'main' into feature/onchain_upgrade_to_consumer_chain_840
shaspitz Mar 14, 2023
331f206
split out preCCV flag and initial valset
shaspitz Mar 14, 2023
08bb06b
cleanup consumer module
shaspitz Mar 14, 2023
91d7bee
cleanup
shaspitz Mar 14, 2023
110d710
more cleanup
shaspitz Mar 14, 2023
3584537
temp changes to validators.go
shaspitz Mar 14, 2023
1107280
comment out test
shaspitz Mar 14, 2023
fa5a6eb
rm bad code from merge
shaspitz Mar 14, 2023
4b5fd84
comment
shaspitz Mar 15, 2023
00a78ef
Update app.go
shaspitz Mar 15, 2023
e09066d
UTs for CRUD
shaspitz Mar 15, 2023
772c09c
UTs for keys
shaspitz Mar 15, 2023
2dc79e4
Merge branch 'main' into feature/onchain_upgrade_to_consumer_chain_840
shaspitz Mar 16, 2023
c0847e1
use make for mocks
shaspitz Mar 16, 2023
e0e5699
todo
shaspitz Mar 16, 2023
a7982de
changeover method and test
shaspitz Mar 16, 2023
aa6da31
resolve #783
shaspitz Mar 17, 2023
53dd6ea
comment
shaspitz Mar 17, 2023
3651164
comments
shaspitz Mar 17, 2023
45453b8
add appropriate TODOs, restore changes to main
shaspitz Mar 17, 2023
7fa624b
final nits before non-draft
shaspitz Mar 17, 2023
a07e84b
comment on ChangeoverToConsumer
shaspitz Mar 17, 2023
541aeb2
Merge branch 'main' into feature/onchain_upgrade_to_consumer_chain_840
shaspitz Mar 17, 2023
0ce68ce
more clear comment
shaspitz Mar 17, 2023
4f31546
Merge branch 'feature/onchain_upgrade_to_consumer_chain_840' of https…
shaspitz Mar 17, 2023
3652b2a
small comment change
shaspitz Mar 17, 2023
4f2e77e
update InitGenesis comment
shaspitz Mar 17, 2023
6b63b7e
sovereign -> standalone
shaspitz Mar 20, 2023
b80fe0f
missed a file
shaspitz Mar 20, 2023
17f020a
builds now
shaspitz Mar 20, 2023
f395584
Merge branch 'main' into feature/onchain_upgrade_to_consumer_chain_840
shaspitz Mar 20, 2023
2a76cd1
update comment after debug
shaspitz Mar 20, 2023
8cf1da3
naming refactor
shaspitz Mar 21, 2023
a349d84
Merge branch 'main' into feature/onchain_upgrade_to_consumer_chain_840
shaspitz Apr 4, 2023
f518e9b
edge case for val in old and new sets
shaspitz Apr 5, 2023
bbc1ed7
Merge branch 'main' into feature/onchain_upgrade_to_consumer_chain_840
shaspitz Apr 5, 2023
26bfcdf
restore keys after rebase
shaspitz Apr 5, 2023
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
50 changes: 43 additions & 7 deletions app/consumer-democracy/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"os"
"path/filepath"

genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
Expand Down Expand Up @@ -114,7 +116,7 @@ import (

const (
AppName = "interchain-security-cd"
upgradeName = "v07-Theta"
upgradeName = "v07-Theta" // arbitrary name, define your own appropriately named upgrade
AccountAddressPrefix = "cosmos"
)

Expand Down Expand Up @@ -331,7 +333,7 @@ func New(
app.AccountKeeper,
)

ccvstakingKeeper := stakingkeeper.NewKeeper(
stakingKeeper := stakingkeeper.NewKeeper(
appCodec,
keys[stakingtypes.StoreKey],
app.AccountKeeper,
Expand All @@ -340,7 +342,7 @@ func New(
)

app.MintKeeper = mintkeeper.NewKeeper(
appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &ccvstakingKeeper,
appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper,
app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName,
)

Expand All @@ -356,7 +358,7 @@ func New(
app.GetSubspace(distrtypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
&ccvstakingKeeper,
&stakingKeeper,
consumertypes.ConsumerRedistributeName,
app.ModuleAccountAddrs(),
)
Expand All @@ -377,7 +379,7 @@ func New(
// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
// NOTE: slashing hook was removed since it's only relevant for consumerKeeper
app.StakingKeeper = *ccvstakingKeeper.SetHooks(
app.StakingKeeper = *stakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks()),
)

Expand All @@ -390,7 +392,7 @@ func New(
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper))
govKeeper := govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
&ccvstakingKeeper, ccvgovRouter,
&stakingKeeper, ccvgovRouter,
)

app.GovKeeper = *govKeeper.SetHooks(
Expand Down Expand Up @@ -426,6 +428,9 @@ func New(
authtypes.FeeCollectorName,
)

// Setting the staking keeper is only needed for standalone to consumer changeover chains
app.ConsumerKeeper.SetStandaloneStakingKeeper(app.StakingKeeper)

// consumer keeper satisfies the staking keeper interface
// of the slashing module
app.SlashingKeeper = slashingkeeper.NewKeeper(
Expand Down Expand Up @@ -626,6 +631,7 @@ func New(
app.UpgradeKeeper.SetUpgradeHandler(
upgradeName,
func(ctx sdk.Context, _ upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) {

app.IBCKeeper.ConnectionKeeper.SetParams(ctx, ibcconnectiontypes.DefaultParams())

fromVM := make(map[string]uint64)
Expand All @@ -634,8 +640,33 @@ func New(
fromVM[moduleName] = eachModule.ConsensusVersion()
}

// For a new consumer chain, this code (together with the entire SetUpgradeHandler) is not needed at all,
// upgrade handler code is application specific. However, as an example, standalone to consumer
// changeover chains should utilize customized upgrade handler code similar to below.

// TODO: should have a way to read from current node home
shaspitz marked this conversation as resolved.
Show resolved Hide resolved
userHomeDir, err := os.UserHomeDir()
if err != nil {
stdlog.Println("Failed to get home dir %2", err)
}
nodeHome := userHomeDir + "/.sovereign/config/genesis.json"
appState, _, err := genutiltypes.GenesisStateFromGenFile(nodeHome)
if err != nil {
return fromVM, fmt.Errorf("failed to unmarshal genesis state: %w", err)
}

var consumerGenesis = consumertypes.GenesisState{}
appCodec.MustUnmarshalJSON(appState[consumertypes.ModuleName], &consumerGenesis)

consumerGenesis.PreCCV = true
app.ConsumerKeeper.InitGenesis(ctx, &consumerGenesis)

ctx.Logger().Info("start to run module migrations...")

// Note: consumer ccv module is added to app.MM.Modules constructor above,
// meaning the consumer ccv module will have an entry in fromVM.
// Since a consumer ccv module entry exists in fromVM, the RunMigrations method
// will not call the consumer ccv module's InitGenesis method a second time.
return app.MM.RunMigrations(ctx, app.configurator, fromVM)
},
)
Expand All @@ -646,7 +677,12 @@ func New(
}

if upgradeInfo.Name == upgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := store.StoreUpgrades{}
// Chains may need to add a KV store to their application. The following code
// is needed for standalone chains that're changing over to a consumer chain, with a consumer ccv module.
// When a chain starts from height 0 (like for testing purposes in this repo), the following code is not needed.
storeUpgrades := store.StoreUpgrades{
Added: []string{consumertypes.ModuleName},
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
Expand Down
1 change: 1 addition & 0 deletions proto/interchain_security/ccv/consumer/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ message GenesisState {
// LastTransmissionBlockHeight nil on new chain, filled in on restart.
interchain_security.ccv.consumer.v1.LastTransmissionBlockHeight last_transmission_block_height = 12
[ (gogoproto.nullable) = false ];
bool preCCV = 13; // flag indicating whether the consumer CCV module starts in pre-CCV state
}

// HeightValsetUpdateID defines the genesis information for the mapping
Expand Down
108 changes: 108 additions & 0 deletions testutil/keeper/mocks.go

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

40 changes: 40 additions & 0 deletions x/ccv/consumer/keeper/changeover.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
)

// ChangeoverToConsumer includes the logic that needs to execute during the process of a
// standalone to consumer changeover, where the previously standalone chain has
// just been upgraded to include the consumer ccv module, but the provider valset is not
// yet responsible for POS/block production. This method constructs validator updates
// that will be given to tendermint, which allows the consumer chain to
// start using the provider valset, while the standalone valset is given zero voting power where appropriate.
func (k Keeper) ChangeoverToConsumer(ctx sdk.Context) (initialValUpdates []abci.ValidatorUpdate) {
shaspitz marked this conversation as resolved.
Show resolved Hide resolved

initialValUpdates = k.GetInitialValSet(ctx)
// set last standalone height
k.SetLastStandaloneHeight(ctx, ctx.BlockHeight())
// populate cross chain validators states with initial valset
k.ApplyCCValidatorChanges(ctx, initialValUpdates)

// Add validator updates to initialValUpdates, such that the "old" validators returned from standalone staking module
// are given zero power, and the provider validators are given their full power.
initialUpdatesFlag := make(map[string]bool)
for _, val := range initialValUpdates {
initialUpdatesFlag[val.PubKey.String()] = true
}
for _, val := range k.GetLastStandaloneValidators(ctx) {
zeroPowerUpdate := val.ABCIValidatorUpdateZero()
if !initialUpdatesFlag[zeroPowerUpdate.PubKey.String()] {
initialValUpdates = append(initialValUpdates, zeroPowerUpdate)
}
}

// Note: this method should only be executed once as a part of the changeover process.
// Therefore we set the PreCCV state to false so the endblocker caller doesn't call this method again.
k.DeletePreCCV(ctx)

return initialValUpdates
}
Loading