From 620c9d3a9ed0cdce022cb55032a0028d9295c9b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCller?= Date: Tue, 10 Dec 2024 15:32:29 +0100 Subject: [PATCH 1/2] fix: error on duplicate event processors --- octane/evmengine/keeper/keeper.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/octane/evmengine/keeper/keeper.go b/octane/evmengine/keeper/keeper.go index 7d8750883..be8bd5847 100644 --- a/octane/evmengine/keeper/keeper.go +++ b/octane/evmengine/keeper/keeper.go @@ -13,6 +13,7 @@ import ( "github.com/omni-network/omni/octane/evmengine/types" "github.com/ethereum/go-ethereum/beacon/engine" + "github.com/ethereum/go-ethereum/common" ormv1alpha1 "cosmossdk.io/api/cosmos/orm/v1alpha1" "cosmossdk.io/core/store" @@ -71,6 +72,22 @@ func NewKeeper( return nil, errors.Wrap(err, "create evmengine store") } + names := make(map[string]bool) + addresses := make(map[common.Address]bool) + for _, proc := range eventProcs { + for _, address := range proc.Addresses() { + if found := addresses[address]; found { + return nil, errors.New("duplicate event processors", "address", address) + } + addresses[address] = true + } + name := proc.Name() + if found := names[name]; found { + return nil, errors.New("duplicate event processors", "name", name) + } + names[name] = true + } + return &Keeper{ cdc: cdc, storeService: storeService, From aca34c409565a22c16effbe18a35bf903338df4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCller?= Date: Tue, 10 Dec 2024 18:17:04 +0100 Subject: [PATCH 2/2] fix: review comments --- octane/evmengine/keeper/keeper.go | 39 ++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/octane/evmengine/keeper/keeper.go b/octane/evmengine/keeper/keeper.go index be8bd5847..b40d549e9 100644 --- a/octane/evmengine/keeper/keeper.go +++ b/octane/evmengine/keeper/keeper.go @@ -72,20 +72,8 @@ func NewKeeper( return nil, errors.Wrap(err, "create evmengine store") } - names := make(map[string]bool) - addresses := make(map[common.Address]bool) - for _, proc := range eventProcs { - for _, address := range proc.Addresses() { - if found := addresses[address]; found { - return nil, errors.New("duplicate event processors", "address", address) - } - addresses[address] = true - } - name := proc.Name() - if found := names[name]; found { - return nil, errors.New("duplicate event processors", "name", name) - } - names[name] = true + if err := verifyProcs(eventProcs); err != nil { + return nil, err } return &Keeper{ @@ -100,6 +88,29 @@ func NewKeeper( }, nil } +// verifyProcs ensures that all event processors have distinct names and addresses. +// If it's not the case an error is returned. +// This is needed to prevent duplicate event processing on name or address conflicts. +func verifyProcs(eventProcs []types.EvmEventProcessor) error { + names := make(map[string]bool) + addresses := make(map[common.Address]bool) + for _, proc := range eventProcs { + for _, address := range proc.Addresses() { + if addresses[address] { + return errors.New("duplicate event processors", "address", address) + } + addresses[address] = true + } + name := proc.Name() + if names[name] { + return errors.New("duplicate event processors", "name", name) + } + names[name] = true + } + + return nil +} + func (k *Keeper) SetVoteProvider(p types.VoteExtensionProvider) { k.voteProvider = p }