Skip to content

Commit

Permalink
remove unnecessary check
Browse files Browse the repository at this point in the history
  • Loading branch information
sainoe committed Mar 5, 2024
1 parent 8e2111a commit 2951e9b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 18 deletions.
11 changes: 1 addition & 10 deletions x/ccv/provider/keeper/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,21 +282,12 @@ func (k Keeper) IdentifyConsumerChainIDFromIBCPacket(ctx sdk.Context, packet cha
}

// HandleSetConsumerCommissionRate sets a per-consumer chain commission rate for the given provider address
// on the condition that the given consumer chain exists.
func (k Keeper) HandleSetConsumerCommissionRate(ctx sdk.Context, chainID string, providerAddr types.ProviderConsAddress, commissionRate sdk.Dec) error {
// check that the consumer chain exists
if !k.IsConsumerProposedOrRegistered(ctx, chainID) {
return errorsmod.Wrapf(
types.ErrUnknownConsumerChainId,
"unknown consumer chain, with id: %s", chainID)
}
func (k Keeper) HandleSetConsumerCommissionRate(ctx sdk.Context, chainID string, providerAddr types.ProviderConsAddress, commissionRate sdk.Dec) {
// set per-consumer chain commission rate for the validator address
k.SetConsumerCommissionRate(
ctx,
chainID,
providerAddr,
commissionRate,
)

return nil
}
4 changes: 1 addition & 3 deletions x/ccv/provider/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ func (k msgServer) SetConsumerCommissionRate(goCtx context.Context, msg *types.M
return nil, err
}

if err := k.HandleSetConsumerCommissionRate(ctx, msg.ChainId, types.NewProviderConsAddress(consAddr), msg.Rate); err != nil {
return nil, err
}
k.HandleSetConsumerCommissionRate(ctx, msg.ChainId, types.NewProviderConsAddress(consAddr), msg.Rate)

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
Expand Down
6 changes: 1 addition & 5 deletions x/ccv/provider/keeper/partial_set_security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,14 @@ func TestHandleSetConsumerCommissionRate(t *testing.T) {

providerAddr := types.NewProviderConsAddress([]byte("providerAddr"))

// trying to set a commission rate to a unknown consumer chain
require.Error(t, providerKeeper.HandleSetConsumerCommissionRate(ctx, "unknownChainID", providerAddr, sdk.ZeroDec()))

// setup a pending consumer chain
chainID := "pendingChainID"
providerKeeper.SetPendingConsumerAdditionProp(ctx, &types.ConsumerAdditionProposal{ChainId: chainID})

// check that there's no commission rate set for the validator yet
_, found := providerKeeper.GetConsumerCommissionRate(ctx, chainID, providerAddr)
require.False(t, found)

require.NoError(t, providerKeeper.HandleSetConsumerCommissionRate(ctx, chainID, providerAddr, sdk.OneDec()))
providerKeeper.HandleSetConsumerCommissionRate(ctx, chainID, providerAddr, sdk.OneDec())

// check that the commission rate is now set
cr, found := providerKeeper.GetConsumerCommissionRate(ctx, chainID, providerAddr)
Expand Down

0 comments on commit 2951e9b

Please sign in to comment.