aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-01-04 21:20:16 +0800
committerobscuren <geffobscura@gmail.com>2015-01-04 21:20:16 +0800
commit09841b1c9b2553a4572590128580df37c8fa83ad (patch)
tree42a846801bde7d8f7edc5ec07ccbba7806261128 /core
parentbd0c267cbe9db805b5a272d29ef8860c62ddafe5 (diff)
downloadgo-tangerine-09841b1c9b2553a4572590128580df37c8fa83ad.tar
go-tangerine-09841b1c9b2553a4572590128580df37c8fa83ad.tar.gz
go-tangerine-09841b1c9b2553a4572590128580df37c8fa83ad.tar.bz2
go-tangerine-09841b1c9b2553a4572590128580df37c8fa83ad.tar.lz
go-tangerine-09841b1c9b2553a4572590128580df37c8fa83ad.tar.xz
go-tangerine-09841b1c9b2553a4572590128580df37c8fa83ad.tar.zst
go-tangerine-09841b1c9b2553a4572590128580df37c8fa83ad.zip
Cleaned up some of that util
Diffstat (limited to 'core')
-rw-r--r--core/block_manager.go13
-rw-r--r--core/dagger.go160
-rw-r--r--core/dagger_test.go19
3 files changed, 0 insertions, 192 deletions
diff --git a/core/block_manager.go b/core/block_manager.go
index 09f569d96..76385ea1f 100644
--- a/core/block_manager.go
+++ b/core/block_manager.go
@@ -6,7 +6,6 @@ import (
"fmt"
"math/big"
"sync"
- "time"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
@@ -22,18 +21,6 @@ import (
var statelogger = logger.NewLogger("BLOCK")
-type Peer interface {
- Inbound() bool
- LastSend() time.Time
- LastPong() int64
- Host() []byte
- Port() uint16
- Version() string
- PingTime() string
- Connected() *int32
- Caps() *ethutil.Value
-}
-
type EthManager interface {
BlockManager() *BlockManager
ChainManager() *ChainManager
diff --git a/core/dagger.go b/core/dagger.go
deleted file mode 100644
index 3039d8995..000000000
--- a/core/dagger.go
+++ /dev/null
@@ -1,160 +0,0 @@
-package core
-
-import (
- "hash"
- "math/big"
- "math/rand"
- "time"
-
- "github.com/ethereum/go-ethereum/ethutil"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/obscuren/sha3"
-)
-
-var powlogger = logger.NewLogger("POW")
-
-type Dagger struct {
- hash *big.Int
- xn *big.Int
-}
-
-var Found bool
-
-func (dag *Dagger) Find(obj *big.Int, resChan chan int64) {
- r := rand.New(rand.NewSource(time.Now().UnixNano()))
-
- for i := 0; i < 1000; i++ {
- rnd := r.Int63()
-
- res := dag.Eval(big.NewInt(rnd))
- powlogger.Infof("rnd %v\nres %v\nobj %v\n", rnd, res, obj)
- if res.Cmp(obj) < 0 {
- // Post back result on the channel
- resChan <- rnd
- // Notify other threads we've found a valid nonce
- Found = true
- }
-
- // Break out if found
- if Found {
- break
- }
- }
-
- resChan <- 0
-}
-
-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 = hash
-
- obj := ethutil.BigPow(2, 256)
- obj = obj.Div(obj, diff)
-
- Found = false
- resChan := make(chan int64, 3)
- var res int64
-
- for k := 0; k < amountOfRoutines; k++ {
- go dag.Find(obj, resChan)
-
- // Wait for each go routine to finish
- }
- for k := 0; k < amountOfRoutines; k++ {
- // Get the result from the channel. 0 = quit
- if r := <-resChan; r != 0 {
- res = r
- }
- }
-
- return big.NewInt(res)
-}
-
-func (dag *Dagger) Verify(hash, diff, nonce *big.Int) bool {
- dag.hash = hash
-
- obj := ethutil.BigPow(2, 256)
- obj = obj.Div(obj, diff)
-
- return dag.Eval(nonce).Cmp(obj) < 0
-}
-
-func DaggerVerify(hash, diff, nonce *big.Int) bool {
- dagger := &Dagger{}
- dagger.hash = hash
-
- obj := ethutil.BigPow(2, 256)
- obj = obj.Div(obj, diff)
-
- return dagger.Eval(nonce).Cmp(obj) < 0
-}
-
-func (dag *Dagger) Node(L uint64, i uint64) *big.Int {
- if L == i {
- return dag.hash
- }
-
- var m *big.Int
- if L == 9 {
- m = big.NewInt(16)
- } else {
- m = big.NewInt(3)
- }
-
- sha := sha3.NewKeccak256()
- sha.Reset()
- d := sha3.NewKeccak256()
- b := new(big.Int)
- ret := new(big.Int)
-
- for k := 0; k < int(m.Uint64()); k++ {
- d.Reset()
- d.Write(dag.hash.Bytes())
- d.Write(dag.xn.Bytes())
- d.Write(big.NewInt(int64(L)).Bytes())
- d.Write(big.NewInt(int64(i)).Bytes())
- d.Write(big.NewInt(int64(k)).Bytes())
-
- b.SetBytes(Sum(d))
- pk := b.Uint64() & ((1 << ((L - 1) * 3)) - 1)
- sha.Write(dag.Node(L-1, pk).Bytes())
- }
-
- ret.SetBytes(Sum(sha))
-
- return ret
-}
-
-func Sum(sha hash.Hash) []byte {
- //in := make([]byte, 32)
- return sha.Sum(nil)
-}
-
-func (dag *Dagger) Eval(N *big.Int) *big.Int {
- pow := ethutil.BigPow(2, 26)
- dag.xn = pow.Div(N, pow)
-
- sha := sha3.NewKeccak256()
- sha.Reset()
- ret := new(big.Int)
-
- for k := 0; k < 4; k++ {
- d := sha3.NewKeccak256()
- 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())
- }
-
- return ret.SetBytes(Sum(sha))
-}
diff --git a/core/dagger_test.go b/core/dagger_test.go
deleted file mode 100644
index e80064e6b..000000000
--- a/core/dagger_test.go
+++ /dev/null
@@ -1,19 +0,0 @@
-package core
-
-import (
- "math/big"
- "testing"
-
- "github.com/ethereum/go-ethereum/ethutil"
-)
-
-func BenchmarkDaggerSearch(b *testing.B) {
- hash := big.NewInt(0)
- diff := ethutil.BigPow(2, 36)
- o := big.NewInt(0) // nonce doesn't matter. We're only testing against speed, not validity
-
- // Reset timer so the big generation isn't included in the benchmark
- b.ResetTimer()
- // Validate
- DaggerVerify(hash, diff, o)
-}