From 2012e0c67abd8e3012a3eb1fae2e282e2a442d01 Mon Sep 17 00:00:00 2001 From: Maran Date: Wed, 14 May 2014 13:26:15 +0200 Subject: [PATCH 1/4] Rewritten a check to only start mining once we are caught up with all peers --- utils/cmd.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/utils/cmd.go b/utils/cmd.go index a99fd9eed..44924ce91 100644 --- a/utils/cmd.go +++ b/utils/cmd.go @@ -8,24 +8,27 @@ import ( _ "github.com/ethereum/eth-go/ethrpc" "github.com/ethereum/eth-go/ethutil" "log" + "time" ) func DoMining(ethereum *eth.Ethereum) { // Set Mining status ethereum.Mining = true - log.Println("Miner started") - - // Fake block mining. It broadcasts a new block every 5 seconds 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") + data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) keyRing := ethutil.NewValueFromBytes(data) addr := keyRing.Get(0).Bytes() - pair, _ := ethchain.NewKeyPairFromSec(ethutil.FromHex(hex.EncodeToString(addr))) - miner := ethminer.NewDefaultMiner(pair.Address(), ethereum) miner.Start() - }() } From 9fce273ce97a8db091a0bf9d0b503a2ea7261f81 Mon Sep 17 00:00:00 2001 From: Maran Date: Wed, 14 May 2014 13:32:49 +0200 Subject: [PATCH 2/4] Refactored RPC client to utils so it can be reused --- ethereal/ethereum.go | 9 +-------- ethereum/ethereum.go | 9 +-------- utils/cmd.go | 13 ++++++++++++- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/ethereal/ethereum.go b/ethereal/ethereum.go index 32c16f64f..a97d7f498 100644 --- a/ethereal/ethereum.go +++ b/ethereal/ethereum.go @@ -4,8 +4,6 @@ import ( "fmt" "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" - "github.com/ethereum/eth-go/ethpub" - "github.com/ethereum/eth-go/ethrpc" "github.com/ethereum/eth-go/ethutil" "github.com/ethereum/go-ethereum/ethereal/ui" "github.com/ethereum/go-ethereum/utils" @@ -104,12 +102,7 @@ func main() { } if StartRpc { - ethereum.RpcServer, err = ethrpc.NewJsonRpcServer(ethpub.NewPEthereum(ethereum), RpcPort) - if err != nil { - log.Println("Could not start RPC interface:", err) - } else { - go ethereum.RpcServer.Start() - } + utils.DoRpc(ethereum, RpcPort) } log.Printf("Starting Ethereum GUI v%s\n", ethutil.Config.Ver) diff --git a/ethereum/ethereum.go b/ethereum/ethereum.go index 207e61c88..448223c37 100644 --- a/ethereum/ethereum.go +++ b/ethereum/ethereum.go @@ -4,8 +4,6 @@ import ( "fmt" "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" - "github.com/ethereum/eth-go/ethpub" - "github.com/ethereum/eth-go/ethrpc" "github.com/ethereum/eth-go/ethutil" "github.com/ethereum/go-ethereum/utils" "log" @@ -139,12 +137,7 @@ func main() { go console.Start() } if StartRpc { - ethereum.RpcServer, err = ethrpc.NewJsonRpcServer(ethpub.NewPEthereum(ethereum), RpcPort) - if err != nil { - logger.Infoln("Could not start RPC interface:", err) - } else { - go ethereum.RpcServer.Start() - } + utils.DoRpc(ethereum, RpcPort) } RegisterInterrupts(ethereum) diff --git a/utils/cmd.go b/utils/cmd.go index 44924ce91..5a100ca4f 100644 --- a/utils/cmd.go +++ b/utils/cmd.go @@ -5,12 +5,23 @@ import ( "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethminer" - _ "github.com/ethereum/eth-go/ethrpc" + "github.com/ethereum/eth-go/ethpub" + "github.com/ethereum/eth-go/ethrpc" "github.com/ethereum/eth-go/ethutil" "log" "time" ) +func DoRpc(ethereum *eth.Ethereum, RpcPort int) { + var err error + ethereum.RpcServer, err = ethrpc.NewJsonRpcServer(ethpub.NewPEthereum(ethereum), RpcPort) + if err != nil { + log.Println("Could not start RPC interface:", err) + } else { + go ethereum.RpcServer.Start() + } +} + func DoMining(ethereum *eth.Ethereum) { // Set Mining status ethereum.Mining = true From 2c7b625daaf062192db2fa604344f79c1bdbb232 Mon Sep 17 00:00:00 2001 From: Maran Date: Wed, 14 May 2014 13:55:55 +0200 Subject: [PATCH 3/4] Make sure we have a coinbase address to mine with --- utils/cmd.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/utils/cmd.go b/utils/cmd.go index 5a100ca4f..66cfbeff9 100644 --- a/utils/cmd.go +++ b/utils/cmd.go @@ -26,6 +26,16 @@ func DoMining(ethereum *eth.Ethereum) { // Set Mining status ethereum.Mining = true + data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) + if len(data) == 0 { + log.Println("No address found, can't start mining") + return + } + + keyRing := ethutil.NewValueFromBytes(data) + addr := keyRing.Get(0).Bytes() + pair, _ := ethchain.NewKeyPairFromSec(ethutil.FromHex(hex.EncodeToString(addr))) + go func() { // Give it some time to connect with peers time.Sleep(3 * time.Second) @@ -35,10 +45,6 @@ func DoMining(ethereum *eth.Ethereum) { } log.Println("Miner started") - data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) - keyRing := ethutil.NewValueFromBytes(data) - addr := keyRing.Get(0).Bytes() - pair, _ := ethchain.NewKeyPairFromSec(ethutil.FromHex(hex.EncodeToString(addr))) miner := ethminer.NewDefaultMiner(pair.Address(), ethereum) miner.Start() }() From a1dcc5cd1793dc05e2ff38e8a8024690e09aebf5 Mon Sep 17 00:00:00 2001 From: Maran Date: Wed, 14 May 2014 14:11:45 +0200 Subject: [PATCH 4/4] Prevent crash during import of privkeys. @obscuren please check if this was commented out for a reason --- ethereum/ethereum.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ethereum/ethereum.go b/ethereum/ethereum.go index d22513972..2abf6da42 100644 --- a/ethereum/ethereum.go +++ b/ethereum/ethereum.go @@ -64,10 +64,9 @@ func main() { log.SetOutput(logfile) logSys = log.New(logfile, "", flags) logger.AddLogSystem(logSys) - } - /*else { + } else { logSys = log.New(os.Stdout, "", flags) - }*/ + } ethchain.InitFees()