aboutsummaryrefslogtreecommitdiffstats
path: root/pow/ezp/pow.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-02-09 23:20:34 +0800
committerobscuren <geffobscura@gmail.com>2015-02-10 20:04:38 +0800
commitda2fae0e437f9467a943acfe0571a8a24e8e76fd (patch)
treed760375fbcd441a6460c1ea1d7db930f78e1df20 /pow/ezp/pow.go
parentb22f0f2ef51bdb769259b3cf7d9ee0e8e5b0635e (diff)
downloadgo-tangerine-da2fae0e437f9467a943acfe0571a8a24e8e76fd.tar.gz
go-tangerine-da2fae0e437f9467a943acfe0571a8a24e8e76fd.tar.zst
go-tangerine-da2fae0e437f9467a943acfe0571a8a24e8e76fd.zip
Basic structure miner
Diffstat (limited to 'pow/ezp/pow.go')
-rw-r--r--pow/ezp/pow.go29
1 files changed, 18 insertions, 11 deletions
diff --git a/pow/ezp/pow.go b/pow/ezp/pow.go
index e4caa076a..5571e73cd 100644
--- a/pow/ezp/pow.go
+++ b/pow/ezp/pow.go
@@ -21,7 +21,7 @@ type EasyPow struct {
}
func New() *EasyPow {
- return &EasyPow{turbo: false}
+ return &EasyPow{turbo: true}
}
func (pow *EasyPow) GetHashrate() int64 {
@@ -36,26 +36,33 @@ func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) []byte {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
hash := block.HashNoNonce()
diff := block.Difficulty()
- i := int64(0)
+ //i := int64(0)
+ // TODO fix offset
+ i := rand.Int63()
+ starti := i
start := time.Now().UnixNano()
- t := time.Now()
+
+ // Make sure stop is empty
+empty:
+ for {
+ select {
+ case <-stop:
+ default:
+ break empty
+ }
+ }
for {
select {
case <-stop:
- powlogger.Infoln("Breaking from mining")
pow.HashRate = 0
return nil
default:
i++
- if time.Since(t) > (1 * time.Second) {
- elapsed := time.Now().UnixNano() - start
- hashes := ((float64(1e9) / float64(elapsed)) * float64(i)) / 1000
- pow.HashRate = int64(hashes)
-
- t = time.Now()
- }
+ elapsed := time.Now().UnixNano() - start
+ hashes := ((float64(1e9) / float64(elapsed)) * float64(i-starti)) / 1000
+ pow.HashRate = int64(hashes)
sha := crypto.Sha3(big.NewInt(r.Int63()).Bytes())
if verify(hash, diff, sha) {