CacheWrap after AnteHandler
This commit is contained in:
+24
-1
@@ -297,16 +297,31 @@ func (app *BaseApp) runTx(isCheckTx bool, txBytes []byte, tx sdk.Tx) (result sdk
|
||||
// TODO: override default ante handler w/ custom ante handler.
|
||||
|
||||
// Run the ante handler.
|
||||
ctx, result, abort := app.defaultAnteHandler(ctx, tx)
|
||||
if ctx.IsZero() {
|
||||
panic("why? before")
|
||||
}
|
||||
newCtx, result, abort := app.defaultAnteHandler(ctx, tx)
|
||||
if isCheckTx || abort {
|
||||
return result
|
||||
}
|
||||
if !newCtx.IsZero() {
|
||||
ctx = newCtx
|
||||
}
|
||||
|
||||
// CacheWrap app.msDeliver in case it fails.
|
||||
msCache := app.getMultiStore(isCheckTx).CacheMultiStore()
|
||||
ctx = ctx.WithMultiStore(msCache)
|
||||
|
||||
// Match and run route.
|
||||
msgType := tx.Type()
|
||||
handler := app.router.Route(msgType)
|
||||
result = handler(ctx, tx)
|
||||
|
||||
// If result was successful, write to app.msDeliver or app.msCheck.
|
||||
if result.IsOK() {
|
||||
msCache.Write()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -335,6 +350,14 @@ func (app *BaseApp) Commit() (res abci.ResponseCommit) {
|
||||
//----------------------------------------
|
||||
// Misc.
|
||||
|
||||
func (app *BaseApp) getMultiStore(isCheckTx bool) sdk.MultiStore {
|
||||
if isCheckTx {
|
||||
return app.msCheck
|
||||
} else {
|
||||
return app.msDeliver
|
||||
}
|
||||
}
|
||||
|
||||
// Return index of list with validator of same PubKey, or -1 if no match
|
||||
func pubKeyIndex(val *abci.Validator, list []*abci.Validator) int {
|
||||
for i, v := range list {
|
||||
|
||||
@@ -77,7 +77,7 @@ func TestBasic(t *testing.T) {
|
||||
}
|
||||
txBytes := toJSON(tx)
|
||||
res := app.DeliverTx(txBytes)
|
||||
assert.True(t, res.IsOK(), "%#v", res)
|
||||
assert.True(t, res.IsOK(), "%#v\nABCI log: %s", res, res.Log)
|
||||
}
|
||||
|
||||
// Simulate the end of a block.
|
||||
|
||||
Reference in New Issue
Block a user