Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sainoe committed Feb 29, 2024
1 parent f2e44c6 commit 8e2111a
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 94 deletions.
10 changes: 5 additions & 5 deletions proto/interchain_security/ccv/provider/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ message MsgOptOutResponse {}
message MsgSetConsumerCommissionRate {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
// The chain id of the consumer chain to set a commission rate
string chain_id = 1;
// The validator address on the provider
string provider_addr = 2 [ (gogoproto.moretags) = "yaml:\"address\"" ];
// The rate to charge delegators on the consumer chain, as a fraction
string rate = 3 [
string provider_addr = 1 [ (gogoproto.moretags) = "yaml:\"address\"" ];
// The chain id of the consumer chain to set a commission rate
string chain_id = 2;
// The rate to charge delegators on the consumer chain, as a fraction
string rate = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ func (s *CCVTestSuite) TestAllocateTokensToValidator() {
s.Require().NoError(err)

// check that the withdrawn coins is equal to the entire reward amount
// times the set consumer commission
// times the set consumer commission rate
commission := rewards.Rewards.MulDec(tc.rate)
c, _ := commission.TruncateDecimal()
s.Require().Equal(withdrawnCoins, c)
Expand Down
20 changes: 20 additions & 0 deletions x/ccv/provider/keeper/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,23 @@ func (k Keeper) IdentifyConsumerChainIDFromIBCPacket(ctx sdk.Context, packet cha

return chainID, nil
}

// 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)
}
// set per-consumer chain commission rate for the validator address
k.SetConsumerCommissionRate(
ctx,
chainID,
providerAddr,
commissionRate,
)

return nil
}
4 changes: 0 additions & 4 deletions x/ccv/provider/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1287,9 +1287,6 @@ func (k Keeper) GetConsumerCommissionRate(
return cr, true
}

<<<<<<< Updated upstream
// DeleteConsumerCommissionRate deletes the per-consumer chain commission rate
=======
// GetAllCommissionRateValidators returns all the validator address
// that set a commission rate for the given chain ID
func (k Keeper) GetAllCommissionRateValidators(
Expand All @@ -1310,7 +1307,6 @@ func (k Keeper) GetAllCommissionRateValidators(
}

// DeleteConsumerCommissionRate the per-consumer chain commission rate
>>>>>>> Stashed changes
// associated to the given validator address
func (k Keeper) DeleteConsumerCommissionRate(
ctx sdk.Context,
Expand Down
9 changes: 9 additions & 0 deletions x/ccv/provider/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,14 @@ func (k msgServer) SetConsumerCommissionRate(goCtx context.Context, msg *types.M
return nil, err
}

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeSetConsumerCommissionRate,
sdk.NewAttribute(types.AttributeConsumerChainID, msg.ChainId),
sdk.NewAttribute(types.AttributeProviderValidatorAddress, msg.ProviderAddr),
sdk.NewAttribute(types.AttributeConsumerCommissionRate, msg.Rate.String()),
),
})

return &types.MsgSetConsumerCommissionRateResponse{}, nil
}
18 changes: 0 additions & 18 deletions x/ccv/provider/keeper/partial_set_security.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,3 @@ func (k Keeper) HandleOptOut(ctx sdk.Context, chainID string, providerAddr types

return nil
}

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)
}
// set per-consumer chain commission rate for the validator address
k.SetConsumerCommissionRate(
ctx,
chainID,
providerAddr,
commissionRate,
)

return nil
}
3 changes: 3 additions & 0 deletions x/ccv/provider/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const (
EventTypeAddConsumerRewardDenom = "add_consumer_reward_denom"
EventTypeRemoveConsumerRewardDenom = "remove_consumer_reward_denom"
EventTypeExecuteConsumerChainSlash = "execute_consumer_chain_slash"
EventTypeSetConsumerCommissionRate = "set_consumer_commission_rate"
AttributeInfractionHeight = "infraction_height"
AttributeInitialHeight = "initial_height"
AttributeInitializationTimeout = "initialization_timeout"
Expand All @@ -15,4 +16,6 @@ const (
AttributeProviderValidatorAddress = "provider_validator_address"
AttributeConsumerConsensusPubKey = "consumer_consensus_pub_key"
AttributeConsumerRewardDenom = "consumer_reward_denom"
AttributeConsumerCommissionRate = "consumer_commission_rate"
AttributeConsumerChainID = "consumer_chain_id"
)
Loading

0 comments on commit 8e2111a

Please sign in to comment.