From fde99c20f4de6dea611807dbbcbc5119ad6eabad Mon Sep 17 00:00:00 2001 From: Devon Bear Date: Fri, 13 Oct 2023 14:28:35 -0400 Subject: [PATCH] bing --- cosmos/runtime/runtime.go | 32 +++++++++++++++++++++++++------- cosmos/x/evm/keeper/genesis.go | 3 +++ cosmos/x/evm/keeper/keeper.go | 12 ++++++++++++ e2e/testapp/app.go | 20 ++++---------------- 4 files changed, 44 insertions(+), 23 deletions(-) diff --git a/cosmos/runtime/runtime.go b/cosmos/runtime/runtime.go index 091bcbbd1..c588e5f6e 100644 --- a/cosmos/runtime/runtime.go +++ b/cosmos/runtime/runtime.go @@ -24,9 +24,9 @@ import ( "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/mempool" "github.com/ethereum/go-ethereum/beacon/engine" "github.com/ethereum/go-ethereum/node" @@ -35,6 +35,7 @@ import ( libtx "pkg.berachain.dev/polaris/cosmos/lib/tx" "pkg.berachain.dev/polaris/cosmos/miner" "pkg.berachain.dev/polaris/cosmos/txpool" + evmkeeper "pkg.berachain.dev/polaris/cosmos/x/evm/keeper" evmtypes "pkg.berachain.dev/polaris/cosmos/x/evm/types" "pkg.berachain.dev/polaris/eth/core" coretypes "pkg.berachain.dev/polaris/eth/core/types" @@ -42,6 +43,16 @@ import ( "pkg.berachain.dev/polaris/eth/polar" ) +type EVMKeeper interface { + Setup(evmkeeper.Blockchain) error +} + +type BaseApp interface { + SetMempool(mempool.Mempool) + SetPrepareProposal(sdk.PrepareProposalHandler) + SetAnteHandler(sdk.AnteHandler) +} + type Polaris struct { *polar.Polaris @@ -77,17 +88,17 @@ func New(cfg *config.Config, logger log.Logger, host core.PolarisHostChain) *Pol }), ) + // Init is used to setup the polaris struct. + if err = polaris.Init(); err != nil { + panic(err) + } + return &Polaris{ Polaris: polaris, } } -func (p *Polaris) Setup(bApp *baseapp.BaseApp) error { - // Init is used to setup the polaris struct. - if err := p.Polaris.Init(); err != nil { - return err - } - +func (p *Polaris) Setup(bApp BaseApp, ek EVMKeeper) error { // Setup TxPool Wrapper p.WrappedTxPool = txpool.New(p.TxPool()) bApp.SetMempool(p.WrappedTxPool) @@ -95,6 +106,13 @@ func (p *Polaris) Setup(bApp *baseapp.BaseApp) error { p.WrappedMiner = miner.New(p.Miner()) bApp.SetPrepareProposal(p.WrappedMiner.PrepareProposal) + if err := ek.Setup(p.Blockchain()); err != nil { + return err + } + + // Set the ante handler to nil, since it is not needed. + bApp.SetAnteHandler(nil) + return nil } diff --git a/cosmos/x/evm/keeper/genesis.go b/cosmos/x/evm/keeper/genesis.go index c88696b61..1928a5205 100644 --- a/cosmos/x/evm/keeper/genesis.go +++ b/cosmos/x/evm/keeper/genesis.go @@ -30,6 +30,9 @@ import ( // InitGenesis is called during the InitGenesis. func (k *Keeper) InitGenesis(ctx sdk.Context, genState *core.Genesis) error { + // TODO: Feels jank as fuck lol, but it works. + genState.Config = k.chain.Config() + // Initialize all the plugins. for _, plugin := range k.Host.GetAllPlugins() { // checks whether plugin implements methods of HasGenesis and executes them if it does diff --git a/cosmos/x/evm/keeper/keeper.go b/cosmos/x/evm/keeper/keeper.go index 8823510a3..8d609b4c2 100644 --- a/cosmos/x/evm/keeper/keeper.go +++ b/cosmos/x/evm/keeper/keeper.go @@ -26,6 +26,7 @@ import ( "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/client" sdk "github.com/cosmos/cosmos-sdk/types" "pkg.berachain.dev/polaris/cosmos/config" @@ -34,10 +35,12 @@ import ( "pkg.berachain.dev/polaris/cosmos/x/evm/types" "pkg.berachain.dev/polaris/eth/core" ethprecompile "pkg.berachain.dev/polaris/eth/core/precompile" + "pkg.berachain.dev/polaris/eth/params" ) type Blockchain interface { PreparePlugins(context.Context) + Config() *params.ChainConfig core.ChainWriter core.ChainReader } @@ -78,6 +81,15 @@ func NewKeeper( } } +func (k *Keeper) Setup(chain Blockchain) error { + k.chain = chain + return k.SetupPrecompiles() +} + +func (k *Keeper) StartEnginePlguin(ctx client.Context) { + k.ep.Start(ctx) +} + // SetBlock sets the underlying ethereum blockchain on the keeper. func (k *Keeper) SetBlockchain(chain Blockchain) { k.chain = chain diff --git a/e2e/testapp/app.go b/e2e/testapp/app.go index 1db121cf8..8124b3324 100644 --- a/e2e/testapp/app.go +++ b/e2e/testapp/app.go @@ -58,7 +58,6 @@ import ( signinglib "pkg.berachain.dev/polaris/cosmos/lib/signing" polarruntime "pkg.berachain.dev/polaris/cosmos/runtime" evmkeeper "pkg.berachain.dev/polaris/cosmos/x/evm/keeper" - enginep "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/engine" ) // DefaultNodeHome default home directories for the application daemon. @@ -191,22 +190,11 @@ func NewPolarisApp( evmconfig.MustReadConfigFromAppOpts(appOpts), app.Logger(), app.EVMKeeper.Host, ) - // SetupPrecompiles is used to setup the precompile contracts post depinject. - if err := app.EVMKeeper.SetupPrecompiles(); err != nil { + // Setup Polaris Runtime. + if err := app.Polaris.Setup(app.BaseApp, app.EVMKeeper); err != nil { panic(err) } - // Initialize Polaris Runtime. - if err := app.Polaris.Setup(app.BaseApp); err != nil { - panic(err) - } - - // TODO: deprecate this - app.EVMKeeper.SetBlockchain(app.Polaris.Blockchain()) - - // Set the ante handler to nil, since it is not needed. - app.SetAnteHandler(nil) - // register streaming services if err := app.RegisterStreamingServices(appOpts, app.kvStoreKeys()); err != nil { panic(err) @@ -271,8 +259,8 @@ func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APICon panic(err) } - // TODO: probably get rid of engine plugin or something and handle rpc methods better. - app.EVMKeeper.Host.GetEnginePlugin().(enginep.Plugin).Start(apiSvr.ClientCtx) + // TODO, register this better. + app.EVMKeeper.StartEnginePlguin(apiSvr.ClientCtx) if err := app.Polaris.Init(apiSvr.ClientCtx, app.Logger()); err != nil { panic(err)