aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
Diffstat (limited to 'eth')
-rw-r--r--eth/api.go10
-rw-r--r--eth/backend.go26
-rw-r--r--eth/config.go4
-rw-r--r--eth/gen_config.go6
-rw-r--r--eth/handler.go5
-rw-r--r--eth/sync.go1
6 files changed, 41 insertions, 11 deletions
diff --git a/eth/api.go b/eth/api.go
index 88b3dbbf9..81570988c 100644
--- a/eth/api.go
+++ b/eth/api.go
@@ -154,7 +154,11 @@ func (api *PrivateMinerAPI) Start(threads *int) error {
// Start the miner and return
if !api.e.IsMining() {
// Propagate the initial price point to the transaction pool
- api.e.txPool.SetGasPrice(api.e.gasPrice)
+ api.e.lock.RLock()
+ price := api.e.gasPrice
+ api.e.lock.RUnlock()
+
+ api.e.txPool.SetGasPrice(price)
return api.e.StartMining(true)
}
return nil
@@ -182,6 +186,10 @@ func (api *PrivateMinerAPI) SetExtra(extra string) (bool, error) {
// SetGasPrice sets the minimum accepted gas price for the miner.
func (api *PrivateMinerAPI) SetGasPrice(gasPrice hexutil.Big) bool {
+ api.e.lock.Lock()
+ api.e.gasPrice = (*big.Int)(&gasPrice)
+ api.e.lock.Unlock()
+
api.e.txPool.SetGasPrice((*big.Int)(&gasPrice))
return true
}
diff --git a/eth/backend.go b/eth/backend.go
index 7c63fa51d..639792333 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -76,14 +76,14 @@ type Ethereum struct {
ApiBackend *EthApiBackend
- miner *miner.Miner
- gasPrice *big.Int
- Mining bool
- MinerThreads int
- etherbase common.Address
+ miner *miner.Miner
+ gasPrice *big.Int
+ etherbase common.Address
networkId uint64
netRPCService *ethapi.PublicNetAPI
+
+ lock sync.RWMutex // Protects the variadic fields (e.g. gas price and etherbase)
}
func (s *Ethereum) AddLesServer(ls LesServer) {
@@ -121,8 +121,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
shutdownChan: make(chan bool),
stopDbUpgrade: stopDbUpgrade,
networkId: config.NetworkId,
+ gasPrice: config.GasPrice,
etherbase: config.Etherbase,
- MinerThreads: config.MinerThreads,
}
if err := addMipmapBloomBins(chainDb); err != nil {
@@ -150,7 +150,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
core.WriteChainConfig(chainDb, genesisHash, chainConfig)
}
- newPool := core.NewTxPool(eth.chainConfig, eth.EventMux(), eth.blockchain.State, eth.blockchain.GasLimit)
+ newPool := core.NewTxPool(config.TxPool, eth.chainConfig, eth.EventMux(), eth.blockchain.State, eth.blockchain.GasLimit)
eth.txPool = newPool
maxPeers := config.MaxPeers
@@ -169,7 +169,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
}
eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine)
- eth.gasPrice = config.GasPrice
eth.miner.SetExtra(makeExtraData(config.ExtraData))
eth.ApiBackend = &EthApiBackend{eth, nil}
@@ -295,8 +294,12 @@ func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) {
}
func (s *Ethereum) Etherbase() (eb common.Address, err error) {
- if s.etherbase != (common.Address{}) {
- return s.etherbase, nil
+ s.lock.RLock()
+ etherbase := s.etherbase
+ s.lock.RUnlock()
+
+ if etherbase != (common.Address{}) {
+ return etherbase, nil
}
if wallets := s.AccountManager().Wallets(); len(wallets) > 0 {
if accounts := wallets[0].Accounts(); len(accounts) > 0 {
@@ -308,7 +311,10 @@ func (s *Ethereum) Etherbase() (eb common.Address, err error) {
// set in js console via admin interface or wrapper from cli flags
func (self *Ethereum) SetEtherbase(etherbase common.Address) {
+ self.lock.Lock()
self.etherbase = etherbase
+ self.lock.Unlock()
+
self.miner.SetEtherbase(etherbase)
}
diff --git a/eth/config.go b/eth/config.go
index 22c09b170..4109cff8b 100644
--- a/eth/config.go
+++ b/eth/config.go
@@ -44,6 +44,7 @@ var DefaultConfig = Config{
DatabaseCache: 128,
GasPrice: big.NewInt(18 * params.Shannon),
+ TxPool: core.DefaultTxPoolConfig,
GPO: gasprice.Config{
Blocks: 10,
Percentile: 50,
@@ -99,6 +100,9 @@ type Config struct {
EthashDatasetsInMem int
EthashDatasetsOnDisk int
+ // Transaction pool options
+ TxPool core.TxPoolConfig
+
// Gas Price Oracle options
GPO gasprice.Config
diff --git a/eth/gen_config.go b/eth/gen_config.go
index 955facf8f..477479419 100644
--- a/eth/gen_config.go
+++ b/eth/gen_config.go
@@ -33,6 +33,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
EthashDatasetDir string
EthashDatasetsInMem int
EthashDatasetsOnDisk int
+ TxPool core.TxPoolConfig
GPO gasprice.Config
EnablePreimageRecording bool
DocRoot string `toml:"-"`
@@ -60,6 +61,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.EthashDatasetDir = c.EthashDatasetDir
enc.EthashDatasetsInMem = c.EthashDatasetsInMem
enc.EthashDatasetsOnDisk = c.EthashDatasetsOnDisk
+ enc.TxPool = c.TxPool
enc.GPO = c.GPO
enc.EnablePreimageRecording = c.EnablePreimageRecording
enc.DocRoot = c.DocRoot
@@ -90,6 +92,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
EthashDatasetDir *string
EthashDatasetsInMem *int
EthashDatasetsOnDisk *int
+ TxPool *core.TxPoolConfig
GPO *gasprice.Config
EnablePreimageRecording *bool
DocRoot *string `toml:"-"`
@@ -158,6 +161,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.EthashDatasetsOnDisk != nil {
c.EthashDatasetsOnDisk = *dec.EthashDatasetsOnDisk
}
+ if dec.TxPool != nil {
+ c.TxPool = *dec.TxPool
+ }
if dec.GPO != nil {
c.GPO = *dec.GPO
}
diff --git a/eth/handler.go b/eth/handler.go
index 16e371227..8c2f5660d 100644
--- a/eth/handler.go
+++ b/eth/handler.go
@@ -171,6 +171,11 @@ func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, ne
return blockchain.CurrentBlock().NumberU64()
}
inserter := func(blocks types.Blocks) (int, error) {
+ // If fast sync is running, deny importing weird blocks
+ if atomic.LoadUint32(&manager.fastSync) == 1 {
+ log.Warn("Discarded bad propagated block", "number", blocks[0].Number(), "hash", blocks[0].Hash())
+ return 0, nil
+ }
atomic.StoreUint32(&manager.acceptTxs, 1) // Mark initial sync done on any fetcher import
return manager.blockchain.InsertChain(blocks)
}
diff --git a/eth/sync.go b/eth/sync.go
index b0653acf9..8784b225d 100644
--- a/eth/sync.go
+++ b/eth/sync.go
@@ -183,6 +183,7 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
// The only scenario where this can happen is if the user manually (or via a
// bad block) rolled back a fast sync node below the sync point. In this case
// however it's safe to reenable fast sync.
+ atomic.StoreUint32(&pm.fastSync, 1)
mode = downloader.FastSync
}
if err := pm.downloader.Synchronise(peer.id, pHead, pTd, mode); err != nil {