Commit Graph

1134 Commits

Author SHA1 Message Date
Arya 6e29727861 Adds a `new_regtest()` method on `Network` and `testnet::Parameters`, updates config deserialization to return an error if the initial_testnet_peers include any default initial peers AND contain configured activation heights 2024-04-19 15:43:51 -04:00
Arya c79e06f2b5 Merge remote-tracking branch 'origin/main' into params-network-name 2024-04-19 15:42:21 -04:00
Arya f8c153991b
add(consensus): Add `activation_heights` field to `NetworkParameters` and implement `Parameters` for `Network` (#8383)
* minor cleanup and rename

* Adds an empty NetworkParameters struct to Network::Testnet variant, updates production code.

* Updates tests

* Adds `NetworkKind` and uses it instead of `Network` in `HistoryTreeParts` and `transparent::Address`

* Adds a [network.testnet_parameters] section to the config, uses `NetworkKind` as zebra_network::Config::network field type, and converts 'Network' to `NetworkKind` before serializing

* Applies some suggestions from code review

* Applies suggestions from code review

* returns b58 prefix constants directly to remove From<NetworkKind> impl for zcash_primitives::consensus::Network

* Applies more suggestions from code review.

* moves conversions to zcash_primitives::consensus::Network to where they're used.

* Apply suggestions from code review

Co-authored-by: Marek <mail@marek.onl>

* rename `network` variables and method names typed as NetworkKind to `network_kind`

* use only test block heights for the network associated with them

* Applies more suggestions from code review.

* Rename `NetworkParameters` to `Parameters` and move it a new `testnet` module

* adds activation heights field

* updates stored test config, adds a quicker test for checking that stored configs can be parsed, adds an intermediate representation of activation heights

* implement Parameters for Network

* Passes &Network directly instead of converting to zp_consensus::Network where there were conversions

* fixes a bad merge (removes a network conversion in zcash_note_encryption)

* Adds a test for the Parameters impl for zebra_chain::Network

* fixes doc links

* - Makes the `activation_heights` config field optional by adding a #[serde(default)]
- Panics if a non-zero activation height is provided for the `Genesis` network upgrade
- Always sets the `Genesis` and `BeforeOverwinter` network upgrade activation heights to 0 and 1, `BeforeOverwinter` could be overwritten by a later network upgrade
- Makes the `activation_heights` field on `Parameters` private, adds/uses an accessor method instead, and adds a builder struct and `build()` method

* small refactor of activation_heights() method

* check that activation heights are in the right order

* Updates `NetworkUpgrade::activation_height()` to return the height of the next NetworkUpgrade if it doesn't find the activation height of `&self`

* checks that the miner address is of TestnetKind on Regtest and update assertion message

* Adds a DNetworkUpgradeActivationHeights struct for better control over how activation heights can be configured

* moves all ordered network upgrades to a constant, adds a no_duplicates test, moves struct with activation heights outside deserialization impl and accepts it in `ParametersBuilder::activation_heights()` instead of a Vec

* panics if any network upgrades are configured to activate at Height(0) because it's reserved for Genesis

* Simplifies the `ParametersBuilder::activation_heights()` method and removes an unnecessary test.

* Adds Sapling HRPs as fields on testnet params. (#8398)

* Applies suggestions from code review.

* Update zebra-chain/src/parameters/network_upgrade.rs

Co-authored-by: Marek <mail@marek.onl>

---------

Co-authored-by: Marek <mail@marek.onl>
2024-04-19 01:20:34 +00:00
Arya a842c12d55 updates stored test configs and fixes `network_name()` docs 2024-04-18 14:06:22 -04:00
Arya 0e97b53937 Adds `MainnetKind`, `TestnetKind`, and `RegtestKind` to reserved network names 2024-04-18 14:06:22 -04:00
Arya 08f0838079 adds config field for setting network name, adds "with_" prefix to ParameterBuilder setter methods 2024-04-18 14:06:22 -04:00
Arya 1608472f5a adds constraints on valid network names and a test 2024-04-18 14:06:22 -04:00
Arya 1173faf894 Removes unnecessary `.filter()` 2024-04-18 14:06:22 -04:00
Arya a94dcabaca Adds `network_name` field and accessor method on `Parameters`, uses it in the `Display` impl for `Network` 2024-04-18 14:06:22 -04:00
Arya fea2162419
Update zebra-chain/src/parameters/network_upgrade.rs
Co-authored-by: Marek <mail@marek.onl>
2024-04-18 10:13:53 -04:00
Alfredo Garcia 887d4a2457
fix(beta-toolchain): Warnings (#8404)
* fix beta imports and other warnings

* clippy lints beta

* move attributes to after docs

Co-authored-by: Marek <mail@marek.onl>

* move some code to test module

* implement display instead of direct tostring for LongPollId

Co-authored-by: Arya <aryasolhi@gmail.com>

* fix typo

---------

Co-authored-by: Marek <mail@marek.onl>
Co-authored-by: Arya <aryasolhi@gmail.com>
2024-04-18 01:45:22 +00:00
Arya fb2d13a706 Applies suggestions from code review. 2024-04-17 18:57:01 -04:00
Arya 0b835f1f05
Adds Sapling HRPs as fields on testnet params. (#8398) 2024-04-18 00:39:16 +02:00
Arya 868535b54c Merge branch 'main' into activ-heights-param-impl 2024-04-17 11:13:54 -04:00
Arya 16a39f89d0
add(consensus/network): Add an empty `Parameters` struct in `Network::Testnet` (#8368)
* minor cleanup and rename

* Adds an empty NetworkParameters struct to Network::Testnet variant, updates production code.

* Updates tests

* Adds `NetworkKind` and uses it instead of `Network` in `HistoryTreeParts` and `transparent::Address`

* Adds a [network.testnet_parameters] section to the config, uses `NetworkKind` as zebra_network::Config::network field type, and converts 'Network' to `NetworkKind` before serializing

* Applies some suggestions from code review

* Applies suggestions from code review

* returns b58 prefix constants directly to remove From<NetworkKind> impl for zcash_primitives::consensus::Network

* Applies more suggestions from code review.

* moves conversions to zcash_primitives::consensus::Network to where they're used.

* Apply suggestions from code review

Co-authored-by: Marek <mail@marek.onl>

* rename `network` variables and method names typed as NetworkKind to `network_kind`

* use only test block heights for the network associated with them

* Applies more suggestions from code review.

* Rename `NetworkParameters` to `Parameters` and move it a new `testnet` module

---------

Co-authored-by: Marek <mail@marek.onl>
2024-04-17 02:20:34 +00:00
Arya 1dfad530b1 Simplifies the `ParametersBuilder::activation_heights()` method and removes an unnecessary test. 2024-04-12 18:15:52 -04:00
Arya 0abe87312b panics if any network upgrades are configured to activate at Height(0) because it's reserved for Genesis 2024-04-12 17:36:07 -04:00
Arya a37510a67b moves all ordered network upgrades to a constant, adds a no_duplicates test, moves struct with activation heights outside deserialization impl and accepts it in `ParametersBuilder::activation_heights()` instead of a Vec 2024-04-12 17:19:34 -04:00
Arya e697d36dee Updates `NetworkUpgrade::activation_height()` to return the height of the next NetworkUpgrade if it doesn't find the activation height of `&self` 2024-04-11 23:38:51 -04:00
Arya 3952caa022 check that activation heights are in the right order 2024-04-11 23:06:53 -04:00
Arya 0fd4158dad small refactor of activation_heights() method 2024-04-11 22:29:52 -04:00
Arya 93c7a58330 - Makes the `activation_heights` config field optional by adding a #[serde(default)]
- Panics if a non-zero activation height is provided for the `Genesis` network upgrade
- Always sets the `Genesis` and `BeforeOverwinter` network upgrade activation heights to 0 and 1, `BeforeOverwinter` could be overwritten by a later network upgrade
- Makes the `activation_heights` field on `Parameters` private, adds/uses an accessor method instead, and adds a builder struct and `build()` method
2024-04-11 22:07:20 -04:00
Arya 997e265636 fixes doc links 2024-04-11 16:47:19 -04:00
Arya 2493e7ec76 Adds a test for the Parameters impl for zebra_chain::Network 2024-04-11 16:37:13 -04:00
Arya 080affd6d7 fixes a bad merge (removes a network conversion in zcash_note_encryption) 2024-04-11 15:52:20 -04:00
Arya 4347a80c24 Passes &Network directly instead of converting to zp_consensus::Network where there were conversions 2024-04-11 15:47:19 -04:00
Arya ad4e7dcf8a implement Parameters for Network 2024-04-11 15:47:19 -04:00
Arya 60248e3f1f adds activation heights field 2024-04-11 15:45:17 -04:00
Arya 365b58ea3f Rename `NetworkParameters` to `Parameters` and move it a new `testnet` module 2024-04-11 13:56:43 -04:00
Arya 86cd919135 Applies more suggestions from code review. 2024-04-11 13:39:04 -04:00
Arya f04b94b13a rename `network` variables and method names typed as NetworkKind to `network_kind` 2024-04-11 12:43:11 -04:00
Arya fd3d50572c
Apply suggestions from code review
Co-authored-by: Marek <mail@marek.onl>
2024-04-11 12:36:30 -04:00
Arya 05e41a2803 moves conversions to zcash_primitives::consensus::Network to where they're used. 2024-04-01 21:45:03 -04:00
Arya 574b1f9487 Applies more suggestions from code review. 2024-04-01 21:45:03 -04:00
Arya d108ec6355 returns b58 prefix constants directly to remove From<NetworkKind> impl for zcash_primitives::consensus::Network 2024-04-01 21:45:03 -04:00
Arya d5a807a508 Applies suggestions from code review 2024-04-01 21:45:03 -04:00
Arya cb8726b38a Applies some suggestions from code review 2024-04-01 21:45:03 -04:00
Arya 4900a20cad Adds a [network.testnet_parameters] section to the config, uses `NetworkKind` as zebra_network::Config::network field type, and converts 'Network' to `NetworkKind` before serializing 2024-04-01 21:45:03 -04:00
Arya 06cf9474ce Adds `NetworkKind` and uses it instead of `Network` in `HistoryTreeParts` and `transparent::Address` 2024-04-01 21:45:03 -04:00
Arya 7533e2fbc0 Updates tests 2024-04-01 21:45:03 -04:00
Arya 4b86bd6952 Adds an empty NetworkParameters struct to Network::Testnet variant, updates production code. 2024-04-01 21:45:03 -04:00
idky137 4579722833
change(chain): Remove `Copy` trait impl from `Network` (#8354)
* removed derive copy from network, address and ledgerstate

* changed is_max_block_time_enforced to accept ref

* changed NetworkUpgrade::Current to accept ref

* changed NetworkUpgrade::Next to accept ref

* changed NetworkUpgrade::IsActivationHeight to accept ref

* changed NetworkUpgrade::TargetSpacingForHeight to accept ref

* changed NetworkUpgrade::TargetSpacings to accept ref

* changed NetworkUpgrade::MinimumDifficultySpacing_forHeight to accept ref

* changed NetworkUpgrade::IsTestnetMinDifficultyBlock to accept ref

* changed NetworkUpgrade::AveragingWindowTimespanForHeight to accept ref

* changed NetworkUpgrade::ActivationHeight to accept ref

* changed sapling_activation_height to accept ref

* fixed lifetime for target_spacings

* fixed sapling_activation_height

* changed transaction_to_fake_v5 and fake_v5_transactions_for_network to accept ref to network

* changed Input::vec_strategy to accept ref to network

* changed functions in zebra-chain/src/primitives/zcash_history.rs to accept ref to network

* changed functions in zebra-chain/src/history_tree.rs to accept ref to network

* changed functions in zebra-chain/src/history_tree.rs to accept ref to network

* changed functions in zebra-chain/src/primitives/address.rs to accept ref to network

* changed functions in zebra-chain/src/primitives/viewing_key* to accept ref to network

* changed functions in zebra-chain/src/transparent/address.rs to accept ref to network

* changed functions in zebra-chain/src/primitives/zcash_primitives.rs to accept ref to network

* changed functions in zebra-chain/src/primitives/zcash_note_encryption.rs to accept ref to network

* changed functions in zebra-chain/src/primitives/history_tree* to accept ref to network

* changed functions in zebra-chain/src/block* to accept ref to network

* fixed errors in zebra-chain::parameters::network

* fixed errors in zebra-chain::parameters::network

* fixed errors in zebra-chain

* changed NonEmptyHistoryTree and InnerHistoryTree to hold value instead of ref

* changed NonEmptyHistoryTree and InnerHistoryTree to hold value instead of ref

* fixed errors in zebra-chain/src/block/arbitrary.rs

* finished fixing errors in zebra-chain - all crate tests pass

* changed functions in zebra-state::service::finalized_state to accept &Network

* changed functions in zebra-state::service::non_finalized_state to accept &Network

* zebra-state tests run but fail with overflow error

* zebra-state tests all pass

* converted zebra-network -- all crate tests pass

* applied all requested changes from review

* converted zebra-consensus -- all crate tests pass

* converted zebra-scan -- all crate tests pass

* converted zebra-rpc -- all crate tests pass

* converted zebra-grpc -- all crate tests pass

* converted zebrad -- all crate tests pass

* applied all requested changes from review

* fixed all clippy errors

* fixed build error in zebrad/src/components/mempool/crawler.rs
2024-03-19 20:45:27 +00:00
Alfredo Garcia f2be73eebb
feat(rpc): OpenAPI spec (#8342)
* add an openapi generator

* fix run command

Co-authored-by: Marek <mail@marek.onl>

---------

Co-authored-by: Marek <mail@marek.onl>
2024-03-14 15:04:19 +00:00
Arya 00a3120c7b
minor/trivial cleanup (#8348) 2024-03-14 11:54:01 +00:00
Za Wilcox 3bef54b764
change(consensus): Refactor production code for network consensus rules to `Network` methods (#8340)
* begin refactor suggested as "step 2": https://github.com/ZcashFoundation/zebra/issues/7968#issue-2003245309
Squashed from multiple commits to enable partial rebase

* break out more little traits

* add activation implementation leveraging From<Network> for lrz::cons::

* for transfer of ownership I cannot return a type that's owned by the method

* hrp_sapling_extended_full_viewing_key

* complete implementation of interface of Parameters on Network reuse Parameters on zcash Network where possible

* move doc-comments to trait declarations (from impls)

* Simplify/complete Parameters impl for Network

* Add checkpoint_list method, move documentation, etc

* move last match network to inside network method

* add back comment

* use zcash_address for parameter types in zebra-chain

* use inherent methods instead of big parameters passthrough

* revert to implementation of From on zcash_primitives::..::Network vs &zcash_prim...

* move match

* add test to block maximum time rule

* update changelog

* finish porting target_difficutly_limit

* remove obscelete code comment

* revert non-functional change

* finish migrating target_difficulty_limit, checkpoint_list

* update changelog

---------

Co-authored-by: Hazel OHearn <gygaxis@zingolabs.org>
2024-03-12 21:41:44 +00:00
idky137 9b91d4bc0e
change(tests): Remove Matches on Network From Tests (#8295)
* added functions for fetching block vectors

* inserted new network methods for vector fetching into zebra-chain

* changed tag back to test/feature=branch

* changed tag back to test/feature=branch

* changed tag back to test/feature=branch

* changed feature tag to proptest-impl, started implementing in zebra-consensus tests

* adding methods to zebra-consensus, lifetime error in src/transaction/tests.rs, needs refactoring

* finished adding methods to zebra-consensus

* finished adding new methods to zebrad

* added new methods to zebra-rpc and zebra-scan

* finished removing statements matching on Network from tests

* updated new error message

* changed get_block_bytes() and get_block_sapling_roots_bytes to return option and removed serialization error types as per requested changes in PR review

* removed match statements from zebra_chain::transaction::arbitrary::test_transactions() and new zebra-grpc tests

* moved zebra-chain::test_utils to zebra-chain::test

* removed get_ prefix from getter methods

* renamed zebra-chain::test to zebra-chain::tests

* renamed zebra-chain::test to zebra-chain::tests

* fixed clippy warnings

* changed block_map to return clone
2024-03-05 09:12:25 -05:00
Marek 663c57700b
add(scan): Test the `RegisterKeys` scan service call (#8281)
* Impl generating continuous deserialized blocks

* Make `sapling_efvk_hrp` `pub`

* Don't wait for Sapling activation height in tests

* Set the sleep interval for scan service to 10 secs

* Simplify `sapling_key_to_scan_block_keys`

* Enable mocking Sapling scanning keys for Testnet

* Test the `RegisterKeys` scan service call

* Enable `shielded-scan` for `zebra-chain`

* Use an ephemeral database so results don't persist

* Don't generate blocks when mocking the state

* Improve error messages

* Simplify seeding mocked Sapling viewing keys

* Apply suggestions from code review

Co-authored-by: Arya <aryasolhi@gmail.com>

* Use a manual iterator over `Network`

---------

Co-authored-by: Arya <aryasolhi@gmail.com>
2024-02-19 23:45:38 +00:00
Marek 6b8cbf9904
add(scan): Implement `RegisterKeys` service request to register new keys (#8251)
* Refactor obtaining of activation heights

* Impl the `RegisterKeys` service request

* Mock viewing keys for tests

* Refactor tests

* Apply suggestions from code review

Co-authored-by: Arya <aryasolhi@gmail.com>

* Remove a redundant comment

I don't think we need to assume the genesis block doesn't contain
shielded data as the comment says.

* Avoid using a single-letter variable

* Refactor mocking Sapling scanning keys

---------

Co-authored-by: Arya <aryasolhi@gmail.com>
2024-02-09 15:23:19 +00:00
Marek 130c4e95e8
Fix formatting in `proptest` macros (#8252) 2024-02-09 01:54:54 +00:00
Arya 768eb90722
add(chain): Adds `ViewingKey` type in zebra-chain (#8198)
* adds/impls types in zebra-chain to be used by the zebra-scan RPC server

* Adds methods for parsing and a test

* adds test for key hash encoding

* Apply suggestions from code review

Co-authored-by: Marek <mail@marek.onl>

* refactors viewing key type

* refactors/renames for viewing keys

* fixes doc links

* Apply suggestions from code review

* Apply suggestions from code review

* removes ViewingKeyHash and ViewingKeyWithHash types

* removes `to_bytes` methods

* remove outdated method and call

---------

Co-authored-by: Marek <mail@marek.onl>
2024-01-30 20:32:36 +00:00