detailed hashimoto debug

This commit is contained in:
Martin Holst Swende 2020-01-21 10:49:54 +01:00
parent df2114616d
commit c5f29f7510
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
2 changed files with 14 additions and 6 deletions

View file

@ -18,6 +18,7 @@ package ethash
import ( import (
"encoding/binary" "encoding/binary"
"fmt"
"hash" "hash"
"math/big" "math/big"
"reflect" "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 // 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 // in-memory cache) in order to produce our final value for a particular header
// hash and nonce. // 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()) keccak512 := makeHasher(sha3.NewLegacyKeccak512())
lookup := func(index uint32) []uint32 { 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++ { for i := 0; i < len(data); i++ {
data[i] = binary.LittleEndian.Uint32(rawData[i*4:]) data[i] = binary.LittleEndian.Uint32(rawData[i*4:])
} }
if verbose {
fmt.Printf("lookup(%d)=%x\n", index, data)
}
return data return data
} }
return hashimoto(hash, nonce, size, lookup) return hashimoto(hash, nonce, size, lookup)

View file

@ -546,17 +546,21 @@ func (ethash *Ethash) verifySeal(chain consensus.ChainReader, header *types.Head
ctx = append(ctx, "hdr.nonce", nonce) ctx = append(ctx, "hdr.nonce", nonce)
sealHash := ethash.SealHash(header).Bytes() sealHash := ethash.SealHash(header).Bytes()
ctx = append(ctx, "sealHash", fmt.Sprintf("%x", sealHash)) 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, "result", fmt.Sprintf("%x", result))
ctx = append(ctx, "epoch", cache.epoch) ctx = append(ctx, "epoch", cache.epoch)
ctx = append(ctx, "cachedir", ethash.config.CacheDir) ctx = append(ctx, "cachedir", ethash.config.CacheDir)
ctx = append(ctx, "datasetdir", ethash.config.DatasetDir) ctx = append(ctx, "datasetdir", ethash.config.DatasetDir)
// For debuggging only // For debuggging only
sum := uint32(0) if verbose {
for _, val := range cache.cache { sum := uint32(0)
sum = sum ^ val 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 // 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. // until after the call to hashimotoLight so it's not unmapped while being used.