@@ -31,10 +31,13 @@ import (
3131 "github.com/ethereum/go-ethereum/consensus"
3232 "github.com/ethereum/go-ethereum/consensus/clique"
3333 "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"
3436 "github.com/ethereum/go-ethereum/core"
3537 "github.com/ethereum/go-ethereum/core/bloombits"
3638 "github.com/ethereum/go-ethereum/core/types"
3739 "github.com/ethereum/go-ethereum/core/vm"
40+ "github.com/ethereum/go-ethereum/crypto"
3841 "github.com/ethereum/go-ethereum/eth/downloader"
3942 "github.com/ethereum/go-ethereum/eth/filters"
4043 "github.com/ethereum/go-ethereum/eth/gasprice"
@@ -125,7 +128,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
125128 chainConfig : chainConfig ,
126129 eventMux : ctx .EventMux ,
127130 accountManager : ctx .AccountManager ,
128- engine : CreateConsensusEngine (ctx , & config . Ethash , chainConfig , chainDb ),
131+ engine : CreateConsensusEngine (ctx , config , chainConfig , chainDb ),
129132 shutdownChan : make (chan bool ),
130133 stopDbUpgrade : stopDbUpgrade ,
131134 networkId : config .NetworkId ,
@@ -135,6 +138,11 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
135138 bloomIndexer : NewBloomIndexer (chainDb , params .BloomBitsBlocks ),
136139 }
137140
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+
138146 log .Info ("Initialising Ethereum protocol" , "versions" , eth .engine .Protocol ().Versions , "network" , config .NetworkId )
139147
140148 if ! config .SkipBcVersionCheck {
@@ -209,30 +217,40 @@ func CreateDB(ctx *node.ServiceContext, config *Config, name string) (ethdb.Data
209217}
210218
211219// CreateConsensusEngine creates the required type of consensus engine instance for an Ethereum service
212- func CreateConsensusEngine (ctx * node.ServiceContext , config * ethash. Config , chainConfig * params.ChainConfig , db ethdb.Database ) consensus.Engine {
220+ func CreateConsensusEngine (ctx * node.ServiceContext , config * Config , chainConfig * params.ChainConfig , db ethdb.Database ) consensus.Engine {
213221 // If proof-of-authority is requested, set it up
214222 if chainConfig .Clique != nil {
215223 return clique .New (chainConfig .Clique , db )
216224 }
225+ // If Istanbul is requested, set it up
226+ if chainConfig .Istanbul != nil {
227+ if chainConfig .Istanbul .Epoch != 0 {
228+ config .Istanbul .Epoch = chainConfig .Istanbul .Epoch
229+ }
230+ config .Istanbul .ProposerPolicy = istanbul .ProposerPolicy (chainConfig .Istanbul .ProposerPolicy )
231+ return istanbulBackend .New (& config .Istanbul , ctx .NodeKey (), db )
232+ }
233+
217234 // Otherwise assume proof-of-work
235+ ethConfig := config .Ethash
218236 switch {
219- case config .PowMode == ethash .ModeFake :
237+ case ethConfig .PowMode == ethash .ModeFake :
220238 log .Warn ("Ethash used in fake mode" )
221239 return ethash .NewFaker ()
222- case config .PowMode == ethash .ModeTest :
240+ case ethConfig .PowMode == ethash .ModeTest :
223241 log .Warn ("Ethash used in test mode" )
224242 return ethash .NewTester ()
225- case config .PowMode == ethash .ModeShared :
243+ case ethConfig .PowMode == ethash .ModeShared :
226244 log .Warn ("Ethash used in shared mode" )
227245 return ethash .NewShared ()
228246 default :
229247 engine := ethash .New (ethash.Config {
230- CacheDir : ctx .ResolvePath (config .CacheDir ),
231- CachesInMem : config .CachesInMem ,
232- CachesOnDisk : config .CachesOnDisk ,
233- DatasetDir : config .DatasetDir ,
234- DatasetsInMem : config .DatasetsInMem ,
235- DatasetsOnDisk : config .DatasetsOnDisk ,
248+ CacheDir : ctx .ResolvePath (ethConfig .CacheDir ),
249+ CachesInMem : ethConfig .CachesInMem ,
250+ CachesOnDisk : ethConfig .CachesOnDisk ,
251+ DatasetDir : ethConfig .DatasetDir ,
252+ DatasetsInMem : ethConfig .DatasetsInMem ,
253+ DatasetsOnDisk : ethConfig .DatasetsOnDisk ,
236254 })
237255 engine .SetThreads (- 1 ) // Disable CPU mining
238256 return engine
@@ -326,6 +344,10 @@ func (s *Ethereum) Etherbase() (eb common.Address, err error) {
326344// set in js console via admin interface or wrapper from cli flags
327345func (self * Ethereum ) SetEtherbase (etherbase common.Address ) {
328346 self .lock .Lock ()
347+ if _ , ok := self .engine .(consensus.Istanbul ); ok {
348+ log .Error ("Cannot set etherbase in Istanbul consensus" )
349+ return
350+ }
329351 self .etherbase = etherbase
330352 self .lock .Unlock ()
331353
0 commit comments