Skip to content

Commit b7d9350

Browse files
karalabefjl
authored andcommitted
all: finish integrating Go ethash, delete C++ vendor
1 parent df72e20 commit b7d9350

File tree

20 files changed

+230
-800
lines changed

20 files changed

+230
-800
lines changed

cmd/geth/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func init() {
9595
utils.EthashCachesInMemoryFlag,
9696
utils.EthashCachesOnDiskFlag,
9797
utils.EthashDatasetDirFlag,
98+
utils.EthashDatasetsInMemoryFlag,
9899
utils.EthashDatasetsOnDiskFlag,
99100
utils.FastSyncFlag,
100101
utils.LightModeFlag,
@@ -111,7 +112,6 @@ func init() {
111112
utils.GasPriceFlag,
112113
utils.MinerThreadsFlag,
113114
utils.MiningEnabledFlag,
114-
utils.AutoDAGFlag,
115115
utils.TargetGasLimitFlag,
116116
utils.NATFlag,
117117
utils.NoDiscoverFlag,

cmd/geth/misccmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import (
2525
"strconv"
2626
"strings"
2727

28-
"github.com/ethereum/ethash"
2928
"github.com/ethereum/go-ethereum/cmd/utils"
3029
"github.com/ethereum/go-ethereum/eth"
3130
"github.com/ethereum/go-ethereum/params"
31+
"github.com/ethereum/go-ethereum/pow"
3232
"gopkg.in/urfave/cli.v1"
3333
)
3434

@@ -87,7 +87,7 @@ func makedag(ctx *cli.Context) error {
8787
utils.Fatalf("Can't find dir")
8888
}
8989
fmt.Println("making DAG, this could take awhile...")
90-
ethash.MakeDAG(blockNum, dir)
90+
pow.MakeDataset(blockNum, dir)
9191
}
9292
default:
9393
wrongArgs()

cmd/geth/usage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ var AppHelpFlagGroups = []flagGroup{
8484
utils.EthashCachesInMemoryFlag,
8585
utils.EthashCachesOnDiskFlag,
8686
utils.EthashDatasetDirFlag,
87+
utils.EthashDatasetsInMemoryFlag,
8788
utils.EthashDatasetsOnDiskFlag,
8889
},
8990
},
@@ -141,7 +142,6 @@ var AppHelpFlagGroups = []flagGroup{
141142
Flags: []cli.Flag{
142143
utils.MiningEnabledFlag,
143144
utils.MinerThreadsFlag,
144-
utils.AutoDAGFlag,
145145
utils.EtherbaseFlag,
146146
utils.TargetGasLimitFlag,
147147
utils.GasPriceFlag,

cmd/utils/flags.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,14 @@ var (
132132
Name: "ethash.dagdir",
133133
Usage: "Directory to store the ethash mining DAGs (default = inside home folder)",
134134
}
135+
EthashDatasetsInMemoryFlag = cli.IntFlag{
136+
Name: "ethash.dagsinmem",
137+
Usage: "Number of recent ethash mining DAGs to keep in memory (1+GB each)",
138+
Value: 1,
139+
}
135140
EthashDatasetsOnDiskFlag = cli.IntFlag{
136141
Name: "ethash.dagsondisk",
137-
Usage: "Number of ethash mining DAGs to keep on disk (1+GB each)",
142+
Usage: "Number of recent ethash mining DAGs to keep on disk (1+GB each)",
138143
Value: 2,
139144
}
140145
NetworkIdFlag = cli.IntFlag{
@@ -207,10 +212,6 @@ var (
207212
Usage: "Target gas limit sets the artificial target gas floor for the blocks to mine",
208213
Value: params.GenesisGasLimit.Uint64(),
209214
}
210-
AutoDAGFlag = cli.BoolFlag{
211-
Name: "autodag",
212-
Usage: "Enable automatic DAG pregeneration",
213-
}
214215
EtherbaseFlag = cli.StringFlag{
215216
Name: "etherbase",
216217
Usage: "Public address for block mining rewards (default = first account created)",
@@ -809,8 +810,8 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
809810
EthashCachesInMem: ctx.GlobalInt(EthashCachesInMemoryFlag.Name),
810811
EthashCachesOnDisk: ctx.GlobalInt(EthashCachesOnDiskFlag.Name),
811812
EthashDatasetDir: MakeEthashDatasetDir(ctx),
813+
EthashDatasetsInMem: ctx.GlobalInt(EthashDatasetsInMemoryFlag.Name),
812814
EthashDatasetsOnDisk: ctx.GlobalInt(EthashDatasetsOnDiskFlag.Name),
813-
AutoDAG: ctx.GlobalBool(AutoDAGFlag.Name) || ctx.GlobalBool(MiningEnabledFlag.Name),
814815
EnablePreimageRecording: ctx.GlobalBool(VMEnableDebugFlag.Name),
815816
}
816817

@@ -982,7 +983,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
982983

983984
seal := pow.PoW(pow.FakePow{})
984985
if !ctx.GlobalBool(FakePoWFlag.Name) {
985-
seal = pow.NewFullEthash("", 1, 0, "", 0)
986+
seal = pow.NewFullEthash("", 1, 0, "", 1, 0)
986987
}
987988
chain, err = core.NewBlockChain(chainDb, chainConfig, seal, new(event.TypeMux), vm.Config{EnablePreimageRecording: ctx.GlobalBool(VMEnableDebugFlag.Name)})
988989
if err != nil {

eth/api.go

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"strings"
3030
"time"
3131

32-
"github.com/ethereum/ethash"
3332
"github.com/ethereum/go-ethereum/common"
3433
"github.com/ethereum/go-ethereum/common/hexutil"
3534
"github.com/ethereum/go-ethereum/core"
@@ -40,7 +39,6 @@ import (
4039
"github.com/ethereum/go-ethereum/miner"
4140
"github.com/ethereum/go-ethereum/params"
4241
"github.com/ethereum/go-ethereum/rlp"
43-
"github.com/ethereum/go-ethereum/rpc"
4442
"golang.org/x/net/context"
4543
)
4644

@@ -137,7 +135,6 @@ func NewPrivateMinerAPI(e *Ethereum) *PrivateMinerAPI {
137135
// Start the miner with the given number of threads. If threads is nil the number of
138136
// workers started is equal to the number of logical CPU's that are usable by this process.
139137
func (s *PrivateMinerAPI) Start(threads *int) (bool, error) {
140-
s.e.StartAutoDAG()
141138
var err error
142139
if threads == nil {
143140
err = s.e.StartMining(runtime.NumCPU())
@@ -173,25 +170,9 @@ func (s *PrivateMinerAPI) SetEtherbase(etherbase common.Address) bool {
173170
return true
174171
}
175172

176-
// StartAutoDAG starts auto DAG generation. This will prevent the DAG generating on epoch change
177-
// which will cause the node to stop mining during the generation process.
178-
func (s *PrivateMinerAPI) StartAutoDAG() bool {
179-
s.e.StartAutoDAG()
180-
return true
181-
}
182-
183-
// StopAutoDAG stops auto DAG generation
184-
func (s *PrivateMinerAPI) StopAutoDAG() bool {
185-
s.e.StopAutoDAG()
186-
return true
187-
}
188-
189-
// MakeDAG creates the new DAG for the given block number
190-
func (s *PrivateMinerAPI) MakeDAG(blockNr rpc.BlockNumber) (bool, error) {
191-
if err := ethash.MakeDAG(uint64(blockNr.Int64()), ""); err != nil {
192-
return false, err
193-
}
194-
return true, nil
173+
// GetHashrate returns the current hashrate of the miner.
174+
func (s *PrivateMinerAPI) GetHashrate() uint64 {
175+
return uint64(s.e.miner.HashRate())
195176
}
196177

197178
// PrivateAdminAPI is the collection of Etheruem full node-related APIs

eth/backend.go

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
415409
func (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 {
451441
func (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-
}

internal/web3ext/web3ext.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -399,20 +399,8 @@ web3._extend({
399399
inputFormatter: [web3._extend.utils.fromDecimal]
400400
}),
401401
new web3._extend.Method({
402-
name: 'startAutoDAG',
403-
call: 'miner_startAutoDAG',
404-
params: 0
405-
}),
406-
new web3._extend.Method({
407-
name: 'stopAutoDAG',
408-
call: 'miner_stopAutoDAG',
409-
params: 0
410-
}),
411-
new web3._extend.Method({
412-
name: 'makeDAG',
413-
call: 'miner_makeDAG',
414-
params: 1,
415-
inputFormatter: [web3._extend.formatters.inputDefaultBlockNumberFormatter]
402+
name: 'getHashrate',
403+
call: 'miner_getHashrate'
416404
})
417405
],
418406
properties: []

miner/miner.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ func (self *Miner) HashRate() (tot int64) {
164164
// aspects of the worker/locking up agents so we can get an accurate
165165
// hashrate?
166166
for agent := range self.worker.agents {
167-
tot += agent.GetHashRate()
167+
if _, ok := agent.(*CpuAgent); !ok {
168+
tot += agent.GetHashRate()
169+
}
168170
}
169171
return
170172
}

mobile/geth.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) {
151151
GpobaseStepDown: 10,
152152
GpobaseStepUp: 100,
153153
GpobaseCorrectionFactor: 110,
154+
EthashCacheDir: "ethash",
155+
EthashCachesInMem: 2,
156+
EthashCachesOnDisk: 3,
154157
}
155158
if err := rawStack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
156159
return les.New(ctx, ethConf)

0 commit comments

Comments
 (0)