-
Notifications
You must be signed in to change notification settings - Fork 46
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
Standard minimum fee implementation #314
Conversation
# Conflicts: # CHANGELOG.md
…eonardo/standard-minimum-fee � Conflicts: � app/app.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation seems good, but I think there is one key point that could be improved.
Right now the FeeDenom
and fixedRequiredFee
values are all hard coded. This makes it nearly impossible to change them without creating a new version of the application and then performing a hard fork of the chain.
Instead, what I think could be done is create a new x/fee
module inside which we can create some Params
holding the data we want; eg:
type Params struct {
MinFee sdk.Coin `json:"min_fee",yaml:"min_fee"`
}
Then, inside the newly created AnteDecorator
what we could do is the following:
minFee := feekeper.GetMinFee(ctx)
if !stableRequiredQty.IsZero() && stableRequiredQty.GT(minFee) {
...
}
By doing so we could easily change the minimum fee amount or denom by simply using governance proposals, which is very nice to have.
While taking a look at the current implementation, I came up with some improvements that could be applied in order to make this module more generic. File organizationI would move the Improving the fee parametersCurrently, the fee parameter is formed as follows: type Params struct {
MinFee sdk.Coin `json:"min_fee",yaml:"min_fee"`
} While this might work in some cases, it surely does not for everyone. What if we want to have a minimum fee only for some specific messages? How can we achieve this? In order to make the module more generic and usable by other projects as well, I think what we can do is change the parameters to be as follows: // MinFee contains the minimum amount of coins that should be paid as a fee for each message of the specified type sent
type MinFee struct {
MessageType string `json:"message", yaml:"message"`
Amount sdk.Coin `json:"amount", yaml:"amount"`
}
type Params struct {
MinFees []MinFee `json:"min_fees", yaml:"min_fees"`
} By doing so, we could then have the following parameters: {
"min_fees": [
{
"message": "desmos/MsgCreatePost",
"amount": {
"amount": "10000",
"denom": "udaric"
}
},
{
"message": "cosmos-sdk/MsgCreateValidator",
"amount": {
"amount": "2000",
"denom": "stake"
}
}
]
} Improving the minimum fee checkcurrently, the minimum fee check is all performed inside the // CheckFees checks whether the given fees are sufficient to pay for all the given messages.
// The check is performed considering the minimum fee amounts specified inside the module parameters.
func (k Keeper) CheckFees(ctx sdk.Context, fees sdk.Coins, msgs []sdk.Msg) error This method should:
This would simplify a lot the working of the // ...
// Check the minimum fees
if err := mfd.feesKeeper.CheckFees(ctx, stdTx.Fee.Amount, stdTx.Msgs); err != nil {
return ctx, err
}
// ... |
@RiccardoM Finally fixed everything! 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks mostly OK. There are some things I recommend changing
return fmt.Errorf("invalid minimum fee message type") | ||
} | ||
|
||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also validate the Amount
field by using the IsValid
method of sdk.Coins
here probably
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default when creating a Coin
or Coins
type that check is performed automatically
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that check is performed only when creating the Coin
or Coins
using the NewCoin
and NewCoins
methods respectively. I don't think it's performed when the Coins
are parsed from a JSON file. I think it might be better to add it for this reason anyway
@RiccardoM I had a look at the
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
} where the function // ParamKeyTable Key declaration for parameters
func ParamKeyTable() paramsModule.KeyTable {
return paramsModule.NewKeyTable().RegisterParamSet(&Params{})
} So basically we will never be in the case of having |
@bragaz You're right. I've also checked if there would be some cases in which the params could be set as empty ( |
Description
This PR introduces a custom
AnteHandler
that checks minimum standard fee at0.01 daric
.Closes #230.
Checklist
CHANGELOG.md
file.Files changed
in the Github PR explorer.