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

feat: track latest 256 cosmos block hashes #76

Merged
merged 5 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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 app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import (
"github.com/initia-labs/minievm/app/posthandler"
evmindexer "github.com/initia-labs/minievm/indexer"
evmconfig "github.com/initia-labs/minievm/x/evm/config"
evmtypes "github.com/initia-labs/minievm/x/evm/types"

// kvindexer
kvindexermodule "github.com/initia-labs/kvindexer/x/kvindexer"
Expand Down Expand Up @@ -228,6 +229,7 @@ func NewMinitiaApp(
// NOTE: upgrade module is required to be prioritized
app.ModuleManager.SetOrderPreBlockers(
upgradetypes.ModuleName,
evmtypes.ModuleName,
)

// set order of module operations
Expand Down
13 changes: 7 additions & 6 deletions indexer/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,13 @@ func (e *EVMIndexerImpl) ListenFinalizeBlock(ctx context.Context, req abci.Reque
}
}

// TODO - is this part of the indexer? can we move this to the evm module?
err = e.evmKeeper.TrackBlockHash(sdkCtx, uint64(blockHeight), blockHash)
if err != nil {
e.logger.Error("failed to track block hash", "err", err)
return err
}
// TODO - currently state changes are not supported in abci listener
// so we track cosmos block hash at x/evm endblocker.
// err = e.evmKeeper.TrackBlockHash(sdkCtx, uint64(blockHeight), blockHash)
// if err != nil {
// e.logger.Error("failed to track block hash", "err", err)
// return err
// }

return nil
}
17 changes: 17 additions & 0 deletions x/evm/abci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package evm

import (
"time"

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/initia-labs/minievm/x/evm/keeper"
"github.com/initia-labs/minievm/x/evm/types"
)

// PreBlock track latest 256 block hashes
func PreBlock(ctx sdk.Context, k *keeper.Keeper) (sdk.ResponsePreBlock, error) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)
return sdk.ResponsePreBlock{}, k.TrackBlockHash(ctx, uint64(ctx.BlockHeight()-1), common.BytesToHash(ctx.HeaderHash()))
}
10 changes: 9 additions & 1 deletion x/evm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ var (
_ module.HasConsensusVersion = AppModule{}
_ module.HasName = AppModule{}

_ appmodule.AppModule = AppModule{}
_ appmodule.AppModule = AppModule{}
_ appmodule.HasPreBlocker = AppModule{}
)

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -157,3 +158,10 @@ func (am AppModule) IsAppModule() {}
func (am AppModule) IsOnePerModuleType() {}

// ___________________________________________________________________________

// EndBlock returns the end blocker for the evm module. It returns no validator
// updates.
beer-1 marked this conversation as resolved.
Show resolved Hide resolved
func (am AppModule) PreBlock(ctx context.Context) (appmodule.ResponsePreBlock, error) {
c := sdk.UnwrapSDKContext(ctx)
return PreBlock(c, am.keeper)
}
Loading