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

multi: implement testnet4 and add support for soft forks that are always active #2339

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

Roasbeef
Copy link
Member

Taken over from: #2318

Only the last commit is new.

@Roasbeef Roasbeef force-pushed the testnet4-bip9 branch 2 times, most recently from b2172bd to c5ea1cc Compare March 11, 2025 21:24
@coveralls
Copy link

coveralls commented Mar 11, 2025

Pull Request Test Coverage Report for Build 13818768992

Details

  • 54 of 108 (50.0%) changed or added relevant lines in 12 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.01%) to 55.291%

Changes Missing Coverage Covered Lines Changed/Added Lines %
chaincfg/params.go 15 16 93.75%
blockchain/thresholdstate.go 6 8 75.0%
rpcclient/infrastructure.go 0 2 0.0%
cmd/addblock/config.go 0 4 0.0%
cmd/findcheckpoint/config.go 0 4 0.0%
config.go 0 4 0.0%
database/cmd/dbtool/globalconfig.go 0 4 0.0%
rpcserver.go 0 4 0.0%
blockchain/difficulty.go 2 7 28.57%
blockchain/versionbits.go 10 15 66.67%
Totals Coverage Status
Change from base Build 13794438730: -0.01%
Covered Lines: 29981
Relevant Lines: 54224

💛 - Coveralls

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

I think some tuning of the CONVENTIONS.md file is in order for Aider to be useful in this repo. Otherwise it feels like the workload is shifted from the author to the reviewer...

@@ -175,6 +175,10 @@ func (c customDeploymentChecker) Condition(_ *blockNode) (bool, error) {
return c.conditionTrue, nil
}

func (c customDeploymentChecker) ForceActive(_ *blockNode) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Godoc comment missing.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a mock version, none of the other existing methods have a godoc?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, yes. Missed that, sorry. Only looked at the diff and not the larger context of the file.

Add robust property-based tests for the assertNoTimeWarp function using
the rapid testing library. The tests verify the following scenarios:

- Basic property tests:
  - Only retarget blocks (block height divisible by blocksPerRetarget) are checked
  - Valid timestamps (within maxTimeWarp of previous block) pass validation
  - Invalid timestamps (too early) fail with appropriate ErrTimewarpAttack
  - Correct boundary behavior (exactly at maxTimeWarp limit)

- Invariant tests:
  - Function never panics with valid inputs
  - Non-retarget blocks always return nil regardless of timestamps

- Security tests:
  - All retarget blocks are protected from timewarp attacks
  - Non-retarget blocks are not affected by the timewarp check
…tion

This commit introduces the concept of `AlwaysActiveHeight` to the
deployment mechanism, allowing a deployment to be forced into the active
state if the next block's height meets or exceeds this threshold.

This is intended primarily to be used alongside the new Testnet4
deployment, as the past major soft forks are meant to be active from the
very first block height.
@Roasbeef
Copy link
Member Author

I think some tuning of the CONVENTIONS.md file is in order for Aider to be useful in this repo.

Def, things like require usage in tests, or more details re comments should be pretty easy to capture.

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

Was able to successfully sync a btcd node from scratch and also a Neutrino node referencing the changes in this PR.

@@ -175,6 +175,10 @@ func (c customDeploymentChecker) Condition(_ *blockNode) (bool, error) {
return c.conditionTrue, nil
}

func (c customDeploymentChecker) ForceActive(_ *blockNode) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, yes. Missed that, sorry. Only looked at the diff and not the larger context of the file.

AlwaysActiveHeight: 1,
},
DeploymentCSV: {
BitNumber: 29,
Copy link
Collaborator

Choose a reason for hiding this comment

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

You mentioned the other day that the bit numbers probably shouldn't be the same for CSV and Segwit. Not sure if that's relevant given the AlwaysActiveHeight though.

Copy link
Collaborator

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

❤️

@@ -684,6 +689,12 @@ func compareScript(height int32, script []byte) error {
func CheckBlockHeaderContext(header *wire.BlockHeader, prevNode HeaderCtx,
flags BehaviorFlags, c ChainCtx, skipCheckpoint bool) error {

// The height of this block is one more than the referenced previous
// block.
blockHeight := prevNode.Height() + 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: kinda weird this code block is moved here since blockHeight isn't used until line 729

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants