Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
bing
Browse files Browse the repository at this point in the history
  • Loading branch information
Devon Bear committed Oct 13, 2023
1 parent da06723 commit fde99c2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 23 deletions.
32 changes: 25 additions & 7 deletions cosmos/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -35,13 +35,24 @@ 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"
ethlog "pkg.berachain.dev/polaris/eth/log"
"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

Expand Down Expand Up @@ -77,24 +88,31 @@ 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)

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
}

Expand Down
3 changes: 3 additions & 0 deletions cosmos/x/evm/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions cosmos/x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
20 changes: 4 additions & 16 deletions e2e/testapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fde99c2

Please sign in to comment.