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

RecheckTx Optimizations #5196

Merged
merged 23 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
420faef
Introduce Recheck optimizations
AdityaSripal Oct 15, 2019
dc98bb2
Merge branch 'master' into aditya/recheck
alexanderbez Oct 15, 2019
0310b36
fix tests
AdityaSripal Oct 15, 2019
42ddba9
Merge branch 'aditya/recheck' of https://github.com/cosmos/cosmos-sdk…
AdityaSripal Oct 15, 2019
17b47bf
add unit tests
AdityaSripal Oct 15, 2019
4eb7dc8
add integration tests
AdityaSripal Oct 15, 2019
48bc5cb
update changelog
AdityaSripal Oct 15, 2019
af3b24d
Update x/auth/ante/ante_test.go
AdityaSripal Oct 15, 2019
93fd162
Merge branch 'master' into aditya/recheck
fedekunze Oct 16, 2019
2e24c37
Merge branch 'master' into aditya/recheck
alexanderbez Oct 22, 2019
32f087b
enforce invariant, that recheck mode has IsCheckTx() = true
AdityaSripal Oct 22, 2019
3f94b1c
Merge branch 'aditya/recheck' of https://github.com/cosmos/cosmos-sdk…
AdityaSripal Oct 22, 2019
14f1939
address reviews
AdityaSripal Oct 22, 2019
81a5996
update changelog
alexanderbez Oct 22, 2019
b5232ee
lint: update godoc
alexanderbez Oct 22, 2019
8d2e54b
docs: update checktx section in baseapp doc
alexanderbez Oct 22, 2019
27d0393
doc: update IncrementSequenceDecorator godoc
alexanderbez Oct 22, 2019
08a44d6
cleanup iota const
alexanderbez Oct 23, 2019
39b91bf
remove named return
alexanderbez Oct 23, 2019
0af80d5
Update docs/core/baseapp.md
alexanderbez Oct 23, 2019
a0f895f
Update docs/core/baseapp.md
alexanderbez Oct 23, 2019
da856be
Merge branch 'master' into aditya/recheck
alexanderbez Oct 23, 2019
d14f4ee
Merge branch 'master' into aditya/recheck
alexanderbez Oct 23, 2019
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
4 changes: 3 additions & 1 deletion baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) (res abci.ResponseCheckTx)
tx, err := app.txDecoder(req.Tx)
if err != nil {
result = err.Result()
} else {
} else if req.Type == abci.CheckTxType_New {
result = app.runTx(runTxModeCheck, req.Tx, tx)
} else {
result = app.runTx(runTxModeReCheck, req.Tx, tx)
}
AdityaSripal marked this conversation as resolved.
Show resolved Hide resolved

return abci.ResponseCheckTx{
Expand Down
9 changes: 7 additions & 2 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
const (
// Check a transaction
runTxModeCheck runTxMode = iota
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
// Recheck a transaction
AdityaSripal marked this conversation as resolved.
Show resolved Hide resolved
runTxModeReCheck runTxMode = iota
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
// Simulate a transaction
runTxModeSimulate runTxMode = iota
// Deliver a transaction
Expand Down Expand Up @@ -481,6 +483,9 @@ func (app *BaseApp) getContextForTx(mode runTxMode, txBytes []byte) (ctx sdk.Con
WithVoteInfos(app.voteInfos).
WithConsensusParams(app.consensusParams)

AdityaSripal marked this conversation as resolved.
Show resolved Hide resolved
if mode == runTxModeReCheck {
ctx = ctx.WithIsReCheckTx(true)
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
}
if mode == runTxModeSimulate {
ctx, _ = ctx.CacheContext()
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down Expand Up @@ -653,8 +658,8 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (re

var msgResult sdk.Result

// skip actual execution for CheckTx mode
if mode != runTxModeCheck {
// skip actual execution for CheckTx and ReCheckTx mode
if mode != runTxModeCheck && mode != runTxModeReCheck {
msgResult = handler(ctx, msg)
}

Expand Down
7 changes: 7 additions & 0 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Context struct {
gasMeter GasMeter
blockGasMeter GasMeter
checkTx bool
recheckTx bool
minGasPrice DecCoins
consParams *abci.ConsensusParams
eventManager *EventManager
Expand All @@ -51,6 +52,7 @@ func (c Context) VoteInfos() []abci.VoteInfo { return c.voteInfo }
func (c Context) GasMeter() GasMeter { return c.gasMeter }
func (c Context) BlockGasMeter() GasMeter { return c.blockGasMeter }
func (c Context) IsCheckTx() bool { return c.checkTx }
func (c Context) IsReCheckTx() bool { return c.recheckTx }
func (c Context) MinGasPrices() DecCoins { return c.minGasPrice }
func (c Context) EventManager() *EventManager { return c.eventManager }

Expand Down Expand Up @@ -152,6 +154,11 @@ func (c Context) WithIsCheckTx(isCheckTx bool) Context {
return c
}

func (c Context) WithIsReCheckTx(isRecheckTx bool) Context {
c.recheckTx = isRecheckTx
AdityaSripal marked this conversation as resolved.
Show resolved Hide resolved
return c
}

func (c Context) WithMinGasPrices(gasPrices DecCoins) Context {
c.minGasPrice = gasPrices
return c
Expand Down
4 changes: 4 additions & 0 deletions x/auth/ante/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func NewValidateBasicDecorator() ValidateBasicDecorator {
}

func (vbd ValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
// no need to validate basic on recheck tx
if ctx.IsReCheckTx() {
return next(ctx, tx, simulate)
}
if err := tx.ValidateBasic(); err != nil {
return ctx, err
}
Expand Down
8 changes: 8 additions & 0 deletions x/auth/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ func NewSigVerificationDecorator(ak keeper.AccountKeeper) SigVerificationDecorat
}

func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
// no need to verify signatures on recheck tx
if ctx.IsReCheckTx() {
return next(ctx, tx, simulate)
}
sigTx, ok := tx.(SigVerifiableTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type")
Expand Down Expand Up @@ -220,6 +224,10 @@ func NewIncrementSequenceDecorator(ak keeper.AccountKeeper) IncrementSequenceDec
}

func (isd IncrementSequenceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
// no need to increment sequence on check tx
if ctx.IsCheckTx() {
return next(ctx, tx, simulate)
}
sigTx, ok := tx.(SigVerifiableTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type")
Expand Down