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

add(consensus): Adds block construction and validation for NU5 from block height 1 for Regtest #8475

Merged
merged 19 commits into from
May 2, 2024

Conversation

arya2
Copy link
Contributor

@arya2 arya2 commented Apr 30, 2024

Motivation

We want to support Regtest in Zebra for integration testing.

Closes #8363.
Closes #8280.
Part of #7119.

This PR shouldn't change much, the regtest_nu5_activation_height field in the config should be removed, but that's a minor change.

Update: This PR shouldn't change anymore except to address review comments.

PR Author Checklist

Check before marking the PR as ready for review:

  • Will the PR name make sense to users?
  • Does the PR have a priority label?
  • Have you added or updated tests?
  • Is the documentation up to date?
For significant changes:
  • Is there a summary in the CHANGELOG?
  • Can these changes be split into multiple PRs?

If a checkbox isn't relevant to the PR, mark it as done.

Specifications

  • ZIP 212
  • Mean target difficulty on p. 132 of the spec:

MeanTarget(height ◦ N) :=
PoWLimit, if height ≤ PoWAveragingWindow
mean([ToTarget(nBits(𝑖)) for 𝑖 from height−PoWAveragingWindow up to height−1]),
otherwise.

  • I couldn't find the POW_ADJUSTMENT_BLOCK_SPAN in the protocol spec, I don't think this should be a problem because there are always more than that many blocks where a check was replaced with relevant_chain.is_empty() by Canopy activation.

Update:
It's based on MedianTime and ActualTimespan in the specification, PoWAveragingWindow is also used in MeanTarget.

Solution

  • Checks if the network is_regtest() in the start command, and if it is, commits the Regtest genesis block and skips starting the syncer
  • Skips the ZIP 212 grace period for non-default networks
  • Sets the mandatory checkpoint height at one block below Canopy activation for non-default networks (this may need some follow up changes, or changes in this PR)
  • Adds funding streams and minimal protocol version for NetworkKind::Regtest
  • Returns the reserved activation chain history root hash in the getblocktemplate method for blocks that should activate Heartwood network upgrade
  • Checks Heartwood was activated at a given block height even if the current network upgrade is NU5
  • Uses a slow start interval of Height(0) if PoW is disabled (this should be changed in a follow up PR or in this PR)
  • Uses fewer than 11 blocks for calculating the median time past
  • Uses fewer than 17 blocks for calculating the mean target difficulty

Testing

Added a test that gets block templates and submits them as blocks

Review

Anyone can review.

Reviewer Checklist

Check before approving the PR:

  • Does the PR scope match the ticket?
  • Are there enough tests to make sure it works? Do the tests cover the PR motivation?
  • Are all the PR blockers dealt with?
    PR blockers can be dealt with in new tickets or PRs.

And check the PR Author checklist is complete.

Follow Up Work

@arya2 arya2 added A-consensus Area: Consensus rule updates NU-6 Network Upgrade: NU6 specific tasks P-Medium ⚡ labels Apr 30, 2024
@arya2 arya2 added this to the Regtest Network support milestone Apr 30, 2024
@arya2 arya2 requested a review from oxarbitrage April 30, 2024 03:54
@arya2 arya2 self-assigned this Apr 30, 2024
@arya2 arya2 requested review from a team as code owners April 30, 2024 03:54
@arya2 arya2 requested review from upbqdn and removed request for a team April 30, 2024 03:54
@github-actions github-actions bot added the C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG label Apr 30, 2024
@upbqdn upbqdn removed the C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG label Apr 30, 2024
@github-actions github-actions bot added the C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG label Apr 30, 2024
@arya2 arya2 removed the C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG label Apr 30, 2024
@arya2
Copy link
Contributor Author

arya2 commented May 1, 2024

Running full sync test here: https://github.com/ZcashFoundation/zebra/actions/runs/8904378011

Update:

Applied the correct slow start interval, cancelled the first full sync test, and running a new full sync test here: https://github.com/ZcashFoundation/zebra/actions/runs/8904708364

I'm also running one locally with checkpoint sync disabled on the lower-mandatory-checkpoint-height branch that's based on this branch.

@github-actions github-actions bot added the C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG label May 1, 2024
upbqdn
upbqdn previously approved these changes May 1, 2024
zebra-chain/src/block/commitment.rs Show resolved Hide resolved
zebra-state/src/service/check.rs Show resolved Hide resolved
zebra-state/src/service/check/difficulty.rs Outdated Show resolved Hide resolved
zebra-state/src/service/check/difficulty.rs Outdated Show resolved Hide resolved
upbqdn
upbqdn previously approved these changes May 1, 2024
zebra-state/src/service/check.rs Show resolved Hide resolved
zebra-state/src/service/check.rs Show resolved Hide resolved
zebra-chain/src/block/commitment.rs Show resolved Hide resolved
@arya2
Copy link
Contributor Author

arya2 commented May 2, 2024

@Mergifyio refresh

Copy link
Contributor

mergify bot commented May 2, 2024

refresh

✅ Pull request refreshed

mergify bot added a commit that referenced this pull request May 2, 2024
@mergify mergify bot merged commit 8a786fe into main May 2, 2024
191 checks passed
@mergify mergify bot deleted the params-regtest branch May 2, 2024 19:43
@arya2 arya2 mentioned this pull request Jun 28, 2024
43 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-consensus Area: Consensus rule updates C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG NU-6 Network Upgrade: NU6 specific tasks P-Medium ⚡
Projects
None yet
2 participants