Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: handle consumer commission marshalling errors gracefully #1836

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion proto/interchain_security/ccv/provider/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ service Query {
QueryValidatorConsumerCommissionRateRequest)
returns (QueryValidatorConsumerCommissionRateResponse) {
option (google.api.http).get =
"/interchain_security/ccv/provider/consumer_commission_rate";
"/interchain_security/ccv/provider/consumer_commission_rate/{chain_id}/{provider_address}";
}

// QueryOldestUnconfirmedVsc returns the send timestamp of the oldest unconfirmed VSCPacket for a given chainID
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -989,12 +989,13 @@ func (s *CCVTestSuite) TestAllocateTokensToValidator() {
// set the same consumer commission rate for all consumer validators
for _, v := range consuVals {
provAddr := providertypes.NewProviderConsAddress(sdk.ConsAddress(v.ProviderConsAddr))
providerKeeper.SetConsumerCommissionRate(
err := providerKeeper.SetConsumerCommissionRate(
ctx,
chainID,
provAddr,
tc.rate,
)
s.Require().NoError(err)
}

// allocate tokens
Expand Down
4 changes: 1 addition & 3 deletions x/ccv/provider/keeper/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,10 @@ func (k Keeper) HandleSetConsumerCommissionRate(ctx sdk.Context, chainID string,
"unknown consumer chain, with id: %s", chainID)
}
// set per-consumer chain commission rate for the validator address
k.SetConsumerCommissionRate(
return k.SetConsumerCommissionRate(
ctx,
chainID,
providerAddr,
commissionRate,
)

return nil
}
11 changes: 8 additions & 3 deletions x/ccv/provider/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1240,14 +1240,17 @@ func (k Keeper) SetConsumerCommissionRate(
chainID string,
providerAddr types.ProviderConsAddress,
commissionRate sdk.Dec,
) {
) error {
store := ctx.KVStore(k.storeKey)
bz, err := commissionRate.Marshal()
if err != nil {
panic(fmt.Errorf("consumer commission rate marshalling failed: %s", err))
err = fmt.Errorf("consumer commission rate marshalling failed: %s", err)
k.Logger(ctx).Error(err.Error())
return err
}

store.Set(types.ConsumerCommissionRateKey(chainID, providerAddr), bz)
return nil
}

// GetConsumerCommissionRate returns the per-consumer commission rate set
Expand All @@ -1264,8 +1267,10 @@ func (k Keeper) GetConsumerCommissionRate(
}

cr := sdk.Dec{}
// handle error gracefully since it's called in BeginBlockRD
if err := cr.Unmarshal(bz); err != nil {
panic(fmt.Sprintf("consumer commission rate unmarshalling failed: %s", err))
k.Logger(ctx).Error("consumer commission rate unmarshalling failed: %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this failing to unmarshal mean we have corrupted state? If this is the case, maybe panic is better than moving forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBD when @mpoke is back I guess.

return sdk.ZeroDec(), false
}

return cr, true
Expand Down
4 changes: 4 additions & 0 deletions x/ccv/provider/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
(*exported.ClientMessage)(nil),
&tendermint.Misbehaviour{},
)
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgSetConsumerCommissionRate{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

Expand Down
Loading