From e9904c156347e46cd8cd778642177ba302121ac7 Mon Sep 17 00:00:00 2001 From: YuanXingqiang Date: Fri, 2 Dec 2022 19:46:45 +0800 Subject: [PATCH] Merge PR: fix bug of pgu for 165 (#2837) * add enable config of hgu * simulate tx in new goroutine * add simulation debug info * start more goroutine for simulation * fix bug * udpate * fix bug of sig cache * disable pendingPool * enable hgu default * add log info and query api of simulation gas * add enable config of pgu and adjustment * use atomic to prevent data race * delete temp code * enable async simulation only when pgb is greater than -1 * check error * only update sig cache in VerifySig * get realTx from mempool in baseApp * update to 1.6.5.10 --- Makefile | 2 +- libs/cosmos-sdk/baseapp/abci.go | 15 ++++++++++++--- x/evm/types/msg_evm.go | 26 +++++++++++++++----------- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 6407acdae4..fe07412a5f 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ IGNORE_CHECK_GO=false install_rocksdb_version:=$(ROCKSDB_VERSION) -Version=v1.6.5.9 +Version=v1.6.5.10 CosmosSDK=v0.39.2 Tendermint=v0.33.9 Iavl=v0.14.3 diff --git a/libs/cosmos-sdk/baseapp/abci.go b/libs/cosmos-sdk/baseapp/abci.go index 63abed1d0b..164e8f9df6 100644 --- a/libs/cosmos-sdk/baseapp/abci.go +++ b/libs/cosmos-sdk/baseapp/abci.go @@ -413,10 +413,19 @@ func handleSimulate(app *BaseApp, path []string, height int64, txBytes []byte, o } } } - tx, err := app.txDecoder(txBytes) - if err != nil { - return sdkerrors.QueryResult(sdkerrors.Wrap(err, "failed to decode tx")) + + var tx sdk.Tx + var err error + if mem := GetGlobalMempool(); mem != nil { + tx, _ = mem.ReapEssentialTx(txBytes).(sdk.Tx) } + if tx == nil { + tx, err = app.txDecoder(txBytes) + if err != nil { + return sdkerrors.QueryResult(sdkerrors.Wrap(err, "failed to decode tx")) + } + } + msgs := tx.GetMsgs() if enableFastQuery() { diff --git a/x/evm/types/msg_evm.go b/x/evm/types/msg_evm.go index 4f228e1e79..44aaaa7e9b 100644 --- a/x/evm/types/msg_evm.go +++ b/x/evm/types/msg_evm.go @@ -66,11 +66,14 @@ func (tx *MsgEthereumTx) GetFrom() string { if from != "" { return from } - err := tx.firstVerifySig(tx.ChainID()) + // Verify the signature with chain-id in the tx, so it can be a tx from other chain with unexpected chain. + // Only use from addr for some safe usage and do not update the signature cache or the `From` field of the tx. + sender, err := tx.firstVerifySig(tx.ChainID()) if err != nil { return "" } - return tx.BaseTx.GetFrom() + from = EthAddressToString(&sender) + return from } func (msg MsgEthereumTx) GetSender(ctx sdk.Context) string { @@ -325,13 +328,13 @@ var sigBigNumPool = &sync.Pool{ }, } -func (msg *MsgEthereumTx) firstVerifySig(chainID *big.Int) error { +func (msg *MsgEthereumTx) firstVerifySig(chainID *big.Int) (ethcmn.Address, error) { var V *big.Int var sigHash ethcmn.Hash if isProtectedV(msg.Data.V) { // do not allow recovery for transactions with an unprotected chainID if chainID.Sign() == 0 { - return errors.New("chainID cannot be zero") + return emptyEthAddr, errors.New("chainID cannot be zero") } bigNum := sigBigNumPool.Get().(*big.Int) @@ -352,13 +355,10 @@ func (msg *MsgEthereumTx) firstVerifySig(chainID *big.Int) error { sender, err := recoverEthSig(msg.Data.R, msg.Data.S, V, &sigHash) if err != nil { - return err + return emptyEthAddr, err } - from := EthAddressToString(&sender) - tmtypes.SignatureCache().Add(msg.TxHash(), from) - msg.BaseTx.From = from - msg.addr = sender - return nil + + return sender, nil } // VerifySig attempts to verify a Transaction's signature for a given chainID. @@ -375,10 +375,14 @@ func (msg *MsgEthereumTx) VerifySig(chainID *big.Int, height int64) error { msg.SetFrom(from) return nil } - err := msg.firstVerifySig(chainID) + sender, err := msg.firstVerifySig(chainID) if err != nil { return err } + from = EthAddressToString(&sender) + tmtypes.SignatureCache().Add(msg.TxHash(), from) + msg.BaseTx.From = from + msg.addr = sender return nil }