Merge pull request #1985 from guggero/pow-no-retargeting

blockchain+chaincfg: disable retargeting for regtest
This commit is contained in:
Oliver Gugger 2023-06-22 09:51:09 +02:00 committed by GitHub
commit 7fd5c1e92c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -219,7 +219,15 @@ func (b *BlockChain) findPrevTestNetDifficulty(startNode *blockNode) uint32 {
// This function differs from the exported CalcNextRequiredDifficulty in that
// the exported version uses the current best chain as the previous block node
// while this function accepts any block node.
func (b *BlockChain) calcNextRequiredDifficulty(lastNode *blockNode, newBlockTime time.Time) (uint32, error) {
func (b *BlockChain) calcNextRequiredDifficulty(lastNode *blockNode,
newBlockTime time.Time) (uint32, error) {
// Emulate the same behavior as Bitcoin Core that for regtest there is
// no difficulty retargeting.
if b.chainParams.PoWNoRetargeting {
return b.chainParams.PowLimitBits, nil
}
// Genesis block.
if lastNode == nil {
return b.chainParams.PowLimitBits, nil

View file

@ -183,6 +183,11 @@ type Params struct {
// block in compact form.
PowLimitBits uint32
// PoWNoRetargeting defines whether the network has difficulty
// retargeting enabled or not. This should only be set to true for
// regtest like networks.
PoWNoRetargeting bool
// These fields define the block heights at which the specified softfork
// BIP became active.
BIP0034Height int32
@ -432,6 +437,7 @@ var RegressionNetParams = Params{
GenesisHash: &regTestGenesisHash,
PowLimit: regressionPowLimit,
PowLimitBits: 0x207fffff,
PoWNoRetargeting: true,
CoinbaseMaturity: 100,
BIP0034Height: 100000000, // Not active - Permit ver 1 blocks
BIP0065Height: 1351, // Used by regression tests