|
|
@ -1,11 +1,11 @@ |
|
|
|
package ezp |
|
|
|
package ezp |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"encoding/binary" |
|
|
|
"math/big" |
|
|
|
"math/big" |
|
|
|
"math/rand" |
|
|
|
"math/rand" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/crypto" |
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/crypto/sha3" |
|
|
|
"github.com/ethereum/go-ethereum/crypto/sha3" |
|
|
|
"github.com/ethereum/go-ethereum/ethutil" |
|
|
|
"github.com/ethereum/go-ethereum/ethutil" |
|
|
|
"github.com/ethereum/go-ethereum/logger" |
|
|
|
"github.com/ethereum/go-ethereum/logger" |
|
|
@ -32,7 +32,7 @@ func (pow *EasyPow) Turbo(on bool) { |
|
|
|
pow.turbo = on |
|
|
|
pow.turbo = on |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) ([]byte, []byte, []byte) { |
|
|
|
func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) (uint64, []byte, []byte) { |
|
|
|
r := rand.New(rand.NewSource(time.Now().UnixNano())) |
|
|
|
r := rand.New(rand.NewSource(time.Now().UnixNano())) |
|
|
|
hash := block.HashNoNonce() |
|
|
|
hash := block.HashNoNonce() |
|
|
|
diff := block.Difficulty() |
|
|
|
diff := block.Difficulty() |
|
|
@ -57,7 +57,7 @@ empty: |
|
|
|
for { |
|
|
|
for { |
|
|
|
select { |
|
|
|
select { |
|
|
|
case <-stop: |
|
|
|
case <-stop: |
|
|
|
return nil, nil, nil |
|
|
|
return 0, nil, nil |
|
|
|
default: |
|
|
|
default: |
|
|
|
i++ |
|
|
|
i++ |
|
|
|
|
|
|
|
|
|
|
@ -65,7 +65,7 @@ empty: |
|
|
|
hashes := ((float64(1e9) / float64(elapsed)) * float64(i-starti)) / 1000 |
|
|
|
hashes := ((float64(1e9) / float64(elapsed)) * float64(i-starti)) / 1000 |
|
|
|
pow.HashRate = int64(hashes) |
|
|
|
pow.HashRate = int64(hashes) |
|
|
|
|
|
|
|
|
|
|
|
sha := crypto.Sha3(big.NewInt(r.Int63()).Bytes()) |
|
|
|
sha := uint64(r.Int63()) |
|
|
|
if verify(hash, diff, sha) { |
|
|
|
if verify(hash, diff, sha) { |
|
|
|
return sha, nil, nil |
|
|
|
return sha, nil, nil |
|
|
|
} |
|
|
|
} |
|
|
@ -75,16 +75,20 @@ empty: |
|
|
|
time.Sleep(20 * time.Microsecond) |
|
|
|
time.Sleep(20 * time.Microsecond) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0, nil, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (pow *EasyPow) Verify(block pow.Block) bool { |
|
|
|
func (pow *EasyPow) Verify(block pow.Block) bool { |
|
|
|
return Verify(block) |
|
|
|
return Verify(block) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func verify(hash []byte, diff *big.Int, nonce []byte) bool { |
|
|
|
func verify(hash []byte, diff *big.Int, nonce uint64) bool { |
|
|
|
sha := sha3.NewKeccak256() |
|
|
|
sha := sha3.NewKeccak256() |
|
|
|
|
|
|
|
|
|
|
|
d := append(hash, nonce...) |
|
|
|
n := make([]byte, 8) |
|
|
|
|
|
|
|
binary.PutUvarint(n, nonce) |
|
|
|
|
|
|
|
d := append(hash, n...) |
|
|
|
sha.Write(d) |
|
|
|
sha.Write(d) |
|
|
|
|
|
|
|
|
|
|
|
verification := new(big.Int).Div(ethutil.BigPow(2, 256), diff) |
|
|
|
verification := new(big.Int).Div(ethutil.BigPow(2, 256), diff) |
|
|
|