Turbo mining

pull/150/head
obscuren 10 years ago
parent 854d6d4e5c
commit 732573ba51
  1. 8
      ethchain/dagger.go
  2. 2
      ethchain/genesis.go
  3. 8
      ethminer/miner.go

@ -42,6 +42,7 @@ func (pow *EasyPow) Search(block *Block, reactChan chan ethreact.Event) []byte {
diff := block.Difficulty diff := block.Difficulty
i := int64(0) i := int64(0)
start := time.Now().UnixNano() start := time.Now().UnixNano()
t := time.Now()
for { for {
select { select {
@ -50,11 +51,14 @@ func (pow *EasyPow) Search(block *Block, reactChan chan ethreact.Event) []byte {
return nil return nil
default: default:
i++ i++
if i%1234567 == 0 {
if time.Since(t) > (1 * time.Second) {
elapsed := time.Now().UnixNano() - start elapsed := time.Now().UnixNano() - start
hashes := ((float64(1e9) / float64(elapsed)) * float64(i)) / 1000 hashes := ((float64(1e9) / float64(elapsed)) * float64(i)) / 1000
pow.HashRate = int64(hashes) pow.HashRate = int64(hashes)
powlogger.Infoln("Hashing @", int64(pow.HashRate), "khash") powlogger.Infoln("Hashing @", int64(pow.HashRate), "khash")
t = time.Now()
} }
sha := ethcrypto.Sha3Bin(big.NewInt(r.Int63()).Bytes()) sha := ethcrypto.Sha3Bin(big.NewInt(r.Int63()).Bytes())
@ -64,7 +68,7 @@ func (pow *EasyPow) Search(block *Block, reactChan chan ethreact.Event) []byte {
} }
if !pow.turbo { if !pow.turbo {
time.Sleep(500 * time.Millisecond) time.Sleep(20 * time.Microsecond)
} }
} }

@ -28,7 +28,7 @@ var GenesisHeader = []interface{}{
"", "",
// Difficulty // Difficulty
//ethutil.BigPow(2, 22), //ethutil.BigPow(2, 22),
big.NewInt(4096), big.NewInt(131072),
// Number // Number
ethutil.Big0, ethutil.Big0,
// Block minimum gas price // Block minimum gas price

@ -23,6 +23,8 @@ type Miner struct {
powChan chan []byte powChan chan []byte
powQuitChan chan ethreact.Event powQuitChan chan ethreact.Event
quitChan chan chan error quitChan chan chan error
turbo bool
} }
func (self *Miner) GetPow() ethchain.PoW { func (self *Miner) GetPow() ethchain.PoW {
@ -39,6 +41,12 @@ func NewDefaultMiner(coinbase []byte, ethereum ethchain.EthManager) *Miner {
return &miner return &miner
} }
func (self *Miner) ToggleTurbo() {
self.turbo = !self.turbo
self.pow.Turbo(self.turbo)
}
func (miner *Miner) Start() { func (miner *Miner) Start() {
miner.reactChan = make(chan ethreact.Event, 1) // This is the channel that receives 'updates' when ever a new transaction or block comes in miner.reactChan = make(chan ethreact.Event, 1) // This is the channel that receives 'updates' when ever a new transaction or block comes in
miner.powChan = make(chan []byte, 1) // This is the channel that receives valid sha hashes for a given block miner.powChan = make(chan []byte, 1) // This is the channel that receives valid sha hashes for a given block

Loading…
Cancel
Save