From a32e8829fee3cbbe50e363a0aa91ad62117a8a1d Mon Sep 17 00:00:00 2001 From: insumity Date: Mon, 5 Feb 2024 16:34:43 +0100 Subject: [PATCH] changed cons to val address --- x/ccv/provider/keeper/keeper.go | 54 ++++---- x/ccv/provider/keeper/keeper_test.go | 117 ++++++------------ x/ccv/provider/keeper/key_assignment_test.go | 4 +- x/ccv/provider/keeper/msg_server.go | 18 +-- x/ccv/provider/keeper/partial_set_security.go | 23 ++-- .../keeper/partial_set_security_test.go | 49 ++++---- x/ccv/provider/types/keys.go | 12 +- x/ccv/provider/types/provider.pb.go | 6 +- x/ccv/provider/types/tx.pb.go | 6 +- 9 files changed, 120 insertions(+), 169 deletions(-) diff --git a/x/ccv/provider/keeper/keeper.go b/x/ccv/provider/keeper/keeper.go index bd26d6b87d..816683279d 100644 --- a/x/ccv/provider/keeper/keeper.go +++ b/x/ccv/provider/keeper/keeper.go @@ -1187,7 +1187,7 @@ func (k Keeper) IsOptIn(ctx sdk.Context, chainID string) bool { func (k Keeper) SetOptedIn( ctx sdk.Context, chainID string, - providerAddr types.ProviderConsAddress, + valAddress sdk.ValAddress, blockHeight uint64, ) { store := ctx.KVStore(k.storeKey) @@ -1196,25 +1196,25 @@ func (k Keeper) SetOptedIn( blockHeightBytes := make([]byte, 8) binary.BigEndian.PutUint64(blockHeightBytes, blockHeight) - store.Set(types.OptedInKey(chainID, providerAddr), blockHeightBytes) + store.Set(types.OptedInKey(chainID, valAddress), blockHeightBytes) } func (k Keeper) DeleteOptedIn( ctx sdk.Context, chainID string, - providerAddr types.ProviderConsAddress, + valAddress sdk.ValAddress, ) { store := ctx.KVStore(k.storeKey) - store.Delete(types.OptedInKey(chainID, providerAddr)) + store.Delete(types.OptedInKey(chainID, valAddress)) } func (k Keeper) IsOptedIn( ctx sdk.Context, chainID string, - providerAddr types.ProviderConsAddress, + valAddress sdk.ValAddress, ) bool { store := ctx.KVStore(k.storeKey) - return store.Get(types.OptedInKey(chainID, providerAddr)) != nil + return store.Get(types.OptedInKey(chainID, valAddress)) != nil } func (k Keeper) GetOptedIn( @@ -1227,8 +1227,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()), + ValAddress: iterator.Key()[len(key):], + BlockHeight: binary.BigEndian.Uint64(iterator.Value()), }) } @@ -1238,33 +1238,33 @@ func (k Keeper) GetOptedIn( func (k Keeper) SetToBeOptedIn( ctx sdk.Context, chainID string, - providerAddr types.ProviderConsAddress, + valAddress sdk.ValAddress, ) { store := ctx.KVStore(k.storeKey) - store.Set(types.ToBeOptedInKey(chainID, providerAddr), []byte{}) + store.Set(types.ToBeOptedInKey(chainID, valAddress), []byte{}) } func (k Keeper) DeleteToBeOptedIn( ctx sdk.Context, chainID string, - providerAddr types.ProviderConsAddress, + valAddress sdk.ValAddress, ) { store := ctx.KVStore(k.storeKey) - store.Delete(types.ToBeOptedInKey(chainID, providerAddr)) + store.Delete(types.ToBeOptedInKey(chainID, valAddress)) } func (k Keeper) IsToBeOptedIn( ctx sdk.Context, chainID string, - providerAddr types.ProviderConsAddress, + valAddress sdk.ValAddress, ) bool { store := ctx.KVStore(k.storeKey) - return store.Get(types.ToBeOptedInKey(chainID, providerAddr)) != nil + return store.Get(types.ToBeOptedInKey(chainID, valAddress)) != nil } func (k Keeper) GetToBeOptedIn( ctx sdk.Context, - chainID string) (addresses []types.ProviderConsAddress) { + chainID string) (valAddresses []sdk.ValAddress) { store := ctx.KVStore(k.storeKey) key := types.ChainIdWithLenKey(types.ToBeOptedInBytePrefix, chainID) @@ -1272,43 +1272,42 @@ func (k Keeper) GetToBeOptedIn( defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - providerAddr := types.NewProviderConsAddress(iterator.Key()[len(key):]) - addresses = append(addresses, providerAddr) + valAddresses = append(valAddresses, iterator.Key()[len(key):]) } - return addresses + return valAddresses } func (k Keeper) SetToBeOptedOut( ctx sdk.Context, chainID string, - providerAddr types.ProviderConsAddress, + valAddress sdk.ValAddress, ) { store := ctx.KVStore(k.storeKey) - store.Set(types.ToBeOptedOutKey(chainID, providerAddr), []byte{}) + store.Set(types.ToBeOptedOutKey(chainID, valAddress), []byte{}) } func (k Keeper) DeleteToBeOptedOut( ctx sdk.Context, chainID string, - providerAddr types.ProviderConsAddress, + valAddress sdk.ValAddress, ) { store := ctx.KVStore(k.storeKey) - store.Delete(types.ToBeOptedOutKey(chainID, providerAddr)) + store.Delete(types.ToBeOptedOutKey(chainID, valAddress)) } func (k Keeper) IsToBeOptedOut( ctx sdk.Context, chainID string, - providerAddr types.ProviderConsAddress, + valAddress sdk.ValAddress, ) bool { store := ctx.KVStore(k.storeKey) - return store.Get(types.ToBeOptedOutKey(chainID, providerAddr)) != nil + return store.Get(types.ToBeOptedOutKey(chainID, valAddress)) != nil } func (k Keeper) GetToBeOptedOut( ctx sdk.Context, - chainID string) (addresses []types.ProviderConsAddress) { + chainID string) (valAddresses []sdk.ValAddress) { store := ctx.KVStore(k.storeKey) key := types.ChainIdWithLenKey(types.ToBeOptedOutBytePrefix, chainID) @@ -1316,9 +1315,8 @@ func (k Keeper) GetToBeOptedOut( defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - providerAddr := types.NewProviderConsAddress(iterator.Key()[len(key):]) - addresses = append(addresses, providerAddr) + valAddresses = append(valAddresses, iterator.Key()[len(key):]) } - return addresses + return valAddresses } diff --git a/x/ccv/provider/keeper/keeper_test.go b/x/ccv/provider/keeper/keeper_test.go index 6eb28675ba..685df27191 100644 --- a/x/ccv/provider/keeper/keeper_test.go +++ b/x/ccv/provider/keeper/keeper_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "bytes" "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/interchain-security/v4/x/ccv/provider/keeper" "sort" "testing" @@ -668,22 +669,22 @@ func TestGetOptedIn(t *testing.T) { expectedOptedInValidators := []keeper.OptedInValidator{ { - ProviderAddr: types.NewProviderConsAddress([]byte("providerAddr1")), - BlockHeight: 1, + ValAddress: []byte("valAddr1"), + BlockHeight: 1, }, { - ProviderAddr: types.NewProviderConsAddress([]byte("providerAddr2")), - BlockHeight: 2, + ValAddress: []byte("valAddr2"), + BlockHeight: 2, }, { - ProviderAddr: types.NewProviderConsAddress([]byte("providerAddr3")), - BlockHeight: 3, + ValAddress: []byte("valAddr3"), + BlockHeight: 3, }, } for _, expectedOptedInValidator := range expectedOptedInValidators { providerKeeper.SetOptedIn(ctx, "chainID", - expectedOptedInValidator.ProviderAddr, expectedOptedInValidator.BlockHeight) + expectedOptedInValidator.ValAddress, expectedOptedInValidator.BlockHeight) } actualOptedInValidators := providerKeeper.GetOptedIn(ctx, "chainID") @@ -694,7 +695,7 @@ func TestGetOptedIn(t *testing.T) { a := optedInValidators[i] b := optedInValidators[j] return a.BlockHeight < b.BlockHeight || - (a.BlockHeight == b.BlockHeight && bytes.Compare(a.ProviderAddr.ToSdkConsAddr(), b.ProviderAddr.ToSdkConsAddr()) < 0) + (a.BlockHeight == b.BlockHeight && bytes.Compare(a.ValAddress, b.ValAddress) < 0) }) } sortOptedInValidators(expectedOptedInValidators) @@ -708,25 +709,25 @@ func TestOptedIn(t *testing.T) { defer ctrl.Finish() optedInValidator := keeper.OptedInValidator{ - ProviderAddr: types.NewProviderConsAddress([]byte("providerAddr")), - BlockHeight: 1, + ValAddress: []byte("valAddr"), + BlockHeight: 1, } - require.False(t, providerKeeper.IsOptedIn(ctx, "chainID", optedInValidator.ProviderAddr)) - providerKeeper.SetOptedIn(ctx, "chainID", optedInValidator.ProviderAddr, optedInValidator.BlockHeight) - require.True(t, providerKeeper.IsOptedIn(ctx, "chainID", optedInValidator.ProviderAddr)) - providerKeeper.DeleteOptedIn(ctx, "chainID", optedInValidator.ProviderAddr) - require.False(t, providerKeeper.IsOptedIn(ctx, "chainID", optedInValidator.ProviderAddr)) + require.False(t, providerKeeper.IsOptedIn(ctx, "chainID", optedInValidator.ValAddress)) + providerKeeper.SetOptedIn(ctx, "chainID", optedInValidator.ValAddress, optedInValidator.BlockHeight) + require.True(t, providerKeeper.IsOptedIn(ctx, "chainID", optedInValidator.ValAddress)) + providerKeeper.DeleteOptedIn(ctx, "chainID", optedInValidator.ValAddress) + require.False(t, providerKeeper.IsOptedIn(ctx, "chainID", optedInValidator.ValAddress)) } func TestGetToBeOptedIn(t *testing.T) { providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - expectedAddresses := []types.ProviderConsAddress{ - types.NewProviderConsAddress([]byte("providerAddr1")), - types.NewProviderConsAddress([]byte("providerAddr2")), - types.NewProviderConsAddress([]byte("providerAddr3"))} + expectedAddresses := []sdk.ValAddress{ + []byte("valAddr1"), + []byte("valAddr2"), + []byte("valAddr3")} for _, addr := range expectedAddresses { providerKeeper.SetToBeOptedIn(ctx, "chainID", addr) @@ -735,45 +736,9 @@ func TestGetToBeOptedIn(t *testing.T) { actualAddresses := providerKeeper.GetToBeOptedIn(ctx, "chainID") // sort addresses first to be able to compare - sortAddresses := func(addresses []types.ProviderConsAddress) { + sortAddresses := func(addresses []sdk.ValAddress) { sort.Slice(addresses, func(i int, j int) bool { - a := addresses[i] - b := addresses[j] - return bytes.Compare(a.Address.Bytes(), b.Address.Bytes()) < 0 - }) - } - sortAddresses(expectedAddresses) - sortAddresses(actualAddresses) - require.Equal(t, expectedAddresses, actualAddresses) - - for _, addr := range expectedAddresses { - require.True(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", addr)) - providerKeeper.DeleteToBeOptedIn(ctx, "chainID", addr) - require.False(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", addr)) - } -} - -func TestBeOptedIn(t *testing.T) { - providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) - defer ctrl.Finish() - - expectedAddresses := []types.ProviderConsAddress{ - types.NewProviderConsAddress([]byte("providerAddr1")), - types.NewProviderConsAddress([]byte("providerAddr2")), - types.NewProviderConsAddress([]byte("providerAddr3"))} - - for _, addr := range expectedAddresses { - providerKeeper.SetToBeOptedIn(ctx, "chainID", addr) - } - - actualAddresses := providerKeeper.GetToBeOptedIn(ctx, "chainID") - - // sort addresses first to be able to compare - sortAddresses := func(addresses []types.ProviderConsAddress) { - sort.Slice(addresses, func(i int, j int) bool { - a := addresses[i] - b := addresses[j] - return bytes.Compare(a.Address.Bytes(), b.Address.Bytes()) < 0 + return bytes.Compare(addresses[i], addresses[j]) < 0 }) } sortAddresses(expectedAddresses) @@ -792,23 +757,23 @@ func TestToBeOptedIn(t *testing.T) { providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - providerAddr := types.NewProviderConsAddress([]byte("providerAddr1")) + valAddress := []byte("valAddr1") - require.False(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", providerAddr)) - providerKeeper.SetToBeOptedIn(ctx, "chainID", providerAddr) - require.True(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", providerAddr)) - providerKeeper.DeleteToBeOptedIn(ctx, "chainID", providerAddr) - require.False(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", providerAddr)) + require.False(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", valAddress)) + providerKeeper.SetToBeOptedIn(ctx, "chainID", valAddress) + require.True(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", valAddress)) + providerKeeper.DeleteToBeOptedIn(ctx, "chainID", valAddress) + require.False(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", valAddress)) } func TestGetToBeOptedOut(t *testing.T) { providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - expectedAddresses := []types.ProviderConsAddress{ - types.NewProviderConsAddress([]byte("providerAddr1")), - types.NewProviderConsAddress([]byte("providerAddr2")), - types.NewProviderConsAddress([]byte("providerAddr3"))} + expectedAddresses := []sdk.ValAddress{ + []byte("valAddr1"), + []byte("valAddr2"), + []byte("valAddr3")} for _, addr := range expectedAddresses { providerKeeper.SetToBeOptedOut(ctx, "chainID", addr) @@ -817,11 +782,9 @@ func TestGetToBeOptedOut(t *testing.T) { actualAddresses := providerKeeper.GetToBeOptedOut(ctx, "chainID") // sort addresses first to be able to compare - sortAddresses := func(addresses []types.ProviderConsAddress) { + sortAddresses := func(addresses []sdk.ValAddress) { sort.Slice(addresses, func(i int, j int) bool { - a := addresses[i] - b := addresses[j] - return bytes.Compare(a.Address.Bytes(), b.Address.Bytes()) < 0 + return bytes.Compare(addresses[i], addresses[j]) < 0 }) } sortAddresses(expectedAddresses) @@ -840,11 +803,11 @@ func TestToBeOptedOut(t *testing.T) { providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - providerAddr := types.NewProviderConsAddress([]byte("providerAddr1")) + valAddress := []byte("valAddr1") - require.False(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", providerAddr)) - providerKeeper.SetToBeOptedOut(ctx, "chainID", providerAddr) - require.True(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", providerAddr)) - providerKeeper.DeleteToBeOptedOut(ctx, "chainID", providerAddr) - require.False(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", providerAddr)) + require.False(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", valAddress)) + providerKeeper.SetToBeOptedOut(ctx, "chainID", valAddress) + require.True(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", valAddress)) + providerKeeper.DeleteToBeOptedOut(ctx, "chainID", valAddress) + require.False(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", valAddress)) } diff --git a/x/ccv/provider/keeper/key_assignment_test.go b/x/ccv/provider/keeper/key_assignment_test.go index 4fab08c981..272d5f1593 100644 --- a/x/ccv/provider/keeper/key_assignment_test.go +++ b/x/ccv/provider/keeper/key_assignment_test.go @@ -86,7 +86,7 @@ func TestGetAllValidatorConsumerPubKey(t *testing.T) { expectedGetAllOneConsumerOrder = append(expectedGetAllOneConsumerOrder, assignment) } } - // sorting by ValidatorConsumerPubKey.ProviderAddr + // sorting by ValidatorConsumerPubKey.ValAddress sort.Slice(expectedGetAllOneConsumerOrder, func(i, j int) bool { return bytes.Compare(expectedGetAllOneConsumerOrder[i].ProviderAddr, expectedGetAllOneConsumerOrder[j].ProviderAddr) == -1 }) @@ -228,7 +228,7 @@ func TestGetAllKeyAssignmentReplacements(t *testing.T) { ) } expectedGetAllOrder := testAssignments - // sorting by KeyAssignmentReplacement.ProviderAddr + // sorting by KeyAssignmentReplacement.ValAddress sort.Slice(expectedGetAllOrder, func(i, j int) bool { return bytes.Compare(expectedGetAllOrder[i].ProviderAddr, expectedGetAllOrder[j].ProviderAddr) == -1 }) diff --git a/x/ccv/provider/keeper/msg_server.go b/x/ccv/provider/keeper/msg_server.go index 7cac362a04..df79e5d4d7 100644 --- a/x/ccv/provider/keeper/msg_server.go +++ b/x/ccv/provider/keeper/msg_server.go @@ -178,17 +178,13 @@ func (k msgServer) SubmitConsumerDoubleVoting(goCtx context.Context, msg *types. func (k msgServer) OptIn(goCtx context.Context, msg *types.MsgOptIn) (*types.MsgOptInResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - valAddress, err := sdk.ConsAddressFromBech32(msg.ProviderAddr) - if err != nil { - return nil, err - } - providerAddr := types.NewProviderConsAddress(valAddress) + valAddress, err := sdk.ValAddressFromBech32(msg.ProviderAddr) if err != nil { return nil, err } if msg.ConsumerKey != "" { - k.Keeper.HandleOptIn(ctx, msg.ChainId, providerAddr, &msg.ConsumerKey) + k.Keeper.HandleOptIn(ctx, msg.ChainId, valAddress, &msg.ConsumerKey) ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( ccvtypes.EventTypeOptIn, @@ -197,7 +193,7 @@ func (k msgServer) OptIn(goCtx context.Context, msg *types.MsgOptIn) (*types.Msg ), }) } else { - k.Keeper.HandleOptIn(ctx, msg.ChainId, providerAddr, nil) + k.Keeper.HandleOptIn(ctx, msg.ChainId, valAddress, nil) ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( @@ -213,16 +209,12 @@ func (k msgServer) OptIn(goCtx context.Context, msg *types.MsgOptIn) (*types.Msg func (k msgServer) OptOut(goCtx context.Context, msg *types.MsgOptOut) (*types.MsgOptOutResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - valAddress, err := sdk.ConsAddressFromBech32(msg.ProviderAddr) - if err != nil { - return nil, err - } - providerAddr := types.NewProviderConsAddress(valAddress) + valAddress, err := sdk.ValAddressFromBech32(msg.ProviderAddr) if err != nil { return nil, err } - k.Keeper.HandleOptOut(ctx, msg.ChainId, providerAddr) + k.Keeper.HandleOptOut(ctx, msg.ChainId, valAddress) ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( diff --git a/x/ccv/provider/keeper/partial_set_security.go b/x/ccv/provider/keeper/partial_set_security.go index 1251eda372..0211d4681e 100644 --- a/x/ccv/provider/keeper/partial_set_security.go +++ b/x/ccv/provider/keeper/partial_set_security.go @@ -2,22 +2,21 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/interchain-security/v4/x/ccv/provider/types" ) type OptedInValidator struct { - ProviderAddr types.ProviderConsAddress + ValAddress sdk.ValAddress // block height the validator opted in at BlockHeight uint64 } -func (k Keeper) HandleOptIn(ctx sdk.Context, chainID string, providerAddr types.ProviderConsAddress, consumerKey *string) { - if k.IsToBeOptedOut(ctx, chainID, providerAddr) { +func (k Keeper) HandleOptIn(ctx sdk.Context, chainID string, valAddress sdk.ValAddress, consumerKey *string) { + if k.IsToBeOptedOut(ctx, chainID, valAddress) { // a validator to be opted in cancels out with a validator to be opted out - k.DeleteToBeOptedOut(ctx, chainID, providerAddr) - } else if !k.IsToBeOptedIn(ctx, chainID, providerAddr) && !k.IsOptedIn(ctx, chainID, providerAddr) { + k.DeleteToBeOptedOut(ctx, chainID, valAddress) + } else if !k.IsToBeOptedIn(ctx, chainID, valAddress) && !k.IsOptedIn(ctx, chainID, valAddress) { // a validator can only be set for opt in if it is not opted in and not already set for opt in - k.SetToBeOptedIn(ctx, chainID, providerAddr) + k.SetToBeOptedIn(ctx, chainID, valAddress) } if consumerKey != nil { @@ -25,12 +24,12 @@ func (k Keeper) HandleOptIn(ctx sdk.Context, chainID string, providerAddr types. } } -func (k Keeper) HandleOptOut(ctx sdk.Context, chainID string, providerAddr types.ProviderConsAddress) { - if k.IsToBeOptedIn(ctx, chainID, providerAddr) { +func (k Keeper) HandleOptOut(ctx sdk.Context, chainID string, valAddress sdk.ValAddress) { + if k.IsToBeOptedIn(ctx, chainID, valAddress) { // a validator to be opted out cancels out a validator to be opted in - k.DeleteToBeOptedIn(ctx, chainID, providerAddr) - } else if !k.IsToBeOptedOut(ctx, chainID, providerAddr) && k.IsOptedIn(ctx, chainID, providerAddr) { + k.DeleteToBeOptedIn(ctx, chainID, valAddress) + } else if !k.IsToBeOptedOut(ctx, chainID, valAddress) && k.IsOptedIn(ctx, chainID, valAddress) { // a validator can only be set for opt out if it is opted in and not already set for opt out - k.SetToBeOptedOut(ctx, chainID, providerAddr) + k.SetToBeOptedOut(ctx, chainID, valAddress) } } diff --git a/x/ccv/provider/keeper/partial_set_security_test.go b/x/ccv/provider/keeper/partial_set_security_test.go index 34e99f61f9..0bc8993270 100644 --- a/x/ccv/provider/keeper/partial_set_security_test.go +++ b/x/ccv/provider/keeper/partial_set_security_test.go @@ -2,7 +2,6 @@ package keeper_test import ( testkeeper "github.com/cosmos/interchain-security/v4/testutil/keeper" - "github.com/cosmos/interchain-security/v4/x/ccv/provider/types" "github.com/stretchr/testify/require" "testing" ) @@ -11,38 +10,38 @@ func TestHandleOptIn(t *testing.T) { providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - providerAddr := types.NewProviderConsAddress([]byte("providerAddr")) + valAddress := []byte("valAddr") - // if validator (`providerAddr`) is to be opted out, then we cancel that the validator is about + // if validator (`valAddress`) is to be opted out, then we cancel that the validator is about // to be opted out and do not consider the validator to opt in - providerKeeper.SetToBeOptedOut(ctx, "chainID", providerAddr) - require.True(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", providerAddr)) - providerKeeper.HandleOptIn(ctx, "chainID", providerAddr, nil) - require.False(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", providerAddr)) - require.False(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", providerAddr)) - - // if validator (`providerAddr`) is already opted in, then the validator cannot be opted in - providerKeeper.SetOptedIn(ctx, "chainID", providerAddr, 1) - providerKeeper.HandleOptIn(ctx, "chainID", providerAddr, nil) - require.False(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", providerAddr)) + providerKeeper.SetToBeOptedOut(ctx, "chainID", valAddress) + require.True(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", valAddress)) + providerKeeper.HandleOptIn(ctx, "chainID", valAddress, nil) + require.False(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", valAddress)) + require.False(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", valAddress)) + + // if validator (`valAddress`) is already opted in, then the validator cannot be opted in + providerKeeper.SetOptedIn(ctx, "chainID", valAddress, 1) + providerKeeper.HandleOptIn(ctx, "chainID", valAddress, nil) + require.False(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", valAddress)) } func TestHandleOptOut(t *testing.T) { providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - providerAddr := types.NewProviderConsAddress([]byte("providerAddr")) + valAddress := []byte("valAddr") - // if validator (`providerAddr`) is to be opted in, then we cancel that the validator is about + // if validator (`valAddress`) is to be opted in, then we cancel that the validator is about // to be opted out and do not consider the validator to opt out - providerKeeper.SetToBeOptedIn(ctx, "chainID", providerAddr) - require.True(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", providerAddr)) - providerKeeper.HandleOptOut(ctx, "chainID", providerAddr) - require.False(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", providerAddr)) - require.False(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", providerAddr)) - - // if validator (`providerAddr`) is not opted in, then the validator cannot be opted out - providerKeeper.DeleteOptedIn(ctx, "chainID", providerAddr) - providerKeeper.HandleOptOut(ctx, "chainID", providerAddr) - require.False(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", providerAddr)) + providerKeeper.SetToBeOptedIn(ctx, "chainID", valAddress) + require.True(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", valAddress)) + providerKeeper.HandleOptOut(ctx, "chainID", valAddress) + require.False(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", valAddress)) + require.False(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", valAddress)) + + // if validator (`valAddress`) is not opted in, then the validator cannot be opted out + providerKeeper.DeleteOptedIn(ctx, "chainID", valAddress) + providerKeeper.HandleOptOut(ctx, "chainID", valAddress) + require.False(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", valAddress)) } diff --git a/x/ccv/provider/types/keys.go b/x/ccv/provider/types/keys.go index 20824454cb..c42cbad4b3 100644 --- a/x/ccv/provider/types/keys.go +++ b/x/ccv/provider/types/keys.go @@ -538,21 +538,21 @@ func TopNKey(chainID string) []byte { } // OptedInKey returns the key of consumer chain `chainID` and validator with `providerAddr` -func OptedInKey(chainID string, providerAddr ProviderConsAddress) []byte { +func OptedInKey(chainID string, valAddress sdk.ValAddress) []byte { prefix := ChainIdWithLenKey(OptedInBytePrefix, chainID) - return append(prefix, providerAddr.ToSdkConsAddr().Bytes()...) + return append(prefix, valAddress...) } // ToBeOptedInKey returns the key of consumer chain `chainID` and validator with `providerAddr` -func ToBeOptedInKey(chainID string, providerAddr ProviderConsAddress) []byte { +func ToBeOptedInKey(chainID string, valAddress sdk.ValAddress) []byte { prefix := ChainIdWithLenKey(ToBeOptedInBytePrefix, chainID) - return append(prefix, providerAddr.ToSdkConsAddr().Bytes()...) + return append(prefix, valAddress...) } // ToBeOptedOutKey returns the key of consumer chain `chainID` and validator with `providerAddr` -func ToBeOptedOutKey(chainID string, providerAddr ProviderConsAddress) []byte { +func ToBeOptedOutKey(chainID string, valAddress sdk.ValAddress) []byte { prefix := ChainIdWithLenKey(ToBeOptedOutBytePrefix, chainID) - return append(prefix, providerAddr.ToSdkConsAddr().Bytes()...) + return append(prefix, valAddress...) } // diff --git a/x/ccv/provider/types/provider.pb.go b/x/ccv/provider/types/provider.pb.go index fd9d63bc7e..89339d12ab 100644 --- a/x/ccv/provider/types/provider.pb.go +++ b/x/ccv/provider/types/provider.pb.go @@ -5813,7 +5813,7 @@ func (m *KeyAssignmentReplacement) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ProviderAddr", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ValAddress", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -5984,7 +5984,7 @@ func (m *ValidatorConsumerPubKey) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ProviderAddr", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ValAddress", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -6170,7 +6170,7 @@ func (m *ValidatorByConsumerAddr) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ProviderAddr", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ValAddress", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { diff --git a/x/ccv/provider/types/tx.pb.go b/x/ccv/provider/types/tx.pb.go index 647f5f49dc..35691c4f91 100644 --- a/x/ccv/provider/types/tx.pb.go +++ b/x/ccv/provider/types/tx.pb.go @@ -1272,7 +1272,7 @@ func (m *MsgAssignConsumerKey) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ProviderAddr", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ValAddress", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1840,7 +1840,7 @@ func (m *MsgOptIn) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ProviderAddr", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ValAddress", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -2036,7 +2036,7 @@ func (m *MsgOptOut) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ProviderAddr", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ValAddress", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 {