Skip to content

Commit

Permalink
Merge PR: fix bug of pgu for 165 (#2837)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
yann-sjtu authored Dec 2, 2022
1 parent e18eb77 commit e9904c1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions libs/cosmos-sdk/baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
26 changes: 15 additions & 11 deletions x/evm/types/msg_evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand All @@ -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
}

Expand Down

0 comments on commit e9904c1

Please sign in to comment.