Skip to content

Commit

Permalink
fix: review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chmllr committed Dec 10, 2024
1 parent 620c9d3 commit aca34c4
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions octane/evmengine/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
}
Expand Down

0 comments on commit aca34c4

Please sign in to comment.