From bf15e31b791c219bf43065a7e880bc7da2788ad7 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 16 Jan 2020 10:03:24 +0100 Subject: [PATCH] consensus/ethash: verbose output on mixhash errror --- consensus/ethash/consensus.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 8ae99b1994..c4c222c25c 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -20,6 +20,7 @@ import ( "bytes" "errors" "fmt" + "github.com/ethereum/go-ethereum/log" "math/big" "runtime" "time" @@ -532,21 +533,30 @@ func (ethash *Ethash) verifySeal(chain consensus.ChainReader, header *types.Head } } // If slow-but-light PoW verification was requested (or DAG not yet ready), use an ethash cache + var ctx []interface{} if !fulldag { cache := ethash.cache(number) - + ctx = append(ctx, "number", number) size := datasetSize(number) if ethash.config.PowMode == ModeTest { size = 32 * 1024 } - digest, result = hashimotoLight(size, cache.cache, ethash.SealHash(header).Bytes(), header.Nonce.Uint64()) - + ctx = append(ctx, "datasetSize", size) + nonce := header.Nonce.Uint64() + ctx = append(ctx, "hdr.nonce", nonce) + sealHash := ethash.SealHash(header).Bytes() + ctx = append(ctx, "sealHash", sealHash) + digest, result = hashimotoLight(size, cache.cache, sealHash, nonce) + ctx = append(ctx, "result", result) // 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. runtime.KeepAlive(cache) } // Verify the calculated values against the ones provided in the header if !bytes.Equal(header.MixDigest[:], digest) { + ctx = append(ctx, "digest", digest) + ctx = append(ctx, "hdr.digest", header.MixDigest[:]) + log.Error("Invalid mix digest", ctx...) return errInvalidMixDigest } target := new(big.Int).Div(two256, header.Difficulty)