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

v0.45.x #176

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7ef483e
fix: types/errors Wrap and Wrapf (backport #10674) (#10676)
mergify[bot] Dec 6, 2021
d404619
fix: Charge gas even when there are no entries in gaskv (backport #10…
mergify[bot] Dec 8, 2021
e01217c
feat: add configurable iavl cache size (backport #10561) (#10698)
mergify[bot] Dec 8, 2021
b9250f3
feat: Add `HasSupply` method to bank keeper (backport #10393) (#10699)
mergify[bot] Dec 9, 2021
16da4a4
fix!: Charge gas for key length in gas meter (backport #10247) (#10697)
mergify[bot] Dec 10, 2021
a8a1101
build(deps): upgrade rosetta to 0.7.0 (backport #10432) (#10716)
mergify[bot] Dec 10, 2021
ad443cb
perf: Speedup cachekv iterator on large deletions & IBC v2 upgrade lo…
mergify[bot] Dec 13, 2021
51f7d31
fix: populate ctx.ConsensusParams for begin blockers (backport #10725…
mergify[bot] Dec 16, 2021
f67928a
fix: nil pointer panic on `NewIntFromBigInt` (backport #9627) (#10845)
mergify[bot] Dec 29, 2021
8ad8d5d
perf: Improve the speed of coins.String() (backport #10076) (#10850)
mergify[bot] Dec 30, 2021
1321bc1
perf!: Add HasAccount to the AuthKeeper to save protobuf decoding tim…
mergify[bot] Dec 31, 2021
7115d3b
fix: enable setting sequence (nonce) for module account (backport #10…
mergify[bot] Jan 3, 2022
14cd943
perf: store/cachekv: avoid a map lookup if unnecessary, clear maps fa…
mergify[bot] Jan 3, 2022
19e924d
fix: adding checks to ensure coin denoms are sorted in `Balance` duri…
mergify[bot] Jan 3, 2022
44d3f4d
fix: register evidence regression (backport #10595) (#10775)
mergify[bot] Jan 3, 2022
a0503e5
fix: Panic if SetOrder* functions forgot modules (backport #10711) (#…
mergify[bot] Jan 3, 2022
0be9863
fix: create query context with requested block height (#10827) (#10866)
mergify[bot] Jan 4, 2022
71a168d
fix: recreate compat field, of null pubkeys in multisig (backport #10…
mergify[bot] Jan 5, 2022
6d44d71
fix!: tx result don't report block gas used as tx gas used (#10833)
yihuang Jan 5, 2022
8932338
feat: support in-place migration ordering (backport #10614) (#10890)
mergify[bot] Jan 6, 2022
05656a2
fix: use full gas on overflow (backport #10897) (#10912)
mergify[bot] Jan 7, 2022
a5c60b7
feat!: x/gov: raise max description length to 10k chars (backport #10…
mergify[bot] Jan 10, 2022
ba1e099
fix: revert tx when block gas limit exceeded (backport: #10770) (#10814)
yihuang Jan 12, 2022
c1c1ad7
chore: v0.45.0 Release Notes (#10760)
amaury1093 Jan 12, 2022
90ffbce
feat: support custom mnemonics in in-process testing network (backpor…
mergify[bot] Jan 13, 2022
8236b26
chore: move server.GenerateCoinKey and server.GenerateSaveCoinKey to …
robert-zaremba Jan 18, 2022
b6c77e6
chore: release v0.45 changelog (#10964)
robert-zaremba Jan 18, 2022
ced57ea
docs: guidelines for ValidateBasic (#10983) (#11001)
mergify[bot] Jan 23, 2022
7ecf4d4
fix: return 404 on non-existing tx (backport #10992) (#11014)
mergify[bot] Jan 25, 2022
dfd47f5
chore: update 0.45 migration and support notes (backport #10973) (#10…
mergify[bot] Jan 26, 2022
985d221
feat!: add protection against accidental downgrades (backport #10407)…
mergify[bot] Jan 27, 2022
0c9bbbc
fix: add iavl-cache-size config parsing to GetConfig (backport #10990…
mergify[bot] Jan 29, 2022
f69c82f
feat: extra logging in in-place store migrations (backport #10768) (#…
mergify[bot] Feb 3, 2022
2646b47
chore: 0.45.1 Release Notes (#11109)
robert-zaremba Feb 3, 2022
9bf8c9a
fix: add concurrency fence on traceContext to avoid data races (backp…
mergify[bot] Feb 8, 2022
4161d2b
feat: add get all versions (backport #11124) (#11144)
mergify[bot] Feb 9, 2022
7f949c0
support debug trace QueryResult (#11148)
yihuang Feb 18, 2022
4368a18
disable url parameter in swagger-ui page (backport #11202) (#11207)
mergify[bot] Feb 21, 2022
d862c66
feat: Allow to restrict MintCoins from app.go (backport #10771) (#11227)
mergify[bot] Feb 21, 2022
febcb92
refactor: prune everything (backport #11177) (#11258)
mergify[bot] Feb 23, 2022
147720c
feat: min and max operators on coins (backport #11200) (#11249)
mergify[bot] Feb 23, 2022
c7ddf4d
feat: include transactions in QueryBlockByHeight (backport #10880) (…
mergify[bot] Feb 24, 2022
d69a7b6
chore: fix changelog entry for #11177 (backport #11263) (#11264)
mergify[bot] Feb 24, 2022
12fffc1
fix: reject query with block height in the future (backport #11222) (…
mergify[bot] Feb 25, 2022
01711d9
Merge branch 'release/v0.45.x' of https://github.com/cosmos/cosmos-sd…
faddat Feb 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: guidelines for ValidateBasic (cosmos#10983) (cosmos#11001)
## Description

Closes: cosmos#10680

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)

(cherry picked from commit 87bb06c)

Co-authored-by: Robert Zaremba <robert@zaremba.ch>
  • Loading branch information
mergify[bot] and robert-zaremba committed Jan 23, 2022
commit ced57ea5de0e28323adb9c8cddba960b3d515100
13 changes: 12 additions & 1 deletion docs/basics/tx-lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,18 @@ When `Tx` is received by the application from the underlying consensus engine (e

### ValidateBasic

[`sdk.Msg`s](../core/transactions.md#messages) are extracted from `Tx`, and `ValidateBasic`, a method of the `sdk.Msg` interface implemented by the module developer, is run for each one. `ValidateBasic` should include basic **stateless** sanity checks. For example, if the message is to send coins from one address to another, `ValidateBasic` likely checks for nonempty addresses and a nonnegative coin amount, but does not require knowledge of state such as the account balance of an address.
Messages ([`sdk.Msg`](../core/transactions.md#messages)) are extracted from transactions (`Tx`). The `ValidateBasic` method of the `sdk.Msg` interface implemented by the module developer is run for each transaction.
To discard obviously invalid messages, the BaseApp` type calls the `ValidateBasic` method very early in the processing of the message in the [`CheckTx`](../core/baseapp.md#checktx) and [`DeliverTx`](../core/baseapp.md#delivertx)) transactions.
`ValidateBasic` can include only **stateless** checks (the checks that do not require access to the state).

#### Guideline

Gas is not charged when `ValidateBasic` is executed so we recommend only performing all necessary stateless checks to enable middleware operations (for example, parsing the required signer accounts to validate a signature by a middleware) and stateless sanity checks not impacting performance of the CheckTx phase.
Other validation operations must be performed when [handling a message](../building-modules/msg-services#Validation) in a module Msg Server.

Example, if the message is to send coins from one address to another, `ValidateBasic` likely checks for non-empty addresses and a non-negative coin amount, but does not require knowledge of state such as the account balance of an address.

See also [Msg Service Validation](../building-modules/msg-services.md#Validation).

### AnteHandler

Expand Down
2 changes: 1 addition & 1 deletion docs/building-modules/messages-and-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ It extends `proto.Message` and contains the following methods:

- `Route() string`: Name of the route for this message. Typically all `message`s in a module have the same route, which is most often the module's name.
- `Type() string`: Type of the message, used primarly in [events](../core/events.md). This should return a message-specific `string`, typically the denomination of the message itself.
- `ValidateBasic() error`: This method is called by `BaseApp` very early in the processing of the `message` (in both [`CheckTx`](../core/baseapp.md#checktx) and [`DeliverTx`](../core/baseapp.md#delivertx)), in order to discard obviously invalid messages. `ValidateBasic` should only include *stateless* checks, i.e. checks that do not require access to the state. This usually consists in checking that the message's parameters are correctly formatted and valid (i.e. that the `amount` is strictly positive for a transfer).
- [`ValidateBasic() error`](../basics/tx-lifecycle.md#ValidateBasic).
- `GetSignBytes() []byte`: Return the canonical byte representation of the message. Used to generate a signature.
- `GetSigners() []AccAddress`: Return the list of signers. The SDK will make sure that each `message` contained in a transaction is signed by all the signers listed in the list returned by this method.

Expand Down
2 changes: 1 addition & 1 deletion docs/building-modules/module-interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ In general, the getter function does the following:
- **RunE:** Defines a function that can return an error. This is the function that is called when the command is executed. This function encapsulates all of the logic to create a new transaction.
- The function typically starts by getting the `clientCtx`, which can be done with `client.GetClientTxContext(cmd)`. The `clientCtx` contains information relevant to transaction handling, including information about the user. In this example, the `clientCtx` is used to retrieve the address of the sender by calling `clientCtx.GetFromAddress()`.
- If applicable, the command's arguments are parsed. In this example, the arguments `[to_address]` and `[amount]` are both parsed.
- A [message](./messages-and-queries.md) is created using the parsed arguments and information from the `clientCtx`. The constructor function of the message type is called directly. In this case, `types.NewMsgSend(fromAddr, toAddr, amount)`. Its good practice to call `msg.ValidateBasic()` after creating the message, which runs a sanity check on the provided arguments.
- A [message](./messages-and-queries.md) is created using the parsed arguments and information from the `clientCtx`. The constructor function of the message type is called directly. In this case, `types.NewMsgSend(fromAddr, toAddr, amount)`. Its good practice to call [`msg.ValidateBasic()`](../basics/tx-lifecycle.md#ValidateBasic) and other validation methods before broadcasting the message.
- Depending on what the user wants, the transaction is either generated offline or signed and broadcasted to the preconfigured node using `tx.GenerateOrBroadcastTxCLI(clientCtx, flags, msg)`.
- **Adds transaction flags:** All transaction commands must add a set of transaction [flags](#flags). The transaction flags are used to collect additional information from the user (e.g. the amount of fees the user is willing to pay). The transaction flags are added to the constructed command using `AddTxFlagsToCmd(cmd)`.
- **Returns the command:** Finally, the transaction command is returned.
Expand Down
46 changes: 37 additions & 9 deletions docs/building-modules/msg-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,48 @@ When possible, the existing module's [`Keeper`](keeper.md) should implement `Msg

+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/x/bank/keeper/msg_server.go#L27-L28

`sdk.Msg` processing usually follows these 2 steps:
`sdk.Msg` processing usually follows these 3 steps:

- First, they perform *stateful* checks to make sure the `message` is valid. At this stage, the `message`'s `ValidateBasic()` method has already been called, meaning *stateless* checks on the message (like making sure parameters are correctly formatted) have already been performed. Checks performed in the `msgServer` method can be more expensive and require access to the state. For example, a `msgServer` method for a `transfer` message might check that the sending account has enough funds to actually perform the transfer. To access the state, the `msgServer` method needs to call the [`keeper`'s](./keeper.md) getter functions.
- Then, if the checks are successful, the `msgServer` method calls the [`keeper`'s](./keeper.md) setter functions to actually perform the state transition.
### Validation

Before returning, `msgServer` methods generally emit one or more [events](../core/events.md) via the `EventManager` held in the `ctx`:
Before a `msgServer` method is executed, the message's [`ValidateBasic()`](../basics/tx-lifecycle.md#ValidateBasic) method has already been called. Since `msg.ValidateBasic()` performs only the most basic checks, this stage must perform all other validation (both *stateful* and *stateless*) to make sure the `message` is valid. Checks performed in the `msgServer` method can be more expensive and the signer is charged gas for these operations.
For example, a `msgServer` method for a `transfer` message might check that the sending account has enough funds to actually perform the transfer.

It is recommended to implement all validation checks in a separate function that passes state values as arguments. This implementation simplifies testing. As expected, expensive validation functions charge additional gas. Example:

```go
ValidateMsgA(msg MsgA, now Time, gm GasMeter) error {
if now.Before(msg.Expire) {
return sdkerrrors.ErrInvalidRequest.Wrap("msg expired")
}
gm.ConsumeGas(1000, "signature verification")
return signatureVerificaton(msg.Prover, msg.Data)
}
```

### State Transition

After the validation is successful, the `msgServer` method uses the [`keeper`](./keeper.md) functions to access the state and perform a state transition.

### Events

Before returning, `msgServer` methods generally emit one or more [events](../core/events.md) by using the `EventManager` held in the `ctx`. Use the new `EmitTypedEvent` function that uses protobuf-based event types:

```
ctx.EventManager().EmitTypedEvent(
&group.EventABC{Key1: Value1, Key2, Value2})
```

or the older `EmitEvent` function:

```go
ctx.EventManager().EmitEvent(
sdk.NewEvent(
eventType, // e.g. sdk.EventTypeMessage for a message, types.CustomEventType for a custom event defined in the module
sdk.NewAttribute(attributeKey, attributeValue),
),
)
sdk.NewEvent(
eventType, // e.g. sdk.EventTypeMessage for a message, types.CustomEventType for a custom event defined in the module
sdk.NewAttribute(key1, value1),
sdk.NewAttribute(key2, value2),
),
)
```

These events are relayed back to the underlying consensus engine and can be used by service providers to implement services around the application. Click [here](../core/events.md) to learn more about events.
Expand Down
11 changes: 6 additions & 5 deletions docs/core/baseapp.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ transaction is received by a full-node. The role of `CheckTx` is to guard the fu
Unconfirmed transactions are relayed to peers only if they pass `CheckTx`.

`CheckTx()` can perform both _stateful_ and _stateless_ checks, but developers should strive to
make them lightweight. In the Cosmos SDK, after [decoding transactions](./encoding.md), `CheckTx()` is implemented
make the checks **lightweight** because gas fees are not charged for the resources (CPU, data load...) used during the `CheckTx`.

In the Cosmos SDK, after [decoding transactions](./encoding.md), `CheckTx()` is implemented
to do the following checks:

1. Extract the `sdk.Msg`s from the transaction.
Expand All @@ -237,9 +239,8 @@ to do the following checks:
as `sdk.Msg`s are not processed. Usually, the [`AnteHandler`](../basics/gas-fees.md#antehandler) will check that the `gas` provided
with the transaction is superior to a minimum reference gas amount based on the raw transaction size,
in order to avoid spam with transactions that provide 0 gas.
4. Ensure that each `sdk.Msg`'s fully-qualified service method matches on of the routes inside the `msgServiceRouter`, but do **not** actually
process `sdk.Msg`s. `sdk.Msg`s only need to be processed when the canonical state need to be updated,
which happens during `DeliverTx`.

`CheckTx` does **not** process `sdk.Msg`s - they only need to be processed when the canonical state need to be updated, which happens during `DeliverTx`.

Steps 2. and 3. are performed by the [`AnteHandler`](../basics/gas-fees.md#antehandler) in the [`RunTx()`](#runtx-antehandler-and-runmsgs)
function, which `CheckTx()` calls with the `runTxModeCheck` mode. During each step of `CheckTx()`, a
Expand Down Expand Up @@ -269,7 +270,7 @@ The response contains:
#### RecheckTx

After `Commit`, `CheckTx` is run again on all transactions that remain in the node's local mempool
after filtering those included in the block. To prevent the mempool from rechecking all transactions
excluding the transactions that are included in the block. To prevent the mempool from rechecking all transactions
every time a block is committed, the configuration option `mempool.recheck=false` can be set. As of
Tendermint v0.32.1, an additional `Type` parameter is made available to the `CheckTx` function that
indicates whether an incoming transaction is new (`CheckTxType_New`), or a recheck (`CheckTxType_Recheck`).
Expand Down
2 changes: 1 addition & 1 deletion docs/core/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Transaction objects are SDK types that implement the `Tx` interface
It contains the following methods:

- **GetMsgs:** unwraps the transaction and returns a list of contained `sdk.Msg`s - one transaction may have one or multiple messages, which are defined by module developers.
- **ValidateBasic:** includes lightweight, [_stateless_](../basics/tx-lifecycle.md#types-of-checks) checks used by ABCI messages [`CheckTx`](./baseapp.md#checktx) and [`DeliverTx`](./baseapp.md#delivertx) to make sure transactions are not invalid. For example, the [`auth`](https://github.com/cosmos/cosmos-sdk/tree/master/x/auth) module's `StdTx` `ValidateBasic` function checks that its transactions are signed by the correct number of signers and that the fees do not exceed what the user's maximum. Note that this function is to be distinct from the `ValidateBasic` functions for `sdk.Msg`s, which perform basic validity checks on messages only. For example, when [`runTx`](./baseapp.md#runtx) is checking a transaction created from the [`auth`](https://github.com/cosmos/cosmos-sdk/tree/master/x/auth/spec) module, it first runs `ValidateBasic` on each message, then runs the `auth` module AnteHandler which calls `ValidateBasic` for the transaction itself.
- **ValidateBasic:** lightweight, [_stateless_](../basics/tx-lifecycle.md#types-of-checks) checks used by ABCI messages [`CheckTx`](./baseapp.md#checktx) and [`DeliverTx`](./baseapp.md#delivertx) to make sure transactions are not invalid. For example, the [`auth`](https://github.com/cosmos/cosmos-sdk/tree/master/x/auth) module's `StdTx` `ValidateBasic` function checks that its transactions are signed by the correct number of signers and that the fees do not exceed what the user's maximum. Note that this function is to be distinct from `sdk.Msg` [`ValidateBasic`](../basics/tx-lifecycle.md#ValidateBasic) methods, which perform basic validity checks on messages only. When [`runTx`](./baseapp.md#runtx) is checking a transaction created from the [`auth`](https://github.com/cosmos/cosmos-sdk/tree/master/x/auth/spec) module, it first runs `ValidateBasic` on each message, then runs the `auth` module AnteHandler which calls `ValidateBasic` for the transaction itself.

As a developer, you should rarely manipulate `Tx` directly, as `Tx` is really an intermediate type used for transaction generation. Instead, developers should prefer the `TxBuilder` interface, which you can learn more about [below](#transaction-generation).

Expand Down