From 3475a4b22586fb443aa35e380b2d3eb143d998b4 Mon Sep 17 00:00:00 2001 From: kane Date: Mon, 30 Jul 2018 02:16:23 -0400 Subject: [PATCH 1/2] catch error if rlp.Encode failed --- core/types/block.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/types/block.go b/core/types/block.go index ae1b4299d3..ddc7e4c097 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -129,7 +129,10 @@ func (h *Header) Size() common.StorageSize { func rlpHash(x interface{}) (h common.Hash) { hw := sha3.NewKeccak256() - rlp.Encode(hw, x) + err := rlp.Encode(hw, x) + if err != nil { + panic("encode error: " + err.Error()) + } hw.Sum(h[:0]) return h } From ef42a3dffdfef87e83a6501a358b00513b31e93d Mon Sep 17 00:00:00 2001 From: kane Date: Mon, 30 Jul 2018 06:26:51 -0400 Subject: [PATCH 2/2] fix --- core/types/block.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/types/block.go b/core/types/block.go index ddc7e4c097..0797af9342 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -137,6 +137,12 @@ func rlpHash(x interface{}) (h common.Hash) { return h } +func hash(x interface{}) (h common.Hash) { + hw := sha3.NewKeccak256() + hw.Sum(h[:0]) + return h +} + // Body is a simple (mutable, non-safe) data container for storing and moving // a block's data contents (transactions and uncles) together. type Body struct { @@ -351,7 +357,7 @@ func (c *writeCounter) Write(b []byte) (int, error) { } func CalcUncleHash(uncles []*Header) common.Hash { - return rlpHash(uncles) + return hash(uncles) } // WithSeal returns a new block with the data from b but the header replaced with