aboutsummaryrefslogtreecommitdiffstats
path: root/dagger.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-01-10 07:39:16 +0800
committerobscuren <geffobscura@gmail.com>2014-01-10 07:39:16 +0800
commitbd0abe2a8187c0ae948bba6a90cbaac07f479cc8 (patch)
treecf3fea9cb3cc09d75609aaffe11374f7e9a72d8b /dagger.go
parent849408dda60fe32d7abb78d103b09ca0bc7b5a60 (diff)
downloadgo-tangerine-bd0abe2a8187c0ae948bba6a90cbaac07f479cc8.tar
go-tangerine-bd0abe2a8187c0ae948bba6a90cbaac07f479cc8.tar.gz
go-tangerine-bd0abe2a8187c0ae948bba6a90cbaac07f479cc8.tar.bz2
go-tangerine-bd0abe2a8187c0ae948bba6a90cbaac07f479cc8.tar.lz
go-tangerine-bd0abe2a8187c0ae948bba6a90cbaac07f479cc8.tar.xz
go-tangerine-bd0abe2a8187c0ae948bba6a90cbaac07f479cc8.tar.zst
go-tangerine-bd0abe2a8187c0ae948bba6a90cbaac07f479cc8.zip
Updated server and peers and mining processing
Diffstat (limited to 'dagger.go')
-rw-r--r--dagger.go46
1 files changed, 14 insertions, 32 deletions
diff --git a/dagger.go b/dagger.go
index 9fef78a36..8509232a2 100644
--- a/dagger.go
+++ b/dagger.go
@@ -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.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)
-
- sha.Write(dag.Node(9, pk).Bytes())
- //doneChan <- true
- //}(k)
- }
+ d := sha3.NewKeccak224()
+ b := new(big.Int)
- //for k := 0; k < 4; k++ {
- // <- doneChan
- //}
+ 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)
+
+ sha.Write(dag.Node(9, pk).Bytes())
+ }
return ret.SetBytes(Sum(sha))
}