Some miner reports

This commit is contained in:
obscuren 2014-01-13 01:22:33 +01:00
parent 7ade1778fb
commit 578b63e2b8
5 changed files with 13 additions and 6 deletions

View File

@ -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 // Verify the nonce of the block. Return an error if it's not valid
if bm.bc.LastBlock != nil && block.PrevHash == "" && if bm.bc.LastBlock != nil && block.PrevHash == "" &&
!DaggerVerify(ethutil.BigD(block.Hash()), block.Difficulty, block.Nonce) { !DaggerVerify(ethutil.BigD(block.Hash()), block.Difficulty, block.Nonce) {
return errors.New("Block's nonce is invalid") return errors.New("Block's nonce is invalid")
} }

View File

@ -7,6 +7,7 @@ import (
"math/big" "math/big"
"math/rand" "math/rand"
"time" "time"
"log"
) )
type Dagger struct { type Dagger struct {
@ -22,7 +23,9 @@ func (dag *Dagger) Find(obj *big.Int, resChan chan int64) {
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
rnd := r.Int63() 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 // Post back result on the channel
resChan <- rnd resChan <- rnd
// Notify other threads we've found a valid nonce // 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 { func (dag *Dagger) Eval(N *big.Int) *big.Int {
pow := ethutil.BigPow(2, 26) pow := ethutil.BigPow(2, 26)
dag.xn = N.Div(N, pow) dag.xn = pow.Div(N, pow)
sha := sha3.NewKeccak256() sha := sha3.NewKeccak256()
sha.Reset() sha.Reset()

View File

@ -64,8 +64,8 @@ func main() {
go func() { go func() {
for { for {
res := dagger.Search(ethutil.Big("0"), ethutil.BigPow(2, 36)) res := dagger.Search(ethutil.Big("01001"), ethutil.BigPow(2, 26))
server.Broadcast("block", ethutil.Encode(res.String())) server.Broadcast("blockmine", ethutil.Encode(res.String()))
} }
}() }()
} }

View File

@ -162,6 +162,9 @@ out:
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} }
case "blockmine":
d, _ := ethutil.Decode(msg.Data, 0)
log.Printf("block mined %s\n", d)
} }
} }

View File

@ -138,15 +138,15 @@ func (s *Server) Start() {
}() }()
// TMP // TMP
/*
go func() { go func() {
//time.Sleep(500 * time.Millisecond)
for { for {
s.Broadcast("block", s.blockManager.bc.GenesisBlock().MarshalRlp()) s.Broadcast("block", s.blockManager.bc.GenesisBlock().MarshalRlp())
time.Sleep(1000 * time.Millisecond) time.Sleep(1000 * time.Millisecond)
} }
}() }()
*/
} }
func (s *Server) Stop() { func (s *Server) Stop() {