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

[ZCash] Implement ShardTree sync process #27255

Merged
merged 6 commits into from
Jan 17, 2025
Merged

[ZCash] Implement ShardTree sync process #27255

merged 6 commits into from
Jan 17, 2025

Conversation

cypt4
Copy link
Collaborator

@cypt4 cypt4 commented Jan 15, 2025

Part of #27018

Implements shard tree state sync process.
Entry point for the sync process is the per-account ZCashShieldSyncService class.
Sync process includes:
Verifying chain state. In some cases chain reorg may happen so we need to check whether latest scanned block hash hasn't been changed. Otherwise we need to clean OrchardStorage to remove notes, nullifiers and commitments that are not valid.
Preparing a set of scan ranges to scan. Each scan range ends with updating of OrchardSyncState with the discovered data.
Scanning ranges one-by-one. This includes reading compact blocks from the gRPC node and extracting related incoming notes and nullifiers for spends along with a set of commitment tree leafs to be inserted to the shard tree in the future. Extracting is done on a separate sequence. This is done using OrchardBlockScanner class.
Inserting extracted leafs to the shard tree(OrchardSyncState::ApplyScanResults).

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

@cypt4 cypt4 requested review from a team as code owners January 15, 2025 20:30
@github-actions github-actions bot added CI/storybook-url Deploy storybook and provide a unique URL for each build feature/web3/wallet feature/web3/wallet/core puLL-Merge labels Jan 15, 2025
Copy link
Contributor

@Douglashdaniel Douglashdaniel left a comment

Choose a reason for hiding this comment

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

++ Wallet Front-end

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

Copy link
Collaborator

@supermassive supermassive left a comment

Choose a reason for hiding this comment

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

wallet core lgtm

Copy link
Contributor

@nuo-xu nuo-xu left a comment

Choose a reason for hiding this comment

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

iOS++

Copy link
Contributor

[puLL-Merge] - brave/brave-core@27255

Description

This pull request introduces significant changes to the ZCash wallet implementation in the Brave Core, focusing on enhancing the Orchard protocol support and improving synchronization mechanisms. The changes include new tasks for scanning blocks, verifying chain state, and managing sync operations more efficiently.

Possible Issues

  1. The introduction of new async tasks and complex operations might increase the overall complexity of the codebase, potentially making it harder to maintain and debug.
  2. The changes to the sync process could potentially introduce race conditions or edge cases that might not be immediately apparent.

Security Hotspots

  1. The handling of account birthday blocks and sync state in ZCashWalletService::MakeAccountShielded and ZCashWalletService::StartShieldSync should be carefully reviewed to ensure no unauthorized access to account data is possible.
  2. The new ResetSyncState function in ZCashWalletService should be examined to ensure it doesn't unintentionally expose sensitive information during the reset process.
Changes

Changes

  1. zcash_action_context.h/cc:

    • Introduced a new ZCashActionContext struct to encapsulate common context for ZCash operations.
  2. zcash_blocks_batch_scan_task.h/cc:

    • Added a new task for batch scanning of ZCash blocks, improving the efficiency of the synchronization process.
  3. zcash_scan_blocks_task.h/cc:

    • Implemented a new task for scanning blocks, which manages the overall scanning process and uses the batch scan task.
  4. zcash_verify_chain_state_task.h/cc:

    • Added a new task for verifying the chain state, handling potential chain reorganizations.
  5. zcash_shield_sync_service.cc:

    • Refactored to use the new task-based approach for scanning and synchronization.
  6. zcash_wallet_service.cc:

    • Updated to support new features like resetting sync state and getting chain tip status.
    • Modified MakeAccountShielded and StartShieldSync to accept additional parameters.
  7. brave_wallet.mojom:

    • Updated the ZCashShieldSyncStatus struct to include more detailed synchronization information.
    • Added a new ZCashChainTipStatus struct.
  8. Various test files:

    • Added and updated unit tests to cover the new functionality.
sequenceDiagram
    participant User
    participant ZCashWalletService
    participant ZCashShieldSyncService
    participant ZCashScanBlocksTask
    participant ZCashBlocksBatchScanTask
    participant ZCashVerifyChainStateTask
    participant OrchardSyncState
    participant ZCashRPC

    User->>ZCashWalletService: StartShieldSync
    ZCashWalletService->>ZCashShieldSyncService: Create & Start
    ZCashShieldSyncService->>ZCashVerifyChainStateTask: Create & Start
    ZCashVerifyChainStateTask->>OrchardSyncState: GetAccountMeta
    ZCashVerifyChainStateTask->>ZCashRPC: GetLatestBlock
    ZCashVerifyChainStateTask->>ZCashRPC: GetTreeState
    ZCashVerifyChainStateTask-->>ZCashShieldSyncService: Chain State Verified
    ZCashShieldSyncService->>ZCashScanBlocksTask: Create & Start
    loop Scanning Blocks
        ZCashScanBlocksTask->>ZCashBlocksBatchScanTask: Create & Start
        ZCashBlocksBatchScanTask->>ZCashRPC: GetCompactBlocks
        ZCashBlocksBatchScanTask->>OrchardSyncState: ApplyScanResults
        ZCashBlocksBatchScanTask-->>ZCashScanBlocksTask: Batch Complete
    end
    ZCashScanBlocksTask-->>ZCashShieldSyncService: Scanning Complete
    ZCashShieldSyncService-->>ZCashWalletService: Sync Status Update
    ZCashWalletService-->>User: Sync Complete
Loading

@cypt4 cypt4 merged commit c008dab into master Jan 17, 2025
20 checks passed
@cypt4 cypt4 deleted the brave_43312 branch January 17, 2025 11:40
@github-actions github-actions bot added this to the 1.76.x - Nightly milestone Jan 17, 2025
@brave-builds
Copy link
Collaborator

Released in v1.76.21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/storybook-url Deploy storybook and provide a unique URL for each build feature/web3/wallet/core feature/web3/wallet puLL-Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants