Skip to content

Commit

Permalink
fix: ethtypes: Correct 'no transactions' hash in NewEthBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Feb 6, 2023
1 parent 4248240 commit 5dc5684
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions chain/types/ethtypes/eth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,19 @@ type EthBlock struct {
}

var (
EmptyEthBloom = [256]byte{}
EmptyEthHash = EthHash{}
NoUncleHash = must.One(ParseEthHash("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"))
EmptyEthInt = EthUint64(0)
EmptyEthNonce = [8]byte{0, 0, 0, 0, 0, 0, 0, 0}
EmptyEthBloom = [256]byte{}
EmptyEthHash = EthHash{}
EmptyUncleHash = must.One(ParseEthHash("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347")) // Keccak-256 of an RLP of an empty array
EmptyRootHash = must.One(ParseEthHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")) // Keccak-256 hash of the RLP of null
EmptyEthInt = EthUint64(0)
EmptyEthNonce = [8]byte{0, 0, 0, 0, 0, 0, 0, 0}
)

func NewEthBlock() EthBlock {
return EthBlock{
Sha3Uncles: NoUncleHash,
func NewEthBlock(hasTransactions bool) EthBlock {
b := EthBlock{
Sha3Uncles: EmptyUncleHash, // Sha3Uncles set to a hardcoded value which is used by some clients to determine if has no uncles.
StateRoot: EmptyEthHash,
TransactionsRoot: EmptyEthHash,
TransactionsRoot: EmptyRootHash, // TransactionsRoot set to a hardcoded value which is used by some clients to determine if has no transactions.
ReceiptsRoot: EmptyEthHash,
Difficulty: EmptyEthInt,
LogsBloom: EmptyEthBloom[:],
Expand All @@ -178,6 +179,11 @@ func NewEthBlock() EthBlock {
Uncles: []EthHash{},
Transactions: []interface{}{},
}
if hasTransactions {
b.TransactionsRoot = EmptyEthHash
}

return b
}

type EthCall struct {
Expand Down
2 changes: 1 addition & 1 deletion node/impl/full/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@ func newEthBlockFromFilecoinTipSet(ctx context.Context, ts *types.TipSet, fullTx
return ethtypes.EthBlock{}, xerrors.Errorf("error loading messages for tipset: %v: %w", ts, err)
}

block := ethtypes.NewEthBlock()
block := ethtypes.NewEthBlock(len(msgs) > 0)

// this seems to be a very expensive way to get gasUsed of the block. may need to find an efficient way to do it
gasUsed := int64(0)
Expand Down

0 comments on commit 5dc5684

Please sign in to comment.