From e034dd519a645384031a80156cb1fa96d3f4c011 Mon Sep 17 00:00:00 2001 From: Freddy Li Date: Thu, 15 Apr 2021 15:12:41 -0400 Subject: [PATCH] merge pr #721 --- CHANGELOG.md | 2 ++ rpc/namespaces/eth/api.go | 9 +++++---- rpc/types/utils.go | 6 +++--- x/evm/client/rest/rest.go | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c460311b5..61a0e2b43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -208,6 +208,8 @@ corresponding Ethereum API namespace: ### Bug Fixes +* (evm) [\#751](https://github.com/cosmos/ethermint/issues/751) Fix misused method to calculate block hash in evm related function. +* (evm) [\#721](https://github.com/cosmos/ethermint/issues/721) Fix mismatch block hash in rpc response when use eth.getBlock. * (evm) [\#730](https://github.com/cosmos/ethermint/issues/730) Fix 'EIP2028' not open when Istanbul version has been enabled. * (app) [\#749](https://github.com/cosmos/ethermint/issues/749) Fix panic in `AnteHandler` when gas price larger than 100000 * (rpc) [\#305](https://github.com/cosmos/ethermint/issues/305) Update `eth_getTransactionCount` to check for account existence before getting sequence and return 0 as the nonce if it doesn't exist. diff --git a/rpc/namespaces/eth/api.go b/rpc/namespaces/eth/api.go index 613d0517f..965b0a49b 100644 --- a/rpc/namespaces/eth/api.go +++ b/rpc/namespaces/eth/api.go @@ -734,10 +734,11 @@ func (api *PublicEthereumAPI) GetBlockByNumber(blockNum rpctypes.BlockNumber, fu ChainID: api.clientCtx.ChainID, Height: latestBlock.Block.Height + 1, Time: time.Unix(0, 0), - LastBlockID: latestBlock.BlockID, + LastBlockID: latestBlock.Block.LastBlockID, ValidatorsHash: latestBlock.Block.NextValidatorsHash, }, 0, + latestBlock.Block.Hash(), 0, gasUsed, pendingTxs, @@ -775,7 +776,7 @@ func (api *PublicEthereumAPI) GetTransactionByHash(hash common.Hash) (*rpctypes. return nil, err } - blockHash := common.BytesToHash(block.Block.Header.Hash()) + blockHash := common.BytesToHash(block.Block.Hash()) ethTx, err := rpctypes.RawTxToEthTx(api.clientCtx, tx.Tx) if err != nil { @@ -852,7 +853,7 @@ func (api *PublicEthereumAPI) getTransactionByBlockAndIndex(block *tmtypes.Block height := uint64(block.Height) txHash := common.BytesToHash(block.Txs[idx].Hash()) - blockHash := common.BytesToHash(block.Header.Hash()) + blockHash := common.BytesToHash(block.Hash()) return rpctypes.NewTransaction(ethTx, txHash, blockHash, height, uint64(idx)) } @@ -871,7 +872,7 @@ func (api *PublicEthereumAPI) GetTransactionReceipt(hash common.Hash) (map[strin return nil, err } - blockHash := common.BytesToHash(block.Block.Header.Hash()) + blockHash := common.BytesToHash(block.Block.Hash()) // Convert tx bytes to eth transaction ethTx, err := rpctypes.RawTxToEthTx(api.clientCtx, tx.Tx) diff --git a/rpc/types/utils.go b/rpc/types/utils.go index 0461452f9..7e160aba0 100644 --- a/rpc/types/utils.go +++ b/rpc/types/utils.go @@ -92,7 +92,7 @@ func EthBlockFromTendermint(clientCtx client.Context, queryClient *QueryClient, bloom := ethtypes.BytesToBloom(res.Bloom) - return FormatBlock(block.Header, block.Size(), gasLimit, gasUsed, transactions, bloom), nil + return FormatBlock(block.Header, block.Size(), block.Hash(), gasLimit, gasUsed, transactions, bloom), nil } // EthHeaderFromTendermint is an util function that returns an Ethereum Header @@ -155,7 +155,7 @@ func BlockMaxGasFromConsensusParams(ctx context.Context, clientCtx client.Contex // FormatBlock creates an ethereum block from a tendermint header and ethereum-formatted // transactions. func FormatBlock( - header tmtypes.Header, size int, gasLimit int64, + header tmtypes.Header, size int, curBlockHash tmbytes.HexBytes, gasLimit int64, gasUsed *big.Int, transactions interface{}, bloom ethtypes.Bloom, ) map[string]interface{} { if len(header.DataHash) == 0 { @@ -164,7 +164,7 @@ func FormatBlock( return map[string]interface{}{ "number": hexutil.Uint64(header.Height), - "hash": hexutil.Bytes(header.Hash()), + "hash": hexutil.Bytes(curBlockHash), "parentHash": hexutil.Bytes(header.LastBlockID.Hash), "nonce": hexutil.Uint64(0), // PoW specific "sha3Uncles": common.Hash{}, // No uncles in Tendermint diff --git a/x/evm/client/rest/rest.go b/x/evm/client/rest/rest.go index 2f7818eb3..01ee019fc 100644 --- a/x/evm/client/rest/rest.go +++ b/x/evm/client/rest/rest.go @@ -81,7 +81,7 @@ func getEthTransactionByHash(clientCtx client.Context, hashHex string) ([]byte, return nil, err } - blockHash := common.BytesToHash(block.Block.Header.Hash()) + blockHash := common.BytesToHash(block.Block.Hash()) ethTx, err := rpctypes.RawTxToEthTx(clientCtx, tx.Tx) if err != nil {