From 2109b4267b7766f491c39ddce1533fdae825a512 Mon Sep 17 00:00:00 2001 From: insumity Date: Thu, 2 May 2024 14:01:11 +0200 Subject: [PATCH 1/2] small naming fix --- x/ccv/provider/keeper/keeper.go | 2 +- x/ccv/provider/keeper/partial_set_security.go | 4 ++-- x/ccv/provider/keeper/proposal.go | 2 +- x/ccv/provider/keeper/relay.go | 2 +- x/ccv/provider/keeper/validator_set_update_test.go | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/x/ccv/provider/keeper/keeper.go b/x/ccv/provider/keeper/keeper.go index bc3664bfd7..179348dd3d 100644 --- a/x/ccv/provider/keeper/keeper.go +++ b/x/ccv/provider/keeper/keeper.go @@ -1279,7 +1279,7 @@ func (k Keeper) HasToValidate( // if the validator is opted in and belongs to the validators of the next epoch, then if nothing changes // the validator would have to validate in the next epoch if k.IsOptedIn(ctx, chainID, provAddr) { - nextValidators := k.ComputeNextValidators(ctx, chainID, k.stakingKeeper.GetLastValidators(ctx)) + nextValidators := k.ComputeNextEpochConsumerValSet(ctx, chainID, k.stakingKeeper.GetLastValidators(ctx)) for _, v := range nextValidators { consAddr := sdk.ConsAddress(v.ProviderConsAddr) if provAddr.ToSdkConsAddr().Equals(consAddr) { diff --git a/x/ccv/provider/keeper/partial_set_security.go b/x/ccv/provider/keeper/partial_set_security.go index 0d5177089a..2e963f53ab 100644 --- a/x/ccv/provider/keeper/partial_set_security.go +++ b/x/ccv/provider/keeper/partial_set_security.go @@ -283,8 +283,8 @@ func (k Keeper) FilterOptedInAndAllowAndDenylistedPredicate(ctx sdk.Context, cha !k.IsDenylisted(ctx, chainID, providerAddr)) } -// ComputeNextValidators computes the validators for the upcoming epoch based on the currently `bondedValidators`. -func (k Keeper) ComputeNextValidators(ctx sdk.Context, chainID string, bondedValidators []stakingtypes.Validator) []types.ConsumerValidator { +// ComputeNextEpochConsumerValSet computes the validators for the upcoming epoch based on the currently `bondedValidators` +func (k Keeper) ComputeNextEpochConsumerValSet(ctx sdk.Context, chainID string, bondedValidators []stakingtypes.Validator) []types.ConsumerValidator { nextValidators := k.FilterValidators(ctx, chainID, bondedValidators, func(providerAddr types.ProviderConsAddress) bool { return k.FilterOptedInAndAllowAndDenylistedPredicate(ctx, chainID, providerAddr) diff --git a/x/ccv/provider/keeper/proposal.go b/x/ccv/provider/keeper/proposal.go index 1d2bf19a4f..0177ed24ab 100644 --- a/x/ccv/provider/keeper/proposal.go +++ b/x/ccv/provider/keeper/proposal.go @@ -292,7 +292,7 @@ func (k Keeper) MakeConsumerGenesis( } } - nextValidators := k.ComputeNextValidators(ctx, chainID, bondedValidators) + nextValidators := k.ComputeNextEpochConsumerValSet(ctx, chainID, bondedValidators) k.SetConsumerValSet(ctx, chainID, nextValidators) diff --git a/x/ccv/provider/keeper/relay.go b/x/ccv/provider/keeper/relay.go index 230ed0a96a..ccaf3a25e8 100644 --- a/x/ccv/provider/keeper/relay.go +++ b/x/ccv/provider/keeper/relay.go @@ -231,7 +231,7 @@ func (k Keeper) QueueVSCPackets(ctx sdk.Context) { } } - nextValidators := k.ComputeNextValidators(ctx, chain.ChainId, bondedValidators) + nextValidators := k.ComputeNextEpochConsumerValSet(ctx, chain.ChainId, bondedValidators) valUpdates := DiffValidators(currentValidators, nextValidators) k.SetConsumerValSet(ctx, chain.ChainId, nextValidators) diff --git a/x/ccv/provider/keeper/validator_set_update_test.go b/x/ccv/provider/keeper/validator_set_update_test.go index 396a74fb1f..3ce6b34e90 100644 --- a/x/ccv/provider/keeper/validator_set_update_test.go +++ b/x/ccv/provider/keeper/validator_set_update_test.go @@ -327,7 +327,7 @@ func TestSetConsumerValSet(t *testing.T) { require.Equal(t, nextValidators, nextCurrentValidators) } -func TestComputeNextEpochConsumerValSetConsiderAll(t *testing.T) { +func TestFilterValidatorsConsiderAll(t *testing.T) { providerKeeper, ctx, ctrl, mocks := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() @@ -367,7 +367,7 @@ func TestComputeNextEpochConsumerValSetConsiderAll(t *testing.T) { require.Equal(t, expectedValidators, actualValidators) } -func TestComputeNextEpochConsumerValSetConsiderOnlyOptIn(t *testing.T) { +func TestFilterValidatorsConsiderOnlyOptIn(t *testing.T) { providerKeeper, ctx, ctrl, mocks := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() From f2482b651a2af24174bc5d27cf1c9f07e45ad1f7 Mon Sep 17 00:00:00 2001 From: insumity Date: Thu, 2 May 2024 14:22:32 +0200 Subject: [PATCH 2/2] reverts name to ComputeNextValidators because the semantics of ComputeNextEpochConsumerValSet were different in v4.1 --- x/ccv/provider/keeper/keeper.go | 2 +- x/ccv/provider/keeper/partial_set_security.go | 4 ++-- x/ccv/provider/keeper/proposal.go | 2 +- x/ccv/provider/keeper/relay.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/x/ccv/provider/keeper/keeper.go b/x/ccv/provider/keeper/keeper.go index 179348dd3d..bc3664bfd7 100644 --- a/x/ccv/provider/keeper/keeper.go +++ b/x/ccv/provider/keeper/keeper.go @@ -1279,7 +1279,7 @@ func (k Keeper) HasToValidate( // if the validator is opted in and belongs to the validators of the next epoch, then if nothing changes // the validator would have to validate in the next epoch if k.IsOptedIn(ctx, chainID, provAddr) { - nextValidators := k.ComputeNextEpochConsumerValSet(ctx, chainID, k.stakingKeeper.GetLastValidators(ctx)) + nextValidators := k.ComputeNextValidators(ctx, chainID, k.stakingKeeper.GetLastValidators(ctx)) for _, v := range nextValidators { consAddr := sdk.ConsAddress(v.ProviderConsAddr) if provAddr.ToSdkConsAddr().Equals(consAddr) { diff --git a/x/ccv/provider/keeper/partial_set_security.go b/x/ccv/provider/keeper/partial_set_security.go index 2e963f53ab..0d5177089a 100644 --- a/x/ccv/provider/keeper/partial_set_security.go +++ b/x/ccv/provider/keeper/partial_set_security.go @@ -283,8 +283,8 @@ func (k Keeper) FilterOptedInAndAllowAndDenylistedPredicate(ctx sdk.Context, cha !k.IsDenylisted(ctx, chainID, providerAddr)) } -// ComputeNextEpochConsumerValSet computes the validators for the upcoming epoch based on the currently `bondedValidators` -func (k Keeper) ComputeNextEpochConsumerValSet(ctx sdk.Context, chainID string, bondedValidators []stakingtypes.Validator) []types.ConsumerValidator { +// ComputeNextValidators computes the validators for the upcoming epoch based on the currently `bondedValidators`. +func (k Keeper) ComputeNextValidators(ctx sdk.Context, chainID string, bondedValidators []stakingtypes.Validator) []types.ConsumerValidator { nextValidators := k.FilterValidators(ctx, chainID, bondedValidators, func(providerAddr types.ProviderConsAddress) bool { return k.FilterOptedInAndAllowAndDenylistedPredicate(ctx, chainID, providerAddr) diff --git a/x/ccv/provider/keeper/proposal.go b/x/ccv/provider/keeper/proposal.go index 0177ed24ab..1d2bf19a4f 100644 --- a/x/ccv/provider/keeper/proposal.go +++ b/x/ccv/provider/keeper/proposal.go @@ -292,7 +292,7 @@ func (k Keeper) MakeConsumerGenesis( } } - nextValidators := k.ComputeNextEpochConsumerValSet(ctx, chainID, bondedValidators) + nextValidators := k.ComputeNextValidators(ctx, chainID, bondedValidators) k.SetConsumerValSet(ctx, chainID, nextValidators) diff --git a/x/ccv/provider/keeper/relay.go b/x/ccv/provider/keeper/relay.go index ccaf3a25e8..230ed0a96a 100644 --- a/x/ccv/provider/keeper/relay.go +++ b/x/ccv/provider/keeper/relay.go @@ -231,7 +231,7 @@ func (k Keeper) QueueVSCPackets(ctx sdk.Context) { } } - nextValidators := k.ComputeNextEpochConsumerValSet(ctx, chain.ChainId, bondedValidators) + nextValidators := k.ComputeNextValidators(ctx, chain.ChainId, bondedValidators) valUpdates := DiffValidators(currentValidators, nextValidators) k.SetConsumerValSet(ctx, chain.ChainId, nextValidators)