Skip to content

Commit

Permalink
Merge branch 'master' into prathyusha/8572_parse_key
Browse files Browse the repository at this point in the history
  • Loading branch information
PrathyushaLakkireddy authored May 12, 2021
2 parents 3f1afa8 + b4125d1 commit 08c4122
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v3
- uses: actions/stale@v3.0.18
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-pr-message: "This pull request has been automatically marked as stale because it has not had
Expand Down
72 changes: 34 additions & 38 deletions x/auth/spec/03_antehandlers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,37 @@ order: 3

# AnteHandlers

## Handlers

The auth module presently has no transaction handlers of its own, but does expose
the special `AnteHandler`, used for performing basic validity checks on a transaction,
such that it could be thrown out of the mempool. Note that the ante handler is called on
`CheckTx`, but _also_ on `DeliverTx`, as Tendermint proposers presently have the ability
to include in their proposed block transactions which fail `CheckTx`.

### Ante Handler

```go
anteHandler(ak AccountKeeper, fck FeeCollectionKeeper, tx sdk.Tx)
if !tx.(StdTx)
fail with "not a StdTx"

if isCheckTx and tx.Fee < config.SubjectiveMinimumFee
fail with "insufficient fee for mempool inclusion"

if tx.ValidateBasic() != nil
fail with "tx failed ValidateBasic"

if tx.Fee > 0
account = GetAccount(tx.GetSigners()[0])
coins := acount.GetCoins()
if coins < tx.Fee
fail with "insufficient fee to pay for transaction"
account.SetCoins(coins - tx.Fee)
fck.AddCollectedFees(tx.Fee)

for index, signature in tx.GetSignatures()
account = GetAccount(tx.GetSigners()[index])
bytesToSign := StdSignBytes(chainID, acc.GetAccountNumber(),
acc.GetSequence(), tx.Fee, tx.Msgs, tx.Memo)
if !signature.Verify(bytesToSign)
fail with "invalid signature"

return
```
The `x/auth` module presently has no transaction handlers of its own, but does expose the special `AnteHandler`, used for performing basic validity checks on a transaction, such that it could be thrown out of the mempool.
The `AnteHandler` can be seen as a set of decorators that check transactions within the current context, per [ADR 010](https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-alpha1/docs/architecture/adr-010-modular-antehandler.md).

Note that the `AnteHandler` is called on both `CheckTx` and `DeliverTx`, as Tendermint proposers presently have the ability to include in their proposed block transactions which fail `CheckTx`.

## Decorators

The auth module provides `AnteDecorator`s that are recursively chained together into a single `AnteHandler` in the following order:

- `SetUpContextDecorator`: Sets the `GasMeter` in the `Context` and wraps the next `AnteHandler` with a defer clause to recover from any downstream `OutOfGas` panics in the `AnteHandler` chain to return an error with information on gas provided and gas used.

- `RejectExtensionOptionsDecorator`: Rejects all extension options which can optionally be included in protobuf transactions.

- `MempoolFeeDecorator`: Checks if the `tx` fee is above local mempool `minFee` parameter during `CheckTx`.

- `ValidateBasicDecorator`: Calls `tx.ValidateBasic` and returns any non-nil error.

- `TxTimeoutHeightDecorator`: Check for a `tx` height timeout.

- `ValidateMemoDecorator`: Validates `tx` memo with application parameters and returns any non-nil error.

- `ConsumeGasTxSizeDecorator`: Consumes gas proportional to the `tx` size based on application parameters.

- `DeductFeeDecorator`: Deducts the `FeeAmount` from first signer of the `tx`. If the `x/feegrant` module is enabled and a fee granter is set, it will deduct fees from the fee granter account.

- `SetPubKeyDecorator`: Sets the pubkey from a `tx`'s signers that does not already have its corresponding pubkey saved in the state machine and in the current context.

- `ValidateSigCountDecorator`: Validates the number of signatures in `tx` based on app-parameters.

- `SigGasConsumeDecorator`: Consumes parameter-defined amount of gas for each signature. This requires pubkeys to be set in context for all signers as part of `SetPubKeyDecorator`.

- `SigVerificationDecorator`: Verifies all signatures are valid. This requires pubkeys to be set in context for all signers as part of `SetPubKeyDecorator`.

- `IncrementSequenceDecorator`: Increments the account sequence for each signer to prevent replay attacks.

0 comments on commit 08c4122

Please sign in to comment.