aboutsummaryrefslogtreecommitdiffstats
path: root/pow/ezp
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-10 00:55:01 +0800
committerobscuren <geffobscura@gmail.com>2015-03-10 00:55:01 +0800
commit8560004f380dc688a1171ad5aeffa593aae41193 (patch)
treefea395acf042b51e97a86e2c4cbcf8c16b2912b7 /pow/ezp
parent9723191b19f6ddc12f0c3376ede7529b2d72e6a2 (diff)
parent676a0de58d3d7c508b0eeeff192d2095a46f7382 (diff)
downloaddexon-8560004f380dc688a1171ad5aeffa593aae41193.tar.gz
dexon-8560004f380dc688a1171ad5aeffa593aae41193.tar.zst
dexon-8560004f380dc688a1171ad5aeffa593aae41193.zip
wip
Diffstat (limited to 'pow/ezp')
-rw-r--r--pow/ezp/pow.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/pow/ezp/pow.go b/pow/ezp/pow.go
index 540381243..3ca502d06 100644
--- a/pow/ezp/pow.go
+++ b/pow/ezp/pow.go
@@ -1,11 +1,11 @@
package ezp
import (
+ "encoding/binary"
"math/big"
"math/rand"
"time"
- "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/sha3"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
@@ -32,7 +32,7 @@ func (pow *EasyPow) Turbo(on bool) {
pow.turbo = on
}
-func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) []byte {
+func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) (uint64, []byte, []byte) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
hash := block.HashNoNonce()
diff := block.Difficulty()
@@ -57,7 +57,7 @@ empty:
for {
select {
case <-stop:
- return nil
+ return 0, nil, nil
default:
i++
@@ -65,9 +65,9 @@ empty:
hashes := ((float64(1e9) / float64(elapsed)) * float64(i-starti)) / 1000
pow.HashRate = int64(hashes)
- sha := crypto.Sha3(big.NewInt(r.Int63()).Bytes())
+ sha := uint64(r.Int63())
if verify(hash, diff, sha) {
- return sha
+ return sha, nil, nil
}
}
@@ -76,17 +76,19 @@ empty:
}
}
- return nil
+ return 0, nil, nil
}
func (pow *EasyPow) Verify(block pow.Block) bool {
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()
- d := append(hash, nonce...)
+ n := make([]byte, 8)
+ binary.PutUvarint(n, nonce)
+ d := append(hash, n...)
sha.Write(d)
verification := new(big.Int).Div(ethutil.BigPow(2, 256), diff)
@@ -96,5 +98,5 @@ func verify(hash []byte, diff *big.Int, nonce []byte) bool {
}
func Verify(block pow.Block) bool {
- return verify(block.HashNoNonce(), block.Difficulty(), block.N())
+ return verify(block.HashNoNonce(), block.Difficulty(), block.Nonce())
}