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

Add specs for feegrant #8496

Merged
merged 11 commits into from
Feb 4, 2021
77 changes: 77 additions & 0 deletions x/feegrant/spec/01_concepts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!--
order: 1
-->

# Concepts

## FeeAllowanceGrant

`FeeAllowanceGrant` is stored in the KVStore to record a grant with full context. Every grant will contain `granter`, `grantee` and what kind of `allowance` is granted. `granter` is an account address who is giving permission to `grantee`(another account address) to use fees, where as `grantee` is an account address of beneficiary. `allowance` defines what kind of fee allowance (`BasicFeeAllowance` or `PeriodicFeeAllowance`) is granted to grantee. `allowance` can accepts an interface which implements `FeeAllowanceI` as `Any` type. There can be only one existing feegrant allowed for a `grantee` and `granter`, self grant not allowed.
atheeshp marked this conversation as resolved.
Show resolved Hide resolved

+++ https://github.com/cosmos/cosmos-sdk/blob/d97e7907f176777ed8a464006d360bb3e1a223e4/proto/cosmos/feegrant/v1beta1/feegrant.proto#L75-L81

`FeeAllowanceI` looks like:

+++ https://github.com/cosmos/cosmos-sdk/blob/d97e7907f176777ed8a464006d360bb3e1a223e4/x/feegrant/types/fees.go#L9-L32

## Fee Allowance types
There are two types of fee allowances present at the moment:
- `BasicFeeAllowance`
- `PeriodicFeeAllowance`

## BasicFeeAllowance

`BasicFeeAllowance` is one time permission for `grantee` to use fee from a `granter`'s account. if any of the `spend_limit` or `expiration` reached the grant will be removed from the state.
atheeshp marked this conversation as resolved.
Show resolved Hide resolved


+++ https://github.com/cosmos/cosmos-sdk/blob/d97e7907f176777ed8a464006d360bb3e1a223e4/proto/cosmos/feegrant/v1beta1/feegrant.proto#L13-L26

- `spend_limit` is a limit of coins that are allowed to use from the `granter` account. If it is empty, it assumes there's no spend limit, `grantee` can use any number of available tokens from `granter` account address before the expiration.
atheeshp marked this conversation as resolved.
Show resolved Hide resolved

- `expiration` specifies an optional time when this allowance expires. If the value is left empty, there is no expiry for the grant.

- Whenever a grant is created with empty values for `spend_limit` and `expiration`, it is still a valid grant. It won't restrict the `grantee` to use any number of tokens from `granter` and it won't have any expiration. The only way to restrict the `grantee` is by revoking the grant.
atheeshp marked this conversation as resolved.
Show resolved Hide resolved

## PeriodicFeeAllowance

`PeriodicFeeAllowance` is a repeating fee allowance for the mentioned period, we can mention when the grant can expire as well as when a period can reset. We can also mention how many maximum of coins can be used in a mentioned period of time.
atheeshp marked this conversation as resolved.
Show resolved Hide resolved

+++ https://github.com/cosmos/cosmos-sdk/blob/d97e7907f176777ed8a464006d360bb3e1a223e4/proto/cosmos/feegrant/v1beta1/feegrant.proto#L28-L73

- `basic` is the instance of `BasicFeeAllowance` which is optional for periodic fee allowance. If empty, the grant will have no `expiration` and no `spend_limit`.

- `period` is the specific period of time or blocks, after period crossed `period_spend_limit` will be reset.
atheeshp marked this conversation as resolved.
Show resolved Hide resolved

- `period_spend_limit` specifies the maximum number of coins that can be spent in the period.

- `period_can_spend` is the number of coins left to be spent before the period_reset time.

- `period_reset` keeps track of when a next period reset should happen.

## FeeAccount flag

`feegrant` module introduces a `FeeAccount` flag for CLI for the sake of executing transactions with fee granter. When this flag is set, `clientCtx` will append the granter account address for transactions generated through CLI.

+++ https://github.com/cosmos/cosmos-sdk/blob/d97e7907f176777ed8a464006d360bb3e1a223e4/client/cmd.go#L224-L235

+++ https://github.com/cosmos/cosmos-sdk/blob/d97e7907f176777ed8a464006d360bb3e1a223e4/client/tx/tx.go#L120

+++ https://github.com/cosmos/cosmos-sdk/blob/d97e7907f176777ed8a464006d360bb3e1a223e4/x/auth/tx/builder.go#L268-L277

```go
atheeshp marked this conversation as resolved.
Show resolved Hide resolved
message Fee {
repeated cosmos.base.v1beta1.Coin amount = 1;
uint64 gas_limit = 2;
string payer = 3;
string granter = 4;
}
```

Example cmd:
```go
./simd tx gov submit-proposal --title="Test Proposal" --description="My awesome proposal" --type="Text" --from validator-key --fee-account=cosmos1xh44hxt7spr67hqaa7nyx5gnutrz5fraw6grxn --chain-id=testnet --fees="10stake"
```

## DeductGrantedFeeDecorator

`feegrant` module also adds a `DeductGrantedFeeDecorator` ante handler. Whenever a transaction is being executed with `granter` field set, then this ante handler will check whether `payer` and `granter` has proper fee allowance grant in state. If it exists the fees will be deducted from the `granter`'s account address. If the `granter` field isn't set then this ante handler works as normal fee deductor.
atheeshp marked this conversation as resolved.
Show resolved Hide resolved
15 changes: 15 additions & 0 deletions x/feegrant/spec/02_state.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!--
order: 2
-->

# State

## FeeAllowance

Fee Allowances are identified by combining `Grantee` (The account address of fee allowance grantee) with the `Granter` (The account address of fee allowance granter).
atheeshp marked this conversation as resolved.
Show resolved Hide resolved

Fee allowances are stored in the state as follows:

- FeeAllowance: `0x00 | grantee | granter -> ProtocolBuffer(FeeAllowance)`
atheeshp marked this conversation as resolved.
Show resolved Hide resolved

+++ https://github.com/cosmos/cosmos-sdk/blob/d97e7907f176777ed8a464006d360bb3e1a223e4/x/feegrant/types/feegrant.pb.go#L358-L363
18 changes: 18 additions & 0 deletions x/feegrant/spec/03_messages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!--
order: 3
-->

# Messages

## MsgGrantFeeAllowance
atheeshp marked this conversation as resolved.
Show resolved Hide resolved

A fee allowance grant will be created `MsgGrantFeeAllowance` message.
atheeshp marked this conversation as resolved.
Show resolved Hide resolved

+++ https://github.com/cosmos/cosmos-sdk/blob/d97e7907f176777ed8a464006d360bb3e1a223e4/proto/cosmos/feegrant/v1beta1/tx.proto#L22-L28

## MsgRevokeFeeAllowance

An allowed grant fee allowance can be removed with `MsgRevokeFeeAllowance` message.
atheeshp marked this conversation as resolved.
Show resolved Hide resolved

+++ https://github.com/cosmos/cosmos-sdk/blob/d97e7907f176777ed8a464006d360bb3e1a223e4/proto/cosmos/feegrant/v1beta1/tx.proto#L33-L37

33 changes: 33 additions & 0 deletions x/feegrant/spec/04_events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!--
order: 4
-->

# Events

The feegrant module emits the following events:

# Handlers

### MsgGrantFeeAllowance

| Type | Attribute Key | Attribute Value |
| -------- | ------------- | ------------------ |
| message | action | set_feegrant |
| message | granter | {granterAddress} |
| message | grantee | {granteeAddress} |

### MsgRevokeFeeAllowance

| Type | Attribute Key | Attribute Value |
| -------- | ------------- | ------------------ |
| message | action | revoke_feegrant |
| message | granter | {granterAddress} |
| message | grantee | {granteeAddress} |

### Exec fee allowance

| Type | Attribute Key | Attribute Value |
| -------- | ------------- | ------------------ |
| message | action | use_feegrant |
| message | granter | {granterAddress} |
| message | grantee | {granteeAddress} |
32 changes: 32 additions & 0 deletions x/feegrant/spec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!--
order: 0
title: Fee grant
parent:
title: "feegrant"
-->

## Abstract

This document specifies the feegrant module. [Fee Grant](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/docs/architecture/adr-029-fee-grant-module.md)
atheeshp marked this conversation as resolved.
Show resolved Hide resolved

This module allows accounts to grant fee allowances and to use fees from their accounts. Grantees can execute any transaction without the need to maintain sufficient fees.

## Contents

1. **[Concepts](01_concepts.md)**
- [FeeAllowanceGrant](01_concepts.md#feeallowancegrant)
- [Fee Allowance types](01_concepts.md#fee-allowance-types)
- [BasicFeeAllowance](01_concepts.md#basicfeeallowance)
- [PeriodicFeeAllowance](01_concepts.md#periodicfeeallowance)
- [FeeAccount flag](01_concepts.md#feeaccount-flag)
- [DeductGrantedFeeDecorator](01_concepts.md#deductgrantedfeedecorator)
2. **[State](02_state.md)**
- [FeeAllowance](02_state.md#feeallowance)
3. **[Messages](03_messages.md)**
- [MsgGrantFeeAllowance](03_messages.md#msggrantfeeallowance)
atheeshp marked this conversation as resolved.
Show resolved Hide resolved
- [MsgRevokeFeeAllowance](03_messages.md#msgrevokefeeallowance)
atheeshp marked this conversation as resolved.
Show resolved Hide resolved
3. **[Events](04_events.md)**
- [MsgGrantFeeAllowance](04_events.md#msggrantfeeallowance)
- [MsgrevokeFeeAllowance](04_events.md#msgrevokefeeallowance)
- [Exec fee allowance](04_events.md#exec-fee-allowance)