diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-03-06 23:20:25 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-03-09 22:50:14 +0800 |
commit | b7d93500f13e3054c81196273ebf676ad8ecb5ba (patch) | |
tree | 1b6c60cbb6b235d87f78ff9a814f1a574510215a /eth/backend.go | |
parent | df72e20cc521b43092b9e3cc684836d4d673e126 (diff) | |
download | go-tangerine-b7d93500f13e3054c81196273ebf676ad8ecb5ba.tar go-tangerine-b7d93500f13e3054c81196273ebf676ad8ecb5ba.tar.gz go-tangerine-b7d93500f13e3054c81196273ebf676ad8ecb5ba.tar.bz2 go-tangerine-b7d93500f13e3054c81196273ebf676ad8ecb5ba.tar.lz go-tangerine-b7d93500f13e3054c81196273ebf676ad8ecb5ba.tar.xz go-tangerine-b7d93500f13e3054c81196273ebf676ad8ecb5ba.tar.zst go-tangerine-b7d93500f13e3054c81196273ebf676ad8ecb5ba.zip |
all: finish integrating Go ethash, delete C++ vendor
Diffstat (limited to 'eth/backend.go')
-rw-r--r-- | eth/backend.go | 87 |
1 files changed, 3 insertions, 84 deletions
diff --git a/eth/backend.go b/eth/backend.go index d49251d75..ef951a6c2 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -21,14 +21,11 @@ import ( "errors" "fmt" "math/big" - "os" - "path/filepath" "regexp" "strings" "sync" "time" - "github.com/ethereum/ethash" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" @@ -78,7 +75,6 @@ type Config struct { DatabaseHandles int DocRoot string - AutoDAG bool PowFake bool PowTest bool PowShared bool @@ -88,6 +84,7 @@ type Config struct { EthashCachesInMem int EthashCachesOnDisk int EthashDatasetDir string + EthashDatasetsInMem int EthashDatasetsOnDisk int Etherbase common.Address @@ -138,8 +135,6 @@ type Ethereum struct { miner *miner.Miner Mining bool MinerThreads int - AutoDAG bool - autodagquit chan bool etherbase common.Address solcPath string @@ -173,7 +168,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { netVersionId: config.NetworkId, etherbase: config.Etherbase, MinerThreads: config.MinerThreads, - AutoDAG: config.AutoDAG, solcPath: config.SolcPath, } @@ -298,7 +292,7 @@ func CreatePoW(ctx *node.ServiceContext, config *Config) pow.PoW { return pow.NewSharedEthash() default: return pow.NewFullEthash(ctx.ResolvePath(config.EthashCacheDir), config.EthashCachesInMem, config.EthashCachesOnDisk, - config.EthashDatasetDir, config.EthashDatasetsOnDisk) + config.EthashDatasetDir, config.EthashDatasetsInMem, config.EthashDatasetsOnDisk) } } @@ -414,9 +408,7 @@ func (s *Ethereum) Protocols() []p2p.Protocol { // Ethereum protocol implementation. func (s *Ethereum) Start(srvr *p2p.Server) error { s.netRPCService = ethapi.NewPublicNetAPI(srvr, s.NetVersion()) - if s.AutoDAG { - s.StartAutoDAG() - } + s.protocolManager.Start() if s.lesServer != nil { s.lesServer.Start(srvr) @@ -439,8 +431,6 @@ func (s *Ethereum) Stop() error { s.miner.Stop() s.eventMux.Stop() - s.StopAutoDAG() - s.chainDb.Close() close(s.shutdownChan) @@ -451,74 +441,3 @@ func (s *Ethereum) Stop() error { func (s *Ethereum) WaitForShutdown() { <-s.shutdownChan } - -// StartAutoDAG() spawns a go routine that checks the DAG every autoDAGcheckInterval -// by default that is 10 times per epoch -// in epoch n, if we past autoDAGepochHeight within-epoch blocks, -// it calls ethash.MakeDAG to pregenerate the DAG for the next epoch n+1 -// if it does not exist yet as well as remove the DAG for epoch n-1 -// the loop quits if autodagquit channel is closed, it can safely restart and -// stop any number of times. -// For any more sophisticated pattern of DAG generation, use CLI subcommand -// makedag -func (self *Ethereum) StartAutoDAG() { - if self.autodagquit != nil { - return // already started - } - go func() { - log.Info("Pre-generation of ethash DAG on", "dir", ethash.DefaultDir) - var nextEpoch uint64 - timer := time.After(0) - self.autodagquit = make(chan bool) - for { - select { - case <-timer: - log.Info("Checking DAG availability", "dir", ethash.DefaultDir) - currentBlock := self.BlockChain().CurrentBlock().NumberU64() - thisEpoch := currentBlock / epochLength - if nextEpoch <= thisEpoch { - if currentBlock%epochLength > autoDAGepochHeight { - if thisEpoch > 0 { - previousDag, previousDagFull := dagFiles(thisEpoch - 1) - os.Remove(filepath.Join(ethash.DefaultDir, previousDag)) - os.Remove(filepath.Join(ethash.DefaultDir, previousDagFull)) - log.Info("Removed previous DAG", "epoch", thisEpoch-1, "dag", previousDag) - } - nextEpoch = thisEpoch + 1 - dag, _ := dagFiles(nextEpoch) - if _, err := os.Stat(dag); os.IsNotExist(err) { - log.Info("Pre-generating next DAG", "epoch", nextEpoch, "dag", dag) - err := ethash.MakeDAG(nextEpoch*epochLength, "") // "" -> ethash.DefaultDir - if err != nil { - log.Error("Error generating DAG", "epoch", nextEpoch, "dag", dag, "err", err) - return - } - } else { - log.Warn("DAG already exists", "epoch", nextEpoch, "dag", dag) - } - } - } - timer = time.After(autoDAGcheckInterval) - case <-self.autodagquit: - return - } - } - }() -} - -// stopAutoDAG stops automatic DAG pregeneration by quitting the loop -func (self *Ethereum) StopAutoDAG() { - if self.autodagquit != nil { - close(self.autodagquit) - self.autodagquit = nil - } - log.Info("Pre-generation of ethash DAG off", "dir", ethash.DefaultDir) -} - -// dagFiles(epoch) returns the two alternative DAG filenames (not a path) -// 1) <revision>-<hex(seedhash[8])> 2) full-R<revision>-<hex(seedhash[8])> -func dagFiles(epoch uint64) (string, string) { - seedHash, _ := ethash.GetSeedHash(epoch * epochLength) - dag := fmt.Sprintf("full-R%d-%x", ethashRevision, seedHash[:8]) - return dag, "full-R" + dag -} |