aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-03-06 23:20:25 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-03-09 22:50:14 +0800
commitb7d93500f13e3054c81196273ebf676ad8ecb5ba (patch)
tree1b6c60cbb6b235d87f78ff9a814f1a574510215a /eth
parentdf72e20cc521b43092b9e3cc684836d4d673e126 (diff)
downloadgo-tangerine-b7d93500f13e3054c81196273ebf676ad8ecb5ba.tar.gz
go-tangerine-b7d93500f13e3054c81196273ebf676ad8ecb5ba.tar.zst
go-tangerine-b7d93500f13e3054c81196273ebf676ad8ecb5ba.zip
all: finish integrating Go ethash, delete C++ vendor
Diffstat (limited to 'eth')
-rw-r--r--eth/api.go25
-rw-r--r--eth/backend.go87
2 files changed, 6 insertions, 106 deletions
diff --git a/eth/api.go b/eth/api.go
index 3aac34ee0..b17968ebb 100644
--- a/eth/api.go
+++ b/eth/api.go
@@ -29,7 +29,6 @@ import (
"strings"
"time"
- "github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core"
@@ -40,7 +39,6 @@ import (
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
- "github.com/ethereum/go-ethereum/rpc"
"golang.org/x/net/context"
)
@@ -137,7 +135,6 @@ func NewPrivateMinerAPI(e *Ethereum) *PrivateMinerAPI {
// Start the miner with the given number of threads. If threads is nil the number of
// workers started is equal to the number of logical CPU's that are usable by this process.
func (s *PrivateMinerAPI) Start(threads *int) (bool, error) {
- s.e.StartAutoDAG()
var err error
if threads == nil {
err = s.e.StartMining(runtime.NumCPU())
@@ -173,25 +170,9 @@ func (s *PrivateMinerAPI) SetEtherbase(etherbase common.Address) bool {
return true
}
-// StartAutoDAG starts auto DAG generation. This will prevent the DAG generating on epoch change
-// which will cause the node to stop mining during the generation process.
-func (s *PrivateMinerAPI) StartAutoDAG() bool {
- s.e.StartAutoDAG()
- return true
-}
-
-// StopAutoDAG stops auto DAG generation
-func (s *PrivateMinerAPI) StopAutoDAG() bool {
- s.e.StopAutoDAG()
- return true
-}
-
-// MakeDAG creates the new DAG for the given block number
-func (s *PrivateMinerAPI) MakeDAG(blockNr rpc.BlockNumber) (bool, error) {
- if err := ethash.MakeDAG(uint64(blockNr.Int64()), ""); err != nil {
- return false, err
- }
- return true, nil
+// GetHashrate returns the current hashrate of the miner.
+func (s *PrivateMinerAPI) GetHashrate() uint64 {
+ return uint64(s.e.miner.HashRate())
}
// PrivateAdminAPI is the collection of Etheruem full node-related APIs
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
-}