diff options
author | obscuren <geffobscura@gmail.com> | 2015-02-09 23:20:34 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-02-10 20:04:38 +0800 |
commit | da2fae0e437f9467a943acfe0571a8a24e8e76fd (patch) | |
tree | d760375fbcd441a6460c1ea1d7db930f78e1df20 /pow | |
parent | b22f0f2ef51bdb769259b3cf7d9ee0e8e5b0635e (diff) | |
download | go-tangerine-da2fae0e437f9467a943acfe0571a8a24e8e76fd.tar go-tangerine-da2fae0e437f9467a943acfe0571a8a24e8e76fd.tar.gz go-tangerine-da2fae0e437f9467a943acfe0571a8a24e8e76fd.tar.bz2 go-tangerine-da2fae0e437f9467a943acfe0571a8a24e8e76fd.tar.lz go-tangerine-da2fae0e437f9467a943acfe0571a8a24e8e76fd.tar.xz go-tangerine-da2fae0e437f9467a943acfe0571a8a24e8e76fd.tar.zst go-tangerine-da2fae0e437f9467a943acfe0571a8a24e8e76fd.zip |
Basic structure miner
Diffstat (limited to 'pow')
-rw-r--r-- | pow/ezp/pow.go | 29 |
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) { |