From 5b14a73708b3541d64a06a340eb3083fb16deac6 Mon Sep 17 00:00:00 2001 From: iquidus Date: Fri, 13 Nov 2020 17:50:59 +0100 Subject: [PATCH] ethash/sealer: use epoch boundary + 1 (not block number) for seedHash in makeWork - fixes #234 --- consensus/ethash/algorithm.go | 3 ++- consensus/ethash/sealer.go | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/consensus/ethash/algorithm.go b/consensus/ethash/algorithm.go index 2593e29e4cd2a..c6ad295e160f1 100644 --- a/consensus/ethash/algorithm.go +++ b/consensus/ethash/algorithm.go @@ -133,7 +133,8 @@ func makeHasher(h hash.Hash) hasher { } // seedHash is the seed to use for generating a verification cache and the mining -// dataset. +// dataset. The block number passed should be pre-rounded to an epoch boundary + 1 +// e.g: epoch * epochLength + 1 func seedHash(block uint64) []byte { seed := make([]byte, 32) if block < epochLengthDefault { diff --git a/consensus/ethash/sealer.go b/consensus/ethash/sealer.go index 205353402852e..08f6db8c980cd 100644 --- a/consensus/ethash/sealer.go +++ b/consensus/ethash/sealer.go @@ -344,8 +344,10 @@ func (s *remoteSealer) loop() { // result[3], hex encoded block number func (s *remoteSealer) makeWork(block *types.Block) { hash := s.ethash.SealHash(block.Header()) + epochLength := calcEpochLength(block.NumberU64(), s.ethash.config.ECIP1099Block) + epoch := calcEpoch(block.NumberU64(), epochLength) s.currentWork[0] = hash.Hex() - s.currentWork[1] = common.BytesToHash(SeedHash(block.NumberU64())).Hex() + s.currentWork[1] = common.BytesToHash(SeedHash(epoch*epochLength + 1)).Hex() s.currentWork[2] = common.BytesToHash(new(big.Int).Div(two256, block.Difficulty()).Bytes()).Hex() s.currentWork[3] = hexutil.EncodeBig(block.Number())