Skip to content

Commit

Permalink
Merge pull request #345 from maran/feature/minerthreads
Browse files Browse the repository at this point in the history
Implement command line argument to set the amount miner threads
  • Loading branch information
obscuren committed Feb 19, 2015
2 parents 07c3475 + 5aff8bf commit 765740b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
3 changes: 3 additions & 0 deletions cmd/mist/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ var (
DebugFile string
LogLevel int
VmType int
MinerThreads int
)

// flags specific to gui client
Expand Down Expand Up @@ -137,6 +138,8 @@ func Init() {
flag.StringVar(&BootNodes, "bootnodes", "", "space-separated node URLs for discovery bootstrap")
flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers")

flag.IntVar(&MinerThreads, "minerthreads", runtime.NumCPU(), "number of miner threads")

flag.Parse()

var err error
Expand Down
27 changes: 14 additions & 13 deletions cmd/mist/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,20 @@ func run() error {
config := utils.InitConfig(VmType, ConfigFile, Datadir, "ETH")

ethereum, err := eth.New(&eth.Config{
Name: p2p.MakeName(ClientIdentifier, Version),
KeyStore: KeyStore,
DataDir: Datadir,
LogFile: LogFile,
LogLevel: LogLevel,
MaxPeers: MaxPeer,
Port: OutboundPort,
NAT: NAT,
Shh: true,
BootNodes: BootNodes,
NodeKey: NodeKey,
KeyRing: KeyRing,
Dial: true,
Name: p2p.MakeName(ClientIdentifier, Version),
KeyStore: KeyStore,
DataDir: Datadir,
LogFile: LogFile,
LogLevel: LogLevel,
MaxPeers: MaxPeer,
Port: OutboundPort,
NAT: NAT,
Shh: true,
BootNodes: BootNodes,
NodeKey: NodeKey,
KeyRing: KeyRing,
Dial: true,
MinerThreads: MinerThreads,
})
if err != nil {
mainlogger.Fatalln(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/utils/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func StartMining(ethereum *eth.Ethereum) bool {
go func() {
clilogger.Infoln("Start mining")
if gminer == nil {
gminer = miner.New(addr, ethereum)
gminer = miner.New(addr, ethereum, 4)
}
gminer.Start()
}()
Expand Down
4 changes: 3 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type Config struct {
Shh bool
Dial bool

MinerThreads int

KeyManager *crypto.KeyManager
}

Expand Down Expand Up @@ -153,7 +155,7 @@ func New(config *Config) (*Ethereum, error) {
eth.blockProcessor = core.NewBlockProcessor(db, eth.txPool, eth.chainManager, eth.EventMux())
eth.chainManager.SetProcessor(eth.blockProcessor)
eth.whisper = whisper.New()
eth.miner = miner.New(keyManager.Address(), eth)
eth.miner = miner.New(keyManager.Address(), eth, config.MinerThreads)

hasBlock := eth.chainManager.HasBlock
insertChain := eth.chainManager.InsertChain
Expand Down
4 changes: 2 additions & 2 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ type Miner struct {
mining bool
}

func New(coinbase []byte, eth core.Backend) *Miner {
func New(coinbase []byte, eth core.Backend, minerThreads int) *Miner {
miner := &Miner{
Coinbase: coinbase,
worker: newWorker(coinbase, eth),
}

for i := 0; i < 4; i++ {
for i := 0; i < minerThreads; i++ {
miner.worker.register(NewCpuMiner(i, ezp.New()))
}

Expand Down

0 comments on commit 765740b

Please sign in to comment.