Don't abort after AnteHandler if CheckTx
Currently we are aborting running a transaction after the AnteHandler in case it is a checkTx. This means that the handler never gets the chance to check the validity of a transaction. Furthermore the AnteHandler should not handle CheckTx logic. The AnteHandler should handle global validation, whereas each Handler should handle module validation.
This commit is contained in:
parent
834f98c692
commit
ec4711afd8
|
@ -40,9 +40,8 @@ type BaseApp struct {
|
||||||
// Volatile
|
// Volatile
|
||||||
// .msCheck and .ctxCheck are set on initialization and reset on Commit.
|
// .msCheck and .ctxCheck are set on initialization and reset on Commit.
|
||||||
// .msDeliver and .ctxDeliver are (re-)set on BeginBlock.
|
// .msDeliver and .ctxDeliver are (re-)set on BeginBlock.
|
||||||
// .valUpdates accumulate in DeliverTx and reset in BeginBlock.
|
// .valUpdates accumulate in DeliverTx and are reset in BeginBlock.
|
||||||
// QUESTION: should we put valUpdates in the ctxDeliver?
|
// QUESTION: should we put valUpdates in the ctxDeliver?
|
||||||
|
|
||||||
msCheck sdk.CacheMultiStore // CheckTx state, a cache-wrap of `.cms`
|
msCheck sdk.CacheMultiStore // CheckTx state, a cache-wrap of `.cms`
|
||||||
msDeliver sdk.CacheMultiStore // DeliverTx state, a cache-wrap of `.cms`
|
msDeliver sdk.CacheMultiStore // DeliverTx state, a cache-wrap of `.cms`
|
||||||
ctxCheck sdk.Context // CheckTx context
|
ctxCheck sdk.Context // CheckTx context
|
||||||
|
@ -51,6 +50,7 @@ type BaseApp struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ abci.Application = &BaseApp{}
|
var _ abci.Application = &BaseApp{}
|
||||||
|
var _ abci.Application = (*BaseApp)(nil)
|
||||||
|
|
||||||
// Create and name new BaseApp
|
// Create and name new BaseApp
|
||||||
func NewBaseApp(name string, logger log.Logger, db dbm.DB) *BaseApp {
|
func NewBaseApp(name string, logger log.Logger, db dbm.DB) *BaseApp {
|
||||||
|
@ -94,11 +94,9 @@ func (app *BaseApp) SetEndBlocker(endBlocker sdk.EndBlocker) {
|
||||||
app.endBlocker = endBlocker
|
app.endBlocker = endBlocker
|
||||||
}
|
}
|
||||||
func (app *BaseApp) SetAnteHandler(ah sdk.AnteHandler) {
|
func (app *BaseApp) SetAnteHandler(ah sdk.AnteHandler) {
|
||||||
// deducts fee from payer, verifies signatures and nonces, sets Signers to ctx.
|
|
||||||
app.anteHandler = ah
|
app.anteHandler = ah
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint - Get functions
|
|
||||||
func (app *BaseApp) Router() Router { return app.router }
|
func (app *BaseApp) Router() Router { return app.router }
|
||||||
|
|
||||||
// load latest application version
|
// load latest application version
|
||||||
|
@ -172,7 +170,6 @@ func (app *BaseApp) NewContext(isCheckTx bool, header abci.Header) sdk.Context {
|
||||||
|
|
||||||
// Implements ABCI
|
// Implements ABCI
|
||||||
func (app *BaseApp) Info(req abci.RequestInfo) abci.ResponseInfo {
|
func (app *BaseApp) Info(req abci.RequestInfo) abci.ResponseInfo {
|
||||||
|
|
||||||
lastCommitID := app.cms.LastCommitID()
|
lastCommitID := app.cms.LastCommitID()
|
||||||
|
|
||||||
return abci.ResponseInfo{
|
return abci.ResponseInfo{
|
||||||
|
@ -234,7 +231,6 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
|
||||||
|
|
||||||
// Implements ABCI
|
// Implements ABCI
|
||||||
func (app *BaseApp) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) {
|
func (app *BaseApp) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) {
|
||||||
|
|
||||||
// Decode the Tx.
|
// Decode the Tx.
|
||||||
var result sdk.Result
|
var result sdk.Result
|
||||||
var tx, err = app.txDecoder(txBytes)
|
var tx, err = app.txDecoder(txBytes)
|
||||||
|
@ -259,7 +255,6 @@ func (app *BaseApp) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) {
|
||||||
|
|
||||||
// Implements ABCI
|
// Implements ABCI
|
||||||
func (app *BaseApp) DeliverTx(txBytes []byte) (res abci.ResponseDeliverTx) {
|
func (app *BaseApp) DeliverTx(txBytes []byte) (res abci.ResponseDeliverTx) {
|
||||||
|
|
||||||
// Decode the Tx.
|
// Decode the Tx.
|
||||||
var result sdk.Result
|
var result sdk.Result
|
||||||
var tx, err = app.txDecoder(txBytes)
|
var tx, err = app.txDecoder(txBytes)
|
||||||
|
@ -300,7 +295,6 @@ func (app *BaseApp) Deliver(tx sdk.Tx) (result sdk.Result) {
|
||||||
// txBytes may be nil in some cases, eg. in tests.
|
// txBytes may be nil in some cases, eg. in tests.
|
||||||
// Also, in the future we may support "internal" transactions.
|
// Also, in the future we may support "internal" transactions.
|
||||||
func (app *BaseApp) runTx(isCheckTx bool, txBytes []byte, tx sdk.Tx) (result sdk.Result) {
|
func (app *BaseApp) runTx(isCheckTx bool, txBytes []byte, tx sdk.Tx) (result sdk.Result) {
|
||||||
|
|
||||||
// Handle any panics.
|
// Handle any panics.
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
|
@ -329,20 +323,27 @@ func (app *BaseApp) runTx(isCheckTx bool, txBytes []byte, tx sdk.Tx) (result sdk
|
||||||
ctx = app.ctxDeliver.WithTxBytes(txBytes)
|
ctx = app.ctxDeliver.WithTxBytes(txBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: override default ante handler w/ custom ante handler.
|
|
||||||
|
|
||||||
// Run the ante handler.
|
// Run the ante handler.
|
||||||
newCtx, result, abort := app.anteHandler(ctx, tx)
|
newCtx, result, abort := app.anteHandler(ctx, tx)
|
||||||
if isCheckTx || abort {
|
if abort {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
if !newCtx.IsZero() {
|
if !newCtx.IsZero() {
|
||||||
ctx = newCtx
|
ctx = newCtx
|
||||||
}
|
}
|
||||||
|
|
||||||
// CacheWrap app.msDeliver in case it fails.
|
// Get the correct cache
|
||||||
msCache := app.msDeliver.CacheMultiStore()
|
var msCache sdk.CacheMultiStore
|
||||||
ctx = ctx.WithMultiStore(msCache)
|
if isCheckTx == true {
|
||||||
|
// CacheWrap app.msCheck in case it fails.
|
||||||
|
msCache = app.msCheck.CacheMultiStore()
|
||||||
|
ctx = ctx.WithMultiStore(msCache)
|
||||||
|
} else {
|
||||||
|
// CacheWrap app.msDeliver in case it fails.
|
||||||
|
msCache = app.msDeliver.CacheMultiStore()
|
||||||
|
ctx = ctx.WithMultiStore(msCache)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Match and run route.
|
// Match and run route.
|
||||||
msgType := msg.Type()
|
msgType := msg.Type()
|
||||||
|
|
Loading…
Reference in New Issue