diff --git a/CHANGELOG.md b/CHANGELOG.md index b22b4c30b..3ee859ff7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - [\#467](https://github.com/cosmos/evm/pull/467) Replace GlobalEVMMempool by passing to JSONRPC on initiate. - [\#352](https://github.com/cosmos/evm/pull/352) Remove the creation of a Geth EVM instance, stateDB during the AnteHandler balance check. - [\#496](https://github.com/cosmos/evm/pull/496) Simplify mempool instantiation by using configs instead of objects. +- [\#568](https://github.com/cosmos/evm/pull/568) Avoid unnecessary block notifications when the event bus is already set up. - [\#511](https://github.com/cosmos/evm/pull/511) Minor code cleanup for `AddPrecompileFn`. ### FEATURES diff --git a/mempool/blockchain.go b/mempool/blockchain.go index 00fc7dd40..fc4be909b 100644 --- a/mempool/blockchain.go +++ b/mempool/blockchain.go @@ -86,6 +86,11 @@ func (b Blockchain) CurrentBlock() *types.Header { } blockHeight := ctx.BlockHeight() + // prevent the reorg from triggering after a restart since previousHeaderHash is stored as an in-memory variable + if blockHeight > 1 && b.previousHeaderHash == (common.Hash{}) { + return b.zeroHeader + } + blockTime := ctx.BlockTime().Unix() gasUsed := b.feeMarketKeeper.GetBlockGasWanted(ctx) appHash := common.BytesToHash(ctx.BlockHeader().AppHash) diff --git a/mempool/mempool.go b/mempool/mempool.go index e2a574e3e..23ad670a2 100644 --- a/mempool/mempool.go +++ b/mempool/mempool.go @@ -381,7 +381,7 @@ func (m *ExperimentalEVMMempool) SelectBy(goCtx context.Context, i [][]byte, f f // SetEventBus sets CometBFT event bus to listen for new block header event. func (m *ExperimentalEVMMempool) SetEventBus(eventBus *cmttypes.EventBus) { - if m.eventBus != nil { + if m.HasEventBus() { m.eventBus.Unsubscribe(context.Background(), SubscriberName, stream.NewBlockHeaderEvents) //nolint: errcheck } m.eventBus = eventBus @@ -396,6 +396,11 @@ func (m *ExperimentalEVMMempool) SetEventBus(eventBus *cmttypes.EventBus) { }() } +// HasEventBus returns true if the blockchain is configured to use an event bus for block notifications. +func (m *ExperimentalEVMMempool) HasEventBus() bool { + return m.eventBus != nil +} + // Close unsubscribes from the CometBFT event bus and shuts down the mempool. func (m *ExperimentalEVMMempool) Close() error { var errs []error diff --git a/x/vm/keeper/abci.go b/x/vm/keeper/abci.go index b10026070..558c230be 100644 --- a/x/vm/keeper/abci.go +++ b/x/vm/keeper/abci.go @@ -43,7 +43,7 @@ func (k *Keeper) EndBlock(ctx sdk.Context) error { // Gas costs are handled within msg handler so costs should be ignored infCtx := ctx.WithGasMeter(storetypes.NewInfiniteGasMeter()) - if k.evmMempool != nil { + if k.evmMempool != nil && !k.evmMempool.HasEventBus() { k.evmMempool.GetBlockchain().NotifyNewBlock() }