isaac-etc
    • 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
    # Ethercluster __Situation:__ Cloudflare is used to provide the services at ethercluster.com (et al) by fetching and returning original block information from Rivet. __Problem:__ 25k unique users/day and 25M requests per day is getting expensive, driven mostly by the Rivet cost. ## Load balancing __Solution:__ Use the RPC server of an existing always-on geth instance of our own instead of the expensive Rivet origin. The self-hosted instance can use a caching proxy in front of it to further mitigate origin request counts. __Requirements:__ - [ ] Ensure consistency between origins at some regular interval, using Rivet as the canonical/control and as the fallback origin in case of mismatch. ## Caching __Solution:__ Use Cloudflare Workers to cache chain data, avoiding redundant calls to Rivet. OpenRPC? Some method calls return network-static data. These are VERY time insensitive. These can be cached indefinitely, or for the longest allowable time. - eth_chainId - eth_coinbase (?) - eth_mining - net_listening Some method calls return SOMEWHAT time insensitive data. These can be cached at some reasonable non-tiny interval, eg. 5m. - eth_mining - web3_clientVersion - net_version - eth_protocolVersion - eth_gasPrice (?) - eth_syncing (?) - net_peerCount (?) Some method calls are INVALID. Some method calls return ADMINISTRATIVE data. These should be dropped. Instead of compiling a list, as below, we could "blacklist" request methods based on their responses; eg. `response: -13200 method does not exist`. Any calls returning this error once would be dropped forever (OK, for a long time). This way Rivet gets to tell us what is and is not allowed. - miner_start - eth_setCoinbase - admin_xxx - personal_xxx - debug_xxx - miner_xxx Finally, some method calls return freshness-required data. The MOST granular the state ever needs to be maintained is at the block level, where any change in the response to `eth_getBlockByNumber("latest", false)` should cause these caches to bust. Note that `eth_blockNumber` alone is not sufficient (reorgs). - eth_blockNumber - eth_getBalance - eth_getBlockByNumber Specifics: ### `eth_getBalance` `eth_getBalance` is the MOST USED call, by far (eg. 380k vs the number-two spot at 29k / TODO: FACTCHECK). Cache the call by params: `address` and `blockNumber`. Note that an unlimited cache presents a vulnerability to cache explosion. We'll need to bust a cache size limit. ``` ethrpc eth_getBalance --help Params: - (0): [Required] <address> type: string, pattern: ^0x[a-fA-F\\d]40$ - (1):<blockNumber> description: The hex representation of the block's height, type: string, pattern: ^0x[a-fA-F\\d]+$ # SIC: special strings "latest", "pending", and "earliest" are allowed. "pending" is "latest"+1 Returns: title: getBalanceResult, oneOf: [ description: Hex representation of the integer, type: string, pattern: ^0x[a-fA-F0-9]+$, , description: Null, type: null, ``` ## Cache key For the methods which return fresh data referred above, we can generate the cache key in a way that has all the unique info + the requested **block_hash**. > NOTE: we need to translate "latest", "pending" tags to the appropriate block_hash as well. "pending" might be left out of caching. Using the following request as an example use case: ``` '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0xc94770007dda54cF92009BFF0dE90c06F603a09f", "latest"],"id":0}' ``` The cache key will be `eth_getBalance|0xc628dc616c51384ea399e18d248120a795d486a6145f3bac766d23616cbb8efa|0xc94770007dda54cF92009BFF0dE90c06F603a09f` based on the following schema `<method>|<block_hash>|<...unique_args>`. Generally, this defines the cache key as some serialization of `method+params...`, where `+` is some simple concatenation (either empty or some delimiter). We know, however, that SOME params mean the request is dynamic, for example: - `eth_getBalance("0xc94770007dda54cF92009BFF0dE90c06F603a09f", "latest")` This request's cache should bust whenever the value of `"latest"` changes. On the other hand, some parameters make the request one for a constant response, for example: - `eth_getBalance("0xc94770007dda54cF92009BFF0dE90c06F603a09f", "0x430e43e4e4c09dbc8aa722cbb833a0c707d2ed281320b64ee83558094a5060c3")`. ## Expiration All of the cached keys have to expire at some point, as we don't want to keep stuff consuming cache size forever. Based on the importance and freshness of each call we have to set the expiry time as appropriate. ## External cache setter Methods have to introduced so as external services (we own) can call them authenticated in order to clean cache(s) under certain circumstances. In case of a reorg, we might want to call a method to set/change the head block info. In advance, but not needed we might want to clear cached data on the forked blocks, but if logical expiration times are being set, then we don't have to worry till they expire. ## Split of batched requests Almost 30% of the requests at Rivet are batched ones, which means a single HTTP request, might perform >1 JSON RPC requests. Rivet bills on individual JSON RPC requests. ## Good to check - [x] Check if CF cache allows us to clear cache using wildcard cache keys. e.g.: clean all `eth_getBalance|0xdead|*`. - Cache Tags are user for that, and it's an Enterprise feature (we don't have Enterprise). # Development ## References - https://developers.cloudflare.com/workers/examples/cache-using-fetch - https://developers.cloudflare.com/workers/examples/cache-post-request - https://developers.cloudflare.com/workers/examples/cache-api - https://developers.cloudflare.com/cache/about/cache-control#cache-control-directives - https://developers.cloudflare.com/workers/runtime-apis/cache

    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