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

Commit

Permalink
rpc: fix empty root and uncle hash (#45)
Browse files Browse the repository at this point in the history
* rpc: fix empty root and uncle hash

* changelog
  • Loading branch information
fedekunze authored May 26, 2021
1 parent 6c1e7fe commit 956b18f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
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.

## [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

0 comments on commit 956b18f

Please sign in to comment.