Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blockchain+chaincfg: disable retargeting for regtest #1985

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion blockchain/difficulty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is only desired for Regtest (maybe simnet in btcd as well?), how about something like:

       if b.chainParams.Name == chaincfg.RegressionNetParams.Name {

instead of introducing a new field in Params?.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this makes it just way more explicit what's going on. See lightninglabs/neutrino#256 (comment) 😅

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Ok seems alright

return b.chainParams.PowLimitBits, nil
}

// Genesis block.
if lastNode == nil {
return b.chainParams.PowLimitBits, nil
Expand Down
6 changes: 6 additions & 0 deletions chaincfg/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down