Skip to content

Commit b865fad

Browse files
authored
Merge pull request #14537 from karalabe/setgasprice-durning-nomine
eth: update default gas price when not mining too
2 parents afb17cf + c2a494c commit b865fad

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

eth/api.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ func (api *PrivateMinerAPI) Start(threads *int) error {
154154
// Start the miner and return
155155
if !api.e.IsMining() {
156156
// Propagate the initial price point to the transaction pool
157-
api.e.txPool.SetGasPrice(api.e.gasPrice)
157+
api.e.lock.RLock()
158+
price := api.e.gasPrice
159+
api.e.lock.RUnlock()
160+
161+
api.e.txPool.SetGasPrice(price)
158162
return api.e.StartMining(true)
159163
}
160164
return nil
@@ -182,6 +186,10 @@ func (api *PrivateMinerAPI) SetExtra(extra string) (bool, error) {
182186

183187
// SetGasPrice sets the minimum accepted gas price for the miner.
184188
func (api *PrivateMinerAPI) SetGasPrice(gasPrice hexutil.Big) bool {
189+
api.e.lock.Lock()
190+
api.e.gasPrice = (*big.Int)(&gasPrice)
191+
api.e.lock.Unlock()
192+
185193
api.e.txPool.SetGasPrice((*big.Int)(&gasPrice))
186194
return true
187195
}

eth/backend.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ type Ethereum struct {
7676

7777
ApiBackend *EthApiBackend
7878

79-
miner *miner.Miner
80-
gasPrice *big.Int
81-
Mining bool
82-
MinerThreads int
83-
etherbase common.Address
79+
miner *miner.Miner
80+
gasPrice *big.Int
81+
etherbase common.Address
8482

8583
networkId uint64
8684
netRPCService *ethapi.PublicNetAPI
85+
86+
lock sync.RWMutex // Protects the variadic fields (e.g. gas price and etherbase)
8787
}
8888

8989
func (s *Ethereum) AddLesServer(ls LesServer) {
@@ -121,8 +121,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
121121
shutdownChan: make(chan bool),
122122
stopDbUpgrade: stopDbUpgrade,
123123
networkId: config.NetworkId,
124+
gasPrice: config.GasPrice,
124125
etherbase: config.Etherbase,
125-
MinerThreads: config.MinerThreads,
126126
}
127127

128128
if err := addMipmapBloomBins(chainDb); err != nil {
@@ -169,7 +169,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
169169
}
170170

171171
eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine)
172-
eth.gasPrice = config.GasPrice
173172
eth.miner.SetExtra(makeExtraData(config.ExtraData))
174173

175174
eth.ApiBackend = &EthApiBackend{eth, nil}
@@ -295,8 +294,12 @@ func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) {
295294
}
296295

297296
func (s *Ethereum) Etherbase() (eb common.Address, err error) {
298-
if s.etherbase != (common.Address{}) {
299-
return s.etherbase, nil
297+
s.lock.RLock()
298+
etherbase := s.etherbase
299+
s.lock.RUnlock()
300+
301+
if etherbase != (common.Address{}) {
302+
return etherbase, nil
300303
}
301304
if wallets := s.AccountManager().Wallets(); len(wallets) > 0 {
302305
if accounts := wallets[0].Accounts(); len(accounts) > 0 {
@@ -308,7 +311,10 @@ func (s *Ethereum) Etherbase() (eb common.Address, err error) {
308311

309312
// set in js console via admin interface or wrapper from cli flags
310313
func (self *Ethereum) SetEtherbase(etherbase common.Address) {
314+
self.lock.Lock()
311315
self.etherbase = etherbase
316+
self.lock.Unlock()
317+
312318
self.miner.SetEtherbase(etherbase)
313319
}
314320

0 commit comments

Comments
 (0)