From 44612c2964e2a8fa8bd76dcf54a3be84c80c966c Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Sat, 28 Jan 2023 00:56:51 -0600 Subject: [PATCH] Add a new param to the config for capping the maximum difficulty. This is useful for speeding up block creation on a test network. --- consensus/ethash/consensus.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 1c38b80ea..b6e7b9511 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -31,6 +31,7 @@ import ( "github.com/ethereum/go-ethereum/consensus/misc" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie" @@ -330,7 +331,13 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainHeaderReader, header, pa // 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.ChainHeaderReader, time uint64, parent *types.Header) *big.Int { - return CalcDifficulty(chain.Config(), time, parent) + var config = chain.Config() + var ret = CalcDifficulty(config, time, parent) + if nil != config.CappedMaximumDifficulty && ret.Cmp(config.CappedMaximumDifficulty) >= 0 { + log.Info(fmt.Sprintf("Using capped difficulty %d", config.CappedMaximumDifficulty)) + return config.CappedMaximumDifficulty + } + return ret } // CalcDifficulty is the difficulty adjustment algorithm. It returns