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

Adds IBC and BasicModuleManager #1879

Merged
merged 25 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ed36526
Modify changelog.
Taztingo Mar 15, 2024
bc13158
Add skeleton for ibc upgrade.
Taztingo Mar 15, 2024
9cced76
Add logic for v7 upgrade.
Taztingo Mar 15, 2024
cfb72ac
Add param migration.
Taztingo Mar 15, 2024
33a7897
Add upgrades for ibcv8 and add logging. Updated umber tests as well
Taztingo Mar 15, 2024
48f6190
Remove ModuleBasics, and migrate ibc params.
Taztingo Mar 20, 2024
dd6b263
Update changelog to account for ModuleBasics.
Taztingo Mar 20, 2024
fd7c82d
Fix typo in changelog.
Taztingo Mar 20, 2024
5884af3
Add signing options.
Taztingo Mar 21, 2024
5ae8427
Add finalize block to make test pass and help ensure encoder/decoders…
Taztingo Mar 21, 2024
853bd31
Fix remaining test in app_test.go
Taztingo Mar 21, 2024
215a8ca
Remove replace comment for ibc-go dependency.
Taztingo Mar 21, 2024
b7646e0
Remove commented out code.
Taztingo Mar 21, 2024
76be962
Update interfaces for modules.
Taztingo Mar 21, 2024
533c184
Merge in main-v0.50
Taztingo Mar 28, 2024
552236d
Fix some migration documentation and fix order of pruning.
Taztingo Apr 1, 2024
93f0d92
Remove TODO.
Taztingo Apr 1, 2024
2a89460
Update function comment.
Taztingo Apr 1, 2024
bf496e1
Rename upgradeIBCv8 to updateIBCClients.
Taztingo Apr 1, 2024
fffa6be
Add periods to logs.
Taztingo Apr 1, 2024
6fc5bd7
Change how tempdir is made.
Taztingo Apr 4, 2024
bd44c8c
Merge in main v0.50
Taztingo Apr 4, 2024
f795dbc
Merge in main v0.50
Taztingo Apr 4, 2024
4f2063e
Fix redeclared dependency.
Taztingo Apr 4, 2024
33c113d
Merge in main v0.50
Taztingo Apr 4, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Updated documentation for each module to work with docusaurus [PR 1763](https://github.com/provenance-io/provenance/pull/1763).
* Create a default market in `make run`, `localnet`, `devnet` and the `provenanced testnet` command [#1757](https://github.com/provenance-io/provenance/issues/1757).
* Remove unsupported database types [#1760](https://github.com/provenance-io/provenance/issues/1760).
* Update ibc and migrate params [#1760](https://github.com/provenance-io/provenance/issues/1760).
* Replace ModuleBasics with BasicModuleManager [#1760](https://github.com/provenance-io/provenance/issues/1760).
* Bump the SDK to `v0.50.5-pio-1` (from an earlier ephemeral version) [#1897](https://github.com/provenance-io/provenance/pull/1897).

### Dependencies
Expand Down
97 changes: 23 additions & 74 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,56 +189,6 @@
// DefaultPowerReduction pio specific value for power reduction for TokensFromConsensusPower
DefaultPowerReduction = sdkmath.NewIntFromUint64(1_000_000_000)

// ModuleBasics defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration
// and genesis verification.
ModuleBasics = module.NewBasicManager(
auth.AppModuleBasic{},
genutil.AppModuleBasic{},
bank.AppModuleBasic{},
capability.AppModuleBasic{},
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(append(
[]govclient.ProposalHandler{},
paramsclient.ProposalHandler,
nameclient.RootNameProposalHandler,
),
),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
feegrantmodule.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
authzmodule.AppModuleBasic{},
groupmodule.AppModuleBasic{},
vesting.AppModuleBasic{},
// quarantinemodule.AppModuleBasic{}, // TODO[1760]: quarantine
// sanctionmodule.AppModuleBasic{}, // TODO[1760]: sanction
consensus.AppModuleBasic{},

ibc.AppModuleBasic{},
ibctransfer.AppModuleBasic{},
ica.AppModuleBasic{},
icq.AppModuleBasic{},
ibchooks.AppModuleBasic{},
ibcratelimitmodule.AppModuleBasic{},

marker.AppModuleBasic{},
attribute.AppModuleBasic{},
name.AppModuleBasic{},
metadata.AppModuleBasic{},
wasm.AppModuleBasic{},
msgfeesmodule.AppModuleBasic{},
rewardmodule.AppModuleBasic{},
triggermodule.AppModuleBasic{},
oraclemodule.AppModuleBasic{},
holdmodule.AppModuleBasic{},
exchangemodule.AppModuleBasic{},
)

// module account permissions
maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
Expand Down Expand Up @@ -443,7 +393,7 @@
app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])

// set the BaseApp's parameter store
// TODO[1760]: Update upgrade handler

app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]),
Expand Down Expand Up @@ -811,25 +761,24 @@
icaModule,
)

// TODO[1760]: app-module: BasicModuleManager: Make sure that this setup has everything we need (it was just copied from the SDK).
// BasicModuleManager defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration and genesis verification.
// By default it is composed of all the module from the module manager.
// Additionally, app module basics can be overwritten by passing them as argument.
/*
app.BasicModuleManager = module.NewBasicManagerFromManager(
app.mm,
map[string]module.AppModuleBasic{
genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
govtypes.ModuleName: gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
},
app.BasicModuleManager = module.NewBasicManagerFromManager(
app.mm,
map[string]module.AppModuleBasic{
genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
govtypes.ModuleName: gov.NewAppModuleBasic(
append(
[]govclient.ProposalHandler{},
paramsclient.ProposalHandler,
nameclient.RootNameProposalHandler, // TODO[1760]: Do we still need the nameclient?
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
),
})
app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino)
app.BasicModuleManager.RegisterInterfaces(interfaceRegistry)
*/
),
})
app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino)
app.BasicModuleManager.RegisterInterfaces(interfaceRegistry)

// NOTE: upgrade module is required to be prioritized
app.mm.SetOrderPreBlockers(
Expand Down Expand Up @@ -1019,7 +968,7 @@

app.mm.RegisterInvariants(app.CrisisKeeper)
app.configurator = module.NewConfigurator(app.appCodec, app.BaseApp.MsgServiceRouter(), app.GRPCQueryRouter())
app.mm.RegisterServices(app.configurator)

Check failure on line 971 in app/app.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Error return value of `app.mm.RegisterServices` is not checked (errcheck)

app.sm = module.NewSimulationManager(
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
Expand Down Expand Up @@ -1198,7 +1147,7 @@
if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}
app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())

Check failure on line 1150 in app/app.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Error return value of `app.UpgradeKeeper.SetModuleVersionMap` is not checked (errcheck)
return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
}

Expand Down Expand Up @@ -1239,9 +1188,8 @@
}

// DefaultGenesis returns a default genesis from the registered AppModuleBasic's.
func (a *App) DefaultGenesis() map[string]json.RawMessage {
// TODO[1760] This was changed to ModuleBasics, but it will be removed
return ModuleBasics.DefaultGenesis(a.appCodec)
func (app *App) DefaultGenesis() map[string]json.RawMessage {
return app.BasicModuleManager.DefaultGenesis(app.appCodec)
}

// GetKey returns the KVStoreKey for the provided store key.
Expand Down Expand Up @@ -1292,7 +1240,7 @@
nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// Register grpc-gateway routes for all modules.
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
app.BasicModuleManager.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// register swagger API from root so that other applications can override easily
if apiConfig.Swagger {
Expand Down Expand Up @@ -1390,11 +1338,12 @@
// register the key tables for legacy param subspaces
keyTable := ibcclienttypes.ParamKeyTable()
keyTable.RegisterParamSet(&ibcconnectiontypes.Params{})
paramsKeeper.Subspace(ibctransfertypes.ModuleName) // TODO[1760]: params: Migrate ibc-transfer params.
paramsKeeper.Subspace(ibcexported.ModuleName) // TODO[1760]: params: Migrate ibc-host params.
paramsKeeper.Subspace(icahosttypes.SubModuleName) // TODO[1760]: params: Migrate ica-host params.
paramsKeeper.Subspace(icqtypes.ModuleName) // TODO[1760]: params: Migrate icq params.
paramsKeeper.Subspace(ibchookstypes.ModuleName) // TODO[1760]: params: Migrate ibc-hooks params.
paramsKeeper.Subspace(ibcexported.ModuleName).WithKeyTable(keyTable)
paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable())
paramsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable())

paramsKeeper.Subspace(icqtypes.ModuleName) // TODO[1760]: params: Migrate icq params.
paramsKeeper.Subspace(ibchookstypes.ModuleName) // TODO[1760]: params: Migrate ibc-hooks params.

return paramsKeeper
}
Expand Down Expand Up @@ -1442,7 +1391,7 @@
// But the upgrade keeper often its own migration stuff that change some store key stuff.
// ScheduleUpgrade tries to read some of that changed store stuff and fails if the migration hasn't
// been applied yet. So we're doing things the hard way here.
app.UpgradeKeeper.ClearUpgradePlan(ctx)

Check failure on line 1394 in app/app.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Error return value of `app.UpgradeKeeper.ClearUpgradePlan` is not checked (errcheck)
store := ctx.KVStore(app.GetKey(upgradetypes.StoreKey))
bz := app.appCodec.MustMarshal(&plan)
store.Set(upgradetypes.PlanKey(), bz)
Expand Down
16 changes: 14 additions & 2 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sort"
"testing"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -43,12 +44,17 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) {
)
}

// finalize block so we have CheckTx state set
_, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{
Height: 1,
})
require.NoError(t, err)

app.Commit()

// Making a new app object with the db, so that initchain hasn't been called
app2 := New(log.NewTestLogger(t), opts.DB, nil, true,
map[int64]bool{}, opts.HomePath, 0, opts.EncConfig, simtestutil.EmptyAppOptions{})
var err error
map[int64]bool{}, opts.HomePath, 0, MakeEncodingConfig(), simtestutil.EmptyAppOptions{})
require.NotPanics(t, func() {
_, err = app2.ExportAppStateAndValidators(false, nil, nil)
}, "exporting app state at current height")
Expand Down Expand Up @@ -140,6 +146,12 @@ func TestExportAppStateAndValidators(t *testing.T) {
allAccounts := app.AccountKeeper.GetAllAccounts(ctx)
logAccounts(t, allAccounts, "allAccounts")

// finalize block so we have CheckTx state set
_, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{
Height: 1,
})
require.NoError(t, err)

app.Commit()

// Get an export
Expand Down
4 changes: 0 additions & 4 deletions app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app

import (
"github.com/cosmos/cosmos-sdk/std"

"github.com/provenance-io/provenance/app/params"
)

Expand All @@ -14,8 +13,5 @@ func MakeEncodingConfig() params.EncodingConfig {
encodingConfig := params.MakeTestEncodingConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)

ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}
7 changes: 0 additions & 7 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package app

import (
"encoding/json"

"github.com/cosmos/cosmos-sdk/codec"
)

// The genesis state of the blockchain is represented here as a map of raw json
Expand All @@ -14,8 +12,3 @@ import (
// the ModuleBasicManager which populates json from each BasicModule
// object provided to it during init.
type GenesisState map[string]json.RawMessage

// NewDefaultGenesisState generates the default state for the application.
func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState {
return ModuleBasics.DefaultGenesis(cdc)
}
20 changes: 18 additions & 2 deletions app/params/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,34 @@
package params

import (
"cosmossdk.io/x/tx/signing"
"github.com/cosmos/cosmos-sdk/codec"
amino "github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/cosmos/gogoproto/proto"
)

// MakeTestEncodingConfig creates an EncodingConfig for a non-amino based test configuration.
// This function should be used only internally (in the SDK).
// App user shouldn't create new codecs - use the app.AppCodec instead.
// [DEPRECATED]
func MakeTestEncodingConfig() EncodingConfig {
cdc := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
cdc := amino.NewLegacyAmino()
signingOptions := signing.Options{
AddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(),
},
ValidatorAddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(),
},
}
interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
SigningOptions: signingOptions,
})
marshaler := codec.NewProtoCodec(interfaceRegistry)

return EncodingConfig{
Expand Down
8 changes: 4 additions & 4 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func setup(t *testing.T, withGenesis bool, invCheckPeriod uint) (*App, GenesisSt

app := New(loggerMaker(), db, nil, true, map[int64]bool{}, t.TempDir(), invCheckPeriod, encCdc, simtestutil.EmptyAppOptions{})
if withGenesis {
return app, NewDefaultGenesisState(encCdc.Marshaler)
return app, app.DefaultGenesis()
}
return app, GenesisState{}
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func NewAppWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptions)
}

app := New(options.Logger, options.DB, nil, true, options.SkipUpgradeHeights, options.HomePath, options.InvCheckPeriod, options.EncConfig, options.AppOpts)
genesisState := NewDefaultGenesisState(app.appCodec)
genesisState := app.DefaultGenesis()
genesisState = genesisStateWithValSet(t, app, genesisState, valSet, []authtypes.GenesisAccount{acc}, balance)

if !isCheckTx {
Expand Down Expand Up @@ -213,7 +213,7 @@ func genesisStateWithValSet(t *testing.T,
bondAmt := sdk.DefaultPowerReduction

for _, val := range valSet.Validators {
pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey)
pk, err := cryptocodec.FromCmtPubKeyInterface(val.PubKey)
require.NoError(t, err)
pkAny, err := codectypes.NewAnyWithValue(pk)
require.NoError(t, err)
Expand Down Expand Up @@ -342,7 +342,7 @@ func GenesisStateWithSingleValidator(t *testing.T, app *App) GenesisState {
},
}

genesisState := NewDefaultGenesisState(app.appCodec)
genesisState := app.DefaultGenesis()
genesisState = genesisStateWithValSet(t, app, genesisState, valSet, []authtypes.GenesisAccount{acc}, balances...)

return genesisState
Expand Down
70 changes: 70 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
"github.com/cosmos/ibc-go/v8/modules/core/exported"

ibctmmigrations "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint/migrations"
attributekeeper "github.com/provenance-io/provenance/x/attribute/keeper"
attributetypes "github.com/provenance-io/provenance/x/attribute/types"
"github.com/provenance-io/provenance/x/exchange"
Expand Down Expand Up @@ -205,6 +208,17 @@
Added: []string{crisistypes.ModuleName},
Handler: func(ctx sdk.Context, app *App, vm module.VersionMap) (module.VersionMap, error) {
var err error

err = migrateParams(ctx, app)
if err != nil {
return nil, err
}

err = upgradeIBC(ctx, app)
if err != nil {
return nil, err
}

SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
vm, err = runModuleMigrations(ctx, app, vm)
if err != nil {
return nil, err
Expand All @@ -219,6 +233,17 @@
Added: []string{crisistypes.ModuleName},
Handler: func(ctx sdk.Context, app *App, vm module.VersionMap) (module.VersionMap, error) {
var err error

err = migrateParams(ctx, app)
if err != nil {
return nil, err
}

err = upgradeIBC(ctx, app)
if err != nil {
return nil, err
}

vm, err = runModuleMigrations(ctx, app, vm)
if err != nil {
return nil, err
Expand Down Expand Up @@ -450,7 +475,7 @@
// TODO: Remove with the saffron handlers.
func setupICQ(ctx sdk.Context, app *App) {
ctx.Logger().Info("Updating ICQ params")
app.ICQKeeper.SetParams(ctx, icqtypes.NewParams(true, []string{"/provenance.oracle.v1.Query/Oracle"}))

Check failure on line 478 in app/upgrades.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Error return value of `app.ICQKeeper.SetParams` is not checked (errcheck)
ctx.Logger().Info("Done updating ICQ params")
}

Expand Down Expand Up @@ -533,3 +558,48 @@
})
ctx.Logger().Info("Done updating ibc marker denom metadata")
}

// upgradeIBC handles all IBC upgrade logic for each upgrade.
func upgradeIBC(ctx sdk.Context, app *App) error {
if err := pruneIBCExpiredConsensusStates(ctx, app); err != nil {
return err
}
return upgradeToIBCv8(ctx, app)
}

// pruneIBCExpiredConsensusStates upgrades IBC from v6 to v8.
func pruneIBCExpiredConsensusStates(ctx sdk.Context, app *App) error {
ctx.Logger().Info("Pruning expired consensus states for IBC")
Taztingo marked this conversation as resolved.
Show resolved Hide resolved
_, err := ibctmmigrations.PruneExpiredConsensusStates(ctx, app.appCodec, app.IBCKeeper.ClientKeeper)
if err != nil {
ctx.Logger().Error(fmt.Sprintf("unable to prune expired consensus states, error: %s", err))
return err
}
ctx.Logger().Info("Done pruning expired consensus states for IBC")
return nil
}

// upgradeToIBCv8 upgrades IBC from v6 to v8.
// TODO: Remove with the umber handlers.
func upgradeToIBCv8(ctx sdk.Context, app *App) error {
ctx.Logger().Info("Upgrading to IBCv8")
params := app.IBCKeeper.ClientKeeper.GetParams(ctx)
params.AllowedClients = append(params.AllowedClients, exported.Localhost)
app.IBCKeeper.ClientKeeper.SetParams(ctx, params)
ctx.Logger().Info("Done upgrading to IBCv8")
return nil
}

// Migrate to new ConsensusParamsKeeper
// TODO: Remove with the umber handlers.
func migrateParams(ctx sdk.Context, app *App) error {
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
ctx.Logger().Info("Migrating legacy params")
legacyBaseAppSubspace := app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())
err := baseapp.MigrateParams(ctx, legacyBaseAppSubspace, app.ConsensusParamsKeeper.ParamsStore)
if err != nil {
ctx.Logger().Error(fmt.Sprintf("unable to migrate legacy params to ConsensusParamsKeeper, error: %s", err))
return err
}
ctx.Logger().Info("Done migrating legacy params")
return nil
}
Loading
Loading