rpc: fix method to calculate block hash and fix mismatch block hash in eth.getBlock response (#755)

This commit is contained in:
Louis Liu
2021-01-31 23:20:22 -03:00
committed by GitHub
parent e1349e46a3
commit 6d11e23326
4 changed files with 11 additions and 9 deletions
+3 -3
View File
@@ -90,7 +90,7 @@ func EthBlockFromTendermint(clientCtx clientcontext.CLIContext, block *tmtypes.B
bloom := bloomRes.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
@@ -153,7 +153,7 @@ func BlockMaxGasFromConsensusParams(_ context.Context, clientCtx clientcontext.C
// 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 {
@@ -162,7 +162,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