Merge pull request #345 from maran/feature/minerthreads
Implement command line argument to set the amount miner threads
This commit is contained in:
commit
765740b829
@ -63,6 +63,7 @@ var (
|
|||||||
DebugFile string
|
DebugFile string
|
||||||
LogLevel int
|
LogLevel int
|
||||||
VmType int
|
VmType int
|
||||||
|
MinerThreads int
|
||||||
)
|
)
|
||||||
|
|
||||||
// flags specific to gui client
|
// flags specific to gui client
|
||||||
@ -137,6 +138,8 @@ func Init() {
|
|||||||
flag.StringVar(&BootNodes, "bootnodes", "", "space-separated node URLs for discovery bootstrap")
|
flag.StringVar(&BootNodes, "bootnodes", "", "space-separated node URLs for discovery bootstrap")
|
||||||
flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers")
|
flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers")
|
||||||
|
|
||||||
|
flag.IntVar(&MinerThreads, "minerthreads", runtime.NumCPU(), "number of miner threads")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
@ -65,6 +65,7 @@ func run() error {
|
|||||||
NodeKey: NodeKey,
|
NodeKey: NodeKey,
|
||||||
KeyRing: KeyRing,
|
KeyRing: KeyRing,
|
||||||
Dial: true,
|
Dial: true,
|
||||||
|
MinerThreads: MinerThreads,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mainlogger.Fatalln(err)
|
mainlogger.Fatalln(err)
|
||||||
|
@ -225,7 +225,7 @@ func StartMining(ethereum *eth.Ethereum) bool {
|
|||||||
go func() {
|
go func() {
|
||||||
clilogger.Infoln("Start mining")
|
clilogger.Infoln("Start mining")
|
||||||
if gminer == nil {
|
if gminer == nil {
|
||||||
gminer = miner.New(addr, ethereum)
|
gminer = miner.New(addr, ethereum, 4)
|
||||||
}
|
}
|
||||||
gminer.Start()
|
gminer.Start()
|
||||||
}()
|
}()
|
||||||
|
@ -53,6 +53,8 @@ type Config struct {
|
|||||||
Shh bool
|
Shh bool
|
||||||
Dial bool
|
Dial bool
|
||||||
|
|
||||||
|
MinerThreads int
|
||||||
|
|
||||||
KeyManager *crypto.KeyManager
|
KeyManager *crypto.KeyManager
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +155,7 @@ func New(config *Config) (*Ethereum, error) {
|
|||||||
eth.blockProcessor = core.NewBlockProcessor(db, eth.txPool, eth.chainManager, eth.EventMux())
|
eth.blockProcessor = core.NewBlockProcessor(db, eth.txPool, eth.chainManager, eth.EventMux())
|
||||||
eth.chainManager.SetProcessor(eth.blockProcessor)
|
eth.chainManager.SetProcessor(eth.blockProcessor)
|
||||||
eth.whisper = whisper.New()
|
eth.whisper = whisper.New()
|
||||||
eth.miner = miner.New(keyManager.Address(), eth)
|
eth.miner = miner.New(keyManager.Address(), eth, config.MinerThreads)
|
||||||
|
|
||||||
hasBlock := eth.chainManager.HasBlock
|
hasBlock := eth.chainManager.HasBlock
|
||||||
insertChain := eth.chainManager.InsertChain
|
insertChain := eth.chainManager.InsertChain
|
||||||
|
@ -20,13 +20,13 @@ type Miner struct {
|
|||||||
mining bool
|
mining bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(coinbase []byte, eth core.Backend) *Miner {
|
func New(coinbase []byte, eth core.Backend, minerThreads int) *Miner {
|
||||||
miner := &Miner{
|
miner := &Miner{
|
||||||
Coinbase: coinbase,
|
Coinbase: coinbase,
|
||||||
worker: newWorker(coinbase, eth),
|
worker: newWorker(coinbase, eth),
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < minerThreads; i++ {
|
||||||
miner.worker.register(NewCpuMiner(i, ezp.New()))
|
miner.worker.register(NewCpuMiner(i, ezp.New()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user