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

fix(octane/evmengine): error on duplicate event processors #2670

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Changes from all 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
28 changes: 28 additions & 0 deletions octane/evmengine/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -71,6 +72,10 @@ func NewKeeper(
return nil, errors.Wrap(err, "create evmengine store")
}

if err := verifyProcs(eventProcs); err != nil {
return nil, err
}

return &Keeper{
cdc: cdc,
storeService: storeService,
Expand All @@ -83,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
}
Expand Down
Loading