@@ -21,14 +21,11 @@ import (
2121 "errors"
2222 "fmt"
2323 "math/big"
24- "os"
25- "path/filepath"
2624 "regexp"
2725 "strings"
2826 "sync"
2927 "time"
3028
31- "github.com/ethereum/ethash"
3229 "github.com/ethereum/go-ethereum/accounts"
3330 "github.com/ethereum/go-ethereum/common"
3431 "github.com/ethereum/go-ethereum/core"
@@ -78,7 +75,6 @@ type Config struct {
7875 DatabaseHandles int
7976
8077 DocRoot string
81- AutoDAG bool
8278 PowFake bool
8379 PowTest bool
8480 PowShared bool
@@ -88,6 +84,7 @@ type Config struct {
8884 EthashCachesInMem int
8985 EthashCachesOnDisk int
9086 EthashDatasetDir string
87+ EthashDatasetsInMem int
9188 EthashDatasetsOnDisk int
9289
9390 Etherbase common.Address
@@ -138,8 +135,6 @@ type Ethereum struct {
138135 miner * miner.Miner
139136 Mining bool
140137 MinerThreads int
141- AutoDAG bool
142- autodagquit chan bool
143138 etherbase common.Address
144139 solcPath string
145140
@@ -173,7 +168,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
173168 netVersionId : config .NetworkId ,
174169 etherbase : config .Etherbase ,
175170 MinerThreads : config .MinerThreads ,
176- AutoDAG : config .AutoDAG ,
177171 solcPath : config .SolcPath ,
178172 }
179173
@@ -298,7 +292,7 @@ func CreatePoW(ctx *node.ServiceContext, config *Config) pow.PoW {
298292 return pow .NewSharedEthash ()
299293 default :
300294 return pow .NewFullEthash (ctx .ResolvePath (config .EthashCacheDir ), config .EthashCachesInMem , config .EthashCachesOnDisk ,
301- config .EthashDatasetDir , config .EthashDatasetsOnDisk )
295+ config .EthashDatasetDir , config .EthashDatasetsInMem , config . EthashDatasetsOnDisk )
302296 }
303297}
304298
@@ -414,9 +408,7 @@ func (s *Ethereum) Protocols() []p2p.Protocol {
414408// Ethereum protocol implementation.
415409func (s * Ethereum ) Start (srvr * p2p.Server ) error {
416410 s .netRPCService = ethapi .NewPublicNetAPI (srvr , s .NetVersion ())
417- if s .AutoDAG {
418- s .StartAutoDAG ()
419- }
411+
420412 s .protocolManager .Start ()
421413 if s .lesServer != nil {
422414 s .lesServer .Start (srvr )
@@ -439,8 +431,6 @@ func (s *Ethereum) Stop() error {
439431 s .miner .Stop ()
440432 s .eventMux .Stop ()
441433
442- s .StopAutoDAG ()
443-
444434 s .chainDb .Close ()
445435 close (s .shutdownChan )
446436
@@ -451,74 +441,3 @@ func (s *Ethereum) Stop() error {
451441func (s * Ethereum ) WaitForShutdown () {
452442 <- s .shutdownChan
453443}
454-
455- // StartAutoDAG() spawns a go routine that checks the DAG every autoDAGcheckInterval
456- // by default that is 10 times per epoch
457- // in epoch n, if we past autoDAGepochHeight within-epoch blocks,
458- // it calls ethash.MakeDAG to pregenerate the DAG for the next epoch n+1
459- // if it does not exist yet as well as remove the DAG for epoch n-1
460- // the loop quits if autodagquit channel is closed, it can safely restart and
461- // stop any number of times.
462- // For any more sophisticated pattern of DAG generation, use CLI subcommand
463- // makedag
464- func (self * Ethereum ) StartAutoDAG () {
465- if self .autodagquit != nil {
466- return // already started
467- }
468- go func () {
469- log .Info ("Pre-generation of ethash DAG on" , "dir" , ethash .DefaultDir )
470- var nextEpoch uint64
471- timer := time .After (0 )
472- self .autodagquit = make (chan bool )
473- for {
474- select {
475- case <- timer :
476- log .Info ("Checking DAG availability" , "dir" , ethash .DefaultDir )
477- currentBlock := self .BlockChain ().CurrentBlock ().NumberU64 ()
478- thisEpoch := currentBlock / epochLength
479- if nextEpoch <= thisEpoch {
480- if currentBlock % epochLength > autoDAGepochHeight {
481- if thisEpoch > 0 {
482- previousDag , previousDagFull := dagFiles (thisEpoch - 1 )
483- os .Remove (filepath .Join (ethash .DefaultDir , previousDag ))
484- os .Remove (filepath .Join (ethash .DefaultDir , previousDagFull ))
485- log .Info ("Removed previous DAG" , "epoch" , thisEpoch - 1 , "dag" , previousDag )
486- }
487- nextEpoch = thisEpoch + 1
488- dag , _ := dagFiles (nextEpoch )
489- if _ , err := os .Stat (dag ); os .IsNotExist (err ) {
490- log .Info ("Pre-generating next DAG" , "epoch" , nextEpoch , "dag" , dag )
491- err := ethash .MakeDAG (nextEpoch * epochLength , "" ) // "" -> ethash.DefaultDir
492- if err != nil {
493- log .Error ("Error generating DAG" , "epoch" , nextEpoch , "dag" , dag , "err" , err )
494- return
495- }
496- } else {
497- log .Warn ("DAG already exists" , "epoch" , nextEpoch , "dag" , dag )
498- }
499- }
500- }
501- timer = time .After (autoDAGcheckInterval )
502- case <- self .autodagquit :
503- return
504- }
505- }
506- }()
507- }
508-
509- // stopAutoDAG stops automatic DAG pregeneration by quitting the loop
510- func (self * Ethereum ) StopAutoDAG () {
511- if self .autodagquit != nil {
512- close (self .autodagquit )
513- self .autodagquit = nil
514- }
515- log .Info ("Pre-generation of ethash DAG off" , "dir" , ethash .DefaultDir )
516- }
517-
518- // dagFiles(epoch) returns the two alternative DAG filenames (not a path)
519- // 1) <revision>-<hex(seedhash[8])> 2) full-R<revision>-<hex(seedhash[8])>
520- func dagFiles (epoch uint64 ) (string , string ) {
521- seedHash , _ := ethash .GetSeedHash (epoch * epochLength )
522- dag := fmt .Sprintf ("full-R%d-%x" , ethashRevision , seedHash [:8 ])
523- return dag , "full-R" + dag
524- }
0 commit comments