Updated server and peers and mining processing

This commit is contained in:
obscuren
2014-01-10 00:39:16 +01:00
parent 849408dda6
commit bd0abe2a81
4 changed files with 110 additions and 48 deletions

View File

@@ -2,7 +2,6 @@ package main
import (
"math/big"
"fmt"
"math/rand"
"time"
"github.com/obscuren/sha3"
@@ -26,8 +25,6 @@ func (dag *Dagger) Find(obj *big.Int, resChan chan int64) {
resChan <- rnd
// Notify other threads we've found a valid nonce
Found = true
} else {
fmt.Printf(".")
}
// Break out if found
@@ -37,17 +34,15 @@ func (dag *Dagger) Find(obj *big.Int, resChan chan int64) {
resChan <- 0
}
func (dag *Dagger) Search(diff *big.Int) *big.Int {
func (dag *Dagger) Search(hash, diff *big.Int) *big.Int {
// TODO fix multi threading. Somehow it results in the wrong nonce
amountOfRoutines := 1
dag.hash = big.NewInt(0)
dag.hash = hash
obj := BigPow(2, 256)
obj = obj.Div(obj, diff)
fmt.Println("diff", diff, "< objective", obj)
Found = false
resChan := make(chan int64, 3)
var res int64
@@ -64,8 +59,6 @@ func (dag *Dagger) Search(diff *big.Int) *big.Int {
}
}
fmt.Println("\n")
return big.NewInt(res)
}
@@ -128,32 +121,21 @@ func (dag *Dagger) Eval(N *big.Int) *big.Int {
sha.Reset()
ret := new(big.Int)
//doneChan := make(chan bool, 3)
for k := 0; k < 4; k++ {
//go func(_k int) {
_k := k
d := sha3.NewKeccak224()
b := new(big.Int)
d := sha3.NewKeccak224()
b := new(big.Int)
d.Reset()
d.Write(dag.hash.Bytes())
d.Write(dag.xn.Bytes())
d.Write(N.Bytes())
d.Write(big.NewInt(int64(_k)).Bytes())
d.Reset()
d.Write(dag.hash.Bytes())
d.Write(dag.xn.Bytes())
d.Write(N.Bytes())
d.Write(big.NewInt(int64(k)).Bytes())
b.SetBytes(Sum(d))
pk := (b.Uint64() & 0x1ffffff)
b.SetBytes(Sum(d))
pk := (b.Uint64() & 0x1ffffff)
sha.Write(dag.Node(9, pk).Bytes())
//doneChan <- true
//}(k)
sha.Write(dag.Node(9, pk).Bytes())
}
//for k := 0; k < 4; k++ {
// <- doneChan
//}
return ret.SetBytes(Sum(sha))
}