mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
Fix makefile, clean up miner.go
This commit is contained in:
parent
c399152a07
commit
c6782a4284
2 changed files with 19 additions and 47 deletions
2
Makefile
2
Makefile
|
|
@ -98,7 +98,7 @@ geth-ios: xgo
|
|||
@ls -ld $(GOBIN)/geth-ios-*
|
||||
|
||||
evm:
|
||||
build/env.sh $(GOROOT)/bin/go install -v $(shell build/flags.sh) ./cmd/evm
|
||||
build/env.sh go install -v $(shell build/flags.sh) ./cmd/evm
|
||||
@echo "Done building."
|
||||
@echo "Run \"$(GOBIN)/evm to start the evm."
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ type Miner struct {
|
|||
canStart int32 // can start indicates whether we can start the mining operation
|
||||
shouldStart int32 // should start indicates whether we should start after sync
|
||||
|
||||
sub event.Subscription
|
||||
}
|
||||
|
||||
func New(eth core.Backend, config *core.ChainConfig, mux *event.TypeMux, pow pow.PoW) *Miner {
|
||||
|
|
@ -104,48 +103,6 @@ func (m *Miner) SetGasPrice(price *big.Int) {
|
|||
}
|
||||
|
||||
func (self *Miner) Start(coinbase common.Address, threads int) {
|
||||
self.sub = self.mux.Subscribe(core.TxPreEvent{}, core.NewBlockEvent{}, core.NewMinedBlockEvent{})
|
||||
//go self.filterLoop(coinbase, threads)
|
||||
self.actuallyStart(coinbase, threads)
|
||||
|
||||
}
|
||||
|
||||
func (self *Miner) runLoop() {
|
||||
for true {
|
||||
if len(self.worker.current.txs) == 0 {
|
||||
if self.Mining() {
|
||||
glog.V(logger.Info).Infoln("Nothing to do. The miner sleeps.")
|
||||
self.Stop()
|
||||
}
|
||||
} else {
|
||||
if self.Mining() == false {
|
||||
glog.V(logger.Info).Infoln("A transaction awaits! Waking up miner.")
|
||||
self.Start(self.coinbase, self.threads)
|
||||
}
|
||||
}
|
||||
time.Sleep(3000 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *Miner) filterLoop(coinbase common.Address, threads int) {
|
||||
for event := range self.sub.Chan() {
|
||||
switch event.Data.(type) {
|
||||
case core.TxPreEvent:
|
||||
glog.V(logger.Info).Infoln("New pending tranny yo, start mining!")
|
||||
self.actuallyStart(coinbase, threads)
|
||||
case core.NewBlockEvent:
|
||||
glog.V(logger.Info).Infoln("New block event")
|
||||
self.Stop()
|
||||
self.Start(coinbase, threads)
|
||||
case core.NewMinedBlockEvent:
|
||||
glog.V(logger.Info).Infoln("New MINED block event")
|
||||
self.Stop()
|
||||
self.Start(coinbase, threads)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *Miner) actuallyStart(coinbase common.Address, threads int) {
|
||||
atomic.StoreInt32(&self.shouldStart, 1)
|
||||
self.threads = threads
|
||||
self.worker.coinbase = coinbase
|
||||
|
|
@ -167,12 +124,27 @@ func (self *Miner) actuallyStart(coinbase common.Address, threads int) {
|
|||
self.worker.start()
|
||||
|
||||
self.worker.commitNewWork()
|
||||
|
||||
}
|
||||
|
||||
func (self *Miner) runLoop() {
|
||||
for true {
|
||||
if len(self.worker.current.txs) == 0 {
|
||||
if self.Mining() {
|
||||
glog.V(logger.Info).Infoln("Nothing to do. The miner sleeps.")
|
||||
self.Stop()
|
||||
}
|
||||
} else {
|
||||
if self.Mining() == false {
|
||||
glog.V(logger.Info).Infoln("A transaction awaits! Waking up miner.")
|
||||
self.Start(self.coinbase, self.threads)
|
||||
}
|
||||
}
|
||||
time.Sleep(3000 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *Miner) Stop() {
|
||||
if self.sub != nil {
|
||||
self.sub.Unsubscribe()
|
||||
}
|
||||
self.worker.stop()
|
||||
atomic.StoreInt32(&self.mining, 0)
|
||||
atomic.StoreInt32(&self.shouldStart, 0)
|
||||
|
|
|
|||
Loading…
Reference in a new issue