Rewritten a check to only start mining once we are caught up with all peers

This commit is contained in:
Maran 2014-05-14 13:26:15 +02:00
parent e8147cf7c6
commit 2012e0c67a

@ -8,24 +8,27 @@ import (
_ "github.com/ethereum/eth-go/ethrpc" _ "github.com/ethereum/eth-go/ethrpc"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"log" "log"
"time"
) )
func DoMining(ethereum *eth.Ethereum) { func DoMining(ethereum *eth.Ethereum) {
// Set Mining status // Set Mining status
ethereum.Mining = true ethereum.Mining = true
go func() {
// Give it some time to connect with peers
time.Sleep(3 * time.Second)
for ethereum.IsUpToDate() == false {
time.Sleep(5 * time.Second)
}
log.Println("Miner started") log.Println("Miner started")
// Fake block mining. It broadcasts a new block every 5 seconds
go func() {
data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
keyRing := ethutil.NewValueFromBytes(data) keyRing := ethutil.NewValueFromBytes(data)
addr := keyRing.Get(0).Bytes() addr := keyRing.Get(0).Bytes()
pair, _ := ethchain.NewKeyPairFromSec(ethutil.FromHex(hex.EncodeToString(addr))) pair, _ := ethchain.NewKeyPairFromSec(ethutil.FromHex(hex.EncodeToString(addr)))
miner := ethminer.NewDefaultMiner(pair.Address(), ethereum) miner := ethminer.NewDefaultMiner(pair.Address(), ethereum)
miner.Start() miner.Start()
}() }()
} }