From 7f116e34b524e2dd7313fae23efe0be01d2fd065 Mon Sep 17 00:00:00 2001 From: Gustav Simonsson Date: Fri, 24 Apr 2015 13:32:53 +0200 Subject: [PATCH] Update ethash API * Chain no longer passed to ethash.New() * Remove unneeded DAG creation & cache updates * Update makedag cmd to work with new MakeDAG API --- .../src/github.com/ethereum/ethash/ethash.go | 4 +-- cmd/geth/main.go | 35 +++++++++++++++---- cmd/utils/flags.go | 2 +- eth/backend.go | 3 +- miner/miner.go | 7 ---- 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/Godeps/_workspace/src/github.com/ethereum/ethash/ethash.go b/Godeps/_workspace/src/github.com/ethereum/ethash/ethash.go index 7cab3b48b4..91f821731b 100644 --- a/Godeps/_workspace/src/github.com/ethereum/ethash/ethash.go +++ b/Godeps/_workspace/src/github.com/ethereum/ethash/ethash.go @@ -165,7 +165,7 @@ func freeDAG(h *dag) { } } -func makeDAG(blockNum uint64, test bool, dir string) *dag { +func MakeDAG(blockNum uint64, test bool, dir string) *dag { if dir == "" { dir = DefaultDir } @@ -210,7 +210,7 @@ func (pow *Full) getDAG(blockNum uint64) *dag { // This computation is very very expensive. // The lock should prevent more than one of them // to run at the same time. - pow.dag = makeDAG(blockNum, pow.test, pow.Dir) + pow.dag = MakeDAG(blockNum, pow.test, pow.Dir) return pow.dag } diff --git a/cmd/geth/main.go b/cmd/geth/main.go index e399731e73..7bac869103 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -25,8 +25,10 @@ import ( "fmt" "io/ioutil" "os" + "path/filepath" "runtime" "strconv" + "strings" "time" "path" @@ -575,12 +577,33 @@ 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 {true, false} `) + } + switch { + case len(args) == 3: + isTest, err := strconv.ParseBool(args[0]) + blockNum, err := strconv.ParseUint(args[1], 0, 64) + dir := args[2] + 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, isTest, dir) + } + default: + wrongArgs() + } } func version(c *cli.Context) { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index b8f3982e24..033b92d294 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) blockProcessor := core.NewBlockProcessor(stateDb, extraDb, pow, txPool, chainManager, eventMux) chainManager.SetProcessor(blockProcessor) diff --git a/eth/backend.go b/eth/backend.go index 356e7fd1a5..01e2001ee9 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -218,7 +218,7 @@ func New(config *Config) (*Ethereum, error) { eth.chainManager = core.NewChainManager(blockDb, stateDb, eth.EventMux()) eth.downloader = downloader.New(eth.chainManager.HasBlock, eth.chainManager.InsertChain, eth.chainManager.Td) - eth.pow = ethash.New(eth.chainManager) + eth.pow = ethash.New() eth.txPool = core.NewTxPool(eth.EventMux(), eth.chainManager.State) eth.blockProcessor = core.NewBlockProcessor(stateDb, extraDb, eth.pow, eth.txPool, eth.chainManager, eth.EventMux()) eth.chainManager.SetProcessor(eth.blockProcessor) @@ -313,7 +313,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/miner.go b/miner/miner.go index 8839563702..bff0026dc4 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() }