Skip to content

Commit

Permalink
fix: fixing wrong bond denom being considered for callback fees (#559)
Browse files Browse the repository at this point in the history
* removing usage of sdk.DefaultBondDenom

* Update CHANGELOG.md
  • Loading branch information
spoo-bar authored Apr 17, 2024
1 parent 18a857c commit ca24a70
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Contains all the PRs that improved the code without changing the behaviors.
- [#538](https://github.com/archway-network/archway/pull/538) - Fixing the interchain test gh workflow failing cuz rc tags were not recognized
- [#539](https://github.com/archway-network/archway/pull/539) - Remediations for x/callback audit
- [#552](https://github.com/archway-network/archway/pull/552) - Fix issue with x/callback callback error code was not identified correctly when setting cwerrors
- [#559](https://github.com/archway-network/archway/pull/559) - Fixing wrong bond denom being considered for x/callback and x/cwerrors fees


## [v6.0.0](https://github.com/archway-network/archway/releases/tag/v6.0.0)
Expand Down
7 changes: 4 additions & 3 deletions app/upgrades/7_0_0/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var Upgrade = upgrades.Upgrade{
}

ctx.Logger().Info("Setting default params for the new modules")
bondDenom := keepers.StakingKeeper.BondDenom(ctx)
// Setting callback params
callbackParams, err := keepers.CallbackKeeper.GetParams(ctx)
if err != nil {
Expand All @@ -58,9 +59,9 @@ var Upgrade = upgrades.Upgrade{
if err != nil {
return nil, err
}
cwerrorsParams.ErrorStoredTime = 302400 // roughly 21 days
cwerrorsParams.SubscriptionFee = sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000000000000000000) // 1 ARCH (1e18 attoarch)
cwerrorsParams.SubscriptionPeriod = 302400 // roughly 21 days
cwerrorsParams.ErrorStoredTime = 302400 // roughly 21 days
cwerrorsParams.SubscriptionFee = sdk.NewInt64Coin(bondDenom, 1000000000000000000) // 1 ARCH (1e18 attoarch)
cwerrorsParams.SubscriptionPeriod = 302400 // roughly 21 days
err = keepers.CWErrorsKeeper.SetParams(ctx, cwerrorsParams)
if err != nil {
return nil, err
Expand Down
9 changes: 5 additions & 4 deletions x/callback/keeper/fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func (k Keeper) EstimateCallbackFees(ctx sdk.Context, blockHeight int64) (sdk.Co
}
// futureReservationFeeMultiplies * (requestBlockHeight - currentBlockHeight)
futureReservationFeesAmount := params.FutureReservationFeeMultiplier.MulInt64((blockHeight - ctx.BlockHeight()))
futureReservationFee := sdk.NewCoin(sdk.DefaultBondDenom, futureReservationFeesAmount.RoundInt())

// Calculates the fees based on how many callbacks are registered at the given block height
callbacksForHeight, err := k.GetCallbacksByHeight(ctx, blockHeight)
Expand All @@ -42,15 +41,17 @@ func (k Keeper) EstimateCallbackFees(ctx sdk.Context, blockHeight int64) (sdk.Co
}
// blockReservationFeeMultiplier * totalCallbacksRegistered
blockReservationFeesAmount := params.BlockReservationFeeMultiplier.MulInt64(int64(totalCallbacks))
blockReservationFee := sdk.NewCoin(sdk.DefaultBondDenom, blockReservationFeesAmount.RoundInt())

// Calculates the fees based on the max gas limit of the callback and current price of gas
transactionFee := k.CalculateTransactionFees(ctx, params.GetCallbackGasLimit())
futureReservationFee := sdk.NewCoin(transactionFee.Denom, futureReservationFeesAmount.RoundInt())
blockReservationFee := sdk.NewCoin(transactionFee.Denom, blockReservationFeesAmount.RoundInt())
return futureReservationFee, blockReservationFee, transactionFee, nil
}

func (k Keeper) CalculateTransactionFees(ctx sdk.Context, gasAmount uint64) sdk.Coin {
transactionFeeAmount := k.rewardsKeeper.ComputationalPriceOfGas(ctx).Amount.MulInt64(int64(gasAmount))
transactionFee := sdk.NewCoin(sdk.DefaultBondDenom, transactionFeeAmount.RoundInt())
computationPriceOfGas := k.rewardsKeeper.ComputationalPriceOfGas(ctx)
transactionFeeAmount := computationPriceOfGas.Amount.MulInt64(int64(gasAmount))
transactionFee := sdk.NewCoin(computationPriceOfGas.Denom, transactionFeeAmount.RoundInt())
return transactionFee
}
3 changes: 0 additions & 3 deletions x/callback/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ func (m MsgRequestCallback) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(m.ContractAddress); err != nil {
return errorsmod.Wrapf(sdkErrors.ErrInvalidAddress, "invalid contract address: %v", err)
}
if m.Fees.Denom != sdk.DefaultBondDenom {
return errorsmod.Wrapf(sdkErrors.ErrInvalidCoins, "invalid fees denom: %v", m.Fees.Denom)
}

return nil
}
Expand Down

0 comments on commit ca24a70

Please sign in to comment.