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

feat: feePayer for Sudo fees #129

Closed

Conversation

ratik
Copy link
Contributor

@ratik ratik commented Jan 19, 2023

related stuff:

  1. A fee payer is an address that holds tokens that can be used to pay for the interchain transaction fees.
  2. The fee payer can grant an allowance to a contract address, which allows the contract to use tokens from this address for the fees. Optionally, a limit, expire date, and period can be set, please refer to the feegrant module's documentation in the Cosmos SDK for more information.
  3. When an interchain transaction is requested by a contract, the feerefunder module checks the allowance in general by using the feegrant module's GetAllowance function.
  4. The feerefunder module then calls the Accept method on the returned interface with the total fees as an argument to check if the contract has permission to use the required amount of tokens and to deduct them from the allowance.
  5. If the allowance is enough for the interchain transaction, the contract can execute the transaction.
  6. The feegrant module is responsible for ensuring that the contract has enough tokens to pay for the fees, if it doesn't have enough tokens, the transaction should return an error message.
  7. The payer field from the Fee struct is used to specify which address should be used to pay the fees.

@ratik ratik force-pushed the feat/NTRN-331-sudo-fees-payer branch from f1d8419 to 147aae4 Compare January 23, 2023 10:28
@@ -55,7 +55,7 @@ message MsgSubmitTx {

// MsgSubmitTxResponse defines the response for Msg/SubmitTx
message MsgSubmitTxResponse {
// channel's sequence_id for outgoing ibc packet. Unique per a channel.
// channel's sequence_id for outgoing ibc packet. Unique per a channel.y
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo

allowance, err := k.feegrantKeeper.GetAllowance(ctx, payerInfo.FeePayer, payerInfo.Sender)
if err != nil {
return err
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

new line after error handling, please

if payerInfo.FeePayer != nil && !payerInfo.FeePayer.Empty() {
allowance, err := k.feegrantKeeper.GetAllowance(ctx, payerInfo.FeePayer, payerInfo.Sender)
if err != nil {
return err
Copy link
Collaborator

Choose a reason for hiding this comment

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

wrap error to make it more meaningful?

Comment on lines 86 to 91
feePayerAddr, err := sdk.AccAddressFromBech32(msg.Fee.Payer)
if msg.Fee.Payer != "" && err != nil {
k.Logger(ctx).Debug("SubmitTx: failed to parse fee payer address", "fee payer", msg.Fee.Payer)
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to parse address: %s", msg.Fee.Payer)
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a suggestion: maybe we can define a method which accepts sender and payer and returns (feetypes.PayerInfo, error)?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, cause it looks a bit hard to read

Copy link
Contributor

@NeverHappened NeverHappened left a comment

Choose a reason for hiding this comment

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

LGTM, mentioned small things

proto/interchaintxs/v1/tx.proto Outdated Show resolved Hide resolved
coins = append(coins, fee.RecvFee...)
_, err = allowance.Accept(ctx, coins, []sdk.Msg{})
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

wrap an error

x/feerefunder/keeper/keeper.go Outdated Show resolved Hide resolved
x/feerefunder/keeper/keeper_test.go Show resolved Hide resolved
go.mod Show resolved Hide resolved
@ratik ratik requested a review from pr0n00gler January 24, 2023 11:55
…n-org/neutron into feat/NTRN-331-sudo-fees-payer
x/feerefunder/keeper/keeper_test.go Outdated Show resolved Hide resolved
x/feerefunder/keeper/keeper.go Outdated Show resolved Hide resolved
FeePayer: nil,
})

p, err = k.GetPayerInfo(ctx, TestAddress, TestAddress)
Copy link
Contributor

Choose a reason for hiding this comment

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

To test logic to verify that it's different addresses it would probably be better to send different addresses as args

@pr0n00gler pr0n00gler closed this Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants