zcash / librustzcash

Rust-language assets for Zcash
Other
324 stars 243 forks source link

Agree on a sketch of the overall wallet architecture #1373

Open str4d opened 2 months ago

str4d commented 2 months ago

Rough (and incomplete, hence not put into the top post) sketches from a meeting with Daira-Emma and Kris:

Current light client wallet architecture:

flowchart
    zcashdConsensus

    zcashdConsensus -- Chain tip change --> lightwalletd
    zcashdConsensus -- New blocks --> lightwalletd

    subgraph Indexer
    zcashdDb
    lightwalletd
    end

    zcashdConsensus <-- Stuff --> zcashdDb
    zcashdDb<-- UpdateChainTip --> lightwalletd
    zcashdDb<-- GetUTXOs --> lightwalletd
    zcashdDb<-- GetTransaction --> lightwalletd

    subgraph Mobile wallet app
    Scanner
    Wallet
    end

    Wallet -- Register UFVK --> Scanner
    Wallet -- (LC) [nf], ScanRange --> Scanner
    lightwalletd <-- UpdateChainTip --> Wallet
    lightwalletd <-- GetUTXOs --> Wallet
    lightwalletd <-- GetTransaction --> Wallet
    Scanner <-- CompactBlockRange --> lightwalletd
    Scanner -- ScannedBlock --> Wallet

Sketch of possible desired architecture:

flowchart
    FullValidator
    Indexer
    Scanner
    Wallet

    FullValidator -- Chain tip change --> Indexer
    FullValidator -- New blocks --> Indexer

    Wallet -- Register UFVK --> Scanner
    Wallet -- (LC) [nf], ScanRange --> Scanner
    Scanner <-- (Compact)BlockRange --> Indexer
    Scanner -- ScannedBlock --> Wallet

LC: Light Client

str4d commented 2 months ago

See also https://github.com/oxarbitrage/zebra-grpc-scan-spec/blob/main/client_integration.md

jackgavigan commented 2 months ago

Should the Scanner obtain the blocks from the Indexer, or direct from Zebra's database? (Assuming the scanner is running on the same machine as Zebra.)

I assume that t-address balances and transactions will be obtained by querying the Indexer?

ETA: Also, in the diagram above, is it the Indexer's job to index transparent addresses and transactions (e.g. for the block explorer use case)? I think it's worth being pedantically explicit about the functionality of each component to ensure that we don't have differing understandings/expectations.

jackgavigan commented 1 month ago

Temporary diagram for discussion

   flowchart

   subgraph Zcash_P2P_Network
   Other_nodes
   end
   Other_nodes -- chain state -->   FullValidator
   subgraph Zebra
      FullValidator
      Indexer
      TxBroadcaster
  subgraph State
      NonFinalizedState
      FinalizedState
  end
      FullValidator -- Chain tip change --> NonFinalizedState;
      FullValidator -- New blocks --> NonFinalizedState;
      FullValidator -- Finalized blocks --> FinalizedState
      State -- transparent TX info --> Indexer
   end

   State -- Read Zebra State --> Scanner
   Wallet -- T-addrs query --> Indexer
   Indexer --T-addrs state --> Wallet
   Wallet -- New transaction --> TxBroadcaster
   TxBroadcaster -- New Transaction --> Other_nodes
   Indexer --> BlockExplorer

   subgraph CLI_Wallet
      Scanner
      Wallet -- Register viewing key --> Scanner
      Scanner -- Shielded TX scan results  --> Wallet
   end