CacheWrap after AnteHandler

This commit is contained in:
Jae Kwon
2018-01-26 06:54:03 -08:00
parent c6bad0b325
commit 05036e35d2
6 changed files with 48 additions and 25 deletions
+24 -1
View File
@@ -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 {
+1 -1
View File
@@ -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.