diff --git a/cmd/puppeth/module_dashboard.go b/cmd/puppeth/module_dashboard.go index 468bc37e86fb..78f8f9f17632 100644 --- a/cmd/puppeth/module_dashboard.go +++ b/cmd/puppeth/module_dashboard.go @@ -633,7 +633,7 @@ func deployDashboard(client *sshClient, network string, conf *config, config *da "Byzantium": conf.Genesis.Config.ByzantiumBlock, "Constantinople": conf.Genesis.Config.ConstantinopleBlock, "ConstantinopleFix": conf.Genesis.Config.PetersburgBlock, - "ProgPow": conf.Genesis.Config.ProgpowBlock, + "ProgPoW": conf.Genesis.Config.ProgpowBlock, }) files[filepath.Join(workdir, "index.html")] = indexfile.Bytes() diff --git a/cmd/puppeth/wizard_genesis.go b/cmd/puppeth/wizard_genesis.go index 02e54c9ca308..ab8763078036 100644 --- a/cmd/puppeth/wizard_genesis.go +++ b/cmd/puppeth/wizard_genesis.go @@ -229,9 +229,11 @@ func (w *wizard) manageGenesis() { fmt.Printf("Which block should Constantinople-Fix (remove EIP-1283) come into effect? (default = %v)\n", w.conf.Genesis.Config.PetersburgBlock) w.conf.Genesis.Config.PetersburgBlock = w.readDefaultBigInt(w.conf.Genesis.Config.PetersburgBlock) - fmt.Println() - fmt.Printf("Which block should ProgPow come into effect? (default = %v)\n", w.conf.Genesis.Config.ProgpowBlock) - w.conf.Genesis.Config.ProgpowBlock = w.readDefaultBigInt(w.conf.Genesis.Config.ProgpowBlock) + if w.conf.Genesis.Config.Clique == nil { + fmt.Println() + fmt.Printf("Which block should ProgPow come into effect? (default = %v)\n", w.conf.Genesis.Config.ProgpowBlock) + w.conf.Genesis.Config.ProgpowBlock = w.readDefaultBigInt(w.conf.Genesis.Config.ProgpowBlock) + } out, _ := json.MarshalIndent(w.conf.Genesis.Config, "", " ") fmt.Printf("Chain configuration updated:\n\n%s\n", out) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 40895b162638..1b235254f7ef 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1573,13 +1573,13 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai engine = ethash.NewFaker() if !ctx.GlobalBool(FakePoWFlag.Name) { engine = ethash.New(ethash.Config{ - CacheDir: stack.ResolvePath(eth.DefaultConfig.Ethash.CacheDir), - CachesInMem: eth.DefaultConfig.Ethash.CachesInMem, - CachesOnDisk: eth.DefaultConfig.Ethash.CachesOnDisk, - DatasetDir: stack.ResolvePath(eth.DefaultConfig.Ethash.DatasetDir), - DatasetsInMem: eth.DefaultConfig.Ethash.DatasetsInMem, - DatasetsOnDisk: eth.DefaultConfig.Ethash.DatasetsOnDisk, - ProgpowBlockNumber: config.ProgpowBlock, + CacheDir: stack.ResolvePath(eth.DefaultConfig.Ethash.CacheDir), + CachesInMem: eth.DefaultConfig.Ethash.CachesInMem, + CachesOnDisk: eth.DefaultConfig.Ethash.CachesOnDisk, + DatasetDir: stack.ResolvePath(eth.DefaultConfig.Ethash.DatasetDir), + DatasetsInMem: eth.DefaultConfig.Ethash.DatasetsInMem, + DatasetsOnDisk: eth.DefaultConfig.Ethash.DatasetsOnDisk, + ProgpowBlock: config.ProgpowBlock, }, nil, false) } } diff --git a/consensus/ethash/algorithm_test.go b/consensus/ethash/algorithm_test.go index 6890b888db14..38a04c66596f 100644 --- a/consensus/ethash/algorithm_test.go +++ b/consensus/ethash/algorithm_test.go @@ -739,7 +739,7 @@ func TestConcurrentDiskCacheGeneration(t *testing.T) { pend.Wait() } -// Benchmarks the cache generation performance. +// BenchmarkCacheGeneration benchmarks the cache generation performance. func BenchmarkCacheGeneration(b *testing.B) { for i := 0; i < b.N; i++ { cache := make([]uint32, cacheSize(1)/4) @@ -747,7 +747,7 @@ func BenchmarkCacheGeneration(b *testing.B) { } } -// Benchmarks the dataset (small) generation performance. +// BenchmarkSmallDatasetGeneration benchmarks the dataset (small) generation performance. func BenchmarkSmallDatasetGeneration(b *testing.B) { cache := make([]uint32, 65536/4) generateCache(cache, 0, make([]byte, 32)) @@ -759,7 +759,7 @@ func BenchmarkSmallDatasetGeneration(b *testing.B) { } } -// Benchmarks the light verification performance. +// BenchmarkHashimotoLight benchmarks the light verification performance. func BenchmarkHashimotoLight(b *testing.B) { cache := make([]uint32, cacheSize(1)/4) generateCache(cache, 0, make([]byte, 32)) @@ -772,7 +772,7 @@ func BenchmarkHashimotoLight(b *testing.B) { } } -// BenchmarkProgpowLight Benchmarks the light verification performance (not counting cDag generation). +// BenchmarkProgpowLight benchmarks the light verification performance (not counting cDag generation). func BenchmarkProgpowLight(b *testing.B) { cache := make([]uint32, cacheSize(1)/4) generateCache(cache, 0, make([]byte, 32)) @@ -787,7 +787,7 @@ func BenchmarkProgpowLight(b *testing.B) { } } -// Benchmarks the full (small) verification performance. +// BenchmarkHashimotoFullSmall benchmarks the full (small) verification performance. func BenchmarkHashimotoFullSmall(b *testing.B) { cache := make([]uint32, 65536/4) generateCache(cache, 0, make([]byte, 32)) @@ -803,7 +803,7 @@ func BenchmarkHashimotoFullSmall(b *testing.B) { } } -// Benchmarks the full (small) verification performance. +// BenchmarkProgpowFullSmall benchmarks the full (small) verification performance. func BenchmarkProgpowFullSmall(b *testing.B) { cache := make([]uint32, 65536/4) generateCache(cache, 0, make([]byte, 32)) diff --git a/consensus/ethash/consensus_test.go b/consensus/ethash/consensus_test.go index 435eafd947fd..3e99d4d65454 100644 --- a/consensus/ethash/consensus_test.go +++ b/consensus/ethash/consensus_test.go @@ -123,7 +123,7 @@ func TestCalcDifficulty(t *testing.T) { // DatasetDir: "", // DatasetsInMem: 1, // DatasetsOnDisk: 1, -// ProgpowBlockNumber: config.ProgpowBlock, +// ProgpowBlock: config.ProgpowBlock, // }, nil, false) // bc, err := core.NewBlockChain(db, nil, config, engine, vm.Config{}, nil) // //fmt.Printf("Genesis hash %x\n", bc.Genesis().Hash()) diff --git a/consensus/ethash/ethash.go b/consensus/ethash/ethash.go index f1c0bc474d53..f92710b9042e 100644 --- a/consensus/ethash/ethash.go +++ b/consensus/ethash/ethash.go @@ -50,9 +50,9 @@ var ( // two256 is a big integer representing 2^256 two256 = new(big.Int).Exp(big.NewInt(2), big.NewInt(256), big.NewInt(0)) - // sharedEthash is a full instance that can be shared between multiple users. - sharedEthash *Ethash - ethashMu sync.Mutex // lock for initializing sharedEthash + // sharedEngines contains ethash instances which are mapped by progpow blocknumber + sharedEngines map[uint64]*Ethash + ethashMu sync.Mutex // lock for modifying sharedEngines // algorithmRevision is the data structure version used for file naming. algorithmRevision = 23 @@ -405,14 +405,14 @@ const ( // Config are the configuration parameters of the ethash. type Config struct { - CacheDir string - CachesInMem int - CachesOnDisk int - DatasetDir string - DatasetsInMem int - DatasetsOnDisk int - PowMode Mode - ProgpowBlockNumber *big.Int // Block number at which to use progpow instead of hashimoto + CacheDir string + CachesInMem int + CachesOnDisk int + DatasetDir string + DatasetsInMem int + DatasetsOnDisk int + PowMode Mode + ProgpowBlock *big.Int // Block number at which to use progpow instead of hashimoto } // sealTask wraps a seal block with relative result channel for remote sealer thread. @@ -576,11 +576,16 @@ func NewFullFaker() *Ethash { // in the same process. func NewShared(progpowNumber *big.Int) *Ethash { ethashMu.Lock() - if sharedEthash == nil { - sharedEthash = New(Config{"", 3, 0, "", 1, 0, ModeNormal, progpowNumber}, nil, false) + if progpowNumber == nil { + progpowNumber = new(big.Int).SetUint64(uint64(math.MaxUint64)) + } + sharedEngine, exist := sharedEngines[progpowNumber.Uint64()] + if !exist { + sharedEngine = New(Config{"", 3, 0, "", 1, 0, ModeNormal, progpowNumber}, nil, false) + sharedEngines[progpowNumber.Uint64()] = sharedEngine } ethashMu.Unlock() - return &Ethash{shared: sharedEthash} + return &Ethash{shared: sharedEngine} } // Close closes the exit channel to notify all backend threads exiting. @@ -736,7 +741,7 @@ type powLight func(size uint64, cache []uint32, hash []byte, nonce, number uint6 // fullPow returns either hashimoto or progpow full checker depending on number func (ethash *Ethash) fullPow(number *big.Int) powFull { - if progpowNumber := ethash.config.ProgpowBlockNumber; progpowNumber != nil && progpowNumber.Cmp(number) <= 0 { + if progpowNumber := ethash.config.ProgpowBlock; progpowNumber != nil && progpowNumber.Cmp(number) <= 0 { ethashCache := ethash.cache(number.Uint64()) if ethashCache.cDag == nil { log.Warn("cDag is nil, suboptimal performance") @@ -762,7 +767,7 @@ func (ethash *Ethash) fullPow(number *big.Int) powFull { // lightPow returns either hashimoto or progpow depending on number func (ethash *Ethash) lightPow(number *big.Int) powLight { - if progpowNumber := ethash.config.ProgpowBlockNumber; progpowNumber != nil && progpowNumber.Cmp(number) <= 0 { + if progpowNumber := ethash.config.ProgpowBlock; progpowNumber != nil && progpowNumber.Cmp(number) <= 0 { return func(size uint64, cache []uint32, hash []byte, nonce uint64, blockNumber uint64) ([]byte, []byte) { ethashCache := ethash.cache(blockNumber) if ethashCache.cDag == nil { diff --git a/consensus/ethash/progpow.go b/consensus/ethash/progpow.go index 6c3a00b7d080..b81b73208feb 100644 --- a/consensus/ethash/progpow.go +++ b/consensus/ethash/progpow.go @@ -1,3 +1,20 @@ +// Copyright 2019 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +// Package ethash implements the ethash proof-of-work consensus engine. package ethash import ( diff --git a/consensus/ethash/progpow_test.go b/consensus/ethash/progpow_test.go index 6b4eef0c4524..c2ba7865c2df 100644 --- a/consensus/ethash/progpow_test.go +++ b/consensus/ethash/progpow_test.go @@ -250,7 +250,7 @@ func (n *progpowHashTestcase) UnmarshalJSON(buf []byte) error { return nil } func TestProgpowHashes(t *testing.T) { - data, err := ioutil.ReadFile(filepath.Join("..", "..", "tests", "progpow_testvectors.json")) + data, err := ioutil.ReadFile(filepath.Join(".", "testdata", "progpow_testvectors.json")) if err != nil { t.Fatal(err) } diff --git a/tests/progpow_testvectors.json b/consensus/ethash/testdata/progpow_testvectors.json similarity index 100% rename from tests/progpow_testvectors.json rename to consensus/ethash/testdata/progpow_testvectors.json diff --git a/eth/backend.go b/eth/backend.go index 3a94a8e48166..511dadeca94c 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -250,13 +250,13 @@ func CreateConsensusEngine(ctx *node.ServiceContext, chainConfig *params.ChainCo return ethash.NewShared(chainConfig.ProgpowBlock) default: engine := ethash.New(ethash.Config{ - CacheDir: ctx.ResolvePath(config.CacheDir), - CachesInMem: config.CachesInMem, - CachesOnDisk: config.CachesOnDisk, - DatasetDir: config.DatasetDir, - DatasetsInMem: config.DatasetsInMem, - DatasetsOnDisk: config.DatasetsOnDisk, - ProgpowBlockNumber: chainConfig.ProgpowBlock, + CacheDir: ctx.ResolvePath(config.CacheDir), + CachesInMem: config.CachesInMem, + CachesOnDisk: config.CachesOnDisk, + DatasetDir: config.DatasetDir, + DatasetsInMem: config.DatasetsInMem, + DatasetsOnDisk: config.DatasetsOnDisk, + ProgpowBlock: chainConfig.ProgpowBlock, }, notify, noverify) engine.SetThreads(-1) // Disable CPU mining return engine