diff options
-rw-r--r-- | .travis.yml | 8 | ||||
-rw-r--r-- | appveyor.yml | 4 | ||||
-rw-r--r-- | cmd/geth/library.c | 24 | ||||
-rw-r--r-- | cmd/geth/library.go | 46 | ||||
-rw-r--r-- | cmd/geth/library_android.go | 56 | ||||
-rw-r--r-- | cmd/utils/cmd.go | 31 | ||||
-rw-r--r-- | eth/api.go | 19 | ||||
-rw-r--r-- | miner/miner.go | 16 | ||||
-rw-r--r-- | miner/remote_agent.go | 25 | ||||
-rw-r--r-- | miner/worker.go | 6 |
10 files changed, 77 insertions, 158 deletions
diff --git a/.travis.yml b/.travis.yml index 87725251b..d13b77c17 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,15 +13,15 @@ matrix: go: 1.6.2 - os: linux dist: trusty - go: 1.7 + go: 1.7.4 - os: osx - go: 1.7 + go: 1.7.4 # This builder does the Ubuntu PPA and Linux Azure uploads - os: linux dist: trusty sudo: required - go: 1.7 + go: 1.7.4 env: - ubuntu-ppa - azure-linux @@ -55,7 +55,7 @@ matrix: # This builder does the OSX Azure, Android Maven and Azure and iOS CocoaPods and Azure uploads - os: osx - go: 1.7 + go: 1.7.4 env: - azure-osx - mobile diff --git a/appveyor.yml b/appveyor.yml index dbdda9b6c..f5115f6f9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -22,8 +22,8 @@ environment: install: - rmdir C:\go /s /q - - appveyor DownloadFile https://storage.googleapis.com/golang/go1.7.3.windows-%GETH_ARCH%.zip - - 7z x go1.7.3.windows-%GETH_ARCH%.zip -y -oC:\ > NUL + - appveyor DownloadFile https://storage.googleapis.com/golang/go1.7.4.windows-%GETH_ARCH%.zip + - 7z x go1.7.4.windows-%GETH_ARCH%.zip -y -oC:\ > NUL - go version - gcc --version diff --git a/cmd/geth/library.c b/cmd/geth/library.c deleted file mode 100644 index f738621a8..000000000 --- a/cmd/geth/library.c +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2015 The go-ethereum Authors -// This file is part of go-ethereum. -// -// go-ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// go-ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. - -// Simple wrapper to translate the API exposed methods and types to inthernal -// Go versions of the same types. - -#include "_cgo_export.h" - -int run(const char* args) { - return doRun((char*)args); -} diff --git a/cmd/geth/library.go b/cmd/geth/library.go deleted file mode 100644 index b8ffaaed7..000000000 --- a/cmd/geth/library.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2015 The go-ethereum Authors -// This file is part of go-ethereum. -// -// go-ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// go-ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. - -// Contains a simple library definition to allow creating a Geth instance from -// straight C code. - -package main - -// #ifdef __cplusplus -// extern "C" { -// #endif -// -// extern int run(const char*); -// -// #ifdef __cplusplus -// } -// #endif -import "C" -import ( - "fmt" - "os" - "strings" -) - -//export doRun -func doRun(args *C.char) C.int { - // This is equivalent to geth.main, just modified to handle the function arg passing - if err := app.Run(strings.Split("geth "+C.GoString(args), " ")); err != nil { - fmt.Fprintln(os.Stderr, err) - return -1 - } - return 0 -} diff --git a/cmd/geth/library_android.go b/cmd/geth/library_android.go deleted file mode 100644 index fb021bfe0..000000000 --- a/cmd/geth/library_android.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2015 The go-ethereum Authors -// This file is part of go-ethereum. -// -// go-ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// go-ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. - -// Contains specialized code for running Geth on Android. - -package main - -// #include <android/log.h> -// #cgo LDFLAGS: -llog -import "C" -import ( - "bufio" - "os" -) - -func init() { - // Redirect the standard output and error to logcat - oldStdout, oldStderr := os.Stdout, os.Stderr - - outRead, outWrite, _ := os.Pipe() - errRead, errWrite, _ := os.Pipe() - - os.Stdout = outWrite - os.Stderr = errWrite - - go func() { - scanner := bufio.NewScanner(outRead) - for scanner.Scan() { - line := scanner.Text() - C.__android_log_write(C.ANDROID_LOG_INFO, C.CString("Stdout"), C.CString(line)) - oldStdout.WriteString(line + "\n") - } - }() - - go func() { - scanner := bufio.NewScanner(errRead) - for scanner.Scan() { - line := scanner.Text() - C.__android_log_write(C.ANDROID_LOG_INFO, C.CString("Stderr"), C.CString(line)) - oldStderr.WriteString(line + "\n") - } - }() -} diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index 584afc804..a56507e4d 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -18,12 +18,14 @@ package utils import ( + "compress/gzip" "fmt" "io" "os" "os/signal" "regexp" "runtime" + "strings" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" @@ -133,7 +135,15 @@ func ImportChain(chain *core.BlockChain, fn string) error { return err } defer fh.Close() - stream := rlp.NewStream(fh, 0) + + var reader io.Reader = fh + if strings.HasSuffix(fn, ".gz") { + if reader, err = gzip.NewReader(reader); err != nil { + return err + } + } + + stream := rlp.NewStream(reader, 0) // Run actual the import. blocks := make(types.Blocks, importBatchSize) @@ -195,10 +205,18 @@ func ExportChain(blockchain *core.BlockChain, fn string) error { return err } defer fh.Close() - if err := blockchain.Export(fh); err != nil { + + var writer io.Writer = fh + if strings.HasSuffix(fn, ".gz") { + writer = gzip.NewWriter(writer) + defer writer.(*gzip.Writer).Close() + } + + if err := blockchain.Export(writer); err != nil { return err } glog.Infoln("Exported blockchain to ", fn) + return nil } @@ -210,7 +228,14 @@ func ExportAppendChain(blockchain *core.BlockChain, fn string, first uint64, las return err } defer fh.Close() - if err := blockchain.ExportN(fh, first, last); err != nil { + + var writer io.Writer = fh + if strings.HasSuffix(fn, ".gz") { + writer = gzip.NewWriter(writer) + defer writer.(*gzip.Writer).Close() + } + + if err := blockchain.ExportN(writer, first, last); err != nil { return err } glog.Infoln("Exported blockchain to ", fn) diff --git a/eth/api.go b/eth/api.go index a86ed95cf..0a1d097e3 100644 --- a/eth/api.go +++ b/eth/api.go @@ -18,6 +18,7 @@ package eth import ( "bytes" + "compress/gzip" "errors" "fmt" "io" @@ -25,6 +26,7 @@ import ( "math/big" "os" "runtime" + "strings" "time" "github.com/ethereum/ethash" @@ -217,8 +219,14 @@ func (api *PrivateAdminAPI) ExportChain(file string) (bool, error) { } defer out.Close() + var writer io.Writer = out + if strings.HasSuffix(file, ".gz") { + writer = gzip.NewWriter(writer) + defer writer.(*gzip.Writer).Close() + } + // Export the blockchain - if err := api.eth.BlockChain().Export(out); err != nil { + if err := api.eth.BlockChain().Export(writer); err != nil { return false, err } return true, nil @@ -243,8 +251,15 @@ func (api *PrivateAdminAPI) ImportChain(file string) (bool, error) { } defer in.Close() + var reader io.Reader = in + if strings.HasSuffix(file, ".gz") { + if reader, err = gzip.NewReader(reader); err != nil { + return false, err + } + } + // Run actual the import in pre-configured batches - stream := rlp.NewStream(in, 0) + stream := rlp.NewStream(reader, 0) blocks, index := make([]*types.Block, 0, 2500), 0 for batch := 0; ; batch++ { diff --git a/miner/miner.go b/miner/miner.go index 87568ac18..61cd3e049 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -119,15 +119,14 @@ func (m *Miner) SetGasPrice(price *big.Int) { func (self *Miner) Start(coinbase common.Address, threads int) { atomic.StoreInt32(&self.shouldStart, 1) - self.threads = threads - self.worker.coinbase = coinbase + self.worker.setEtherbase(coinbase) self.coinbase = coinbase + self.threads = threads if atomic.LoadInt32(&self.canStart) == 0 { glog.V(logger.Info).Infoln("Can not start mining operation due to network sync (starts when finished)") return } - atomic.StoreInt32(&self.mining, 1) for i := 0; i < threads; i++ { @@ -135,9 +134,7 @@ func (self *Miner) Start(coinbase common.Address, threads int) { } glog.V(logger.Info).Infof("Starting mining operation (CPU=%d TOT=%d)\n", threads, len(self.worker.agents)) - self.worker.start() - self.worker.commitNewWork() } @@ -177,8 +174,7 @@ func (self *Miner) SetExtra(extra []byte) error { if uint64(len(extra)) > params.MaximumExtraDataSize.Uint64() { return fmt.Errorf("Extra exceeds max length. %d > %v", len(extra), params.MaximumExtraDataSize) } - - self.worker.extra = extra + self.worker.setExtra(extra) return nil } @@ -188,9 +184,9 @@ func (self *Miner) Pending() (*types.Block, *state.StateDB) { } // PendingBlock returns the currently pending block. -// -// Note, to access both the pending block and the pending state -// simultaneously, please use Pending(), as the pending state can +// +// Note, to access both the pending block and the pending state +// simultaneously, please use Pending(), as the pending state can // change between multiple method calls func (self *Miner) PendingBlock() *types.Block { return self.worker.pendingBlock() diff --git a/miner/remote_agent.go b/miner/remote_agent.go index 00b5f7e08..1a27a1312 100644 --- a/miner/remote_agent.go +++ b/miner/remote_agent.go @@ -37,7 +37,7 @@ type hashrate struct { type RemoteAgent struct { mu sync.Mutex - quit chan struct{} + quitCh chan struct{} workCh chan *Work returnCh chan<- *Result @@ -76,18 +76,16 @@ func (a *RemoteAgent) Start() { if !atomic.CompareAndSwapInt32(&a.running, 0, 1) { return } - - a.quit = make(chan struct{}) + a.quitCh = make(chan struct{}) a.workCh = make(chan *Work, 1) - go a.maintainLoop() + go a.loop(a.workCh, a.quitCh) } func (a *RemoteAgent) Stop() { if !atomic.CompareAndSwapInt32(&a.running, 1, 0) { return } - - close(a.quit) + close(a.quitCh) close(a.workCh) } @@ -148,15 +146,20 @@ func (a *RemoteAgent) SubmitWork(nonce uint64, mixDigest, hash common.Hash) bool return false } -func (a *RemoteAgent) maintainLoop() { +// loop monitors mining events on the work and quit channels, updating the internal +// state of the rmeote miner until a termination is requested. +// +// Note, the reason the work and quit channels are passed as parameters is because +// RemoteAgent.Start() constantly recreates these channels, so the loop code cannot +// assume data stability in these member fields. +func (a *RemoteAgent) loop(workCh chan *Work, quitCh chan struct{}) { ticker := time.Tick(5 * time.Second) -out: for { select { - case <-a.quit: - break out - case work := <-a.workCh: + case <-quitCh: + return + case work := <-workCh: a.mu.Lock() a.currentWork = work a.mu.Unlock() diff --git a/miner/worker.go b/miner/worker.go index 5fa7c4115..fdc6b7d8e 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -161,6 +161,12 @@ func (self *worker) setEtherbase(addr common.Address) { self.coinbase = addr } +func (self *worker) setExtra(extra []byte) { + self.mu.Lock() + defer self.mu.Unlock() + self.extra = extra +} + func (self *worker) pending() (*types.Block, *state.StateDB) { self.currentMu.Lock() defer self.currentMu.Unlock() |