From a2ce52efbf3391cb7eed3b26906eb0c1eca65280 Mon Sep 17 00:00:00 2001 From: Andrew Roldugin Date: Tue, 21 Aug 2018 20:15:44 +0300 Subject: [PATCH] --ethash.difficulty --- cmd/geth/main.go | 1 + cmd/geth/usage.go | 1 + cmd/utils/flags.go | 5 +++++ consensus/ethash/consensus.go | 2 +- consensus/ethash/ethash.go | 3 ++- eth/backend.go | 1 + eth/config.go | 1 + 7 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index d6aa9173e7..a298683fa8 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -72,6 +72,7 @@ var ( utils.EthashDatasetDirFlag, utils.EthashDatasetsInMemoryFlag, utils.EthashDatasetsOnDiskFlag, + utils.EthashDifficultyFlag, utils.TxPoolNoLocalsFlag, utils.TxPoolJournalFlag, utils.TxPoolRejournalFlag, diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index d8b8e9804d..210cb5bba6 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -99,6 +99,7 @@ var AppHelpFlagGroups = []flagGroup{ utils.EthashDatasetDirFlag, utils.EthashDatasetsInMemoryFlag, utils.EthashDatasetsOnDiskFlag, + utils.EthashDifficultyFlag, }, }, //{ diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 9eb725155e..da292bb953 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -241,6 +241,11 @@ var ( Usage: "Number of recent ethash mining DAGs to keep on disk (1+GB each)", Value: ess.DefaultConfig.Ethash.DatasetsOnDisk, } + EthashDifficultyFlag = BigFlag{ + Name: "ethash.difficulty", + Usage: "Difficulty of ethash", + Value: ess.DefaultConfig.Ethash.Difficulty, + } // Transaction pool settings TxPoolNoLocalsFlag = cli.BoolFlag{ Name: "txpool.nolocals", diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 4c541ce4e3..7250000584 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -288,7 +288,7 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent * // the difficulty that a new block should have when created at time // given the parent block's time and difficulty. func (ethash *Ethash) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int { - return CalcDifficulty(chain.Config(), time, parent) + return ethash.config.Difficulty } // CalcDifficulty is the difficulty adjustment algorithm. It returns diff --git a/consensus/ethash/ethash.go b/consensus/ethash/ethash.go index 440835aaf1..f91ad00812 100644 --- a/consensus/ethash/ethash.go +++ b/consensus/ethash/ethash.go @@ -47,7 +47,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, ModeNormal}) + sharedEthash = New(Config{"", 3, 0, "", 1, 0, ModeNormal, big.NewInt(1)}) // algorithmRevision is the data structure version used for file naming. algorithmRevision = 23 @@ -387,6 +387,7 @@ type Config struct { DatasetsInMem int DatasetsOnDisk int PowMode Mode + Difficulty *big.Int } // Ethash is a consensus engine based on proof-of-work implementing the ethash diff --git a/eth/backend.go b/eth/backend.go index a134850339..d6d3ff4233 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -117,6 +117,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Essentia, error) { return nil, genesisErr } log.Info("Initialised chain configuration", "config", chainConfig) + log.Info("Ethash", "difficulty", config.Ethash.Difficulty) ess := &Essentia{ config: config, diff --git a/eth/config.go b/eth/config.go index c95e194b6e..315dc041c1 100644 --- a/eth/config.go +++ b/eth/config.go @@ -42,6 +42,7 @@ var DefaultConfig = Config{ CachesOnDisk: 3, DatasetsInMem: 1, DatasetsOnDisk: 2, + Difficulty: big.NewInt(1), }, NetworkId: 1, LightPeers: 100,