From e2b1d5ed56248a72d076acda038b17a868fc859b Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 12 Jan 2024 15:27:47 +0800 Subject: [PATCH] Problem: evm tx type is not aligned (#396) * Problem: evm tx type is aligned for more info, https://github.com/ethereum/go-ethereum/blob/v1.11.6/internal/ethapi/transaction_args.go#L284 * fix chainID * Update CHANGELOG.md Signed-off-by: mmsqe --------- Signed-off-by: mmsqe --- CHANGELOG.md | 1 + x/evm/keeper/statedb_test.go | 9 +++++---- x/evm/types/msg.go | 20 +++++++++----------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96b1d704c7..62a68a33ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (rpc) [#386](https://github.com/crypto-org-chain/ethermint/pull/386) Cleanup unused cancel function in filter. * (rpc) [#388](https://github.com/crypto-org-chain/ethermint/pull/388) Avoid out of bound panic when error message. * (rpc) [#391](https://github.com/crypto-org-chain/ethermint/pull/391) Align block param with go-ethereum in debug_traceCall. +- (evm) [#396](https://github.com/crypto-org-chain/ethermint/pull/396) Align evm tx type with go-ethereum. ### Improvements diff --git a/x/evm/keeper/statedb_test.go b/x/evm/keeper/statedb_test.go index 820492155c..69bb233d84 100644 --- a/x/evm/keeper/statedb_test.go +++ b/x/evm/keeper/statedb_test.go @@ -624,28 +624,29 @@ func (suite *KeeperTestSuite) CreateTestTx(msg *types.MsgEthereumTx, priv crypto } func (suite *KeeperTestSuite) TestAddLog() { + chainID := big.NewInt(9000) addr, privKey := tests.NewAddrKey() - msg := types.NewTx(big.NewInt(1), 0, &suite.address, big.NewInt(1), 100000, big.NewInt(1), nil, nil, []byte("test"), nil) + msg := types.NewTx(chainID, 0, &suite.address, big.NewInt(1), 100000, big.NewInt(1), nil, nil, []byte("test"), nil) msg.From = addr.Bytes() tx := suite.CreateTestTx(msg, privKey) msg, _ = tx.GetMsgs()[0].(*types.MsgEthereumTx) txHash := msg.AsTransaction().Hash() - msg2 := types.NewTx(big.NewInt(1), 1, &suite.address, big.NewInt(1), 100000, big.NewInt(1), nil, nil, []byte("test"), nil) + msg2 := types.NewTx(chainID, 1, &suite.address, big.NewInt(1), 100000, big.NewInt(1), nil, nil, []byte("test"), nil) msg2.From = addr.Bytes() tx2 := suite.CreateTestTx(msg2, privKey) msg2, _ = tx2.GetMsgs()[0].(*types.MsgEthereumTx) - msg3 := types.NewTx(big.NewInt(1), 0, &suite.address, big.NewInt(1), 100000, nil, big.NewInt(1), big.NewInt(1), []byte("test"), nil) + msg3 := types.NewTx(chainID, 0, &suite.address, big.NewInt(1), 100000, nil, big.NewInt(1), big.NewInt(1), []byte("test"), nil) msg3.From = addr.Bytes() tx3 := suite.CreateTestTx(msg3, privKey) msg3, _ = tx3.GetMsgs()[0].(*types.MsgEthereumTx) txHash3 := msg3.AsTransaction().Hash() - msg4 := types.NewTx(big.NewInt(1), 1, &suite.address, big.NewInt(1), 100000, nil, big.NewInt(1), big.NewInt(1), []byte("test"), nil) + msg4 := types.NewTx(chainID, 1, &suite.address, big.NewInt(1), 100000, nil, big.NewInt(1), big.NewInt(1), []byte("test"), nil) msg4.From = addr.Bytes() tx4 := suite.CreateTestTx(msg4, privKey) diff --git a/x/evm/types/msg.go b/x/evm/types/msg.go index 32a622c2aa..fef2fee8d3 100644 --- a/x/evm/types/msg.go +++ b/x/evm/types/msg.go @@ -106,19 +106,9 @@ func newMsgEthereumTx( } switch { - case accesses == nil: - txData = &LegacyTx{ - Nonce: nonce, - To: toAddr, - Amount: amt, - GasLimit: gasLimit, - GasPrice: gp, - Data: input, - } - case accesses != nil && gasFeeCap != nil && gasTipCap != nil: + case gasFeeCap != nil: gtc := sdkmath.NewIntFromBigInt(gasTipCap) gfc := sdkmath.NewIntFromBigInt(gasFeeCap) - txData = &DynamicFeeTx{ ChainID: cid, Nonce: nonce, @@ -142,6 +132,14 @@ func newMsgEthereumTx( Accesses: NewAccessList(accesses), } default: + txData = &LegacyTx{ + Nonce: nonce, + To: toAddr, + Amount: amt, + GasLimit: gasLimit, + GasPrice: gp, + Data: input, + } } dataAny, err := PackTxData(txData)