Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
insumity committed Feb 5, 2024
1 parent 28f71c7 commit 86c0d00
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 48 deletions.
28 changes: 0 additions & 28 deletions x/ccv/provider/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,11 +702,7 @@ func TestGetOptedIn(t *testing.T) {
require.Equal(t, expectedOptedInValidators, actualOptedInValidators)
}

<<<<<<< HEAD
// TestOptedIn tests the `SetOptedIn`, `IsOptedIn`, and `DeleteOptedIn` methods
=======
// TestOptedIn tests the `SetOptedIn`, `IsOptedIn`, and `RemoveOptedIn` methods
>>>>>>> d8d7531f (cleaned up tests)
func TestOptedIn(t *testing.T) {
providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()
Expand Down Expand Up @@ -752,20 +748,12 @@ func TestGetToBeOptedIn(t *testing.T) {

for _, addr := range expectedAddresses {
require.True(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", addr))
<<<<<<< HEAD
providerKeeper.DeleteToBeOptedIn(ctx, "chainID", addr)
=======
providerKeeper.RemoveToBeOptedIn(ctx, "chainID", addr)
>>>>>>> d8d7531f (cleaned up tests)
require.False(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", addr))
}
}

<<<<<<< HEAD
// TestToBeOptedIn tests the `SetToBeOptedIn`, `IsToBeOptedIn`, and `DeleteToBeOptedIn` methods
=======
// TestToBeOptedIn tests the `SetToBeOptedIn`, `IsToBeOptedIn`, and `RemoveToBeOptedIn` methods
>>>>>>> d8d7531f (cleaned up tests)
func TestToBeOptedIn(t *testing.T) {
providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()
Expand All @@ -775,11 +763,7 @@ func TestToBeOptedIn(t *testing.T) {
require.False(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", providerAddr))
providerKeeper.SetToBeOptedIn(ctx, "chainID", providerAddr)
require.True(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", providerAddr))
<<<<<<< HEAD
providerKeeper.DeleteToBeOptedIn(ctx, "chainID", providerAddr)
=======
providerKeeper.RemoveToBeOptedIn(ctx, "chainID", providerAddr)
>>>>>>> d8d7531f (cleaned up tests)
require.False(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", providerAddr))
}

Expand Down Expand Up @@ -812,20 +796,12 @@ func TestGetToBeOptedOut(t *testing.T) {

for _, addr := range expectedAddresses {
require.True(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", addr))
<<<<<<< HEAD
providerKeeper.DeleteToBeOptedOut(ctx, "chainID", addr)
=======
providerKeeper.RemoveToBeOptedOut(ctx, "chainID", addr)
>>>>>>> d8d7531f (cleaned up tests)
require.False(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", addr))
}
}

<<<<<<< HEAD
// TestToBeOptedOut tests the `SetToBeOptedOut`, `IsToBeOptedOut`, and `DeleteToBeOptedOut` methods
=======
// TestToBeOptedOut tests the `SetToBeOptedOut`, `IsToBeOptedOut`, and `RemoveToBeOptedOut` methods
>>>>>>> d8d7531f (cleaned up tests)
func TestToBeOptedOut(t *testing.T) {
providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()
Expand All @@ -835,10 +811,6 @@ func TestToBeOptedOut(t *testing.T) {
require.False(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", providerAddr))
providerKeeper.SetToBeOptedOut(ctx, "chainID", providerAddr)
require.True(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", providerAddr))
<<<<<<< HEAD
providerKeeper.DeleteToBeOptedOut(ctx, "chainID", providerAddr)
=======
providerKeeper.RemoveToBeOptedOut(ctx, "chainID", providerAddr)
>>>>>>> d8d7531f (cleaned up tests)
require.False(t, providerKeeper.IsToBeOptedOut(ctx, "chainID", providerAddr))
}
24 changes: 7 additions & 17 deletions x/ccv/provider/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,26 +187,22 @@ func (k msgServer) OptIn(goCtx context.Context, msg *types.MsgOptIn) (*types.Msg
return nil, err
}

<<<<<<< HEAD
k.Keeper.HandleOptIn(ctx, msg.ChainId, providerAddr)

if _, ok := msg.XConsumerKey.(*types.MsgOptIn_ConsumerKey); ok {
=======
// todo also send down the consumer key ...???
if err := k.Keeper.HandleOptIn(ctx, msg.ChainId, providerAddr); err != nil {
return nil, err
}
key := msg.GetConsumerKey()
consumerKey := &key

k.Keeper.HandleOptIn(ctx, msg.ChainId, providerAddr, consumerKey)

if msg.GetConsumerKey() != "" { // FIXME: there should be a nicer way to do this
>>>>>>> defd7cc6 (store opted in and opted out validators)
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
ccvtypes.EventTypeOptIn,
sdk.NewAttribute(types.AttributeProviderValidatorAddress, msg.ProviderAddr),
sdk.NewAttribute(types.AttributeConsumerConsensusPubKey, msg.GetConsumerKey()),
sdk.NewAttribute(types.AttributeConsumerConsensusPubKey, key),
),
})
} else {
k.Keeper.HandleOptIn(ctx, msg.ChainId, providerAddr, nil)

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
ccvtypes.EventTypeOptIn,
Expand All @@ -230,13 +226,7 @@ func (k msgServer) OptOut(goCtx context.Context, msg *types.MsgOptOut) (*types.M
return nil, err
}

<<<<<<< HEAD
k.Keeper.HandleOptOut(ctx, msg.ChainId, providerAddr)
=======
if err := k.Keeper.HandleOptOut(ctx, msg.ChainId, providerAddr); err != nil {
return nil, err
}
>>>>>>> defd7cc6 (store opted in and opted out validators)

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
Expand Down
10 changes: 9 additions & 1 deletion x/ccv/provider/keeper/partial_set_security.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,26 @@ type OptedInValidator struct {
BlockHeight uint64
}

func (k Keeper) HandleOptIn(ctx sdk.Context, chainID string, providerAddr types.ProviderConsAddress) {
func (k Keeper) HandleOptIn(ctx sdk.Context, chainID string, providerAddr types.ProviderConsAddress, consumerKey *string) {
if k.IsToBeOptedOut(ctx, chainID, providerAddr) {
// 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) {
// 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)
}

if consumerKey != nil {
// TODO: assign consumer key in this case
}
}

func (k Keeper) HandleOptOut(ctx sdk.Context, chainID string, providerAddr types.ProviderConsAddress) {
if k.IsToBeOptedIn(ctx, chainID, providerAddr) {
// 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) {
// 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)
}
}
4 changes: 2 additions & 2 deletions x/ccv/provider/keeper/partial_set_security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ func TestHandleOptIn(t *testing.T) {
// 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)
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)
providerKeeper.HandleOptIn(ctx, "chainID", providerAddr, nil)
require.False(t, providerKeeper.IsToBeOptedIn(ctx, "chainID", providerAddr))
}

Expand Down

0 comments on commit 86c0d00

Please sign in to comment.