Skip to content

Commit

Permalink
feat: Upgrade SDK v0.47 to v0.50 (#1069)
Browse files Browse the repository at this point in the history
# Related Github tickets

- Upgrading SDK v0.47.4 to v0.50.2

# Background

_This PR contains all the changes that has to be done for the upgrade,
including integration tests/unit tests. This also contains latest master
branch commits upto
[this](66fb3ff90a08ae1699e068490d4e69f21f622401)_

# Testing completed

- [x] `keeper_integration_tests` are moved to
`tests/integration/{module}` with local fixture setup, leaving the
dependency on app/app_setup.go (so the file app_setup.go is deleted)
- [x] New test cases added are
* **_util/keeper/address_test.go_** which covers
**_util/keeper/address.go_**
* **_/x/gravity/migrations/v1/migrate_test.go_** which covers
**_/x/gravity/migrations/v1/migrate.go_**
- [x] Most of the test coverage exists as it is with upgrade related
changes, only few got updated as listed below
* **_tests/integration/evm/keeper/keeper_integration_test.go_** had
`putMessageInQueue` in the case `there is another upload valset already
in` only but later we needed to add for two more functions,
`TestFirstSnapshot_OnSnapshotBuilt()` function and
`TestOldPublishedSnapshot_OnSnapshotBuilt` function
* In **_x/paloma/ante.go_** after a series of discussion we arrived at
the conclusion to use `libmeta.getSigner` but the test cases were
failing so I mentioned
[here](https://github.com/palomachain/paloma/blob/bcdf4d248c51caa2898f58d4b42e0d91add59395/x/paloma/ante.go#L96)
with comment, you may interpret this change to adapt with the test case.
- [ ] tested in a private testnet
- [x] Upgrade testing is done

# Breaking changes

- [ ] I have checked my code for breaking changes
- [ ] If there are breaking changes, there is a supporting migration.

---------

Co-authored-by: vishal <[email protected]>
Co-authored-by: Christian Lohr <[email protected]>
  • Loading branch information
3 people authored Feb 27, 2024
1 parent 2eb3a05 commit a4b1e22
Show file tree
Hide file tree
Showing 339 changed files with 9,734 additions and 7,811 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ release/
build/
dist/
.scratch/

tests/integration/evm/keeper/testdata
459 changes: 254 additions & 205 deletions app/app.go

Large diffs are not rendered by default.

184 changes: 0 additions & 184 deletions app/app_setup.go

This file was deleted.

3 changes: 0 additions & 3 deletions app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@ func MakeEncodingConfig() params.EncodingConfig {
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)

ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)

return encodingConfig
}
90 changes: 66 additions & 24 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"log"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
storetypes "cosmossdk.io/store/types"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
Expand All @@ -16,7 +16,7 @@ import (
// file.
func (app *App) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs, modulesToExport []string) (servertypes.ExportedApp, error) {
// as if they could withdraw from the start of the next block
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
ctx := app.NewContext(true).WithBlockHeight(app.LastBlockHeight())

// We export at last height + 1, because that's the height at which
// Tendermint will start InitChain.
Expand All @@ -26,7 +26,10 @@ func (app *App) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs
app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs)
}

genState := app.mm.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
genState, err := app.ModuleManager.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
if err != nil {
return servertypes.ExportedApp{}, err
}

appState, err := json.MarshalIndent(genState, "", " ")
if err != nil {
Expand Down Expand Up @@ -73,18 +76,24 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
/* Handle fee distribution state. */

// withdraw all validator commission
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, err := app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
err := app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, err := app.DistrKeeper.WithdrawValidatorCommission(ctx, sdk.ValAddress(val.GetOperator()))
if err != nil {
panic(err)
}
return false
})
if err != nil {
panic(err)
}

// withdraw all delegator rewards
dels := app.StakingKeeper.GetAllDelegations(ctx)
dels, err := app.StakingKeeper.GetAllDelegations(ctx)
if err != nil {
panic(err)
}
for _, delegation := range dels {
_, err := app.DistrKeeper.WithdrawDelegationRewards(ctx, delegation.GetDelegatorAddr(), delegation.GetValidatorAddr())
_, err := app.DistrKeeper.WithdrawDelegationRewards(ctx, sdk.AccAddress(delegation.GetDelegatorAddr()), sdk.ValAddress(delegation.GetValidatorAddr()))
if err != nil {
panic(err)
}
Expand All @@ -101,27 +110,39 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
ctx = ctx.WithBlockHeight(0)

// reinitialize all validators
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
err = app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
feePool := app.DistrKeeper.GetFeePool(ctx)
scraps, err := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, sdk.ValAddress(val.GetOperator()))
if err != nil {
panic(err)
}
feePool, err := app.DistrKeeper.FeePool.Get(ctx)
if err != nil {
panic(err)
}
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.DistrKeeper.SetFeePool(ctx, feePool)
err = app.DistrKeeper.FeePool.Set(ctx, feePool)
if err != nil {
panic(err)
}

if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()); err != nil {
if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, sdk.ValAddress(val.GetOperator())); err != nil {
panic(err)
}

return false
})
if err != nil {
panic(err)
}

// reinitialize all delegations
for _, del := range dels {
if err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr()); err != nil {
if err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, sdk.AccAddress(del.GetDelegatorAddr()), sdk.ValAddress(del.GetValidatorAddr())); err != nil {
panic(err)
}

if err := app.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr()); err != nil {
if err := app.DistrKeeper.Hooks().AfterDelegationModified(ctx, sdk.AccAddress(del.GetDelegatorAddr()), sdk.ValAddress(del.GetValidatorAddr())); err != nil {
panic(err)
}
}
Expand All @@ -132,33 +153,45 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
/* Handle staking state. */

// iterate through redelegations, reset creation height
app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
err = app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
for i := range red.Entries {
red.Entries[i].CreationHeight = 0
}
app.StakingKeeper.SetRedelegation(ctx, red)
err = app.StakingKeeper.SetRedelegation(ctx, red)
if err != nil {
panic(err)
}
return false
})
if err != nil {
panic(err)
}

// iterate through unbonding delegations, reset creation height
app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
err = app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
for i := range ubd.Entries {
ubd.Entries[i].CreationHeight = 0
}
app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
err = app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
if err != nil {
panic(err)
}
return false
})
if err != nil {
panic(err)
}

// Iterate through validators by power descending, reset bond heights, and
// update bond intra-tx counters.
store := ctx.KVStore(app.keys[stakingtypes.StoreKey])
iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
iter := storetypes.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
counter := int16(0)

for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Key()[1:])
validator, found := app.StakingKeeper.GetValidator(ctx, addr)
if !found {
validator, err := app.StakingKeeper.GetValidator(ctx, addr)
if err != nil {
panic("expected validator, not found")
}

Expand All @@ -167,7 +200,10 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
validator.Jailed = true
}

app.StakingKeeper.SetValidator(ctx, validator)
err = app.StakingKeeper.SetValidator(ctx, validator)
if err != nil {
panic(err)
}
counter++
}

Expand All @@ -180,12 +216,18 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
/* Handle slashing state. */

// reset start height on signing infos
app.SlashingKeeper.IterateValidatorSigningInfos(
err = app.SlashingKeeper.IterateValidatorSigningInfos(
ctx,
func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) {
info.StartHeight = 0
app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info)
err = app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info)
if err != nil {
panic(err)
}
return false
},
)
if err != nil {
panic(err)
}
}
Loading

0 comments on commit a4b1e22

Please sign in to comment.