Basic structure miner

This commit is contained in:
obscuren
2015-02-09 16:20:34 +01:00
parent b22f0f2ef5
commit da2fae0e43
9 changed files with 198 additions and 293 deletions

View File

@ -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) {