Tal Derei
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # forwards the high objective right now is block processor performance. heavy operations during chain sync, especially processing of the large genesis, result in blocking all execution of the javascript thread hosting the block processor. the extension backend and entry to the rpc service share a single thread, so this is significant. after onboarding, users encounter confusing behavior and an extended waiting period before it's possible to connect to a frontend interface. the 'offscreen' technique has been used previously to parallelize other heavy operations like transaction building within the rpc services implementation, by providing a way to launch worker threads. if the block processor were also capable of running in its own thread or launching worker threads when necessary, it wouldn't block the entire service worker every time it does something heavy, and it could parallelize tasks by launching workers. so running the block processor partly or completely within the chrome runtime's 'offscreen' document is the accepted technique to improve performance and parallelize work. ### apis we use from chrome runtime - chrome.runtime messaging -- this is outside of the present implementation - chrome.storage storage read -- this is input to the present implementation - (offscreen, to launch workers) -- - chrome.windows - spawning popup for custody approaches: - target standard dom - require offscreen client to be provided (context, or constructor) target standard dom could be: - actual standard dom - polyfilled offscreen ## offscreen the 'offscreen' document is the chrome runtime's facility to support code that requires the standard browser dom api, and the features sought to achieve acceleration are within that standard browser dom api. ### previously unfortunately, previous work using 'offscreen' has been painful. in `@penumbra-zone/services`, the chosen technique has been difficult to develop and debug properly, because it adds multiple layers of abstraction, messaging, and seralization/deserialization between the parent extension thread and its ultimately launched workers. the implementation in `@penumbra-zone/services` is also implicitly dependent (in an undocumented way) upon code that is not present within the penumbra-zone web repo. any third-party consumer of the services package must independently implement significant parts of the feature. it's also the only part of the services package which contains code specific to the chrome runtime. i think replicating that pattern in the block processor is a bad idea. ### don't repeat that instead of digging deeper, it makes more sense to go the opposite direction: parts of the code which need to launch a worker should simply launch a worker in the standard way. this implies chrome runtime consumers must run the entire block processor within the offscreen document. this will involve some minor changes to block-processor init for consumers, but it's not very significant. all init is already passed as parameters. database access is still available from within the offscreen document. the chrome runtime is still available, so control message handlers in any implementation will function the same. thus, the technical goal is to target a standard browser DOM runtime. i would advocate ultimately running the block processor within a worker, so the messaging code is never thread-blocked. ### simplify services this is also an opportunity for simplification. with limited work, services can also execute within the offscreen document, and perhaps also within an independent worker. again parts of the code which need to launch a worker should simply launch a worker. a complete implementation of the transaction build functionality can be provided within the package. complete testing and third party consumption will become possible. most of the work required involves completing specification of the `HandlerContext` interface. ## the plan 0. relocate 'offscreen client' to outside the services package offscreen client becomes a general-purpose 'launch worker' utility which manages lifecycle of the offscreen document only, and wraps provided implementations with the necessary i/o. either create a 'context' package in penumbra-zone web, or require providers like prax to implement it. then services and the block processor can use this tool from handler context or from constructor parameters. 1. create a package specifically for the block processor. right now it's thrown in with `@penumbra-zone/query` when it's significant enough to be its own package. 2. eliminate `@penumbra-zone/query`. the remainder of query is very thin wrappers to rpc methods. it's only consumed by `@penumbra-zone/services` and the block processor. this is a large diff but mostly consists of having callers just use the `PromiseClient`s directly. a method similar to `PenumbraClient.service` replaces all of the 'context client's presently in `HandlerContext`, one for the remote fullnode and one for loopback services (ban cross-method calls). at this point, services' `HandlerContext` looks like this: ```ts // todo: use PenumbraClient, or just a services method? a map? just a transport? const db: IndexedDbInterface = ctx.values.get(dbCtx); // used for obtaining remote rpc clients. // remote.origin is the remote GRPC endpoint const remote: PenumbraClient = ctx.values.get(remoteCtx); // alternatively: const remote: Transport = ctx.values.get(remoteCtx); // used for obtaining clients to other local services. // should also replace same-service cross-method queries. // local.origin refers to this host's `PenumbraProvider` origin (extension url) const local: PenumbraClient = ctx.values.get(localCtx); // alternatively: const loopback: Transport = ctx.values.get(loopbackCtx); // service-restricted context const { sk }: { sk: SpendKey } = ctx.values.get(custodyCtx); const { fvk, walletId } = { fvk: FullViewingKey, walletId: WalletId } = ctx.values.get(viewCtx); ``` the same `PenumbraClient` interface may be provided as a block processor parameter, for access to the full node. ```ts interface QueryClientProps { // to be renamed viewServer: ViewServerInterface; db: PenumbraDb; numeraires: AssetId[]; stakingAssetId: AssetId; genesisBlock: CompactBlock | undefined; // fullnode.origin is the remote GRPC endpoint fullnode: PenumbraClient; } ``` 3. relocate the database interface definition this could be moved either to `@penumbra-zone/storage`, or a new shared package `@penumbra-zone/context` with minimal deps, describing all interfaces necessary to implement `HandlerContext` for services. relocated/collected interfaces simplify dependency relationships for current consumers services, block processor, and (later) their wasm utilites. at this point, the components of block processor and services are very nearly able to run in independent documents or workers - database subscriptions are the last blocking feature. everything is much more easily third-party consumeable, but can't be parallelized by launching individual components in workers until database subscriptions are refactored to work cross-document. 4. remove prax internal messaging types and logic from `@penumbra-zone/services` and target standard dom at this point, services is third-party consumeable. to improve more generally, 5. break up the wasm package into purpose-specific packages - utilities for consumers - utilities for services (building transactions) - utilities for the block processor this will support lower memory consumption of the wasm package, also a high priority issue. wasm will init faster. 6. consume the database interface in the wasm package instead of defining an independent interface in parallel and performing independent access. this has been a source of critical bugs. at this point all packages improved for third-party consumption. consumers just provide their database implementation, and hook up the context required by services (just parameters like keys and constructed clients to the remote node). optionally, 7. `@penumbra-zone/storage` interface can be improved, and the implementation can be deleted or remain penumbra's provided implementation of the database interface. 8. refactor database subscriptions to work cross-document this would enable block processor, services, etc to all run in their own workers. only init, and message routing would occur in the main service worker. thus nothing should ever block RPC or background work with heavy computation. ## overall benefits - the block processor becomes a distinct module instead of weirdly interdependent with queriers and wasm in an unspecified way - the services now use an abstracted interface to other modules so they are pluggable instead of hard dependencies on specific implementations - wasm now consumes an interface to the database instead of defining its own ## Parallelizing the block processor workloads 1. identify the number of encrypted note payloads in a compact block 2. Launch X web workers (X physical cores), and each web workers x_i handles (N mod X) work, where N is the number of note payloads. 3. presently, wasm scan_block performs sct insertion when processing a decrypted payload. the sct position is used in nullifier derivation, so processing decrypted payloads can't happen in parallel, without some mechanism to share the sct. 4. Research feasibility of parallel hashing

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully