Skip to content

Commit

Permalink
took into account comments
Browse files Browse the repository at this point in the history
  • Loading branch information
insumity committed Jun 18, 2024
1 parent 3954091 commit d28aba5
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 160 deletions.
2 changes: 1 addition & 1 deletion proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ message ConsumerValidator {
// If a validator becomes a consumer validator at height `H` and is continuously a consumer validator for all the upcoming
// epochs, then the height of the validator SHOULD remain `H`. This height only resets to a different height if a validator
// stops being a consumer validator during an epoch and later becomes again a consumer validator.
int64 height = 4;
int64 join_height = 4;
}
// ConsumerRewardsAllocation stores the rewards allocated by a consumer chain
// to the consumer rewards pool. It is used to allocate the tokens to the consumer
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -1094,12 +1094,12 @@ func (s *CCVTestSuite) TestAllocateTokensToConsumerValidatorsWithDifferentValida
// update the consumer validators
consuVals := providerKeeper.GetConsumerValSet(ctx, chainID)
// first 2 validators were consumer validators since block height 1 and hence get rewards
consuVals[0].Height = 1
consuVals[1].Height = 1
consuVals[0].JoinHeight = 1
consuVals[1].JoinHeight = 1
// last 2 validators were consumer validators since block height 2 and hence do not get rewards because they
// have not been consumer validators for `GetNumberOfEpochsToStartReceivingRewards * GetBlocksPerEpoch` blocks
consuVals[2].Height = 2
consuVals[3].Height = 2
consuVals[2].JoinHeight = 2
consuVals[3].JoinHeight = 2
providerKeeper.SetConsumerValSet(ctx, chainID, consuVals)

providerKeeper.DeleteConsumerValSet(ctx, chainID)
Expand Down
4 changes: 2 additions & 2 deletions x/ccv/provider/keeper/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (k Keeper) AllocateTokensToConsumerValidators(
// Allocate tokens by iterating over the consumer validators
for _, consumerVal := range k.GetConsumerValSet(ctx, chainID) {
// if a validator is not eligible, this means that the other eligible validators would get more rewards
if !k.IsEligibleForConsumerRewards(ctx, consumerVal.Height) {
if !k.IsEligibleForConsumerRewards(ctx, consumerVal.JoinHeight) {
continue
}

Expand Down Expand Up @@ -256,7 +256,7 @@ func (k Keeper) ComputeConsumerTotalVotingPower(ctx sdk.Context, chainID string)
for _, v := range k.GetConsumerValSet(ctx, chainID) {

// only consider the voting power of a validator that would receive rewards (i.e., validator has been validating for a number of blocks)
if !k.IsEligibleForConsumerRewards(ctx, v.Height) {
if !k.IsEligibleForConsumerRewards(ctx, v.JoinHeight) {
continue
}

Expand Down
6 changes: 3 additions & 3 deletions x/ccv/provider/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestQueueVSCPacketsDoesNotResetConsumerValidatorsHeights(t *testing.T) {
ProviderConsAddr: valAConsAddr,
Power: 1,
ConsumerPublicKey: &valAPubKey,
Height: 123456789,
JoinHeight: 123456789,
}
providerKeeper.SetConsumerValidator(ctx, "chainID", consumerValidatorA)

Expand All @@ -128,12 +128,12 @@ func TestQueueVSCPacketsDoesNotResetConsumerValidatorsHeights(t *testing.T) {

// the height of consumer validator A should not be modified because A was already a consumer validator
cv, _ := providerKeeper.GetConsumerValidator(ctx, "chainID", providertypes.NewProviderConsAddress(valAConsAddr))
require.Equal(t, consumerValidatorA.Height, cv.Height, "the consumer validator's height was erroneously modified")
require.Equal(t, consumerValidatorA.JoinHeight, cv.JoinHeight, "the consumer validator's height was erroneously modified")

// the height of consumer validator B is set to be the same as the one of the current chain height because this
// consumer validator becomes a consumer validator for the first time (i.e., was not a consumer validator in the previous epoch)
cv, _ = providerKeeper.GetConsumerValidator(ctx, "chainID", providertypes.NewProviderConsAddress(valBConsAddr))
require.Equal(t, chainHeight, cv.Height, "the consumer validator's height was not correctly set")
require.Equal(t, chainHeight, cv.JoinHeight, "the consumer validator's height was not correctly set")
}

// TestOnRecvVSCMaturedPacket tests the OnRecvVSCMaturedPacket method of the keeper.
Expand Down
4 changes: 2 additions & 2 deletions x/ccv/provider/keeper/validator_set_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ func (k Keeper) CreateConsumerValidator(ctx sdk.Context, chainID string, validat
if v, found := k.GetConsumerValidator(ctx, chainID, types.ProviderConsAddress{Address: consAddr}); found {
// if validator was already a consumer validator, then do not update the height set the first time
// the validator became a consumer validator
height = v.Height
height = v.JoinHeight
}

return types.ConsumerValidator{
ProviderConsAddr: consAddr,
Power: power,
ConsumerPublicKey: &consumerPublicKey,
Height: height,
JoinHeight: height,
}, nil
}

Expand Down
10 changes: 0 additions & 10 deletions x/ccv/provider/migrations/v6/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,3 @@ func MigrateParams(ctx sdk.Context, paramsSubspace paramtypes.Subspace) {
}
paramsSubspace.Set(ctx, providertypes.KeyNumberOfEpochsToStartReceivingRewards, providertypes.DefaultNumberOfEpochsToStartReceivingRewards)
}

// MigrateSomething adds missing provider chain params to the param store.
func MigrateSomething(ctx sdk.Context, providerKeeper providerkeeper.Keeper) {
for _, chainID := range providerKeeper.GetAllRegisteredConsumerChainIDs(ctx) {
for _, val := range providerKeeper.GetConsumerValSet(ctx, chainID) {
val.Height = ctx.BlockHeight()
providerKeeper.SetConsumerValidator(ctx, chainID, val)
}
}
}
Loading

0 comments on commit d28aba5

Please sign in to comment.