abci: strip mempoolerror from responsechectx (#8620)

* abci:mempoolError from ResponseCheckTx
* responseCheckTx returns an error if Tendermint decides not to accept an app after CheckTx
*updated spec, upgrading.md and changelog.md
This commit is contained in:
Jasmina Malicevic
2022-05-26 11:18:27 +02:00
committed by GitHub
parent b0ec8a0ea7
commit cb9722c2b0
29 changed files with 418 additions and 948 deletions
+9 -8
View File
@@ -278,8 +278,11 @@ func (txmp *TxMempool) CheckTx(
}
txmp.defaultTxCallback(tx, res)
txmp.initTxCallback(wtx, res, txInfo)
err = txmp.initTxCallback(wtx, res, txInfo)
if err != nil {
return err
}
if cb != nil {
cb(res)
}
@@ -488,7 +491,7 @@ func (txmp *TxMempool) Update(
//
// NOTE:
// - An explicit lock is NOT required.
func (txmp *TxMempool) initTxCallback(wtx *WrappedTx, res *abci.ResponseCheckTx, txInfo TxInfo) {
func (txmp *TxMempool) initTxCallback(wtx *WrappedTx, res *abci.ResponseCheckTx, txInfo TxInfo) error {
var err error
if txmp.postCheck != nil {
err = txmp.postCheck(wtx.tx, res)
@@ -510,10 +513,7 @@ func (txmp *TxMempool) initTxCallback(wtx *WrappedTx, res *abci.ResponseCheckTx,
if !txmp.config.KeepInvalidTxsInCache {
txmp.cache.Remove(wtx.tx)
}
if err != nil {
res.MempoolError = err.Error()
}
return
return err
}
sender := res.Sender
@@ -527,7 +527,7 @@ func (txmp *TxMempool) initTxCallback(wtx *WrappedTx, res *abci.ResponseCheckTx,
"sender", sender,
)
txmp.metrics.RejectedTxs.Add(1)
return
return nil
}
}
@@ -548,7 +548,7 @@ func (txmp *TxMempool) initTxCallback(wtx *WrappedTx, res *abci.ResponseCheckTx,
"err", err.Error(),
)
txmp.metrics.RejectedTxs.Add(1)
return
return nil
}
// evict an existing transaction(s)
@@ -588,6 +588,7 @@ func (txmp *TxMempool) initTxCallback(wtx *WrappedTx, res *abci.ResponseCheckTx,
"num_txs", txmp.Size(),
)
txmp.notifyTxsAvailable()
return nil
}
// defaultTxCallback is the CheckTx application callback used when a
+9 -2
View File
@@ -622,10 +622,17 @@ func TestTxMempool_CheckTxPostCheckError(t *testing.T) {
expectedErrString := ""
if testCase.err != nil {
expectedErrString = testCase.err.Error()
require.Equal(t, expectedErrString, txmp.postCheck(tx, res).Error())
} else {
require.Equal(t, nil, txmp.postCheck(tx, res))
}
require.Equal(t, expectedErrString, res.MempoolError)
}
require.NoError(t, txmp.CheckTx(ctx, tx, callback, TxInfo{SenderID: 0}))
if testCase.err == nil {
require.NoError(t, txmp.CheckTx(ctx, tx, callback, TxInfo{SenderID: 0}))
} else {
err = txmp.CheckTx(ctx, tx, callback, TxInfo{SenderID: 0})
fmt.Print(err.Error())
}
})
}
}
+5 -6
View File
@@ -54,11 +54,10 @@ func (env *Environment) BroadcastTxSync(ctx context.Context, req *coretypes.Requ
return nil, fmt.Errorf("broadcast confirmation not received: %w", ctx.Err())
case r := <-resCh:
return &coretypes.ResultBroadcastTx{
Code: r.Code,
Data: r.Data,
Codespace: r.Codespace,
MempoolError: r.MempoolError,
Hash: req.Tx.Hash(),
Code: r.Code,
Data: r.Data,
Codespace: r.Codespace,
Hash: req.Tx.Hash(),
}, nil
}
}
@@ -90,7 +89,7 @@ func (env *Environment) BroadcastTxCommit(ctx context.Context, req *coretypes.Re
return &coretypes.ResultBroadcastTxCommit{
CheckTx: *r,
Hash: req.Tx.Hash(),
}, fmt.Errorf("transaction encountered error (%s)", r.MempoolError)
}, fmt.Errorf("wrong ABCI CodeType, got (%d) instead of OK", r.Code)
}
if !indexer.KVSinkEnabled(env.EventSinks) {