Skip to content

Commit

Permalink
interface changes
Browse files Browse the repository at this point in the history
  • Loading branch information
insumity committed Feb 13, 2024
1 parent 71ac8e3 commit 61a4052
Show file tree
Hide file tree
Showing 8 changed files with 335 additions and 286 deletions.
10 changes: 7 additions & 3 deletions x/ccv/provider/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1190,14 +1190,17 @@ func (k Keeper) SetOptedIn(
chainID string,
providerAddr types.ProviderConsAddress,
blockHeight uint64,
power uint64,
) {
store := ctx.KVStore(k.storeKey)

// validator is considered opted in
blockHeightBytes := make([]byte, 8)
binary.BigEndian.PutUint64(blockHeightBytes, blockHeight)

store.Set(types.OptedInKey(chainID, providerAddr), blockHeightBytes)
powerBytes := make([]byte, 8)
binary.BigEndian.PutUint64(powerBytes, power)

store.Set(types.OptedInKey(chainID, providerAddr), append(blockHeightBytes, powerBytes...))
}

func (k Keeper) DeleteOptedIn(
Expand Down Expand Up @@ -1242,7 +1245,8 @@ func (k Keeper) GetOptedIn(
for ; iterator.Valid(); iterator.Next() {
optedInValidators = append(optedInValidators, OptedInValidator{
ProviderAddr: types.NewProviderConsAddress(iterator.Key()[len(key):]),
BlockHeight: binary.BigEndian.Uint64(iterator.Value()),
BlockHeight: binary.BigEndian.Uint64(iterator.Value()[0:8]),
Power: binary.BigEndian.Uint64(iterator.Value()[8:]),
})
}

Expand Down
9 changes: 7 additions & 2 deletions x/ccv/provider/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,20 +670,24 @@ func TestGetOptedIn(t *testing.T) {
{
ProviderAddr: types.NewProviderConsAddress([]byte("providerAddr1")),
BlockHeight: 1,
Power: 2,
},
{
ProviderAddr: types.NewProviderConsAddress([]byte("providerAddr2")),
BlockHeight: 2,
Power: 3,
},
{
ProviderAddr: types.NewProviderConsAddress([]byte("providerAddr3")),
BlockHeight: 3,
Power: 4,
},
}

for _, expectedOptedInValidator := range expectedOptedInValidators {
providerKeeper.SetOptedIn(ctx, "chainID",
expectedOptedInValidator.ProviderAddr, expectedOptedInValidator.BlockHeight)
expectedOptedInValidator.ProviderAddr, expectedOptedInValidator.BlockHeight,
expectedOptedInValidator.Power)
}

actualOptedInValidators := providerKeeper.GetOptedIn(ctx, "chainID")
Expand All @@ -710,10 +714,11 @@ func TestOptedIn(t *testing.T) {
optedInValidator := keeper.OptedInValidator{
ProviderAddr: types.NewProviderConsAddress([]byte("providerAddr")),
BlockHeight: 1,
Power: 2,
}

require.False(t, providerKeeper.IsOptedIn(ctx, "chainID", optedInValidator.ProviderAddr))
providerKeeper.SetOptedIn(ctx, "chainID", optedInValidator.ProviderAddr, optedInValidator.BlockHeight)
providerKeeper.SetOptedIn(ctx, "chainID", optedInValidator.ProviderAddr, optedInValidator.BlockHeight, optedInValidator.Power)
require.True(t, providerKeeper.IsOptedIn(ctx, "chainID", optedInValidator.ProviderAddr))
providerKeeper.DeleteOptedIn(ctx, "chainID", optedInValidator.ProviderAddr)
require.False(t, providerKeeper.IsOptedIn(ctx, "chainID", optedInValidator.ProviderAddr))
Expand Down
4 changes: 2 additions & 2 deletions x/ccv/provider/keeper/key_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ func (k Keeper) MustApplyKeyAssignmentToValUpdates(
ctx sdk.Context,
chainID string,
valUpdates []abci.ValidatorUpdate,
considerReplacement func(address types.ProviderConsAddress) bool,
considerKeyReplacement func(address types.ProviderConsAddress) bool,
) (newUpdates []abci.ValidatorUpdate) {
for _, valUpdate := range valUpdates {
providerAddrTmp, err := ccvtypes.TMCryptoPublicKeyToConsAddr(valUpdate.PubKey)
Expand Down Expand Up @@ -611,7 +611,7 @@ func (k Keeper) MustApplyKeyAssignmentToValUpdates(
providerAddr := types.NewProviderConsAddress(replacement.ProviderAddr)

// only consider updates for validators that are considered here ...
if !considerReplacement(providerAddr) {
if !considerKeyReplacement(providerAddr) {
return
}
k.DeleteKeyAssignmentReplacement(ctx, chainID, providerAddr)
Expand Down
Loading

0 comments on commit 61a4052

Please sign in to comment.