good morning!!!!

Skip to content
Snippets Groups Projects
Commit be303ba1 authored by Gustav Simonsson's avatar Gustav Simonsson
Browse files

Update ethash Godep (again)

parent a9d6846f
Branches
Tags
No related merge requests found
......@@ -21,8 +21,8 @@
},
{
"ImportPath": "github.com/ethereum/ethash",
"Comment": "v23.1-222-g5cfdcba",
"Rev": "5cfdcba92e634db228d1ddb140e3b7a3c4b38177"
"Comment": "v23.1-222-g173b8ff",
"Rev": "173b8ff953610c13710061e83b95b50c73d7ea50"
},
{
"ImportPath": "github.com/howeyc/fsnotify",
......
......@@ -8,7 +8,6 @@ int ethashGoCallback_cgo(unsigned);
import "C"
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
......@@ -122,7 +121,7 @@ func (l *Light) Verify(block pow.Block) bool {
}
// avoid mixdigest malleability as it's not included in a block's "hashNononce"
if !bytes.Equal(block.MixDigest().Bytes(), C.GoBytes(unsafe.Pointer(&ret.mix_hash), C.int(32))) {
if block.MixDigest() != h256ToHash(ret.mix_hash) {
return false
}
......
......@@ -39,6 +39,7 @@ var validBlocks = []*testBlock{
hashNoNonce: common.HexToHash("372eca2454ead349c3df0ab5d00b0b706b23e49d469387db91811cee0358fc6d"),
difficulty: big.NewInt(132416),
nonce: 0x495732e0ed7a801c,
mixDigest: common.HexToHash("2f74cdeb198af0b9abe65d22d372e22fb2d474371774a9583c1cc427a07939f5"),
},
// from proof of concept nine testnet, epoch 1
{
......@@ -46,6 +47,7 @@ var validBlocks = []*testBlock{
hashNoNonce: common.HexToHash("7e44356ee3441623bc72a683fd3708fdf75e971bbe294f33e539eedad4b92b34"),
difficulty: big.NewInt(1532671),
nonce: 0x318df1c8adef7e5e,
mixDigest: common.HexToHash("144b180aad09ae3c81fb07be92c8e6351b5646dda80e6844ae1b697e55ddde84"),
},
// from proof of concept nine testnet, epoch 2
{
......@@ -53,6 +55,7 @@ var validBlocks = []*testBlock{
hashNoNonce: common.HexToHash("5fc898f16035bf5ac9c6d9077ae1e3d5fc1ecc3c9fd5bee8bb00e810fdacbaa0"),
difficulty: big.NewInt(2467358),
nonce: 0x50377003e5d830ca,
mixDigest: common.HexToHash("ab546a5b73c452ae86dadd36f0ed83a6745226717d3798832d1b20b489e82063"),
},
}
......@@ -73,8 +76,9 @@ func TestEthashConcurrentVerify(t *testing.T) {
defer os.RemoveAll(eth.Full.Dir)
block := &testBlock{difficulty: big.NewInt(10)}
nonce, _ := eth.Search(block, nil)
nonce, md := eth.Search(block, nil)
block.nonce = nonce
block.mixDigest = common.BytesToHash(md)
// Verify the block concurrently to check for data races.
var wg sync.WaitGroup
......@@ -98,21 +102,26 @@ func TestEthashConcurrentSearch(t *testing.T) {
eth.Turbo(true)
defer os.RemoveAll(eth.Full.Dir)
// launch n searches concurrently.
type searchRes struct {
n uint64
md []byte
}
var (
block = &testBlock{difficulty: big.NewInt(35000)}
nsearch = 10
wg = new(sync.WaitGroup)
found = make(chan uint64)
found = make(chan searchRes)
stop = make(chan struct{})
)
rand.Read(block.hashNoNonce[:])
wg.Add(nsearch)
// launch n searches concurrently.
for i := 0; i < nsearch; i++ {
go func() {
nonce, _ := eth.Search(block, stop)
nonce, md := eth.Search(block, stop)
select {
case found <- nonce:
case found <- searchRes{n: nonce, md: md}:
case <-stop:
}
wg.Done()
......@@ -120,12 +129,14 @@ func TestEthashConcurrentSearch(t *testing.T) {
}
// wait for one of them to find the nonce
nonce := <-found
res := <-found
// stop the others
close(stop)
wg.Wait()
if block.nonce = nonce; !eth.Verify(block) {
block.nonce = res.n
block.mixDigest = common.BytesToHash(res.md)
if !eth.Verify(block) {
t.Error("Block could not be verified")
}
}
......@@ -140,8 +151,9 @@ func TestEthashSearchAcrossEpoch(t *testing.T) {
for i := epochLength - 40; i < epochLength+40; i++ {
block := &testBlock{number: i, difficulty: big.NewInt(90)}
rand.Read(block.hashNoNonce[:])
nonce, _ := eth.Search(block, nil)
nonce, md := eth.Search(block, nil)
block.nonce = nonce
block.mixDigest = common.BytesToHash(md)
if !eth.Verify(block) {
t.Fatalf("Block could not be verified")
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment