diff --git a/app/app_parallel.go b/app/app_parallel.go index df2cd1ff2a..523d890b06 100644 --- a/app/app_parallel.go +++ b/app/app_parallel.go @@ -19,13 +19,16 @@ func updateFeeCollectorHandler(bk bank.Keeper, sk supply.Keeper) sdk.UpdateFeeCo // evmTxFeeHandler get tx fee for evm tx func evmTxFeeHandler() sdk.GetTxFeeHandler { - return func(tx sdk.Tx) (fee sdk.Coins, isEvm bool) { - if _, ok := tx.(evmtypes.MsgEthereumTx); ok { + return func(ctx sdk.Context, tx sdk.Tx) (fee sdk.Coins, isEvm bool, signCache sdk.SigCache) { + if evmTx, ok := tx.(evmtypes.MsgEthereumTx); ok { isEvm = true + signCache, _ = evmTx.VerifySig(evmTx.ChainID(), ctx.BlockHeight(), nil) + } if feeTx, ok := tx.(authante.FeeTx); ok { fee = feeTx.GetFee() } + return } } diff --git a/cmd/exchaind/replay.go b/cmd/exchaind/replay.go index b19317b4d8..b9ec124546 100644 --- a/cmd/exchaind/replay.go +++ b/cmd/exchaind/replay.go @@ -262,7 +262,7 @@ func doReplay(ctx *server.Context, state sm.State, stateStoreDB dbm.DB, startDumpPprof() defer stopDumpPprof() } - needSaveBlock := viper.GetBool(saveBlock) || viper.GetBool(sm.FlagParalleledTx) + needSaveBlock := viper.GetBool(saveBlock) for height := lastBlockHeight + 1; height <= haltheight; height++ { log.Println("replaying ", height) block := originBlockStore.LoadBlock(height) diff --git a/libs/cosmos-sdk/baseapp/baseapp.go b/libs/cosmos-sdk/baseapp/baseapp.go index c093978bd4..1971f00504 100644 --- a/libs/cosmos-sdk/baseapp/baseapp.go +++ b/libs/cosmos-sdk/baseapp/baseapp.go @@ -564,6 +564,9 @@ func (app *BaseApp) getContextForTx(mode runTxMode, txBytes []byte) sdk.Context } if app.parallelTxManage.isAsyncDeliverTx { ctx = ctx.WithAsync() + if s, ok := app.parallelTxManage.txStatus[string(txBytes)]; ok && s.signCache != nil { + ctx = ctx.WithSigCache(s.signCache) + } } return ctx diff --git a/libs/cosmos-sdk/baseapp/baseapp_parallel.go b/libs/cosmos-sdk/baseapp/baseapp_parallel.go index 144643d2b7..b17cb1d0c5 100644 --- a/libs/cosmos-sdk/baseapp/baseapp_parallel.go +++ b/libs/cosmos-sdk/baseapp/baseapp_parallel.go @@ -10,26 +10,54 @@ import ( abci "github.com/okex/exchain/libs/tendermint/abci/types" ) +type extraDataForTx struct { + fee sdk.Coins + isEvm bool + signCache sdk.SigCache +} + +func (app *BaseApp) getExtraDataByTxs(txs [][]byte) []*extraDataForTx { + res := make([]*extraDataForTx, len(txs), len(txs)) + var wg sync.WaitGroup + for index, txBytes := range txs { + wg.Add(1) + index := index + txBytes := txBytes + go func() { + tx, err := app.txDecoder(txBytes) + if err != nil { + panic(err) + } + coin, isEvm, s := app.getTxFee(app.getContextForTx(runTxModeDeliverInAsync, txBytes), tx) + res[index] = &extraDataForTx{ + fee: coin, + isEvm: isEvm, + signCache: s, + } + wg.Done() + }() + } + wg.Wait() + return res +} + func (app *BaseApp) ParallelTxs(txs [][]byte) []*abci.ResponseDeliverTx { + extraData := app.getExtraDataByTxs(txs) app.parallelTxManage.isAsyncDeliverTx = true evmIndex := uint32(0) for k, v := range txs { - tx, err := app.txDecoder(v) - if err != nil { - panic(err) - } t := &txStatus{ indexInBlock: uint32(k), + signCache: extraData[k].signCache, } - fee, isEvm := app.getTxFee(tx) - if isEvm { + if extraData[k].isEvm { t.evmIndex = evmIndex t.isEvmTx = true evmIndex++ } vString := string(v) - app.parallelTxManage.setFee(vString, fee) + app.parallelTxManage.setFee(vString, extraData[k].fee) app.parallelTxManage.txStatus[vString] = t app.parallelTxManage.indexMapBytes = append(app.parallelTxManage.indexMapBytes, vString) @@ -290,6 +318,7 @@ type txStatus struct { evmIndex uint32 indexInBlock uint32 anteErr error + signCache sdk.SigCache } func newParallelTxManager() *parallelTxManager { diff --git a/libs/cosmos-sdk/types/handler.go b/libs/cosmos-sdk/types/handler.go index 7ddd4fb3a4..13b007c304 100644 --- a/libs/cosmos-sdk/types/handler.go +++ b/libs/cosmos-sdk/types/handler.go @@ -15,7 +15,7 @@ type UpdateFeeCollectorAccHandler func(ctx Context, balance Coins) error type LogFix func(isAnteFailed [][]string) (logs [][]byte) -type GetTxFeeHandler func(tx Tx) (Coins, bool) +type GetTxFeeHandler func(ctx Context, tx Tx) (Coins, bool, SigCache) // AnteDecorator wraps the next AnteHandler to perform custom pre- and post-processing. type AnteDecorator interface {