aboutsummaryrefslogtreecommitdiffstats
path: root/eth/backend.go
diff options
context:
space:
mode:
Diffstat (limited to 'eth/backend.go')
-rw-r--r--eth/backend.go96
1 files changed, 34 insertions, 62 deletions
diff --git a/eth/backend.go b/eth/backend.go
index 4dffa2990..03c2e38e5 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()
@@ -123,7 +79,6 @@ type Ethereum struct {
Mining bool
MinerThreads int
etherbase common.Address
- solcPath string
netVersionId int
netRPCService *ethapi.PublicNetAPI
@@ -137,6 +92,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
@@ -159,7 +121,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
netVersionId: config.NetworkId,
etherbase: config.Etherbase,
MinerThreads: config.MinerThreads,
- solcPath: config.SolcPath,
}
if err := addMipmapBloomBins(chainDb); err != nil {
@@ -201,25 +162,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)
@@ -257,7 +234,7 @@ func CreateConsensusEngine(ctx *node.ServiceContext, config *Config, chainConfig
// APIs returns the collection of RPC services the ethereum package offers.
// NOTE, some of these services probably need to be moved to somewhere else.
func (s *Ethereum) APIs() []rpc.API {
- apis := ethapi.GetAPIs(s.ApiBackend, s.solcPath)
+ apis := ethapi.GetAPIs(s.ApiBackend)
// Append any APIs exposed explicitly by the consensus engine
apis = append(apis, s.engine.APIs(s.BlockChain())...)
@@ -415,8 +392,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
-}