From d90b71bc5518e1f794268fe58f62525302287bd3 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 26 Feb 2015 21:01:40 +0100 Subject: [PATCH 1/9] Check source directroy for assets as last resort --- ethutil/common.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ethutil/common.go b/ethutil/common.go index c4e7415dc1..5fd9a06e29 100644 --- a/ethutil/common.go +++ b/ethutil/common.go @@ -15,11 +15,13 @@ import ( func DefaultAssetPath() string { var assetPath string + pwd, _ := os.Getwd() + srcdir := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist") + // If the current working directory is the go-ethereum dir // assume a debug build and use the source directory as // asset directory. - pwd, _ := os.Getwd() - if pwd == path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist") { + if pwd == srcdir { assetPath = path.Join(pwd, "assets") } else { switch runtime.GOOS { @@ -34,6 +36,12 @@ func DefaultAssetPath() string { default: assetPath = "." } + + // Check if the assetPath exists. If not, try the source directory + // This happens when binary is run from outside cmd/mist directory + if _, err := os.Stat(assetPath); os.IsNotExist(err) { + assetPath = path.Join(srcdir, "assets") + } } return assetPath } From a39c73672efd542b53b79fdadb89afec93498cc1 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 26 Feb 2015 21:04:26 +0100 Subject: [PATCH 2/9] bump last resort check out of ifelse --- ethutil/common.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ethutil/common.go b/ethutil/common.go index 5fd9a06e29..9b66763b81 100644 --- a/ethutil/common.go +++ b/ethutil/common.go @@ -36,13 +36,14 @@ func DefaultAssetPath() string { default: assetPath = "." } + } - // Check if the assetPath exists. If not, try the source directory - // This happens when binary is run from outside cmd/mist directory - if _, err := os.Stat(assetPath); os.IsNotExist(err) { - assetPath = path.Join(srcdir, "assets") - } + // Check if the assetPath exists. If not, try the source directory + // This happens when binary is run from outside cmd/mist directory + if _, err := os.Stat(assetPath); os.IsNotExist(err) { + assetPath = path.Join(srcdir, "assets") } + return assetPath } From f6e821fd335911c26d515094ac0af4fa69526279 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Sat, 28 Feb 2015 01:00:42 +0100 Subject: [PATCH 3/9] Add flag to set RPC port --- cmd/ethereum/flags.go | 70 ++++++++++++++++++++++--------------------- cmd/ethereum/main.go | 2 +- cmd/mist/flags.go | 52 ++++++++++++++++---------------- cmd/mist/main.go | 2 +- cmd/utils/cmd.go | 4 +-- rpc/http/server.go | 4 +-- 6 files changed, 69 insertions(+), 65 deletions(-) diff --git a/cmd/ethereum/flags.go b/cmd/ethereum/flags.go index 7d410c8e45..79a60039ce 100644 --- a/cmd/ethereum/flags.go +++ b/cmd/ethereum/flags.go @@ -36,40 +36,41 @@ import ( ) var ( - Identifier string - KeyRing string - DiffTool bool - DiffType string - KeyStore string - StartRpc bool - StartWebSockets bool - RpcPort int - WsPort int - OutboundPort string - ShowGenesis bool - AddPeer string - MaxPeer int - GenAddr bool - BootNodes string - NodeKey *ecdsa.PrivateKey - NAT nat.Interface - SecretFile string - ExportDir string - NonInteractive bool - Datadir string - LogFile string - ConfigFile string - DebugFile string - LogLevel int - LogFormat string - Dump bool - DumpHash string - DumpNumber int - VmType int - ImportChain string - SHH bool - Dial bool - PrintVersion bool + Identifier string + KeyRing string + DiffTool bool + DiffType string + KeyStore string + StartRpc bool + StartWebSockets bool + RpcListenAddress string + RpcPort int + WsPort int + OutboundPort string + ShowGenesis bool + AddPeer string + MaxPeer int + GenAddr bool + BootNodes string + NodeKey *ecdsa.PrivateKey + NAT nat.Interface + SecretFile string + ExportDir string + NonInteractive bool + Datadir string + LogFile string + ConfigFile string + DebugFile string + LogLevel int + LogFormat string + Dump bool + DumpHash string + DumpNumber int + VmType int + ImportChain string + SHH bool + Dial bool + PrintVersion bool ) // flags specific to cli client @@ -93,6 +94,7 @@ func Init() { flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use") flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)") + flag.StringVar(&RpcListenAddress, "rpcaddr", "127.0.0.1", "address for json-rpc server to listen on") flag.IntVar(&RpcPort, "rpcport", 8545, "port to start json-rpc server on") flag.IntVar(&WsPort, "wsport", 40404, "port to start websocket rpc server on") flag.BoolVar(&StartRpc, "rpc", false, "start rpc server") diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go index 45e6f7b935..8afab5d283 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -128,7 +128,7 @@ func main() { } if StartRpc { - utils.StartRpc(ethereum, RpcPort) + utils.StartRpc(ethereum, RpcListenAddress, RpcPort) } if StartWebSockets { diff --git a/cmd/mist/flags.go b/cmd/mist/flags.go index 0010df8265..1ffeb19159 100644 --- a/cmd/mist/flags.go +++ b/cmd/mist/flags.go @@ -37,31 +37,32 @@ import ( ) var ( - Identifier string - KeyRing string - KeyStore string - StartRpc bool - StartWebSockets bool - RpcPort int - WsPort int - OutboundPort string - ShowGenesis bool - AddPeer string - MaxPeer int - GenAddr bool - BootNodes string - NodeKey *ecdsa.PrivateKey - NAT nat.Interface - SecretFile string - ExportDir string - NonInteractive bool - Datadir string - LogFile string - ConfigFile string - DebugFile string - LogLevel int - VmType int - MinerThreads int + Identifier string + KeyRing string + KeyStore string + StartRpc bool + StartWebSockets bool + RpcListenAddress string + RpcPort int + WsPort int + OutboundPort string + ShowGenesis bool + AddPeer string + MaxPeer int + GenAddr bool + BootNodes string + NodeKey *ecdsa.PrivateKey + NAT nat.Interface + SecretFile string + ExportDir string + NonInteractive bool + Datadir string + LogFile string + ConfigFile string + DebugFile string + LogLevel int + VmType int + MinerThreads int ) // flags specific to gui client @@ -79,6 +80,7 @@ func Init() { flag.StringVar(&Identifier, "id", "", "Custom client identifier") flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use") flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)") + flag.StringVar(&RpcListenAddress, "rpcaddr", "127.0.0.1", "address for json-rpc server to listen on") flag.IntVar(&RpcPort, "rpcport", 8545, "port to start json-rpc server on") flag.IntVar(&WsPort, "wsport", 40404, "port to start websocket rpc server on") flag.BoolVar(&StartRpc, "rpc", true, "start rpc server") diff --git a/cmd/mist/main.go b/cmd/mist/main.go index 3abe167671..c9a07bfde7 100644 --- a/cmd/mist/main.go +++ b/cmd/mist/main.go @@ -73,7 +73,7 @@ func run() error { utils.KeyTasks(ethereum.KeyManager(), KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive) if StartRpc { - utils.StartRpc(ethereum, RpcPort) + utils.StartRpc(ethereum, RpcListenAddress, RpcPort) } if StartWebSockets { diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index a36c10e3bf..5c7ec3221f 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -160,9 +160,9 @@ func KeyTasks(keyManager *crypto.KeyManager, KeyRing string, GenAddr bool, Secre clilogger.Infof("Main address %x\n", keyManager.Address()) } -func StartRpc(ethereum *eth.Ethereum, RpcPort int) { +func StartRpc(ethereum *eth.Ethereum, RpcListenAddress string, RpcPort int) { var err error - ethereum.RpcServer, err = rpchttp.NewRpcHttpServer(xeth.New(ethereum), RpcPort) + ethereum.RpcServer, err = rpchttp.NewRpcHttpServer(xeth.New(ethereum), RpcListenAddress, RpcPort) if err != nil { clilogger.Errorf("Could not start RPC interface (port %v): %v", RpcPort, err) } else { diff --git a/rpc/http/server.go b/rpc/http/server.go index fa66eed487..063c333d00 100644 --- a/rpc/http/server.go +++ b/rpc/http/server.go @@ -29,8 +29,8 @@ import ( var rpchttplogger = logger.NewLogger("RPC-HTTP") var JSON rpc.JsonWrapper -func NewRpcHttpServer(pipe *xeth.XEth, port int) (*RpcHttpServer, error) { - sport := fmt.Sprintf("127.0.0.1:%d", port) +func NewRpcHttpServer(pipe *xeth.XEth, address string, port int) (*RpcHttpServer, error) { + sport := fmt.Sprintf("%s:%d", address, port) l, err := net.Listen("tcp", sport) if err != nil { return nil, err From ea0517b5396efc7bd47f820ec0263f68f76f29a4 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Sat, 28 Feb 2015 01:04:54 +0100 Subject: [PATCH 4/9] Report RPC listening address in logs --- rpc/http/server.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rpc/http/server.go b/rpc/http/server.go index 063c333d00..452b7c9af0 100644 --- a/rpc/http/server.go +++ b/rpc/http/server.go @@ -41,6 +41,7 @@ func NewRpcHttpServer(pipe *xeth.XEth, address string, port int) (*RpcHttpServer quit: make(chan bool), pipe: pipe, port: port, + addr: address, }, nil } @@ -49,6 +50,7 @@ type RpcHttpServer struct { listener net.Listener pipe *xeth.XEth port int + addr string } func (s *RpcHttpServer) exitHandler() { @@ -69,7 +71,7 @@ func (s *RpcHttpServer) Stop() { } func (s *RpcHttpServer) Start() { - rpchttplogger.Infof("Starting RPC-HTTP server on port %d", s.port) + rpchttplogger.Infof("Starting RPC-HTTP server on %s:%d", s.addr, s.port) go s.exitHandler() api := rpc.NewEthereumApi(s.pipe) From 6ea7aae29ca71e6fe857b85296b574e09df57184 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 28 Feb 2015 19:15:57 +0100 Subject: [PATCH 5/9] Removed some methods from the JS REPL --- cmd/ethereum/flags.go | 6 ++++ cmd/ethereum/main.go | 3 ++ cmd/ethereum/repl/repl.go | 1 + core/genesis.go | 2 -- javascript/javascript_runtime.go | 58 +++++--------------------------- javascript/js_lib.go | 2 +- state/dump.go | 7 ++-- 7 files changed, 25 insertions(+), 54 deletions(-) diff --git a/cmd/ethereum/flags.go b/cmd/ethereum/flags.go index 7d410c8e45..c420831609 100644 --- a/cmd/ethereum/flags.go +++ b/cmd/ethereum/flags.go @@ -135,6 +135,12 @@ func Init() { flag.Parse() + // When the javascript console is started log to a file instead + // of stdout + if StartJsConsole { + LogFile = path.Join(Datadir, "ethereum.log") + } + var err error if NAT, err = nat.Parse(*natstr); err != nil { log.Fatalf("-nat: %v", err) diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go index 45e6f7b935..1562165cd7 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -137,6 +137,9 @@ func main() { utils.StartEthereum(ethereum) + latestBlock := ethereum.ChainManager().CurrentBlock() + fmt.Printf("Welcome to the FRONTIER\n") + if StartJsConsole { InitJsConsole(ethereum) } else if len(InputFile) > 0 { diff --git a/cmd/ethereum/repl/repl.go b/cmd/ethereum/repl/repl.go index 4a7880ff42..11b8126177 100644 --- a/cmd/ethereum/repl/repl.go +++ b/cmd/ethereum/repl/repl.go @@ -60,6 +60,7 @@ func (self *JSRepl) Start() { if !self.running { self.running = true repllogger.Infoln("init JS Console") + reader := bufio.NewReader(self.history) for { line, err := reader.ReadString('\n') diff --git a/core/genesis.go b/core/genesis.go index 75b4fc100d..decffc5418 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -51,8 +51,6 @@ func GenesisBlock(db ethutil.Database) *types.Block { statedb.Sync() genesis.Header().Root = statedb.Root() - fmt.Printf("+++ genesis +++\nRoot: %x\nHash: %x\n", genesis.Header().Root, genesis.Hash()) - return genesis } diff --git a/javascript/javascript_runtime.go b/javascript/javascript_runtime.go index 0aa0f73e2c..beaca45b90 100644 --- a/javascript/javascript_runtime.go +++ b/javascript/javascript_runtime.go @@ -24,7 +24,7 @@ var jsrelogger = logger.NewLogger("JSRE") type JSRE struct { ethereum *eth.Ethereum Vm *otto.Otto - pipe *xeth.XEth + xeth *xeth.XEth events event.Subscription @@ -67,7 +67,7 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE { // We have to make sure that, whoever calls this, calls "Stop" go re.mainLoop() - re.Bind("eth", &JSEthereum{re.pipe, re.Vm, ethereum}) + re.Bind("eth", &JSEthereum{re.xeth, re.Vm, ethereum}) re.initStdFuncs() @@ -113,12 +113,10 @@ func (self *JSRE) mainLoop() { func (self *JSRE) initStdFuncs() { t, _ := self.Vm.Get("eth") eth := t.Object() - eth.Set("watch", self.watch) - eth.Set("addPeer", self.addPeer) + eth.Set("connect", self.connect) eth.Set("require", self.require) eth.Set("stopMining", self.stopMining) eth.Set("startMining", self.startMining) - eth.Set("execBlock", self.execBlock) eth.Set("dump", self.dump) eth.Set("export", self.export) } @@ -152,7 +150,8 @@ func (self *JSRE) dump(call otto.FunctionCall) otto.Value { } statedb := state.New(block.Root(), self.ethereum.Db()) - v, _ := self.Vm.ToValue(statedb.Dump()) + + v, _ := self.Vm.ToValue(statedb.RawDump()) return v } @@ -167,36 +166,7 @@ func (self *JSRE) startMining(call otto.FunctionCall) otto.Value { return v } -// eth.watch -func (self *JSRE) watch(call otto.FunctionCall) otto.Value { - addr, _ := call.Argument(0).ToString() - var storageAddr string - var cb otto.Value - var storageCallback bool - if len(call.ArgumentList) > 2 { - storageCallback = true - storageAddr, _ = call.Argument(1).ToString() - cb = call.Argument(2) - } else { - cb = call.Argument(1) - } - - if storageCallback { - self.objectCb[addr+storageAddr] = append(self.objectCb[addr+storageAddr], cb) - - // event := "storage:" + string(ethutil.Hex2Bytes(addr)) + ":" + string(ethutil.Hex2Bytes(storageAddr)) - // self.ethereum.EventMux().Subscribe(event, self.changeChan) - } else { - self.objectCb[addr] = append(self.objectCb[addr], cb) - - // event := "object:" + string(ethutil.Hex2Bytes(addr)) - // self.ethereum.EventMux().Subscribe(event, self.changeChan) - } - - return otto.UndefinedValue() -} - -func (self *JSRE) addPeer(call otto.FunctionCall) otto.Value { +func (self *JSRE) connect(call otto.FunctionCall) otto.Value { nodeURL, err := call.Argument(0).ToString() if err != nil { return otto.FalseValue() @@ -222,22 +192,12 @@ func (self *JSRE) require(call otto.FunctionCall) otto.Value { return t } -func (self *JSRE) execBlock(call otto.FunctionCall) otto.Value { - hash, err := call.Argument(0).ToString() - if err != nil { - return otto.UndefinedValue() - } - - err = utils.BlockDo(self.ethereum, ethutil.Hex2Bytes(hash)) - if err != nil { - fmt.Println(err) +func (self *JSRE) export(call otto.FunctionCall) otto.Value { + if len(call.ArgumentList) == 0 { + fmt.Println("err: require file name") return otto.FalseValue() } - return otto.TrueValue() -} - -func (self *JSRE) export(call otto.FunctionCall) otto.Value { fn, err := call.Argument(0).ToString() if err != nil { fmt.Println(err) diff --git a/javascript/js_lib.go b/javascript/js_lib.go index dd1fe5f4d0..f828ca3890 100644 --- a/javascript/js_lib.go +++ b/javascript/js_lib.go @@ -16,7 +16,7 @@ function pp(object) { str += " ]"; } else if(typeof(object) === "object") { str += "{ "; - var last = Object.keys(object).sort().pop() + var last = Object.keys(object).pop() for(var k in object) { str += k + ": " + pp(object[k]); diff --git a/state/dump.go b/state/dump.go index 073f89414a..2c611d76b4 100644 --- a/state/dump.go +++ b/state/dump.go @@ -20,7 +20,7 @@ type World struct { Accounts map[string]Account `json:"accounts"` } -func (self *StateDB) Dump() []byte { +func (self *StateDB) RawDump() World { world := World{ Root: ethutil.Bytes2Hex(self.trie.Root()), Accounts: make(map[string]Account), @@ -39,8 +39,11 @@ func (self *StateDB) Dump() []byte { } world.Accounts[ethutil.Bytes2Hex(it.Key)] = account } + return world +} - json, err := json.MarshalIndent(world, "", " ") +func (self *StateDB) Dump() []byte { + json, err := json.MarshalIndent(self.RawDump(), "", " ") if err != nil { fmt.Println("dump err", err) } From 7adf065b10a0a05aea759e7f29a2a4acfa0f5521 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 28 Feb 2015 20:14:01 +0100 Subject: [PATCH 6/9] Simple effective VM optimisation Added a debug flag to the VM which determines if VM output is shown regardless of the log level set. --- vm/vm.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/vm/vm.go b/vm/vm.go index 7aeeea6619..1f386d47c7 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -16,6 +16,8 @@ type Vm struct { logStr string err error + // For logging + debug bool Dbg Debugger @@ -32,7 +34,7 @@ func New(env Environment) *Vm { lt = LogTyDiff } - return &Vm{env: env, logTy: lt, Recoverable: true} + return &Vm{debug: false, env: env, logTy: lt, Recoverable: true} } func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.Int, callData []byte) (ret []byte, err error) { @@ -938,17 +940,21 @@ func (self *Vm) RunPrecompiled(p *PrecompiledAccount, callData []byte, context * } func (self *Vm) Printf(format string, v ...interface{}) VirtualMachine { - if self.logTy == LogTyPretty { - self.logStr += fmt.Sprintf(format, v...) + if self.debug { + if self.logTy == LogTyPretty { + self.logStr += fmt.Sprintf(format, v...) + } } return self } func (self *Vm) Endl() VirtualMachine { - if self.logTy == LogTyPretty { - vmlogger.Debugln(self.logStr) - self.logStr = "" + if self.debug { + if self.logTy == LogTyPretty { + vmlogger.Debugln(self.logStr) + self.logStr = "" + } } return self From 7ab13e0f17e9d1b783d93bd4952cc6d7cc77ea7f Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 28 Feb 2015 20:24:20 +0100 Subject: [PATCH 7/9] Unused variable --- cmd/ethereum/main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go index 1562165cd7..f72b11e14d 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -137,7 +137,6 @@ func main() { utils.StartEthereum(ethereum) - latestBlock := ethereum.ChainManager().CurrentBlock() fmt.Printf("Welcome to the FRONTIER\n") if StartJsConsole { From fdf939a6f9b5360d76415c7118969d92af2774f9 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 28 Feb 2015 23:01:41 +0100 Subject: [PATCH 8/9] Fixed miner threads for ethereum CLI --- cmd/ethereum/flags.go | 3 +++ cmd/ethereum/main.go | 37 +++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/cmd/ethereum/flags.go b/cmd/ethereum/flags.go index 1a0c13c821..356571a238 100644 --- a/cmd/ethereum/flags.go +++ b/cmd/ethereum/flags.go @@ -27,6 +27,7 @@ import ( "log" "os" "path" + "runtime" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" @@ -71,6 +72,7 @@ var ( SHH bool Dial bool PrintVersion bool + MinerThreads int ) // flags specific to cli client @@ -121,6 +123,7 @@ func Init() { flag.BoolVar(&StartMining, "mine", false, "start dagger mining") flag.BoolVar(&StartJsConsole, "js", false, "launches javascript console") flag.BoolVar(&PrintVersion, "version", false, "prints version number") + flag.IntVar(&MinerThreads, "minerthreads", runtime.NumCPU(), "number of miner threads") // Network stuff var ( diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go index 07ef0d5dd1..f79f948d1e 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -62,20 +62,21 @@ func main() { utils.InitConfig(VmType, ConfigFile, Datadir, "ETH") ethereum, err := eth.New(ð.Config{ - Name: p2p.MakeName(ClientIdentifier, Version), - KeyStore: KeyStore, - DataDir: Datadir, - LogFile: LogFile, - LogLevel: LogLevel, - LogFormat: LogFormat, - MaxPeers: MaxPeer, - Port: OutboundPort, - NAT: NAT, - KeyRing: KeyRing, - Shh: true, - Dial: Dial, - BootNodes: BootNodes, - NodeKey: NodeKey, + Name: p2p.MakeName(ClientIdentifier, Version), + KeyStore: KeyStore, + DataDir: Datadir, + LogFile: LogFile, + LogLevel: LogLevel, + LogFormat: LogFormat, + MaxPeers: MaxPeer, + Port: OutboundPort, + NAT: NAT, + KeyRing: KeyRing, + Shh: true, + Dial: Dial, + BootNodes: BootNodes, + NodeKey: NodeKey, + MinerThreads: MinerThreads, }) if err != nil { @@ -113,10 +114,6 @@ func main() { return } - if StartMining { - utils.StartMining(ethereum) - } - if len(ImportChain) > 0 { start := time.Now() err := utils.ImportChain(ethereum, ImportChain) @@ -139,6 +136,10 @@ func main() { fmt.Printf("Welcome to the FRONTIER\n") + if StartMining { + ethereum.Miner().Start() + } + if StartJsConsole { InitJsConsole(ethereum) } else if len(InputFile) > 0 { From 65cad14f9b27db396d036f47814d4843d947ac43 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 28 Feb 2015 23:09:49 +0100 Subject: [PATCH 9/9] Report debug hash rate --- miner/miner.go | 7 +------ miner/worker.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/miner/miner.go b/miner/miner.go index 0cc2361c89..6b416be8ea 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -52,10 +52,5 @@ func (self *Miner) Stop() { } func (self *Miner) HashRate() int64 { - var tot int64 - for _, agent := range self.worker.agents { - tot += agent.Pow().GetHashrate() - } - - return tot + return self.worker.HashRate() } diff --git a/miner/worker.go b/miner/worker.go index 4f0909302c..afce68c355 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -5,6 +5,7 @@ import ( "math/big" "sort" "sync" + "time" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" @@ -111,6 +112,8 @@ func (self *worker) register(agent Agent) { func (self *worker) update() { events := self.mux.Subscribe(core.ChainEvent{}, core.NewMinedBlockEvent{}) + timer := time.NewTicker(2 * time.Second) + out: for { select { @@ -129,6 +132,8 @@ out: agent.Stop() } break out + case <-timer.C: + minerlogger.Debugln("Hash rate:", self.HashRate(), "Khash") } } @@ -244,3 +249,12 @@ func (self *worker) commitTransaction(tx *types.Transaction) error { return nil } + +func (self *worker) HashRate() int64 { + var tot int64 + for _, agent := range self.agents { + tot += agent.Pow().GetHashrate() + } + + return tot +}