Skip to content

Commit

Permalink
feat : upgraded the app with evm module to SDK v0.50 (#1036)
Browse files Browse the repository at this point in the history
* made changes in the app folder

* go mod changes

* cmd folder commits

* util folder commits

* testutil changess

* made changes to the evm module proto and solved the errors in evm module

* evm module changes

* deleted the commented files

* resolved the conflicts

* made chagnes as per review

* added the cmproto header to test file

* added the blockheight in genesis_test

* move params to module state

* Removed params realted code because evm module doesn't contain any params

* Changes made as per review comments

* removed the sdk params types

* used Witherror

* made changes as per review

* Changed sdk.ctx to context. ctx in all keeper mthd

* Mades changes in app.go and keeper.go

* Made changes as per the review commets

* changes as per review comments

* reverted the params.go file

---------

Co-authored-by: deepan95dev <[email protected]>
Co-authored-by: ruthishvitwit <[email protected]>
  • Loading branch information
3 people authored Dec 7, 2023
1 parent 18a2d0e commit 8a60bd6
Show file tree
Hide file tree
Showing 56 changed files with 2,265 additions and 2,684 deletions.
156 changes: 66 additions & 90 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ import (
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/gogoproto/proto"

// xchain "github.com/palomachain/paloma/internal/x-chain"
// "github.com/palomachain/paloma/x/evm"

"github.com/cosmos/cosmos-sdk/std"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/gogoproto/proto"

abci "github.com/cometbft/cometbft/abci/types"
tmjson "github.com/cometbft/cometbft/libs/json"
Expand Down Expand Up @@ -124,7 +120,6 @@ import (
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"

palomamempool "github.com/palomachain/paloma/app/mempool"
appparams "github.com/palomachain/paloma/app/params"
Expand All @@ -133,10 +128,11 @@ import (
// consensusmodule "github.com/palomachain/paloma/x/consensus"
// consensusmodulekeeper "github.com/palomachain/paloma/x/consensus/keeper"
// consensusmoduletypes "github.com/palomachain/paloma/x/consensus/types"
// "github.com/palomachain/paloma/x/evm"
// evmclient "github.com/palomachain/paloma/x/evm/client"
// evmmodulekeeper "github.com/palomachain/paloma/x/evm/keeper"
// evmmoduletypes "github.com/palomachain/paloma/x/evm/types"
"github.com/palomachain/paloma/x/evm"
evmclient "github.com/palomachain/paloma/x/evm/client"
evmmodulekeeper "github.com/palomachain/paloma/x/evm/keeper"
evmmoduletypes "github.com/palomachain/paloma/x/evm/types"

// gravitymodule "github.com/palomachain/paloma/x/gravity"
// gravityclient "github.com/palomachain/paloma/x/gravity/client"
// gravitymodulekeeper "github.com/palomachain/paloma/x/gravity/keeper"
Expand All @@ -151,6 +147,7 @@ import (
// treasuryclient "github.com/palomachain/paloma/x/treasury/client"
// treasurymodulekeeper "github.com/palomachain/paloma/x/treasury/keeper"
// treasurymoduletypes "github.com/palomachain/paloma/x/treasury/types"

// valsetmodule "github.com/palomachain/paloma/x/valset"
// valsetmodulekeeper "github.com/palomachain/paloma/x/valset/keeper"
// valsetmoduletypes "github.com/palomachain/paloma/x/valset/types"
Expand All @@ -168,51 +165,14 @@ const (
func getGovProposalHandlers() []govclient.ProposalHandler {
return []govclient.ProposalHandler{
paramsclient.ProposalHandler,
// evmclient.ProposalHandler,
// gravityclient.ProposalHandler,
// treasuryclient.ProposalHandler,
evmclient.ProposalHandler,
}
}

var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string

// 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.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
BankModule{},
capability.AppModuleBasic{},
StakingModule{},
MintModule{},
distr.AppModuleBasic{},
GovModule{gov.NewAppModuleBasic(getGovProposalHandlers())},
params.AppModuleBasic{},
CrisisModule{},
slashing.AppModule{},
feegrantmodule.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
vesting.AppModuleBasic{},
// schedulermodule.AppModuleBasic{},
// consensusmodule.AppModuleBasic{},
// valsetmodule.AppModuleBasic{},
// wasm.AppModuleBasic{},
// evm.AppModuleBasic{},
// gravitymodule.AppModuleBasic{},
// palomamodule.AppModuleBasic{},
// treasurymodule.AppModuleBasic{},
// consensus.AppModuleBasic{},
transfer.AppModuleBasic{},
ibc.AppModuleBasic{},
ibctm.AppModuleBasic{},
ica.AppModuleBasic{},
ibcfee.AppModuleBasic{},
)

// module account permissions
maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
Expand All @@ -221,12 +181,10 @@ var (
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
// gravitymoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibcfeetypes.ModuleName: nil,
icatypes.ModuleName: nil,
// wasm.ModuleName: {authtypes.Burner},
// treasurymoduletypes.ModuleName: {authtypes.Burner, authtypes.Minter},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibcfeetypes.ModuleName: nil,
icatypes.ModuleName: nil,
evmmoduletypes.ModuleName: {authtypes.Burner, authtypes.Minter},
}
)

Expand Down Expand Up @@ -289,14 +247,14 @@ type App struct {
// ConsensusKeeper consensusmodulekeeper.Keeper
// ValsetKeeper valsetmodulekeeper.Keeper
// PalomaKeeper palomamodulekeeper.Keeper
// TreasuryKeeper treasurymodulekeeper.Keeper
// EvmKeeper evmmodulekeeper.Keeper
// TreasuryKeeper treasurymodulekeeper.Keeper
EvmKeeper evmmodulekeeper.Keeper
// GravityKeeper gravitymodulekeeper.Keeper
wasmKeeper wasmkeeper.Keeper

// mm is the module manager
mm *module.Manager
bm module.BasicManager
ModuleManager *module.Manager
BasicModuleManager module.BasicManager

// sm is the simulation manager
sm *module.SimulationManager
Expand Down Expand Up @@ -367,6 +325,8 @@ func New(
// consensusmoduletypes.StoreKey,
// valsetmoduletypes.StoreKey,
// treasurymoduletypes.StoreKey,
// // wasm.StoreKey,
evmmoduletypes.StoreKey,
wasmtypes.StoreKey,
// evmmoduletypes.StoreKey,
// gravitymoduletypes.StoreKey,
Expand All @@ -378,7 +338,7 @@ func New(
capabilitytypes.MemStoreKey,
// valsetmoduletypes.MemStoreKey,
// consensusmoduletypes.MemStoreKey,
// evmmoduletypes.MemStoreKey,
evmmoduletypes.MemStoreKey,
// schedulermoduletypes.MemStoreKey,
// treasurymoduletypes.MemStoreKey,
// palomamoduletypes.MemStoreKey,
Expand Down Expand Up @@ -587,14 +547,13 @@ func New(
// consensusRegistry,
// )

// app.EvmKeeper = *evmmodulekeeper.NewKeeper(
// appCodec,
// keys[evmmoduletypes.StoreKey],
// memKeys[evmmoduletypes.MemStoreKey],
// app.GetSubspace(evmmoduletypes.ModuleName),
// app.ConsensusKeeper,
// app.ValsetKeeper,
// )
app.EvmKeeper = *evmmodulekeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[evmmoduletypes.StoreKey]),
nil, //TODO
nil, //TODO
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
// app.ValsetKeeper.SnapshotListeners = []valsetmoduletypes.OnSnapshotBuiltListener{
// app.EvmKeeper,
// }
Expand Down Expand Up @@ -655,22 +614,19 @@ func New(
// appCodec,
// keys[treasurymoduletypes.StoreKey],
// memKeys[treasurymoduletypes.MemStoreKey],
// app.GetSubspace(schedulermoduletypes.ModuleName),
// app.GetSubspace("" /*schedulermoduletypes.ModuleName*/),
// app.BankKeeper,
// app.AccountKeeper,
// app.SchedulerKeeper,
// nil, // app.SchedulerKeeper,
// )

// app.ScopedConsensusKeeper = scopedConsensusKeeper

govRouter := govv1beta1.NewRouter()
govRouter.
AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper))
// AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))
// AddRoute(evmmoduletypes.RouterKey, evm.NewReferenceChainReferenceIDProposalHandler(app.EvmKeeper)).
// AddRoute(gravitymoduletypes.RouterKey, gravitymodulekeeper.NewGravityProposalHandler(app.GravityKeeper)).
// AddRoute(treasurymoduletypes.RouterKey, treasurymodule.NewFeeProposalHandler(app.TreasuryKeeper))
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(evmmoduletypes.RouterKey, evm.NewReferenceChainReferenceIDProposalHandler(app.EvmKeeper))

// Example of setting gov params:
govKeeper := govkeeper.NewKeeper(
Expand Down Expand Up @@ -778,14 +734,14 @@ func New(
// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.

// evmModule := evm.NewAppModule(appCodec, app.EvmKeeper, app.AccountKeeper, app.BankKeeper)
evmModule := evm.NewAppModule(appCodec, app.EvmKeeper, app.AccountKeeper, app.BankKeeper)
// consensusModule := consensusmodule.NewAppModule(appCodec, app.ConsensusKeeper, app.AccountKeeper, app.BankKeeper)
// valsetModule := valsetmodule.NewAppModule(appCodec, app.ValsetKeeper, app.AccountKeeper, app.BankKeeper)
// schedulerModule := schedulermodule.NewAppModule(appCodec, app.SchedulerKeeper, app.AccountKeeper, app.BankKeeper)
// palomaModule := palomamodule.NewAppModule(appCodec, app.PalomaKeeper, app.AccountKeeper, app.BankKeeper)
// gravityModule := gravitymodule.NewAppModule(appCodec, app.GravityKeeper, app.BankKeeper)
// treasuryModule := treasurymodule.NewAppModule(appCodec, app.TreasuryKeeper, app.AccountKeeper, app.BankKeeper)
app.mm = module.NewManager(
app.ModuleManager = module.NewManager(
genutil.NewAppModule(
app.AccountKeeper,
app.StakingKeeper,
Expand All @@ -809,7 +765,7 @@ func New(
// schedulerModule,
// consensusModule,
// valsetModule,
// evmModule,
evmModule,
// gravityModule,
// palomaModule,
// treasuryModule,
Expand All @@ -821,11 +777,23 @@ func New(
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
)

app.BasicModuleManager = module.NewBasicManagerFromManager(
app.ModuleManager,
map[string]module.AppModuleBasic{
genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
govtypes.ModuleName: gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
},
),
})
app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino)
app.BasicModuleManager.RegisterInterfaces(interfaceRegistry)
// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
// CanWithdrawInvariant invariant.
// NOTE: staking module is required if HistoricalEntries param > 0
app.mm.SetOrderBeginBlockers(
app.ModuleManager.SetOrderBeginBlockers(
upgradetypes.ModuleName,
capabilitytypes.ModuleName,
minttypes.ModuleName,
Expand All @@ -845,6 +813,8 @@ func New(
genutiltypes.ModuleName,
// valsetmoduletypes.ModuleName,
// palomamoduletypes.ModuleName,
// wasm.ModuleName,
evmmoduletypes.ModuleName,
wasmtypes.ModuleName,
// evmmoduletypes.ModuleName,
// gravitymoduletypes.ModuleName,
Expand All @@ -856,7 +826,7 @@ func New(
consensusparamtypes.ModuleName,
)

app.mm.SetOrderEndBlockers(
app.ModuleManager.SetOrderEndBlockers(
crisistypes.ModuleName,
govtypes.ModuleName,
stakingtypes.ModuleName,
Expand All @@ -877,6 +847,8 @@ func New(
genutiltypes.ModuleName,
// valsetmoduletypes.ModuleName,
// palomamoduletypes.ModuleName,
// wasm.ModuleName,
evmmoduletypes.ModuleName,
wasmtypes.ModuleName,
// evmmoduletypes.ModuleName,
// gravitymoduletypes.ModuleName,
Expand All @@ -893,7 +865,7 @@ func New(
// NOTE: Capability module must occur first so that it can initialize any capabilities
// so that other modules that want to create or claim capabilities afterwards in InitChain
// can do so safely.
app.mm.SetOrderInitGenesis(
app.ModuleManager.SetOrderInitGenesis(
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
Expand All @@ -918,16 +890,18 @@ func New(
ibcexported.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
// wasm.ModuleName,
evmmoduletypes.ModuleName,
wasmtypes.ModuleName,
// evmmoduletypes.ModuleName,
// gravitymoduletypes.ModuleName,
// treasurymoduletypes.ModuleName,
consensusparamtypes.ModuleName,
)

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

// RegisterUpgradeHandlers is used for registering any on-chain upgrades.
// Make sure it's called after `app.ModuleManager` and `app.configurator` are
Expand All @@ -944,7 +918,7 @@ func New(
app.GetSubspace(authtypes.ModuleName),
),
}
app.sm = module.NewSimulationManagerFromAppModules(app.mm.Modules, overrideModules)
app.sm = module.NewSimulationManagerFromAppModules(app.ModuleManager.Modules, overrideModules)
app.sm.RegisterStoreDecoders()

// initialize stores
Expand All @@ -955,6 +929,8 @@ func New(
// initialize BaseApp
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetPreBlocker(app.PreBlocker)
app.SetEndBlocker(app.EndBlocker)

/*baseAnteHandler*/
_, err = ante.NewAnteHandler(
Expand Down Expand Up @@ -1016,17 +992,17 @@ func (app *App) Name() string { return app.BaseApp.Name() }
func (app App) GetBaseApp() *baseapp.BaseApp { return app.BaseApp }

func (app *App) PreBlocker(ctx sdk.Context, _ *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) {
return app.mm.PreBlock(ctx)
return app.ModuleManager.PreBlock(ctx)
}

// BeginBlocker application updates every begin block
func (app *App) BeginBlocker(ctx sdk.Context) (sdk.BeginBlock, error) {
return app.mm.BeginBlock(ctx)
return app.ModuleManager.BeginBlock(ctx)
}

// EndBlocker application updates every end block
func (app *App) EndBlocker(ctx sdk.Context) (sdk.EndBlock, error) {
return app.mm.EndBlock(ctx)
return app.ModuleManager.EndBlock(ctx)
}

// InitChainer application update at chain initialization
Expand All @@ -1036,8 +1012,8 @@ func (app *App) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci.
panic(err)
}

app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap())
return app.ModuleManager.InitGenesis(ctx, app.appCodec, genesisState)
}

// LoadHeight loads a particular height
Expand Down Expand Up @@ -1119,7 +1095,7 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig
nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

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

// RegisterTxService implements the Application.RegisterTxService method.
Expand Down Expand Up @@ -1179,7 +1155,7 @@ func (app *App) SimulationManager() *module.SimulationManager {

// DefaultGenesis returns a default genesis from the registered AppModuleBasic's.
func (app *App) DefaultGenesis() map[string]json.RawMessage {
return ModuleBasics.DefaultGenesis(app.appCodec)
return app.BasicModuleManager.DefaultGenesis(app.appCodec)
}

func (app *App) RegisterNodeService(clientCtx client.Context, cfg config.Config) {
Expand Down
2 changes: 1 addition & 1 deletion app/app_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func NewTestApp(t testing, isCheckTx bool) TestApp {
)

if !isCheckTx {
genesisState := NewDefaultGenesisState(encCfg.Codec)
genesisState := app.DefaultGenesis()
genesisState = genesisStateWithValSet(t, app, genesisState, valSet, []authtypes.GenesisAccount{acc}, balance)
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func MakeEncodingConfig() params.EncodingConfig {
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)

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

return encodingConfig
}
Loading

0 comments on commit 8a60bd6

Please sign in to comment.