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

refactor(blockchain): Minor cleanup and add safety checks. #1266

Merged
merged 16 commits into from
Nov 1, 2023
Prev Previous commit
Next Next commit
bing bong
  • Loading branch information
itsdevbear committed Nov 1, 2023
commit 63229e6267fd0e0a2305a312a7331677875372f4
9 changes: 7 additions & 2 deletions cosmos/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type App interface {
type EVMKeeper interface {
// Setup initializes the EVM keeper.
Setup(evmkeeper.Blockchain) error
PrepareCheckState(context.Context) error
SetLatestQueryContext(context.Context) error
}

// Miner implements the baseapp.TxSelector interface.
Expand Down Expand Up @@ -89,18 +89,23 @@ func (m *Miner) PrepareProposal(
err error
)

if err = m.keeper.PrepareCheckState(ctx); err != nil {
// We have to prime the state plugin.
if err = m.keeper.SetLatestQueryContext(ctx); err != nil {
return nil, err
}

// We have to run the BeginBlocker to get the chain into the state it'll
// be in when the EVM transaction actually runs.
if _, err = m.app.BeginBlocker(ctx); err != nil {
return nil, err
}

// Trigger the geth miner to build a block.
if payloadEnvelopeBz, err = m.buildBlock(ctx); err != nil {
return nil, err
}

// Return the payload as a transaction in the proposal.
return &abci.ResponsePrepareProposal{Txs: [][]byte{payloadEnvelopeBz}}, err
}

Expand Down
2 changes: 1 addition & 1 deletion cosmos/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import (
type EVMKeeper interface {
// Setup initializes the EVM keeper.
Setup(evmkeeper.Blockchain) error
PrepareCheckState(context.Context) error
SetLatestQueryContext(context.Context) error
}

// CosmosApp is an interface that defines the methods needed for the Cosmos setup.
Expand Down
4 changes: 2 additions & 2 deletions cosmos/x/evm/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func (k *Keeper) Precommit(ctx context.Context) error {
return nil
}

// PrepareCheckState runs on the Cosmos-SDK lifecycle PrepareCheckState().
func (k *Keeper) PrepareCheckState(ctx context.Context) error {
// SetLatestQueryContext runs on the Cosmos-SDK lifecycle SetLatestQueryContext().
func (k *Keeper) SetLatestQueryContext(ctx context.Context) error {
k.sp.Prepare(ctx)
return nil
}
4 changes: 2 additions & 2 deletions cosmos/x/evm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }

// PrepareCheckState prepares the application state for a check.
// SetLatestQueryContext prepares the application state for a check.
func (am AppModule) PrepareCheckState(ctx context.Context) error {
return am.keeper.PrepareCheckState(ctx)
return am.keeper.SetLatestQueryContext(ctx)
}

// Precommit performs precommit operations.
Expand Down
Loading