diff --git a/app/rpc/namespaces/eth/api.go b/app/rpc/namespaces/eth/api.go index 6d7eed2b6a..0bda715bb5 100644 --- a/app/rpc/namespaces/eth/api.go +++ b/app/rpc/namespaces/eth/api.go @@ -90,8 +90,8 @@ func NewAPI( gasPrice: ParseGasPrice(), wrappedBackend: watcher.NewQuerier(), watcherBackend: watcher.NewWatcher(), - evmFactory: simulation.EvmFactory{ChainId: clientCtx.ChainID}, } + api.evmFactory = simulation.NewEvmFactory(clientCtx.ChainID, api.wrappedBackend) if err := api.GetKeyringInfo(); err != nil { api.logger.Error("failed to get keybase info", "error", err) diff --git a/app/rpc/namespaces/eth/simulation/evm.go b/app/rpc/namespaces/eth/simulation/evm.go index 607b049553..3a2e06d1ef 100644 --- a/app/rpc/namespaces/eth/simulation/evm.go +++ b/app/rpc/namespaces/eth/simulation/evm.go @@ -15,7 +15,12 @@ import ( ) type EvmFactory struct { - ChainId string + ChainId string + WrappedQuerier *watcher.Querier +} + +func NewEvmFactory(chainId string, q *watcher.Querier) EvmFactory { + return EvmFactory{ChainId: chainId, WrappedQuerier: q} } func (ef EvmFactory) BuildSimulator(qoc QueryOnChainProxy) *EvmSimulator { @@ -67,6 +72,7 @@ func (ef EvmFactory) makeContext(k *evm.Keeper) sdk.Context { cms.MountStoreWithDB(paramsTKey, sdk.StoreTypeTransient, db) cms.LoadLatestVersion() - ctx := sdk.NewContext(cms, abci.Header{ChainID: ef.ChainId}, true, tmlog.NewNopLogger()).WithGasMeter(sdk.NewGasMeter(evmtypes.DefaultMaxGasLimitPerTx)) + latest, _ := ef.WrappedQuerier.GetLatestBlockNumber() + ctx := sdk.NewContext(cms, abci.Header{ChainID: ef.ChainId, Height: int64(latest)}, true, tmlog.NewNopLogger()).WithGasMeter(sdk.NewGasMeter(evmtypes.DefaultMaxGasLimitPerTx)) return ctx }