* upgrade zcash_client_backend for zebra-scan
* leave zebra-utils untouched
* remove unused
* upgrade zcash_primitives and orchard only for zebra-chain crate
* update and use TryFrom for amounts
* fix imports in serialize
* leave doc as it was
* leave doc as it was 2
* use `try_into` for amount
* use `zip_212_enforcement`
* updgrades primitives in zebra-rpc
* upgrade ecc dependencies for cargo-utils
* fix threading issue
* remove non needed Arc
* update deny.toml
* update primitives for zebra-grpc
* fix doc
* remove non needed single thread code in test
* cleanup some tests
* improve a bit the `ready_scan_block_keys` function
* clippy
* add spawn back in `scan_height_and_store_results`
* remove todo
* add note comment
* use a more explicit import of sapling stuff in serialize
* change(scan): Refactor scanning keys (#8577)
* Refactor converting dfvks to scanning keys
* Simplify handling of scanning keys
* Remove `test-dependencies` from the scanner reader
* Add comments
---------
Co-authored-by: Marek <mail@marek.onl>
* 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>
* 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>
* 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
* updates ScanTask.subscribe() to return rsp_tx instead of awaiting it, returns service errors from grpc methods
* Adds a timeout to scan service and improves error message when subscribe responders are dropped
* Returns an error from `RegisterKeys` svc request when no keys are registered
* tests register keys error message
* Adds test for timeouts
* adds TODOs for fixing bugs
* Orders scan service requests in scan method
* removes CheckKeyHashes request
* fixes bad merge conflict resolution
* update test to check downcast to Elapsed error
* update errors in scan method
* update error msg in register_keys method
* fixes compiler error
* 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
* merges scan task tests and checks that the scan task removes keys
* Adds test to CI
* Skip to expected block height and assert that the result is from that height
* Updates test docs and uses zebrad state path for scan cache
* Log "Zcash network: {network}" from scan task commands test
* adds tonic-reflection
* adds listen_addr to log
* Adds user guide for scan server to zebra book
* fixes typo
* Applies suggestions from code review
* update link
Co-authored-by: Marek <mail@marek.onl>
---------
Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
Co-authored-by: Marek <mail@marek.onl>
* update scan task to notify subscribe caller once the new subscribed_keys are sent on the watch channel
* Fixes timing bug in scan gRPC method:
Joins register/subscribe scan service calls, sends SubscribeResults request first, and filters out duplicate results from channel
* Removes outdated TODO
* wraps subscribed_keys in an Arc before sending to watch channel, fixes typo
* Remove result senders for keys that have been removed
* 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>
* processes SubscribeResults messages
* send tx ids of results to the subscribe channel
* replaces BoxError with Report in scan_range
* adds a watch channel for using subscribed_keys in scan_range
* updates args to process_messages in test
* adds a `subscribe` method to ScanTask for sending a SubscribeResults cmd
* updates test for process_messages to cover subscribe cmds
* impls SubscribeResult service request and updates sender type
* adds test for SubscribeResults scan service request
* adds acceptance test
* updates tests and imports
* fixes acceptance test by using spawn_blocking to avoid blocking async executor and setting an appropriate start height
* fixes test
* Applies suggestions from code review.
* use tokio mpsc channel in scan task instead of std/blocking mpsc
* use tokio mpsc channel for results sender
* adds `was_parsed_keys_empty` instead of checking that all the parsed keys are new keys
* fixes test failures related to send errors in scan task
* returns height and key for scan results from subcribe_results results receiver
* hide scan_service mod in zebra-node-service behind feature
* 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>
* adds clear_results RPC method for zebra-scan
* adds delete_keys rpc method
* adds docs
* Update zebra-grpc/proto/scanner.proto
Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
* Apply suggestions from code review
* start zebra-scan gRPC server from zebrad start command
* adds a test that the scanner starts with zebrad
* adds a `listen_addr` field to the shielded scan config
* updates test to use a random port and set the listen_addr config field
* fixes test
* Update zebra-scan/src/config.rs
Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
* fixes panic when trying to open multiple mutable storage instances.
* open db in blocking task
* fixes test
---------
Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
* moves ScanTask to its own module in service module
* moves `process_messages()` method to scan_task.rs
* uses get_mut() and returns new keys
* updates types and adds scan_until() function
* adds and uses wait_for_height() function
* spawns scan_until_task_handler to poll scan_until_tasks FuturesUnordered
* corrects comment
* adds TODO
* updates expected test log, corrects panic msg, fixes fmt
* moves scan functions to scan_task module
* moves ScanTaskCommand and related method impls to its own module
* moves `ScanTask::mock()` test constructor to its own module
* creates `add_keys` mod and moves `scan_until()` function there
* moves scan task executor to its own module and adds ScanRangeTaskBuilder type
* renames add_keys to scan_range, moves executor to scan_task mod
* adds test for process_messages
* updates scan_height_and_store_results() to skip last_scanned_height check if there is no key height for a key in `parsed_keys`
* updates `default_test_config()`
* adds acceptance test for registering keys in ScanTask
* uses the right feature for the new acceptance test
* Applies suggestions from code review
* handle RemoveKeys command in ScanTask
* implements DeleteKeys request
* uses spawn_blocking and updates comments
* removes spawn_init fn
* adds test for new Storage method
* adds fake_sapling_results helper function
* adds test for scan service DeleteKeys request
* adds TODO for unwrap_or_clone
* checks the keys sent to the scan task for removal
* moves message processing to its own function
* adds a timeout for the scanner task response
* hide mock() methods behind cfg(test) or feature
* adds MAX_REQUEST_KEYS constant
* updates test to insert and delete results for a second key
* Update zebra-scan/src/init.rs
Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
* test that the expected number of results are in the db
* fix unused import lint
* fixes unused imports
---------
Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
* 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>
* add `zebra-grpc` crate
* add missing fields
* convert to a lib
* add zebra-scan and tonic as depenency
* add a getinfo grpc
* remove zebra-scanner dependency
* Adds scan_service field to scanner grpc server
* remove dependency
* test launching the grpc server from the zebra-scan crate (not building)
* fix async issue
* fixes build issues
* add binary for manual testing
* try fix try run
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
* impl TryFrom<zcash_primitives::BlockHeight> for Height
* Add type-safe read and write database methods
* Only allow typed access to the scanner DB
* Update docs
* Implement a common method as a trait
* Fix imports
* Tidy state imports
* Activate tracing logging macros in the whole scanner crate
* Fix dead code warnings
* Use a more sensible export order
* Remove a 1.72 lint exception now 1.74 is stable
* Switch history trees over to TypedColumnFamily, and remove redundant code
* Add typed batch creation methods, and switch history trees to them
* Convert ValueBalance to typed column families
* Make the APIs compatible after a merge
* Use `ZebraDb` instead of `DiskDb` where needed
---------
Co-authored-by: Marek <mail@marek.onl>
* impl TryFrom<zcash_primitives::BlockHeight> for Height
* Add type-safe read and write database methods
* Only allow typed access to the scanner DB
* Update docs
* Implement a common method as a trait
* Fix imports
* Tidy state imports
* Activate tracing logging macros in the whole scanner crate
* Fix dead code warnings
* start scanner where it was left
* fix tests
* add a `scan_start_where_left` test
* refactor a log msg
* fix some comments
* remove function
* fix doc comment
* clippy
* fix `sapling_keys_and_last_scanned_heights()`
* simplify start height
* i went too far, revert some changes back
* change log info to every 10k blocks
* fix build
* Update height snapshot code and check last height is consistent
* Add strictly before and strictly after database key gets
* Move to the previous key using strictly before ops
* Assert that keys are only inserted once
* Update the index in each loop
* Update snapshots
* Remove debugging code
* start scanning at min available height
---------
Co-authored-by: teor <teor@riseup.net>
* Refactor test data into functions
* Add a typed snapshot test for scanner storage
* Use standard hex serialization with SaplingScannedResult
* Simplify transaction::Hash hex serialization
* Sort HashMaps before snapshotting
* Add typed snapshot data
* Make some scanner storage methods more flexible
* Move tests to a submodule and expose test functions and constants
* Make scanner functions clearer and easier to use
* Simplify state snapshot test code
* Add raw data snapshot tests for the scanner
* Add snapshots
* Fix import path
* Fix import conditional compilation
* fix imports
* fix imports 2
* Put read and write db exports together
* Remove confusing IntoDisk/FromDisk impl
* Fix an incorrect unused method that could panic
* Delete a test that is no longer valid
---------
Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
* Upgrade the scanner database major version to 1
* Update format docs
* Change the high-level scanner db format
* Change the scanner serialization formats
* Fix value format and tests
* Fix incorrect types
* Update documentation
---------
Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
* Update multiple key docs
* Add a TODO for the tree size
* Fix scan() docs
* Split out a scan_height...() function
* Clarify it's the state database we're using for scanning heights
Co-authored-by: Marek <mail@marek.onl>
* Remove unused import
---------
Co-authored-by: Marek <mail@marek.onl>
* Derive & impl helper traits from `std`
* Create `compact_to_v4` fn
* Create `fake_block` fn
* Refactor existing tests to use the new functions
* Cosmetics
* Refactor docs
* Put `Default` behind `cfg_attr(test)`
Rationale
---------
We avoid implementing `Default` on consensus-critical types because it's
easy to miss an incorrect use in a review. It's easy to hide a
`default()` in a call like `unwrap_or_default()` or even more subtle
methods.
---------
Co-authored-by: teor <teor@riseup.net>
* Fix availability of tokio::time in scanner
* Create a function that parses a key into a list of keys
* Pass a ChainTipChange to the scanner function
* Convert a scanned block to a sapling result
* Make it easier to pass keys and blocks
* Increase scanner wait times
* Parse keys once at the start of the scan
* Get a block from the state instead of the tip
* Don't log secret keys, only log every 100,000 blocks
* Scan each block and add the results to storage
* Move blocking tasks into spawn_blocking()
* Update the acceptance test
* Use a dummy sapling tree size
* Use a larger dummy size
* Expose IntoDisk and FromDisk in zebra-state
* Implement database serialization for SaplingScanningKey Strings
* Implement serialization for Vec<SaplingScannedResult> (Vec<transaction::Hash>)
* Implement seralization for SaplingScannedDatabaseIndex
* Add an is_empty() method
* Add a read method for a specific index, and document it
* Implement writing scanner results to the database
* Make read name more explicit
* Implement writing scanner keys
* Implement reading sapling keys
* Spawn blocking tasks correctly in async code
* Change storage results methods to use the database
* Update tests that use storage
* Use spawn_blocking() for database methods
* Change the check interval to slightly less than the block interval
* Expose raw database methods with shielded-scan
* fix `scan_task_starts` test
* minor doc change in test
---------
Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
* Create an empty storage/db module
* Use ephemeral storage in tests
* Populate storage inside new() method
* Move scanner setup into an init() method
* Pass the network to scanner init
* Create a database but don't actually use it
* Skip shutdown format checks when skipping format upgrades
* Allow the scanner to skip launching format upgrades in production
* Refactor skipping format upgrades so it is consistent
* Allow checking configs for equality
* Restore Network import
* Run clippy and build all targets on all crates individually
* Fix prod and test features for scanner deps
* Standardise dependency order
* Remove unnecessary async in tests
* Fix an unused import in a test
* Work around a no space left on device error
* Actually just use a larger runner
* Wrap `zcash_client_backend::scanning::scan_block`
* Use the new `scan_block` fn
* Use full path for `zcash::primitives::Network`
* Add docs for `scan_block`
* Impl `From` for networks in `zcash_primitives`
* Update zebra-scan/src/tests.rs
Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
* Move code from `tests.rs` to `scan.rs`
---------
Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
* connect zebrad with zebra-scan
* remove unwrap
* use tokio::sleep
* fix the task handler
* Don't panic on an empty state
---------
Co-authored-by: teor <teor@riseup.net>
* add a basic RAM database for the scanner
* specify a crate version for zebra-chain dependency
* add a type for sapling keys
* rename everything to reflect sapling
* change some storage methods
* get started with the blockchain scanner poc
* rustfmt
* fix the tests
* Reads blocks from db
* Adds conversion functions
* scans blocks and counts transactions
* fix bug
* split into 2 tests
* add duplicated dependencies to deny.toml
* upgrade zebra-scanner version
* try removing ecc duplicated dependencies
* try fix deny.toml
* remove unintended paste from deny.toml
* remove duplicated code from the other test
* remove strict version of `zcash_primitives` crate
* change description
* remove feture
* remove tokio features
* change lib doc
* add more documentation
* change expect
* do not use default in compact block creation
* more docs
* add more checks to test
* remove zebra-consensus dependency
* move all deps to dev-deps
* change crate version
* rename crate to zebra-scan
* lock file
* add test for zecpages populated state
* scans all cached blocks for zecpages viewing key expecting Ok results.
* use test blocks
* fixes test
* fix expect messages
* Discard changes to Cargo.lock
* Discard changes to deny.toml
---------
Co-authored-by: arya2 <aryasolhi@gmail.com>
Co-authored-by: teor <teor@riseup.net>
* get started with the blockchain scanner poc
* rustfmt
* fix the tests
* Reads blocks from db
* Adds conversion functions
* scans blocks and counts transactions
* fix bug
* split into 2 tests
* add duplicated dependencies to deny.toml
* upgrade zebra-scanner version
* try removing ecc duplicated dependencies
* try fix deny.toml
* remove unintended paste from deny.toml
* remove duplicated code from the other test
* remove strict version of `zcash_primitives` crate
* change description
* remove feture
* remove tokio features
* change lib doc
* add more documentation
* change expect
* do not use default in compact block creation
* more docs
* add more checks to test
* remove zebra-consensus dependency
* move all deps to dev-deps
* change crate version
* rename crate to zebra-scan
* lock file
* ifix cargo.lock
* remove internal dev dependencies versions
Co-authored-by: teor <teor@riseup.net>
* fix docs url
Co-authored-by: teor <teor@riseup.net>
* fix expect messages
Co-authored-by: teor <teor@riseup.net>
* remove duplicated in deny.toml
Co-authored-by: teor <teor@riseup.net>
* add a comment about moving code to production
---------
Co-authored-by: arya2 <aryasolhi@gmail.com>
Co-authored-by: teor <teor@riseup.net>