diff --git a/cmd/geth/main.go b/cmd/geth/main.go index e00b139c0..f2497ccf4 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -27,8 +27,10 @@ import ( "io/ioutil" "os" "path" + "path/filepath" "runtime" "strconv" + "strings" "time" "github.com/codegangsta/cli" @@ -601,12 +603,32 @@ func dump(ctx *cli.Context) { } func makedag(ctx *cli.Context) { - chain, _, _ := utils.GetChain(ctx) - pow := ethash.New(chain) - fmt.Println("making cache") - pow.UpdateCache(0, true) - fmt.Println("making DAG") - pow.UpdateDAG() + args := ctx.Args() + wrongArgs := func() { + utils.Fatalf(`Usage: geth makedag `) + } + switch { + case len(args) == 2: + blockNum, err := strconv.ParseUint(args[0], 0, 64) + dir := args[1] + if err != nil { + wrongArgs() + } else { + dir = filepath.Clean(dir) + // seems to require a trailing slash + if !strings.HasSuffix(dir, "/") { + dir = dir + "/" + } + _, err = ioutil.ReadDir(dir) + if err != nil { + utils.Fatalf("Can't find dir") + } + fmt.Println("making DAG, this could take awhile...") + ethash.MakeDAG(blockNum, dir) + } + default: + wrongArgs() + } } func version(c *cli.Context) { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index c013510d8..1fdc8dfe5 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -316,7 +316,7 @@ func GetChain(ctx *cli.Context) (*core.ChainManager, common.Database, common.Dat eventMux := new(event.TypeMux) chainManager := core.NewChainManager(blockDb, stateDb, eventMux) - pow := ethash.New(chainManager) + pow := ethash.New() txPool := core.NewTxPool(eventMux, chainManager.State, chainManager.GasLimit) blockProcessor := core.NewBlockProcessor(stateDb, extraDb, pow, txPool, chainManager, eventMux) chainManager.SetProcessor(blockProcessor) diff --git a/core/chain_makers.go b/core/chain_makers.go index 73c2205f4..5cd7ab4ab 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -14,8 +14,8 @@ import ( // So we can generate blocks easily type FakePow struct{} -func (f FakePow) Search(block pow.Block, stop <-chan struct{}) (uint64, []byte, []byte) { - return 0, nil, nil +func (f FakePow) Search(block pow.Block, stop <-chan struct{}) (uint64, []byte) { + return 0, nil } func (f FakePow) Verify(block pow.Block) bool { return true } func (f FakePow) GetHashrate() int64 { return 0 } diff --git a/eth/backend.go b/eth/backend.go index a8b0fae50..5acef2ded 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -220,7 +220,7 @@ func New(config *Config) (*Ethereum, error) { eth.chainManager = core.NewChainManager(blockDb, stateDb, eth.EventMux()) eth.downloader = downloader.New(eth.chainManager.HasBlock, eth.chainManager.GetBlock) - eth.pow = ethash.New(eth.chainManager) + eth.pow = ethash.New() eth.txPool = core.NewTxPool(eth.EventMux(), eth.chainManager.State, eth.chainManager.GasLimit) eth.blockProcessor = core.NewBlockProcessor(stateDb, extraDb, eth.pow, eth.txPool, eth.chainManager, eth.EventMux()) eth.chainManager.SetProcessor(eth.blockProcessor) @@ -318,7 +318,6 @@ func (s *Ethereum) PeersInfo() (peersinfo []*PeerInfo) { func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) { s.chainManager.ResetWithGenesisBlock(gb) - s.pow.UpdateCache(0, true) } func (s *Ethereum) StartMining() error { diff --git a/miner/agent.go b/miner/agent.go index 547fdfbef..b2f89aaab 100644 --- a/miner/agent.go +++ b/miner/agent.go @@ -85,7 +85,7 @@ func (self *CpuMiner) mine(block *types.Block) { self.chMu.Unlock() // Mine - nonce, mixDigest, _ := self.pow.Search(block, self.quitCurrentOp) + nonce, mixDigest := self.pow.Search(block, self.quitCurrentOp) if nonce != 0 { block.SetNonce(nonce) block.Header().MixDigest = common.BytesToHash(mixDigest) diff --git a/miner/miner.go b/miner/miner.go index 883956370..bff0026dc 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -3,7 +3,6 @@ package miner import ( "math/big" - "github.com/ethereum/ethash" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/state" @@ -41,13 +40,7 @@ func (self *Miner) Mining() bool { func (self *Miner) Start(coinbase common.Address) { self.mining = true self.worker.coinbase = coinbase - - if self.threads > 0 { - self.pow.(*ethash.Ethash).UpdateDAG() - } - self.worker.start() - self.worker.commitNewWork() } diff --git a/pow/dagger/dagger.go b/pow/dagger/dagger.go index f2d65e8ef..b941c0eeb 100644 --- a/pow/dagger/dagger.go +++ b/pow/dagger/dagger.go @@ -6,8 +6,8 @@ import ( "math/rand" "time" - "github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/logger" ) @@ -44,7 +44,7 @@ func (dag *Dagger) Find(obj *big.Int, resChan chan int64) { resChan <- 0 } -func (dag *Dagger) Search(hash, diff *big.Int) ([]byte, []byte, []byte) { +func (dag *Dagger) Search(hash, diff *big.Int) (uint64, []byte) { // TODO fix multi threading. Somehow it results in the wrong nonce amountOfRoutines := 1 @@ -69,7 +69,7 @@ func (dag *Dagger) Search(hash, diff *big.Int) ([]byte, []byte, []byte) { } } - return big.NewInt(res).Bytes(), nil, nil + return uint64(res), nil } func (dag *Dagger) Verify(hash, diff, nonce *big.Int) bool { diff --git a/pow/ezp/pow.go b/pow/ezp/pow.go index bd2927fe8..c838dd5ec 100644 --- a/pow/ezp/pow.go +++ b/pow/ezp/pow.go @@ -32,7 +32,7 @@ func (pow *EasyPow) Turbo(on bool) { pow.turbo = on } -func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) (uint64, []byte, []byte) { +func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) (uint64, []byte) { r := rand.New(rand.NewSource(time.Now().UnixNano())) hash := block.HashNoNonce() diff := block.Difficulty() @@ -57,7 +57,7 @@ empty: for { select { case <-stop: - return 0, nil, nil + return 0, nil default: i++ @@ -67,7 +67,7 @@ empty: sha := uint64(r.Int63()) if verify(hash, diff, sha) { - return sha, nil, nil + return sha, nil } } @@ -76,7 +76,7 @@ empty: } } - return 0, nil, nil + return 0, nil } func (pow *EasyPow) Verify(block pow.Block) bool { diff --git a/pow/pow.go b/pow/pow.go index 3908e5f76..73984a4ae 100644 --- a/pow/pow.go +++ b/pow/pow.go @@ -1,7 +1,7 @@ package pow type PoW interface { - Search(block Block, stop <-chan struct{}) (uint64, []byte, []byte) + Search(block Block, stop <-chan struct{}) (uint64, []byte) Verify(block Block) bool GetHashrate() int64 Turbo(bool)