diff --git a/app/app.go b/app/app.go index d459b12ade..4b25a4f198 100644 --- a/app/app.go +++ b/app/app.go @@ -1599,6 +1599,12 @@ func (app *App) DecodeTransactionsConcurrently(ctx sdk.Context, txs [][]byte) [] wg.Add(1) go func(idx int, encodedTx []byte) { defer wg.Done() + defer func() { + if err := recover(); err != nil { + ctx.Logger().Error(fmt.Sprintf("encountered panic during transaction decoding: %s", err)) + typedTxs[idx] = nil + } + }() typedTx, err := app.txDecoder(encodedTx) // get txkey from tx if err != nil { @@ -1899,6 +1905,11 @@ func (app *App) BlacklistedAccAddrs() map[string]bool { return blacklistedAddrs } +// test-only +func (app *App) SetTxDecoder(txDecoder sdk.TxDecoder) { + app.txDecoder = txDecoder +} + func init() { // override max wasm size to 2MB wasmtypes.MaxWasmSize = 2 * 1024 * 1024 diff --git a/app/app_test.go b/app/app_test.go index 60d51d42f5..d486ff30e8 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -4,15 +4,16 @@ import ( "context" "encoding/hex" "fmt" + "math/big" + "reflect" + "testing" + "time" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/server/api" cosmosConfig "github.com/cosmos/cosmos-sdk/server/config" "github.com/gorilla/mux" "github.com/grpc-ecosystem/grpc-gateway/runtime" - "math/big" - "reflect" - "testing" - "time" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" @@ -360,6 +361,13 @@ func TestDecodeTransactionsConcurrently(t *testing.T) { require.NotNil(t, typedTxs[0].GetMsgs()[0].(*evmtypes.MsgEVMTransaction).Derived) require.Nil(t, typedTxs[1]) require.NotNil(t, typedTxs[2]) + + // test panic handling + testWrapper.App.SetTxDecoder(func(txBytes []byte) (sdk.Tx, error) { panic("test") }) + typedTxs = testWrapper.App.DecodeTransactionsConcurrently(testWrapper.Ctx, [][]byte{evmtxbz, invalidbz, banktxbz}) + require.Nil(t, typedTxs[0]) + require.Nil(t, typedTxs[1]) + require.Nil(t, typedTxs[2]) } func TestApp_RegisterAPIRoutes(t *testing.T) {