Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

rpc: fix empty root and uncle hash #45

Merged
merged 2 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


## [v0.4.1] - 2021-03-01

### API Breaking
Expand Down
36 changes: 24 additions & 12 deletions ethereum/rpc/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down Expand Up @@ -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)),
}
}

Expand Down Expand Up @@ -308,6 +316,10 @@ func NewTransactionFromData(
to = &recipient
}

if txHash == (common.Hash{}) {
txHash = ethtypes.EmptyRootHash
}

rpcTx := &RPCTransaction{
From: from,
Gas: hexutil.Uint64(txData.GasLimit),
Expand Down