diff --git a/consensus/ethash/algorithm.go b/consensus/ethash/algorithm.go index d6c871092e..2b01f2843e 100644 --- a/consensus/ethash/algorithm.go +++ b/consensus/ethash/algorithm.go @@ -18,6 +18,7 @@ package ethash import ( "encoding/binary" + "fmt" "hash" "math/big" "reflect" @@ -374,7 +375,7 @@ func hashimoto(hash []byte, nonce uint64, size uint64, lookup func(index uint32) // hashimotoLight aggregates data from the full dataset (using only a small // in-memory cache) in order to produce our final value for a particular header // hash and nonce. -func hashimotoLight(size uint64, cache []uint32, hash []byte, nonce uint64) ([]byte, []byte) { +func hashimotoLight(size uint64, cache []uint32, hash []byte, nonce uint64, verbose bool) ([]byte, []byte) { keccak512 := makeHasher(sha3.NewLegacyKeccak512()) lookup := func(index uint32) []uint32 { @@ -384,6 +385,9 @@ func hashimotoLight(size uint64, cache []uint32, hash []byte, nonce uint64) ([]b for i := 0; i < len(data); i++ { data[i] = binary.LittleEndian.Uint32(rawData[i*4:]) } + if verbose { + fmt.Printf("lookup(%d)=%x\n", index, data) + } return data } return hashimoto(hash, nonce, size, lookup) diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index c71001f424..d427f1b353 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -546,17 +546,21 @@ func (ethash *Ethash) verifySeal(chain consensus.ChainReader, header *types.Head ctx = append(ctx, "hdr.nonce", nonce) sealHash := ethash.SealHash(header).Bytes() ctx = append(ctx, "sealHash", fmt.Sprintf("%x", sealHash)) - digest, result = hashimotoLight(size, cache.cache, sealHash, nonce) + verbose := (number == 5901768) + + digest, result = hashimotoLight(size, cache.cache, sealHash, nonce, verbose) ctx = append(ctx, "result", fmt.Sprintf("%x", result)) ctx = append(ctx, "epoch", cache.epoch) ctx = append(ctx, "cachedir", ethash.config.CacheDir) ctx = append(ctx, "datasetdir", ethash.config.DatasetDir) // For debuggging only - sum := uint32(0) - for _, val := range cache.cache { - sum = sum ^ val + if verbose { + sum := uint32(0) + for _, val := range cache.cache { + sum = sum ^ val + } + ctx = append(ctx, "cachexor", fmt.Sprintf("%x", sum)) } - ctx = append(ctx, "cachexor", fmt.Sprintf("%x", sum)) // Caches are unmapped in a finalizer. Ensure that the cache stays alive // until after the call to hashimotoLight so it's not unmapped while being used.