rpc: fix empty root and uncle hash (#45)

* rpc: fix empty root and uncle hash

* changelog
This commit is contained in:
Federico Kunze 2021-05-26 06:33:24 -04:00 committed by GitHub
parent 6c1e7fec01
commit 956b18f45e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 12 deletions

View File

@ -46,6 +46,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (evm) [tharsis#24](https://github.com/tharsis/ethermint/pull/24)Implement metrics for `MsgEthereumTx`, state transtitions, `BeginBlock` and `EndBlock`.
* (deps) [\#602](https://github.com/cosmos/ethermint/pull/856) Bump tendermint version to [v0.39.3](https://github.com/tendermint/tendermint/releases/tag/v0.39.3)
### Bug Fixes
* (rpc) [tharsis#45](https://github.com/tharsis/ethermint/pull/45) Use `EmptyUncleHash` and `EmptyRootHash` for empty ethereum `Header` fields.
## [v0.4.1] - 2021-03-01
### API Breaking

View File

@ -108,15 +108,22 @@ func NewTransaction(tx *ethtypes.Transaction, blockHash common.Hash, blockNumber
// EthHeaderFromTendermint is an util function that returns an Ethereum Header
// from a tendermint Header.
func EthHeaderFromTendermint(header tmtypes.Header) *ethtypes.Header {
txHash := ethtypes.EmptyRootHash
if len(header.DataHash) == 0 {
txHash = common.BytesToHash(header.DataHash)
}
return &ethtypes.Header{
ParentHash: common.BytesToHash(header.LastBlockID.Hash.Bytes()),
UncleHash: common.Hash{},
UncleHash: ethtypes.EmptyUncleHash,
Coinbase: common.Address{},
Root: common.BytesToHash(header.AppHash),
TxHash: common.BytesToHash(header.DataHash),
ReceiptHash: common.Hash{},
Difficulty: nil,
TxHash: txHash,
ReceiptHash: ethtypes.EmptyRootHash,
Bloom: ethtypes.Bloom{},
Difficulty: big.NewInt(0),
Number: big.NewInt(header.Height),
GasLimit: 0,
GasUsed: 0,
Time: uint64(header.Time.Unix()),
Extra: nil,
MixDigest: common.Hash{},
@ -176,23 +183,24 @@ func FormatBlock(
"number": hexutil.Uint64(header.Height),
"hash": hexutil.Bytes(header.Hash()),
"parentHash": hexutil.Bytes(header.LastBlockID.Hash),
"nonce": hexutil.Uint64(0), // PoW specific
"sha3Uncles": common.Hash{}, // No uncles in Tendermint
"nonce": hexutil.Uint64(0), // PoW specific
"sha3Uncles": ethtypes.EmptyUncleHash, // No uncles in Tendermint
"logsBloom": bloom,
"transactionsRoot": hexutil.Bytes(header.DataHash),
"stateRoot": hexutil.Bytes(header.AppHash),
"miner": common.Address{},
"mixHash": common.Hash{},
"difficulty": 0,
"totalDifficulty": 0,
"difficulty": (*hexutil.Big)(big.NewInt(0)),
"extraData": hexutil.Uint64(0),
"size": hexutil.Uint64(size),
"gasLimit": hexutil.Uint64(gasLimit), // Static gas limit
"gasUsed": (*hexutil.Big)(gasUsed),
"timestamp": hexutil.Uint64(header.Time.Unix()),
"transactions": transactions.([]common.Hash),
"uncles": []string{},
"receiptsRoot": common.Hash{},
"transactionsRoot": hexutil.Bytes(header.DataHash),
"receiptsRoot": ethtypes.EmptyRootHash,
"uncles": []common.Hash{},
"transactions": transactions.([]common.Hash),
"totalDifficulty": (*hexutil.Big)(big.NewInt(0)),
}
}
@ -308,6 +316,10 @@ func NewTransactionFromData(
to = &recipient
}
if txHash == (common.Hash{}) {
txHash = ethtypes.EmptyRootHash
}
rpcTx := &RPCTransaction{
From: from,
Gas: hexutil.Uint64(txData.GasLimit),