@@ -31,10 +31,13 @@ import (
31
31
"github.com/ethereum/go-ethereum/consensus"
32
32
"github.com/ethereum/go-ethereum/consensus/clique"
33
33
"github.com/ethereum/go-ethereum/consensus/ethash"
34
+ "github.com/ethereum/go-ethereum/consensus/istanbul"
35
+ istanbulBackend "github.com/ethereum/go-ethereum/consensus/istanbul/backend"
34
36
"github.com/ethereum/go-ethereum/core"
35
37
"github.com/ethereum/go-ethereum/core/bloombits"
36
38
"github.com/ethereum/go-ethereum/core/types"
37
39
"github.com/ethereum/go-ethereum/core/vm"
40
+ "github.com/ethereum/go-ethereum/crypto"
38
41
"github.com/ethereum/go-ethereum/eth/downloader"
39
42
"github.com/ethereum/go-ethereum/eth/filters"
40
43
"github.com/ethereum/go-ethereum/eth/gasprice"
@@ -125,7 +128,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
125
128
chainConfig : chainConfig ,
126
129
eventMux : ctx .EventMux ,
127
130
accountManager : ctx .AccountManager ,
128
- engine : CreateConsensusEngine (ctx , & config . Ethash , chainConfig , chainDb ),
131
+ engine : CreateConsensusEngine (ctx , config , chainConfig , chainDb ),
129
132
shutdownChan : make (chan bool ),
130
133
stopDbUpgrade : stopDbUpgrade ,
131
134
networkId : config .NetworkId ,
@@ -135,6 +138,11 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
135
138
bloomIndexer : NewBloomIndexer (chainDb , params .BloomBitsBlocks ),
136
139
}
137
140
141
+ // force to set the istanbul etherbase to node key address
142
+ if chainConfig .Istanbul != nil {
143
+ eth .etherbase = crypto .PubkeyToAddress (ctx .NodeKey ().PublicKey )
144
+ }
145
+
138
146
log .Info ("Initialising Ethereum protocol" , "versions" , eth .engine .Protocol ().Versions , "network" , config .NetworkId )
139
147
140
148
if ! config .SkipBcVersionCheck {
@@ -211,30 +219,40 @@ func CreateDB(ctx *node.ServiceContext, config *Config, name string) (ethdb.Data
211
219
}
212
220
213
221
// CreateConsensusEngine creates the required type of consensus engine instance for an Ethereum service
214
- func CreateConsensusEngine (ctx * node.ServiceContext , config * ethash. Config , chainConfig * params.ChainConfig , db ethdb.Database ) consensus.Engine {
222
+ func CreateConsensusEngine (ctx * node.ServiceContext , config * Config , chainConfig * params.ChainConfig , db ethdb.Database ) consensus.Engine {
215
223
// If proof-of-authority is requested, set it up
216
224
if chainConfig .Clique != nil {
217
225
return clique .New (chainConfig .Clique , db )
218
226
}
227
+ // If Istanbul is requested, set it up
228
+ if chainConfig .Istanbul != nil {
229
+ if chainConfig .Istanbul .Epoch != 0 {
230
+ config .Istanbul .Epoch = chainConfig .Istanbul .Epoch
231
+ }
232
+ config .Istanbul .ProposerPolicy = istanbul .ProposerPolicy (chainConfig .Istanbul .ProposerPolicy )
233
+ return istanbulBackend .New (& config .Istanbul , ctx .NodeKey (), db )
234
+ }
235
+
219
236
// Otherwise assume proof-of-work
237
+ ethConfig := config .Ethash
220
238
switch {
221
- case config .PowMode == ethash .ModeFake :
239
+ case ethConfig .PowMode == ethash .ModeFake :
222
240
log .Warn ("Ethash used in fake mode" )
223
241
return ethash .NewFaker ()
224
- case config .PowMode == ethash .ModeTest :
242
+ case ethConfig .PowMode == ethash .ModeTest :
225
243
log .Warn ("Ethash used in test mode" )
226
244
return ethash .NewTester ()
227
- case config .PowMode == ethash .ModeShared :
245
+ case ethConfig .PowMode == ethash .ModeShared :
228
246
log .Warn ("Ethash used in shared mode" )
229
247
return ethash .NewShared ()
230
248
default :
231
249
engine := ethash .New (ethash.Config {
232
- CacheDir : ctx .ResolvePath (config .CacheDir ),
233
- CachesInMem : config .CachesInMem ,
234
- CachesOnDisk : config .CachesOnDisk ,
235
- DatasetDir : config .DatasetDir ,
236
- DatasetsInMem : config .DatasetsInMem ,
237
- DatasetsOnDisk : config .DatasetsOnDisk ,
250
+ CacheDir : ctx .ResolvePath (ethConfig .CacheDir ),
251
+ CachesInMem : ethConfig .CachesInMem ,
252
+ CachesOnDisk : ethConfig .CachesOnDisk ,
253
+ DatasetDir : ethConfig .DatasetDir ,
254
+ DatasetsInMem : ethConfig .DatasetsInMem ,
255
+ DatasetsOnDisk : ethConfig .DatasetsOnDisk ,
238
256
})
239
257
engine .SetThreads (- 1 ) // Disable CPU mining
240
258
return engine
@@ -328,6 +346,10 @@ func (s *Ethereum) Etherbase() (eb common.Address, err error) {
328
346
// set in js console via admin interface or wrapper from cli flags
329
347
func (self * Ethereum ) SetEtherbase (etherbase common.Address ) {
330
348
self .lock .Lock ()
349
+ if _ , ok := self .engine .(consensus.Istanbul ); ok {
350
+ log .Error ("Cannot set etherbase in Istanbul consensus" )
351
+ return
352
+ }
331
353
self .etherbase = etherbase
332
354
self .lock .Unlock ()
333
355
0 commit comments