aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--block_manager.go1
-rw-r--r--dagger.go7
-rw-r--r--ethereum.go4
-rw-r--r--peer.go3
-rw-r--r--server.go4
5 files changed, 13 insertions, 6 deletions
diff --git a/block_manager.go b/block_manager.go
index b6c2cace7..7e16cdb3a 100644
--- a/block_manager.go
+++ b/block_manager.go
@@ -154,6 +154,7 @@ func (bm *BlockManager) ValidateBlock(block *ethutil.Block) error {
// Verify the nonce of the block. Return an error if it's not valid
if bm.bc.LastBlock != nil && block.PrevHash == "" &&
!DaggerVerify(ethutil.BigD(block.Hash()), block.Difficulty, block.Nonce) {
+
return errors.New("Block's nonce is invalid")
}
diff --git a/dagger.go b/dagger.go
index 70b0b4692..0cc63ea94 100644
--- a/dagger.go
+++ b/dagger.go
@@ -7,6 +7,7 @@ import (
"math/big"
"math/rand"
"time"
+ "log"
)
type Dagger struct {
@@ -22,7 +23,9 @@ func (dag *Dagger) Find(obj *big.Int, resChan chan int64) {
for i := 0; i < 1000; i++ {
rnd := r.Int63()
- if dag.Eval(big.NewInt(rnd)).Cmp(obj) < 0 {
+ res := dag.Eval(big.NewInt(rnd))
+ log.Printf("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
@@ -119,7 +122,7 @@ func Sum(sha hash.Hash) []byte {
func (dag *Dagger) Eval(N *big.Int) *big.Int {
pow := ethutil.BigPow(2, 26)
- dag.xn = N.Div(N, pow)
+ dag.xn = pow.Div(N, pow)
sha := sha3.NewKeccak256()
sha.Reset()
diff --git a/ethereum.go b/ethereum.go
index 055c1a5ad..7e13f197a 100644
--- a/ethereum.go
+++ b/ethereum.go
@@ -64,8 +64,8 @@ func main() {
go func() {
for {
- res := dagger.Search(ethutil.Big("0"), ethutil.BigPow(2, 36))
- server.Broadcast("block", ethutil.Encode(res.String()))
+ res := dagger.Search(ethutil.Big("01001"), ethutil.BigPow(2, 26))
+ server.Broadcast("blockmine", ethutil.Encode(res.String()))
}
}()
}
diff --git a/peer.go b/peer.go
index 16bb22286..8f68a9bec 100644
--- a/peer.go
+++ b/peer.go
@@ -162,6 +162,9 @@ out:
if err != nil {
log.Println(err)
}
+ case "blockmine":
+ d, _ := ethutil.Decode(msg.Data, 0)
+ log.Printf("block mined %s\n", d)
}
}
diff --git a/server.go b/server.go
index e34bc6f20..f658750a9 100644
--- a/server.go
+++ b/server.go
@@ -138,15 +138,15 @@ func (s *Server) Start() {
}()
// TMP
+ /*
go func() {
- //time.Sleep(500 * time.Millisecond)
-
for {
s.Broadcast("block", s.blockManager.bc.GenesisBlock().MarshalRlp())
time.Sleep(1000 * time.Millisecond)
}
}()
+ */
}
func (s *Server) Stop() {