@@ -76,14 +76,14 @@ type Ethereum struct {
76
76
77
77
ApiBackend * EthApiBackend
78
78
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
84
82
85
83
networkId uint64
86
84
netRPCService * ethapi.PublicNetAPI
85
+
86
+ lock sync.RWMutex // Protects the variadic fields (e.g. gas price and etherbase)
87
87
}
88
88
89
89
func (s * Ethereum ) AddLesServer (ls LesServer ) {
@@ -121,8 +121,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
121
121
shutdownChan : make (chan bool ),
122
122
stopDbUpgrade : stopDbUpgrade ,
123
123
networkId : config .NetworkId ,
124
+ gasPrice : config .GasPrice ,
124
125
etherbase : config .Etherbase ,
125
- MinerThreads : config .MinerThreads ,
126
126
}
127
127
128
128
if err := addMipmapBloomBins (chainDb ); err != nil {
@@ -169,7 +169,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
169
169
}
170
170
171
171
eth .miner = miner .New (eth , eth .chainConfig , eth .EventMux (), eth .engine )
172
- eth .gasPrice = config .GasPrice
173
172
eth .miner .SetExtra (makeExtraData (config .ExtraData ))
174
173
175
174
eth .ApiBackend = & EthApiBackend {eth , nil }
@@ -295,8 +294,12 @@ func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) {
295
294
}
296
295
297
296
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
300
303
}
301
304
if wallets := s .AccountManager ().Wallets (); len (wallets ) > 0 {
302
305
if accounts := wallets [0 ].Accounts (); len (accounts ) > 0 {
@@ -308,7 +311,10 @@ func (s *Ethereum) Etherbase() (eb common.Address, err error) {
308
311
309
312
// set in js console via admin interface or wrapper from cli flags
310
313
func (self * Ethereum ) SetEtherbase (etherbase common.Address ) {
314
+ self .lock .Lock ()
311
315
self .etherbase = etherbase
316
+ self .lock .Unlock ()
317
+
312
318
self .miner .SetEtherbase (etherbase )
313
319
}
314
320
0 commit comments