diff --git a/consensus/ethash/algorithm_test.go b/consensus/ethash/algorithm_test.go index 38477f0f71..7765ff9fe6 100644 --- a/consensus/ethash/algorithm_test.go +++ b/consensus/ethash/algorithm_test.go @@ -703,7 +703,7 @@ func TestConcurrentDiskCacheGeneration(t *testing.T) { go func(idx int) { defer pend.Done() - ethash := New(Config{cachedir, 0, 1, "", 0, 0, Normal}) + ethash := New(Config{cachedir, 0, 1, "", 0, 0, ModeNormal}) if err := ethash.VerifySeal(nil, block.Header()); err != nil { t.Errorf("proc %d: block verification failed: %v", idx, err) } diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 7a598e8e81..51bdd9e731 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -68,7 +68,7 @@ func (ethash *Ethash) Author(header *types.Header) (common.Address, error) { // stock Ethereum ethash engine. func (ethash *Ethash) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error { // If we're running a full engine faking, accept any input as valid - if ethash.config.PowMode == FullFake { + if ethash.config.PowMode == ModeFullFake { return nil } // Short circuit if the header is known, or it's parent not @@ -89,7 +89,7 @@ func (ethash *Ethash) VerifyHeader(chain consensus.ChainReader, header *types.He // a results channel to retrieve the async verifications. func (ethash *Ethash) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error) { // If we're running a full engine faking, accept any input as valid - if ethash.config.PowMode == FullFake || len(headers) == 0 { + if ethash.config.PowMode == ModeFullFake || len(headers) == 0 { abort, results := make(chan struct{}), make(chan error, len(headers)) for i := 0; i < len(headers); i++ { results <- nil @@ -169,7 +169,7 @@ func (ethash *Ethash) verifyHeaderWorker(chain consensus.ChainReader, headers [] // rules of the stock Ethereum ethash engine. func (ethash *Ethash) VerifyUncles(chain consensus.ChainReader, block *types.Block) error { // If we're running a full engine faking, accept any input as valid - if ethash.config.PowMode == FullFake { + if ethash.config.PowMode == ModeFullFake { return nil } // Verify that there are at most 2 uncles included in this block @@ -455,7 +455,7 @@ func calcDifficultyFrontier(time uint64, parent *types.Header) *big.Int { // the PoW difficulty requirements. func (ethash *Ethash) VerifySeal(chain consensus.ChainReader, header *types.Header) error { // If we're running a fake PoW, accept any seal as valid - if ethash.config.PowMode == Fake || ethash.config.PowMode == FullFake { + if ethash.config.PowMode == ModeFake || ethash.config.PowMode == ModeFullFake { time.Sleep(ethash.fakeDelay) if ethash.fakeFail == header.Number.Uint64() { return errInvalidPoW @@ -480,7 +480,7 @@ func (ethash *Ethash) VerifySeal(chain consensus.ChainReader, header *types.Head cache := ethash.cache(number) size := datasetSize(number) - if ethash.config.PowMode == Test { + if ethash.config.PowMode == ModeTest { size = 32 * 1024 } digest, result := hashimotoLight(size, cache, header.HashNoNonce().Bytes(), header.Nonce.Uint64()) diff --git a/consensus/ethash/ethash.go b/consensus/ethash/ethash.go index 78efae1d48..a78b3a895d 100644 --- a/consensus/ethash/ethash.go +++ b/consensus/ethash/ethash.go @@ -45,7 +45,7 @@ var ( maxUint256 = 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 = New(Config{"", 3, 0, "", 1, 0, Normal}) + sharedEthash = New(Config{"", 3, 0, "", 1, 0, ModeNormal}) // algorithmRevision is the data structure version used for file naming. algorithmRevision = 23 @@ -320,14 +320,15 @@ func MakeDataset(block uint64, dir string) { d.release() } +// Mode defines the type and amount of PoW verification an ethash engine makes. type Mode uint const ( - Normal Mode = iota - Shared - Test - Fake - FullFake + ModeNormal Mode = iota + ModeShared + ModeTest + ModeFake + ModeFullFake ) // Config are the configuration parameters of the ethash. @@ -392,7 +393,7 @@ func NewTester() *Ethash { return &Ethash{ config: Config{ CachesInMem: 1, - PowMode: Test, + PowMode: ModeTest, }, caches: make(map[uint64]*cache), datasets: make(map[uint64]*dataset), @@ -407,7 +408,7 @@ func NewTester() *Ethash { func NewFaker() *Ethash { return &Ethash{ config: Config{ - PowMode: Fake, + PowMode: ModeFake, }, } } @@ -418,7 +419,7 @@ func NewFaker() *Ethash { func NewFakeFailer(fail uint64) *Ethash { return &Ethash{ config: Config{ - PowMode: Fake, + PowMode: ModeFake, }, fakeFail: fail, } @@ -430,7 +431,7 @@ func NewFakeFailer(fail uint64) *Ethash { func NewFakeDelayer(delay time.Duration) *Ethash { return &Ethash{ config: Config{ - PowMode: Fake, + PowMode: ModeFake, }, fakeDelay: delay, } @@ -441,7 +442,7 @@ func NewFakeDelayer(delay time.Duration) *Ethash { func NewFullFaker() *Ethash { return &Ethash{ config: Config{ - PowMode: FullFake, + PowMode: ModeFullFake, }, } } @@ -501,7 +502,7 @@ func (ethash *Ethash) cache(block uint64) []uint32 { ethash.lock.Unlock() // Wait for generation finish, bump the timestamp and finalize the cache - current.generate(ethash.config.CacheDir, ethash.config.CachesOnDisk, ethash.config.PowMode == Test) + current.generate(ethash.config.CacheDir, ethash.config.CachesOnDisk, ethash.config.PowMode == ModeTest) current.lock.Lock() current.used = time.Now() @@ -509,7 +510,7 @@ func (ethash *Ethash) cache(block uint64) []uint32 { // If we exhausted the future cache, now's a good time to regenerate it if future != nil { - go future.generate(ethash.config.CacheDir, ethash.config.CachesOnDisk, ethash.config.PowMode == Test) + go future.generate(ethash.config.CacheDir, ethash.config.CachesOnDisk, ethash.config.PowMode == ModeTest) } return current.cache } @@ -564,7 +565,7 @@ func (ethash *Ethash) dataset(block uint64) []uint32 { ethash.lock.Unlock() // Wait for generation finish, bump the timestamp and finalize the cache - current.generate(ethash.config.DatasetDir, ethash.config.DatasetsOnDisk, ethash.config.PowMode == Test) + current.generate(ethash.config.DatasetDir, ethash.config.DatasetsOnDisk, ethash.config.PowMode == ModeTest) current.lock.Lock() current.used = time.Now() @@ -572,7 +573,7 @@ func (ethash *Ethash) dataset(block uint64) []uint32 { // If we exhausted the future dataset, now's a good time to regenerate it if future != nil { - go future.generate(ethash.config.DatasetDir, ethash.config.DatasetsOnDisk, ethash.config.PowMode == Test) + go future.generate(ethash.config.DatasetDir, ethash.config.DatasetsOnDisk, ethash.config.PowMode == ModeTest) } return current.dataset } diff --git a/consensus/ethash/sealer.go b/consensus/ethash/sealer.go index d7cceb11d4..c2447e4730 100644 --- a/consensus/ethash/sealer.go +++ b/consensus/ethash/sealer.go @@ -34,7 +34,7 @@ import ( // the block's difficulty requirements. func (ethash *Ethash) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error) { // If we're running a fake PoW, simply return a 0 nonce immediately - if ethash.config.PowMode == Fake || ethash.config.PowMode == FullFake { + if ethash.config.PowMode == ModeFake || ethash.config.PowMode == ModeFullFake { header := block.Header() header.Nonce, header.MixDigest = types.BlockNonce{}, common.Hash{} return block.WithSeal(header), nil diff --git a/console/console_test.go b/console/console_test.go index 98d0feddac..d296807854 100644 --- a/console/console_test.go +++ b/console/console_test.go @@ -98,7 +98,7 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester { Genesis: core.DeveloperGenesisBlock(15, common.Address{}), Etherbase: common.HexToAddress(testAddress), Ethash: ethash.Config{ - PowMode: ethash.Test, + PowMode: ethash.ModeTest, }, } if confOverride != nil { diff --git a/eth/backend.go b/eth/backend.go index 8d08feca60..e7f0f57dd4 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -216,13 +216,13 @@ func CreateConsensusEngine(ctx *node.ServiceContext, config *ethash.Config, chai } // Otherwise assume proof-of-work switch { - case config.PowMode == ethash.Fake: + case config.PowMode == ethash.ModeFake: log.Warn("Ethash used in fake mode") return ethash.NewFaker() - case config.PowMode == ethash.Test: + case config.PowMode == ethash.ModeTest: log.Warn("Ethash used in test mode") return ethash.NewTester() - case config.PowMode == ethash.Shared: + case config.PowMode == ethash.ModeShared: log.Warn("Ethash used in shared mode") return ethash.NewShared() default: