aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2019-04-08 18:02:33 +0800
committerGitHub <noreply@github.com>2019-04-08 18:02:33 +0800
commit3996bc1ad91665ad30036713fba11840a36dfff0 (patch)
treef87a4f8483773301d158d8aab75e838733e19ab4 /core
parent2a8a07c2b35f5acea55671616ac4e92a2a48ab3a (diff)
parentd763b49ae3a7975157fed7886ef848ccd04e2e0e (diff)
downloadgo-tangerine-3996bc1ad91665ad30036713fba11840a36dfff0.tar
go-tangerine-3996bc1ad91665ad30036713fba11840a36dfff0.tar.gz
go-tangerine-3996bc1ad91665ad30036713fba11840a36dfff0.tar.bz2
go-tangerine-3996bc1ad91665ad30036713fba11840a36dfff0.tar.lz
go-tangerine-3996bc1ad91665ad30036713fba11840a36dfff0.tar.xz
go-tangerine-3996bc1ad91665ad30036713fba11840a36dfff0.tar.zst
go-tangerine-3996bc1ad91665ad30036713fba11840a36dfff0.zip
Merge pull request #19411 from holiman/uncle_abort_early
consensus,core: shortcut uncle validation
Diffstat (limited to 'core')
-rw-r--r--core/types/block.go5
-rw-r--r--core/types/block_test.go16
2 files changed, 20 insertions, 1 deletions
diff --git a/core/types/block.go b/core/types/block.go
index d611885f1..f754c3c48 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -34,7 +34,7 @@ import (
var (
EmptyRootHash = DeriveSha(Transactions{})
- EmptyUncleHash = CalcUncleHash(nil)
+ EmptyUncleHash = rlpHash([]*Header(nil))
)
// A BlockNonce is a 64-bit hash which proves (combined with the
@@ -324,6 +324,9 @@ func (c *writeCounter) Write(b []byte) (int, error) {
}
func CalcUncleHash(uncles []*Header) common.Hash {
+ if len(uncles) == 0 {
+ return EmptyUncleHash
+ }
return rlpHash(uncles)
}
diff --git a/core/types/block_test.go b/core/types/block_test.go
index 2576f2fbc..bdd0b6571 100644
--- a/core/types/block_test.go
+++ b/core/types/block_test.go
@@ -68,3 +68,19 @@ func TestBlockEncoding(t *testing.T) {
t.Errorf("encoded block mismatch:\ngot: %x\nwant: %x", ourBlockEnc, blockEnc)
}
}
+
+func TestUncleHash(t *testing.T) {
+ uncles := make([]*Header, 0)
+ h := CalcUncleHash(uncles)
+ exp := common.HexToHash("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347")
+ if h != exp {
+ t.Fatalf("empty uncle hash is wrong, got %x != %x", h, exp)
+ }
+}
+func BenchmarkUncleHash(b *testing.B) {
+ uncles := make([]*Header, 0)
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ CalcUncleHash(uncles)
+ }
+}