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/network): Add an empty Parameters struct in Network::Testnet #8368

Merged
merged 16 commits into from
Apr 17, 2024

Conversation

arya2
Copy link
Contributor

@arya2 arya2 commented Mar 20, 2024

Motivation

We want to add configurable network parameters to Network for supporting Regtest and custom Testnets to be used in integration tests.

Closes #7968.

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.

Complex Code or Requirements

The db format for HistoryTrees and transparent::Addresses are the same across any test networks, this could mean that a Regtest cache or a custom Testnet cache could be used on the default Testnet. We may want to follow up this PR with a change that ensures Zebra panics if it's configured to run on the default public testnet with a Regtest cache, or we may want to make that change in this PR.

I'd like special attention to changes in:

  • The db format upgrade code where a network == Testnet condition was replaced with network.is_a_test_network()
  • Tests where Network::iter() was used instead of running with Mainnet and Testnet being applicable to Regtest

Solution

  • Adds a NetworkParameters struct and includes it in Network::Testnet
  • Adds a new_default_testnet() method for creating the default public Testnet
  • Updates a condition in the db format upgrade to be true for any test network
  • Updates the key types in:
    • FUNDING_STREAM_HEIGHT_RANGES,
    • FUNDING_STREAM_ADDRESSES, and
    • INITIAL_MIN_NETWORK_PROTOCOL_VERSION
  • Updates production code matching on Testnet to return appropriate values
  • Adds TODOs to production code where changes are needed when adding new fields
  • Uses Network::iter() in tests that run equivalent code for both Mainnet and Testnet
  • Replaces instances of the Testnet constructor with Network::new_default_testnet()
  • Changes type of network field on transparent::Address and HistoryTreeParts to NetworkKind

Testing

Network::iter() was used in most tests that check both Mainnet and Testnet so they'll cover any new networks we return from that function.

This PR may still need a test for the custom deserialization of Network or other changes.

Review

Anyone can review.

This PR may be easier to review by commit:

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 A-network Area: Network protocol updates or fixes NU-6 Network Upgrade: NU6 specific tasks C-testing Category: These are tests C-feature Category: New features P-Medium ⚡ labels Mar 20, 2024
@arya2 arya2 self-assigned this Mar 20, 2024
@github-actions github-actions bot added the C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG label Mar 20, 2024
@arya2 arya2 added this to the Regtest Network support milestone Mar 20, 2024
@arya2 arya2 force-pushed the network-params branch 2 times, most recently from dbf3296 to c342e5f Compare March 22, 2024 01:27
@arya2 arya2 marked this pull request as ready for review March 22, 2024 01:53
@arya2 arya2 requested review from a team as code owners March 22, 2024 01:53
@arya2 arya2 requested review from upbqdn and removed request for a team March 22, 2024 01:53
@arya2 arya2 added the extra-reviews This PR needs at least 2 reviews to merge label Mar 22, 2024
@arya2 arya2 requested a review from oxarbitrage March 22, 2024 01:54
zebra-chain/src/parameters/network.rs Outdated Show resolved Hide resolved
zebra-chain/src/parameters/network.rs Outdated Show resolved Hide resolved
zebra-chain/src/parameters/network.rs Show resolved Hide resolved
zebra-chain/src/primitives/address.rs Show resolved Hide resolved
zebra-chain/src/primitives/address.rs Outdated Show resolved Hide resolved
zebra-chain/src/primitives/address.rs Outdated Show resolved Hide resolved
zebra-chain/src/parameters/network.rs Show resolved Hide resolved
zebra-chain/src/parameters/network.rs Outdated Show resolved Hide resolved
zebra-chain/src/parameters/network.rs Show resolved Hide resolved
zebra-chain/src/parameters/network.rs Show resolved Hide resolved
zebra-chain/src/primitives/zcash_primitives.rs Outdated Show resolved Hide resolved
zebra-chain/src/primitives/zcash_primitives.rs Outdated Show resolved Hide resolved
zebra-chain/src/transparent/address.rs Outdated Show resolved Hide resolved
zebra-consensus/src/checkpoint/list.rs Outdated Show resolved Hide resolved
zebra-consensus/src/checkpoint/list.rs Outdated Show resolved Hide resolved
zebra-network/src/config.rs Outdated Show resolved Hide resolved
zebra-consensus/src/parameters/subsidy.rs Outdated Show resolved Hide resolved
zebra-network/src/config.rs Outdated Show resolved Hide resolved
zebra-network/src/config.rs Show resolved Hide resolved
zebra-network/src/protocol/external/types.rs Show resolved Hide resolved
Copy link
Contributor

@idky137 idky137 left a comment

Choose a reason for hiding this comment

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

Should we have new_default_regtest and is_a_regtest methods similar to testnet? This would be useful for wallets to use in testing and simplify migration. They could also be used where we need to distinguish between public_testnet and regtest.

@arya2
Copy link
Contributor Author

arya2 commented Mar 27, 2024

Should we have new_default_regtest and is_a_regtest methods similar to testnet?

Yes, we should add a is_regtest() method, but not in this PR, we want to minimize the changes here so it's easy to review, so we're only adding an empty struct to Testnet where we can start adding fields that will be needed for Regtest.

@arya2
Copy link
Contributor Author

arya2 commented Apr 11, 2024

It's a bit unfortunate we need to overload the word "network" since we also have a crate called zebra-network

Yep. It caused some indecisiveness when I was naming the PR and choosing labels, since the PR is related to which Zcash network the node is in, but I think "consensus" actually fits better, I'll update the PR title to include both.

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

@arya2 arya2 changed the title add(network): Add an empty NetworkParameters struct in Network::Testnet add(consensus/network): Add an empty NetworkParameters struct in Network::Testnet Apr 11, 2024
@arya2 arya2 requested a review from upbqdn April 11, 2024 20:49
@upbqdn upbqdn changed the title add(consensus/network): Add an empty NetworkParameters struct in Network::Testnet add(consensus/network): Add an empty Parameters struct in Network::Testnet Apr 12, 2024
@upbqdn
Copy link
Member

upbqdn commented Apr 12, 2024

I changed NetworkParameters to Parameters in the PR name.

@arya2 arya2 added the do-not-merge Tells Mergify not to merge this PR label Apr 12, 2024
@arya2
Copy link
Contributor Author

arya2 commented Apr 12, 2024

Added a do-not-merge label to wait on the full sync test to finish.

@arya2 arya2 removed the C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG label Apr 12, 2024
@mpguerra mpguerra removed the do-not-merge Tells Mergify not to merge this PR label Apr 15, 2024
@arya2
Copy link
Contributor Author

arya2 commented Apr 15, 2024

@Mergifyio refresh

Copy link
Contributor

mergify bot commented Apr 15, 2024

refresh

✅ Pull request refreshed

@arya2 arya2 removed the extra-reviews This PR needs at least 2 reviews to merge label Apr 15, 2024
@arya2
Copy link
Contributor Author

arya2 commented Apr 15, 2024

@Mergifyio refresh

Copy link
Contributor

mergify bot commented Apr 15, 2024

refresh

✅ Pull request refreshed

mergify bot added a commit that referenced this pull request Apr 15, 2024
@arya2 arya2 added do-not-merge Tells Mergify not to merge this PR and removed do-not-merge Tells Mergify not to merge this PR labels Apr 15, 2024
@arya2
Copy link
Contributor Author

arya2 commented Apr 17, 2024

@Mergifyio refresh

Copy link
Contributor

mergify bot commented Apr 17, 2024

refresh

✅ Pull request refreshed

mergify bot added a commit that referenced this pull request Apr 17, 2024
mergify bot added a commit that referenced this pull request Apr 17, 2024
@mergify mergify bot merged commit 16a39f8 into main Apr 17, 2024
211 checks passed
@mergify mergify bot deleted the network-params branch April 17, 2024 02:20
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 A-network Area: Network protocol updates or fixes C-feature Category: New features C-testing Category: These are tests NU-6 Network Upgrade: NU6 specific tasks P-Medium ⚡
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an empty NetworkParameters struct to Network::Testnet
4 participants