Skip to content

refactor: use slices.Equal to simplify code #2572

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
20 changes: 4 additions & 16 deletions x/ccv/provider/keeper/power_shaping.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"slices"
"sort"

errorsmod "cosmossdk.io/errors"
Expand Down Expand Up @@ -335,32 +336,19 @@ func (k Keeper) SetConsumerPowerShapingParameters(ctx sdk.Context, consumerId st
store.Set(types.ConsumerIdToPowerShapingParametersKey(consumerId), bz)

// update allowlist, denylist and prioritylist indexes if needed
if !equalStringSlices(oldParameters.Allowlist, parameters.Allowlist) {
if !slices.Equal(oldParameters.Allowlist, parameters.Allowlist) {
k.UpdateAllowlist(ctx, consumerId, parameters.Allowlist)
}
if !equalStringSlices(oldParameters.Denylist, parameters.Denylist) {
if !slices.Equal(oldParameters.Denylist, parameters.Denylist) {
k.UpdateDenylist(ctx, consumerId, parameters.Denylist)
}
if !equalStringSlices(oldParameters.Prioritylist, parameters.Prioritylist) {
if !slices.Equal(oldParameters.Prioritylist, parameters.Prioritylist) {
k.UpdatePrioritylist(ctx, consumerId, parameters.Prioritylist)
}

return nil
}

// equalStringSlices returns true if two string slices are equal
func equalStringSlices(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}

// SetAllowlist allowlists validator with `providerAddr` address on chain `consumerId`
func (k Keeper) SetAllowlist(
ctx sdk.Context,
Expand Down