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

refactor: Move TxDecoder into its own middleware #10612

Merged
merged 59 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
aa99314
WIP: middleware refactor
atheeshp Nov 12, 2021
58c09f2
refactor `tx.Request`
atheeshp Nov 15, 2021
fd5f84a
Merge branch 'master' of github.com:cosmos/cosmos-sdk into ap/mw-refa…
atheeshp Nov 15, 2021
f766aef
Add MsgResponses any in sdk.Result
amaury1093 Nov 15, 2021
c5e516b
add helper functions in abci
atheeshp Nov 17, 2021
43cda59
Merge branch 'master' of github.com:cosmos/cosmos-sdk into ap/mw-refa…
atheeshp Nov 18, 2021
306c1fc
refactor tips
atheeshp Nov 18, 2021
f1afaab
Merge branch 'master' of github.com:cosmos/cosmos-sdk into ap/mw-refa…
atheeshp Nov 22, 2021
caf2e39
review changes
atheeshp Nov 23, 2021
26285bf
Merge branch 'master' of github.com:cosmos/cosmos-sdk into ap/mw-refa…
atheeshp Nov 23, 2021
81f013a
Fix mock tests
amaury1093 Nov 25, 2021
b2dbf10
Update baseapp/abci.go
amaury1093 Nov 25, 2021
d685963
Update baseapp/abci.go
amaury1093 Nov 25, 2021
043c3d4
Update types/tx/middleware.go
amaury1093 Nov 25, 2021
23ef037
Update types/tx/middleware.go
amaury1093 Nov 25, 2021
fded41a
tx.Response to abci conversion
amaury1093 Nov 25, 2021
dfeac86
refactor makeABCIData
amaury1093 Nov 25, 2021
7d3f868
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into ap/m…
amaury1093 Nov 25, 2021
b75795e
Add comments
amaury1093 Nov 25, 2021
fe7dbbc
Fix build
amaury1093 Nov 25, 2021
51861fb
fix build error
atheeshp Nov 26, 2021
9783965
fix tests
atheeshp Nov 26, 2021
ed08f40
Merge branch 'master' of github.com:cosmos/cosmos-sdk into ap/mw-refa…
atheeshp Nov 26, 2021
4c2320a
fix test
atheeshp Nov 26, 2021
cde4010
fix tests
atheeshp Nov 29, 2021
d5b43d3
Merge branch 'master' of github.com:cosmos/cosmos-sdk into ap/mw-refa…
atheeshp Nov 29, 2021
02e3f93
Fix TestSimulateTx
amaury1093 Nov 29, 2021
e795b2e
fix tests
atheeshp Nov 30, 2021
24d9a04
Merge branch 'master' of github.com:cosmos/cosmos-sdk into ap/mw-refa…
atheeshp Nov 30, 2021
c6c387c
fix test
atheeshp Nov 30, 2021
141d214
Fix build
amaury1093 Nov 30, 2021
2300c28
Merge branch 'ap/mw-refactor' of ssh://github.com/cosmos/cosmos-sdk i…
amaury1093 Nov 30, 2021
d89eee7
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into ap/m…
amaury1093 Nov 30, 2021
fa5df34
Simplify code
amaury1093 Nov 30, 2021
1608e18
fix test build
amaury1093 Nov 30, 2021
4e9071f
Use repeated bytes in txMsgData
amaury1093 Nov 30, 2021
310fee5
Fix grpc-gateway test
amaury1093 Nov 30, 2021
f7e12fb
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into ap/m…
amaury1093 Nov 30, 2021
39bee75
Make proto-gen
amaury1093 Nov 30, 2021
39f0bcc
Automagically register MsgResponse
amaury1093 Nov 30, 2021
72b0c30
review changes
atheeshp Dec 1, 2021
df75f83
Merge branch 'master' into ap/mw-refactor
atheeshp Dec 1, 2021
edffa1b
Merge branch 'ap/mw-refactor' of ssh://github.com/cosmos/cosmos-sdk i…
amaury1093 Dec 1, 2021
473ef1f
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into ap/m…
amaury1093 Dec 1, 2021
cf51edf
Use froydi's trick
amaury1093 Dec 1, 2021
5c93517
Use Any in TxMsgData
amaury1093 Dec 1, 2021
19b7189
Finally remove API breaking change
amaury1093 Dec 1, 2021
ceb97a4
Revert unnecessary stuff
amaury1093 Dec 1, 2021
963e5b6
refactor: Move TxDecoder into its own middleware
amaury1093 Nov 25, 2021
51cbf76
Add test for txDecoderMiddleware
amaury1093 Nov 25, 2021
c63122e
Fix some baseapp tests
amaury1093 Nov 25, 2021
2deca27
Fix some more tests
amaury1093 Dec 1, 2021
00f3681
Fix mock tests
amaury1093 Dec 1, 2021
77ca28a
Fix middleware tests
amaury1093 Dec 1, 2021
66085ab
Add cl
amaury1093 Dec 1, 2021
d6b0884
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/1…
amaury1093 Dec 2, 2021
d6c42d7
Fix tests
amaury1093 Dec 2, 2021
1c6dab1
Update types/tx/middleware.go
amaury1093 Dec 2, 2021
8fa3113
Merge branch 'master' into am/10610-txdecoder-middleware
amaury1093 Dec 6, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/gov) [\#10373](https://github.com/cosmos/cosmos-sdk/pull/10373) Removed gov `keeper.{MustMarshal, MustUnmarshal}`.
* [\#10348](https://github.com/cosmos/cosmos-sdk/pull/10348) StdSignBytes takes a new argument of type `*tx.Tip` for signing over tips using LEGACY_AMINO_JSON.
* [\#10208](https://github.com/cosmos/cosmos-sdk/pull/10208) The `x/auth/signing.Tx` interface now also includes a new `GetTip() *tx.Tip` method for verifying tipped transactions. The `x/auth/types` expected BankKeeper interface now expects the `SendCoins` method too.
* [\#10612](https://github.com/cosmos/cosmos-sdk/pull/10612) `baseapp.NewBaseApp` constructor function doesn't take the `sdk.TxDecoder` anymore. This logic has been moved into the TxDecoderMiddleware.
Copy link
Member

Choose a reason for hiding this comment

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

good to mention this is required to be added in middleware, so when people read this they know this is a change they must make


### Client Breaking Changes

Expand Down
14 changes: 2 additions & 12 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,8 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
panic(fmt.Sprintf("unknown RequestCheckTx type: %s", req.Type))
}

reqTx, err := app.txDecoder(req.Tx)
if err != nil {
return sdkerrors.ResponseCheckTx(err, 0, 0, app.trace)
}

ctx := app.getContextForTx(mode, req.Tx)
res, checkRes, err := app.txHandler.CheckTx(ctx, tx.Request{Tx: reqTx, TxBytes: req.Tx}, tx.RequestCheckTx{Type: req.Type})
res, checkRes, err := app.txHandler.CheckTx(ctx, tx.Request{TxBytes: req.Tx}, tx.RequestCheckTx{Type: req.Type})
if err != nil {
return sdkerrors.ResponseCheckTx(err, uint64(res.GasUsed), uint64(res.GasWanted), app.trace)
}
Expand Down Expand Up @@ -285,14 +280,9 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx
}
}
}()
reqTx, err := app.txDecoder(req.Tx)
if err != nil {
abciRes = sdkerrors.ResponseDeliverTx(err, 0, 0, app.trace)
return abciRes
}

ctx := app.getContextForTx(runTxModeDeliver, req.Tx)
res, err := app.txHandler.DeliverTx(ctx, tx.Request{Tx: reqTx, TxBytes: req.Tx})
res, err := app.txHandler.DeliverTx(ctx, tx.Request{TxBytes: req.Tx})
if err != nil {
abciRes = sdkerrors.ResponseDeliverTx(err, uint64(res.GasUsed), uint64(res.GasWanted), app.trace)
return abciRes
Expand Down
18 changes: 9 additions & 9 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ func TestGetBlockRentionHeight(t *testing.T) {
expected int64
}{
"defaults": {
bapp: baseapp.NewBaseApp(name, logger, db, nil),
bapp: baseapp.NewBaseApp(name, logger, db),
maxAgeBlocks: 0,
commitHeight: 499000,
expected: 0,
},
"pruning unbonding time only": {
bapp: baseapp.NewBaseApp(name, logger, db, nil, baseapp.SetMinRetainBlocks(1)),
bapp: baseapp.NewBaseApp(name, logger, db, baseapp.SetMinRetainBlocks(1)),
maxAgeBlocks: 362880,
commitHeight: 499000,
expected: 136120,
},
"pruning iavl snapshot only": {
bapp: baseapp.NewBaseApp(
name, logger, db, nil,
name, logger, db,
baseapp.SetPruning(sdk.PruningOptions{KeepEvery: 10000}),
baseapp.SetMinRetainBlocks(1),
),
Expand All @@ -48,7 +48,7 @@ func TestGetBlockRentionHeight(t *testing.T) {
},
"pruning state sync snapshot only": {
bapp: baseapp.NewBaseApp(
name, logger, db, nil,
name, logger, db,
baseapp.SetSnapshotInterval(50000),
baseapp.SetSnapshotKeepRecent(3),
baseapp.SetMinRetainBlocks(1),
Expand All @@ -59,7 +59,7 @@ func TestGetBlockRentionHeight(t *testing.T) {
},
"pruning min retention only": {
bapp: baseapp.NewBaseApp(
name, logger, db, nil,
name, logger, db,
baseapp.SetMinRetainBlocks(400000),
),
maxAgeBlocks: 0,
Expand All @@ -68,7 +68,7 @@ func TestGetBlockRentionHeight(t *testing.T) {
},
"pruning all conditions": {
bapp: baseapp.NewBaseApp(
name, logger, db, nil,
name, logger, db,
baseapp.SetPruning(sdk.PruningOptions{KeepEvery: 10000}),
baseapp.SetMinRetainBlocks(400000),
baseapp.SetSnapshotInterval(50000), baseapp.SetSnapshotKeepRecent(3),
Expand All @@ -79,7 +79,7 @@ func TestGetBlockRentionHeight(t *testing.T) {
},
"no pruning due to no persisted state": {
bapp: baseapp.NewBaseApp(
name, logger, db, nil,
name, logger, db,
baseapp.SetPruning(sdk.PruningOptions{KeepEvery: 10000}),
baseapp.SetMinRetainBlocks(400000),
baseapp.SetSnapshotInterval(50000), baseapp.SetSnapshotKeepRecent(3),
Expand All @@ -90,7 +90,7 @@ func TestGetBlockRentionHeight(t *testing.T) {
},
"disable pruning": {
bapp: baseapp.NewBaseApp(
name, logger, db, nil,
name, logger, db,
baseapp.SetPruning(sdk.PruningOptions{KeepEvery: 10000}),
baseapp.SetMinRetainBlocks(0),
baseapp.SetSnapshotInterval(50000), baseapp.SetSnapshotKeepRecent(3),
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestBaseAppCreateQueryContextRejectsNegativeHeights(t *testing.T) {
logger := defaultLogger()
db := dbm.NewMemDB()
name := t.Name()
app := baseapp.NewBaseApp(name, logger, db, nil)
app := baseapp.NewBaseApp(name, logger, db)

proves := []bool{
false, true,
Expand Down
4 changes: 1 addition & 3 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ type BaseApp struct { // nolint: maligned
queryRouter sdk.QueryRouter // router for redirecting query calls
grpcQueryRouter *GRPCQueryRouter // router for redirecting gRPC query calls
interfaceRegistry types.InterfaceRegistry
txDecoder sdk.TxDecoder // unmarshal []byte into sdk.Tx

txHandler tx.Handler // txHandler for {Deliver,Check}Tx and simulations
initChainer sdk.InitChainer // initialize state with validators and state blob
Expand Down Expand Up @@ -137,7 +136,7 @@ type BaseApp struct { // nolint: maligned
//
// NOTE: The db is used to store the version number for now.
func NewBaseApp(
name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, options ...func(*BaseApp),
name string, logger log.Logger, db dbm.DB, options ...func(*BaseApp),
) *BaseApp {
app := &BaseApp{
logger: logger,
Expand All @@ -147,7 +146,6 @@ func NewBaseApp(
storeLoader: DefaultStoreLoader,
queryRouter: NewQueryRouter(),
grpcQueryRouter: NewGRPCQueryRouter(),
txDecoder: txDecoder,
fauxMerkleMode: false,
}

Expand Down
Loading