From e870e61bc95cf40ca9956b2eb887976ef60dfd9c Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Sat, 11 Jul 2015 20:45:59 +0200 Subject: miner: smart mining Work is now handled and carried over multiple sessions. Previously one session only was assumed, potentially resulting in invalid (outdated) work * Larger work / result queue * Full validation option --- miner/agent.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'miner/agent.go') diff --git a/miner/agent.go b/miner/agent.go index 8455ed36e..370e611f8 100644 --- a/miner/agent.go +++ b/miner/agent.go @@ -20,7 +20,6 @@ import ( "sync" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/pow" @@ -29,10 +28,10 @@ import ( type CpuAgent struct { mu sync.Mutex - workCh chan *types.Block + workCh chan *Work quit chan struct{} quitCurrentOp chan struct{} - returnCh chan<- *types.Block + returnCh chan<- *Result index int pow pow.PoW @@ -47,9 +46,9 @@ func NewCpuAgent(index int, pow pow.PoW) *CpuAgent { return miner } -func (self *CpuAgent) Work() chan<- *types.Block { return self.workCh } -func (self *CpuAgent) Pow() pow.PoW { return self.pow } -func (self *CpuAgent) SetReturnCh(ch chan<- *types.Block) { self.returnCh = ch } +func (self *CpuAgent) Work() chan<- *Work { return self.workCh } +func (self *CpuAgent) Pow() pow.PoW { return self.pow } +func (self *CpuAgent) SetReturnCh(ch chan<- *Result) { self.returnCh = ch } func (self *CpuAgent) Stop() { self.mu.Lock() @@ -65,7 +64,7 @@ func (self *CpuAgent) Start() { self.quit = make(chan struct{}) // creating current op ch makes sure we're not closing a nil ch // later on - self.workCh = make(chan *types.Block, 1) + self.workCh = make(chan *Work, 1) go self.update() } @@ -74,13 +73,13 @@ func (self *CpuAgent) update() { out: for { select { - case block := <-self.workCh: + case work := <-self.workCh: self.mu.Lock() if self.quitCurrentOp != nil { close(self.quitCurrentOp) } self.quitCurrentOp = make(chan struct{}) - go self.mine(block, self.quitCurrentOp) + go self.mine(work, self.quitCurrentOp) self.mu.Unlock() case <-self.quit: self.mu.Lock() @@ -106,13 +105,14 @@ done: } } -func (self *CpuAgent) mine(block *types.Block, stop <-chan struct{}) { +func (self *CpuAgent) mine(work *Work, stop <-chan struct{}) { glog.V(logger.Debug).Infof("(re)started agent[%d]. mining...\n", self.index) // Mine - nonce, mixDigest := self.pow.Search(block, stop) + nonce, mixDigest := self.pow.Search(work.Block, stop) if nonce != 0 { - self.returnCh <- block.WithMiningResult(nonce, common.BytesToHash(mixDigest)) + block := work.Block.WithMiningResult(nonce, common.BytesToHash(mixDigest)) + self.returnCh <- &Result{work, block} } else { self.returnCh <- nil } -- cgit v1.2.3 From 3f047be5aa93b6222506445414ca909dd59c7eeb Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 22 Jul 2015 18:48:40 +0200 Subject: all: update license headers to distiguish GPL/LGPL All code outside of cmd/ is licensed as LGPL. The headers now reflect this by calling the whole work "the go-ethereum library". --- miner/agent.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'miner/agent.go') diff --git a/miner/agent.go b/miner/agent.go index 370e611f8..caf1cb322 100644 --- a/miner/agent.go +++ b/miner/agent.go @@ -1,18 +1,18 @@ // Copyright 2015 The go-ethereum Authors -// This file is part of go-ethereum. +// This file is part of the go-ethereum library. // // go-ethereum is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// go-ethereum is distributed in the hope that it will be useful, +// The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with go-ethereum. If not, see . +// along with the go-ethereum library. If not, see . package miner -- cgit v1.2.3 From bfbcfbe4a9dd9125391b56d6a13158cc5ec71c89 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 23 Jul 2015 18:35:11 +0200 Subject: all: fix license headers one more time I forgot to update one instance of "go-ethereum" in commit 3f047be5a. --- miner/agent.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'miner/agent.go') diff --git a/miner/agent.go b/miner/agent.go index caf1cb322..2f8d9fee4 100644 --- a/miner/agent.go +++ b/miner/agent.go @@ -1,7 +1,7 @@ // Copyright 2015 The go-ethereum Authors // This file is part of the go-ethereum library. // -// go-ethereum is free software: you can redistribute it and/or modify +// The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -- cgit v1.2.3