Allow app devs to create Fee Allowances with access to custom data #8937
Description
Summary
Allow app devs to create Fee Allowances with access to custom data
Problem Definition
Right now, all possible fee allowances are hardcoded in the SDK: Basic, Periodic, AllowedMsg. We should allow app developers to create their own, i.e. any proto.Message struct that implements FeeAllowanceI
interface.
The challenge comes from the keeper.UseGrantedFees
function, which currently has the following signature:
func (k Keeper) UseGrantedFees(ctx sdk.Context, granter, grantee sdk.AccAddress, fee sdk.Coins, msgs []sdk.Msgs) error {}
It's impossible for an app developer to come up with a FeeAllowances that needs some data that is not in the function arguments.
Proposal
Maybe the last argument could be an empty interface?
func (k Keeper) UseGrantedFees(ctx sdk.Context, granter, grantee sdk.AccAddress, fee sdk.Coins, customFA interface{}) error {}
and also same thing for FeeAllowanceI
's Accept:
interface FeeAllowanceI {
Accept(fee sdk.Coins, blockTime time.Time, blockHeight int64, customFA interface{}) (remove bool, err error)
}
As an example, let's see how the AllowedMsgsFeeAllowance (#8604) could be implemented using this proposal:
The antehandler passes a custom fee allowance into the UseGrantedFees
last argument:
// my/custom/feegrant/antehandler.go
customFA := types.AllowedMsgsFeeAllowance{...}
decorator.feeKeeper.UseGrantedFees(ctx, feeGranter, feePayer, fee, customFA)
Then, in the Accept()
method of AllowedMsgsFeeAllowance, we would have:
func (a *AllowedMsgFeeAllowance) Accept(fee sdk.Coins, blockTime time.Time, blockHeight int64, customFA) (bool, error) {
allowedMsgsFA := customFA.(*types.AllowedMsgsFeeAllowance)
// business logic as usual
}
And of course, customFA
could be any FeeAllowance (or set of FeeAllowances) the app developer can think of.
Notes
- initial idea from @robert-zaremba, feel free to add more info
- should
customFA interface{}
be a simple interface instead of an empty one?
For Admin Use
- Not duplicate issue
- Appropriate labels applied
- Appropriate contributors tagged
- Contributor assigned/self-assigned
Activity