mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
detailed hashimoto debug
This commit is contained in:
parent
df2114616d
commit
c5f29f7510
2 changed files with 14 additions and 6 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
if verbose {
|
||||
sum := uint32(0)
|
||||
for _, val := range cache.cache {
|
||||
sum = sum ^ val
|
||||
}
|
||||
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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue