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
This commit is contained in:
Gustav Simonsson 2015-04-24 13:32:53 +02:00
parent 18eae16b29
commit 7f116e34b5
5 changed files with 33 additions and 18 deletions

View file

@ -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
}

View file

@ -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} <block number> <outputdir>`)
}
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) {

View file

@ -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)

View file

@ -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 {

View file

@ -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()
}