aboutsummaryrefslogtreecommitdiffstats
path: root/eth/backend.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@users.noreply.github.com>2017-04-12 22:27:23 +0800
committerPéter Szilágyi <peterke@gmail.com>2017-04-12 22:27:23 +0800
commit30d706c35e16305e2e3ec0eb6a6bdd6aba50d9d2 (patch)
tree3ec076154049f1fa71b19fd9b7762085059ff15b /eth/backend.go
parentb57680b0b21036460c689aab1e82d89297738d50 (diff)
downloadgo-tangerine-30d706c35e16305e2e3ec0eb6a6bdd6aba50d9d2.tar
go-tangerine-30d706c35e16305e2e3ec0eb6a6bdd6aba50d9d2.tar.gz
go-tangerine-30d706c35e16305e2e3ec0eb6a6bdd6aba50d9d2.tar.bz2
go-tangerine-30d706c35e16305e2e3ec0eb6a6bdd6aba50d9d2.tar.lz
go-tangerine-30d706c35e16305e2e3ec0eb6a6bdd6aba50d9d2.tar.xz
go-tangerine-30d706c35e16305e2e3ec0eb6a6bdd6aba50d9d2.tar.zst
go-tangerine-30d706c35e16305e2e3ec0eb6a6bdd6aba50d9d2.zip
cmd/geth: add --config file flag (#13875)
* p2p/discover, p2p/discv5: add marshaling methods to Node * p2p/netutil: make Netlist decodable from TOML * common/math: encode nil HexOrDecimal256 as 0x0 * cmd/geth: add --config file flag * cmd/geth: add missing license header * eth: prettify Config again, fix tests * eth: use gasprice.Config instead of duplicating its fields * eth/gasprice: hide nil default from dumpconfig output * cmd/geth: hide genesis block in dumpconfig output * node: make tests compile * console: fix tests * cmd/geth: make TOML keys look exactly like Go struct fields * p2p: use discovery by default This makes the zero Config slightly more useful. It also fixes package node tests because Node detects reuse of the datadir through the NodeDatabase. * cmd/geth: make ethstats URL settable through config file * cmd/faucet: fix configuration * cmd/geth: dedup attach tests * eth: add comment for DefaultConfig * eth: pass downloader.SyncMode in Config This removes the FastSync, LightSync flags in favour of a more general SyncMode flag. * cmd/utils: remove jitvm flags * cmd/utils: make mutually exclusive flag error prettier It now reads: Fatal: flags --dev, --testnet can't be used at the same time * p2p: fix typo * node: add DefaultConfig, use it for geth * mobile: add missing NoDiscovery option * cmd/utils: drop MakeNode This exposed a couple of places that needed to be updated to use node.DefaultConfig. * node: fix typo * eth: make fast sync the default mode * cmd/utils: remove IPCApiFlag (unused) * node: remove default IPC path Set it in the frontends instead. * cmd/geth: add --syncmode * cmd/utils: make --ipcdisable and --ipcpath mutually exclusive * cmd/utils: don't enable WS, HTTP when setting addr * cmd/utils: fix --identity
Diffstat (limited to 'eth/backend.go')
-rw-r--r--eth/backend.go92
1 files changed, 33 insertions, 59 deletions
diff --git a/eth/backend.go b/eth/backend.go
index 4dffa2990..7ee591f9e 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -18,14 +18,15 @@
package eth
import (
+ "errors"
"fmt"
- "math/big"
- "regexp"
+ "runtime"
"sync"
"sync/atomic"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/clique"
"github.com/ethereum/go-ethereum/consensus/ethash"
@@ -43,55 +44,10 @@ import (
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/params"
+ "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
)
-var (
- datadirInUseErrnos = map[uint]bool{11: true, 32: true, 35: true}
- portInUseErrRE = regexp.MustCompile("address already in use")
-)
-
-type Config struct {
- // The genesis block, which is inserted if the database is empty.
- // If nil, the Ethereum main net block is used.
- Genesis *core.Genesis
-
- NetworkId int // Network ID to use for selecting peers to connect to
-
- FastSync bool // Enables the state download based fast synchronisation algorithm
- LightMode bool // Running in light client mode
- LightServ int // Maximum percentage of time allowed for serving LES requests
- LightPeers int // Maximum number of LES client peers
- MaxPeers int // Maximum number of global peers
-
- SkipBcVersionCheck bool // e.g. blockchain export
- DatabaseCache int
- DatabaseHandles int
-
- DocRoot string
- PowFake bool
- PowTest bool
- PowShared bool
- ExtraData []byte
-
- EthashCacheDir string
- EthashCachesInMem int
- EthashCachesOnDisk int
- EthashDatasetDir string
- EthashDatasetsInMem int
- EthashDatasetsOnDisk int
-
- Etherbase common.Address
- GasPrice *big.Int
- MinerThreads int
- SolcPath string
-
- GpoBlocks int
- GpoPercentile int
-
- EnablePreimageRecording bool
-}
-
type LesServer interface {
Start(srvr *p2p.Server)
Stop()
@@ -137,6 +93,13 @@ func (s *Ethereum) AddLesServer(ls LesServer) {
// New creates a new Ethereum object (including the
// initialisation of the common Ethereum object)
func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
+ if config.SyncMode == downloader.LightSync {
+ return nil, errors.New("can't run eth.Ethereum in light sync mode, use les.LightEthereum")
+ }
+ if !config.SyncMode.IsValid() {
+ return nil, fmt.Errorf("invalid sync mode %d", config.SyncMode)
+ }
+
chainDb, err := CreateDB(ctx, config, "chaindata")
if err != nil {
return nil, err
@@ -201,25 +164,41 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
}
}
- if eth.protocolManager, err = NewProtocolManager(eth.chainConfig, config.FastSync, config.NetworkId, maxPeers, eth.eventMux, eth.txPool, eth.engine, eth.blockchain, chainDb); err != nil {
+ if eth.protocolManager, err = NewProtocolManager(eth.chainConfig, config.SyncMode, config.NetworkId, maxPeers, eth.eventMux, eth.txPool, eth.engine, eth.blockchain, chainDb); err != nil {
return nil, err
}
eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine)
eth.miner.SetGasPrice(config.GasPrice)
- eth.miner.SetExtra(config.ExtraData)
+ eth.miner.SetExtra(makeExtraData(config.ExtraData))
eth.ApiBackend = &EthApiBackend{eth, nil}
- gpoParams := gasprice.Config{
- Blocks: config.GpoBlocks,
- Percentile: config.GpoPercentile,
- Default: config.GasPrice,
+ gpoParams := config.GPO
+ if gpoParams.Default == nil {
+ gpoParams.Default = config.GasPrice
}
eth.ApiBackend.gpo = gasprice.NewOracle(eth.ApiBackend, gpoParams)
return eth, nil
}
+func makeExtraData(extra []byte) []byte {
+ if len(extra) == 0 {
+ // create default extradata
+ extra, _ = rlp.EncodeToBytes([]interface{}{
+ uint(params.VersionMajor<<16 | params.VersionMinor<<8 | params.VersionPatch),
+ "geth",
+ runtime.Version(),
+ runtime.GOOS,
+ })
+ }
+ if uint64(len(extra)) > params.MaximumExtraDataSize {
+ log.Warn("Miner extra data exceed limit", "extra", hexutil.Bytes(extra), "limit", params.MaximumExtraDataSize)
+ extra = nil
+ }
+ return extra
+}
+
// CreateDB creates the chain database.
func CreateDB(ctx *node.ServiceContext, config *Config, name string) (ethdb.Database, error) {
db, err := ctx.OpenDatabase(name, config.DatabaseCache, config.DatabaseHandles)
@@ -415,8 +394,3 @@ func (s *Ethereum) Stop() error {
return nil
}
-
-// This function will wait for a shutdown and resumes main thread execution
-func (s *Ethereum) WaitForShutdown() {
- <-s.shutdownChan
-}