Skip to content

Commit df70191

Browse files
refactor: Mark tips as beta (#12089) (#12097)
## Description Following our SDK call, we decided to mark the Tip decorator as beta for now, and not include it in the default posthandler chain. This PR also fixes events not all included in the response in SimulateTx. --- ### 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/main/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/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/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 ece3d0e) Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
1 parent d278ad1 commit df70191

File tree

7 files changed

+53
-47
lines changed

7 files changed

+53
-47
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ Ref: https://keepachangelog.com/en/1.0.0/
4141

4242
* (cli) [#12028](https://github.com/cosmos/cosmos-sdk/pull/12028) Add the `tendermint key-migrate` to perform Tendermint v0.35 DB key migration.
4343

44+
### Improvements
45+
46+
* [#12089](https://github.com/cosmos/cosmos-sdk/pull/12089) Mark the `TipDecorator` as beta, don't include it in simapp by default.
47+
4448
### Bug Fixes
4549

4650
* (migrations) [#12028](https://github.com/cosmos/cosmos-sdk/pull/12028) Fix v0.45->v0.46 in-place store migrations.
51+
* (baseapp) [#12089](https://github.com/cosmos/cosmos-sdk/pull/12089) Include antehandler and runMsgs events in SimulateTx.
4752

4853
## [v0.46.0-rc1](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.0-rc1) - 2022-05-23
4954

baseapp/baseapp.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,11 +707,11 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re
707707
consumeBlockGas()
708708

709709
msCache.Write()
710+
}
710711

711-
if len(anteEvents) > 0 {
712-
// append the events in the order of occurrence
713-
result.Events = append(anteEvents, result.Events...)
714-
}
712+
if len(anteEvents) > 0 && (mode == runTxModeDeliver || mode == runTxModeSimulate) {
713+
// append the events in the order of occurrence
714+
result.Events = append(anteEvents, result.Events...)
715715
}
716716
}
717717

docs/core/tips.md

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ order: 14
44

55
# Transaction Tips
66

7-
Transaction tips are a mechanism to pay for transaction fees using another denom than the native fee denom of the chain. {synopsis}
7+
Transaction tips are a mechanism to pay for transaction fees using another denom than the native fee denom of the chain. They are still in beta, and are not included by default in the SDK. {synopsis}
88

99
## Context
1010

@@ -72,27 +72,42 @@ In both cases, using `SIGN_MODE_LEGACY_AMINO_JSON` is recommended only if hardwa
7272

7373
## Enabling Tips on your Chain
7474

75-
The transaction tips functionality is introduced in Cosmos SDK v0.46, so earlier versions do not have support for tips. If you're using v0.46 or later, then enabling tips on your chain is as simple as adding the `TipMiddleware` in your middleware stack:
75+
The transaction tips functionality is introduced in Cosmos SDK v0.46, so earlier versions do not have support for tips. It is however not included by default in a v0.46 app. Enabling tips on your chain is done by adding the `TipDecorator` in your posthandler chain:
7676

7777
```go
78-
// NewTxHandler defines a TxHandler middleware stack.
79-
func NewTxHandler(options TxHandlerOptions) (tx.Handler, error) {
80-
// --snip--
81-
82-
return ComposeMiddlewares(
83-
// base tx handler that executes Msgs
84-
NewRunMsgsTxHandler(options.MsgServiceRouter, options.LegacyRouter),
85-
// --snip other middlewares--
86-
87-
// Add the TipMiddleware
88-
NewTipMiddleware(options.BankKeeper),
89-
)
78+
// HandlerOptions are the options required for constructing a default SDK PostHandler.
79+
type HandlerOptions struct {
80+
BankKeeper types.BankKeeper
9081
}
91-
```
9282

93-
Notice that `NewTipMiddleware` needs a reference to the BankKeeper, for transferring the tip to the fee payer.
83+
// MyPostHandler returns a posthandler chain with the TipDecorator.
84+
func MyPostHandler(options HandlerOptions) (sdk.AnteHandler, error) {
85+
if options.BankKeeper == nil {
86+
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for posthandler")
87+
}
88+
89+
postDecorators := []sdk.AnteDecorator{
90+
posthandler.NewTipDecorator(options.bankKeeper),
91+
}
92+
93+
return sdk.ChainAnteDecorators(postDecorators...), nil
94+
}
95+
96+
func (app *SimApp) setPostHandler() {
97+
postHandler, err := MyPostHandler(
98+
HandlerOptions{
99+
BankKeeper: app.BankKeeper,
100+
},
101+
)
102+
if err != nil {
103+
panic(err)
104+
}
105+
106+
app.SetPostHandler(postHandler)
107+
}
108+
```
94109

95-
If you are using the Cosmos SDK's default middleware stack `NewDefaultTxHandler()`, then the tip middleware is included by default.
110+
Notice that `NewTipDecorator` needs a reference to the BankKeeper, for transferring the tip to the fee payer.
96111

97112
## CLI Usage
98113

@@ -170,7 +185,7 @@ For the fee payer, the SDK added a new method on the existing `TxBuilder` to imp
170185
txBuilder := clientCtx.TxConfig.NewTxBuilder()
171186
err := txBuilder.AddAuxSignerData(auxSignerData)
172187
if err != nil {
173-
return err
188+
return err
174189
}
175190

176191
// A lot of fields will be populated in txBuilder, such as its Msgs, tip
@@ -184,6 +199,6 @@ txBuilder.SetGasLimit(...)
184199
// Usual signing code
185200
err = authclient.SignTx(...)
186201
if err != nil {
187-
return err
202+
return err
188203
}
189204
```

simapp/app.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,7 @@ func NewSimApp(
453453
// meaning that both `runMsgs` and `postHandler` state will be committed if
454454
// both are successful, and both will be reverted if any of the two fails.
455455
//
456-
// The SDK exposes a default postHandlers chain, which comprises of only
457-
// one decorator: the Transaction Tips decorator. However, some chains do
458-
// not need it by default, so feel free to comment the next line if you do
459-
// not need tips.
460-
// To read more about tips:
461-
// https://docs.cosmos.network/main/core/tips.html
456+
// The SDK exposes a default empty postHandlers chain.
462457
//
463458
// Please note that changing any of the anteHandler or postHandler chain is
464459
// likely to be a state-machine breaking change, which needs a coordinated
@@ -498,9 +493,7 @@ func (app *SimApp) setAnteHandler(txConfig client.TxConfig, indexEventsStr []str
498493

499494
func (app *SimApp) setPostHandler() {
500495
postHandler, err := posthandler.NewPostHandler(
501-
posthandler.HandlerOptions{
502-
BankKeeper: app.BankKeeper,
503-
},
496+
posthandler.HandlerOptions{},
504497
)
505498
if err != nil {
506499
panic(err)

x/auth/client/testutil/suite.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,9 @@ func (s *IntegrationTestSuite) TestAuxSigner() {
15621562
}
15631563

15641564
func (s *IntegrationTestSuite) TestAuxToFeeWithTips() {
1565+
// Skipping this test as it needs a simapp with the TipDecorator in post handler.
1566+
s.T().Skip()
1567+
15651568
require := s.Require()
15661569
val := s.network.Validators[0]
15671570

x/auth/posthandler/post.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,14 @@ package posthandler
22

33
import (
44
sdk "github.com/cosmos/cosmos-sdk/types"
5-
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
6-
"github.com/cosmos/cosmos-sdk/x/auth/types"
75
)
86

97
// HandlerOptions are the options required for constructing a default SDK PostHandler.
10-
type HandlerOptions struct {
11-
BankKeeper types.BankKeeper
12-
}
8+
type HandlerOptions struct{}
139

14-
// NewAnteHandler returns an AnteHandler that checks and increments sequence
15-
// numbers, checks signatures & account numbers, and deducts fees from the first
16-
// signer.
10+
// NewPostHandler returns an empty posthandler chain.
1711
func NewPostHandler(options HandlerOptions) (sdk.AnteHandler, error) {
18-
if options.BankKeeper == nil {
19-
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for posthandler")
20-
}
21-
22-
postDecorators := []sdk.AnteDecorator{
23-
NewTipDecorator(options.BankKeeper),
24-
}
12+
postDecorators := []sdk.AnteDecorator{}
2513

2614
return sdk.ChainAnteDecorators(postDecorators...), nil
2715
}

x/auth/posthandler/tips.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ type tipDecorator struct {
1616

1717
// NewTipDecorator returns a new decorator for handling transactions with
1818
// tips.
19+
//
20+
// IMPORTANT: This decorator is still in beta, please use it at your own risk.
1921
func NewTipDecorator(bankKeeper types.BankKeeper) sdk.AnteDecorator {
2022
return tipDecorator{
2123
bankKeeper: bankKeeper,

0 commit comments

Comments
 (0)