mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
more debug
This commit is contained in:
parent
bf15e31b79
commit
996c4d1319
2 changed files with 46 additions and 4 deletions
|
|
@ -545,17 +545,17 @@ func (ethash *Ethash) verifySeal(chain consensus.ChainReader, header *types.Head
|
|||
nonce := header.Nonce.Uint64()
|
||||
ctx = append(ctx, "hdr.nonce", nonce)
|
||||
sealHash := ethash.SealHash(header).Bytes()
|
||||
ctx = append(ctx, "sealHash", sealHash)
|
||||
ctx = append(ctx, "sealHash", fmt.Sprintf("%x", sealHash))
|
||||
digest, result = hashimotoLight(size, cache.cache, sealHash, nonce)
|
||||
ctx = append(ctx, "result", result)
|
||||
ctx = append(ctx, "result", fmt.Sprintf("%x", 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[:])
|
||||
ctx = append(ctx, "digest", fmt.Sprintf("%x", digest))
|
||||
ctx = append(ctx, "hdr.digest", fmt.Sprintf("%x", header.MixDigest[:]))
|
||||
log.Error("Invalid mix digest", ctx...)
|
||||
return errInvalidMixDigest
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
package ethash
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
|
|
@ -167,3 +169,43 @@ func TestClosedRemoteSealer(t *testing.T) {
|
|||
t.Error("expect to return false when submit hashrate to a stopped ethash")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEthashVerification(t *testing.T) {
|
||||
|
||||
/*
|
||||
ERROR[01-20|14:19:41.708] Invalid mix digest
|
||||
number=5901768 datasetSize=2717907328 hdr.nonce=8774555798626709531
|
||||
sealHash="[69 201 230 234 206 75 24 9 247 242 180 231 191 184 43 24 242 195 86 93 114 177 250 81 31 11 16 38 7 157 51 241]"
|
||||
result="[103 158 62 246 38 246 6 82 71 33 210 238 177 37 178 13 191 241 61 186 140 226 136 148 83 111 108 166 252 245 249 55]"
|
||||
digest="[243 53 19 163 179 107 241 143 214 217 69 240 230 214 186 30 147 91 37 133 63 119 50 135 143 2 34 91 56 44 57 133]"
|
||||
hdr.digest="[7 230 161 170 212 130 52 40 152 14 130 41 51 80 133 198 228 85 153 243 214 89 81 206 124 121 106 216 112 129 235 114]"
|
||||
*/
|
||||
engine := New(Config{
|
||||
CacheDir: "",
|
||||
CachesInMem: 2,
|
||||
CachesOnDisk: 3,
|
||||
DatasetDir: "",
|
||||
DatasetsInMem: 1,
|
||||
DatasetsOnDisk: 2,
|
||||
}, nil, false)
|
||||
|
||||
var (
|
||||
number = uint64(5901768)
|
||||
nonce = uint64(8774555798626709531)
|
||||
sealHash = []byte{69, 201, 230, 234, 206, 75, 24, 9, 247, 242, 180, 231, 191, 184,
|
||||
43, 24, 242, 195, 86, 93, 114, 177, 250, 81, 31, 11, 16, 38, 7, 157, 51, 241}
|
||||
)
|
||||
cache := engine.cache(number)
|
||||
size := datasetSize(number)
|
||||
fmt.Printf("datasetSize: %d\n", size)
|
||||
digest, result := hashimotoLight(size, cache.cache, sealHash, nonce)
|
||||
fmt.Printf("nonce: %v\n", nonce)
|
||||
fmt.Printf("sealHash: %x\n", sealHash)
|
||||
fmt.Printf("result: %x\n", result)
|
||||
fmt.Println()
|
||||
fmt.Printf("digest: %x\n", digest)
|
||||
expDigest,_ := hexutil.Decode("07e6a1aad4823428980e8229335085c6e45599f3d65951ce7c796ad87081eb72")
|
||||
if bytes.Equal(expDigest, digest){
|
||||
t.Errorf("Mix digest wrong!, got %x exp %x",digest, expDigest )
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue