Mikhail Kalinin
    • 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
    • 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 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
    # Optimistic sync edge cases with the new Engine API semantics This document makes an analysis of a few edge cases taking in account [new Engine API semantics](https://github.com/ethereum/execution-apis/pull/165) and [corresponding changes](https://github.com/ethereum/consensus-specs/pull/2820) to the optimistic sync spec. In this document we distinguish two types of EL clients with respect to a number of state copies kept in the storage: * **Deep-state clients.** Keep up to `N` most recent states in the storage. These clients are capable of validating payloads on multiple forks at the same time because a requisite parent state is usually available. Therefore, this type of clients may instantly validate a payload when a payload belongs to a side branch, and parent state is available. We assume a parent state on a side branch is available if CL is lock-stepping and a payload's `blockNumber` is within a range `[HEAD-N; HEAD]`. If the parent state is unavailable, we assume that this type of clients responds with `ACCEPTED` status to a `newPayload` call. A subsequent `forkchoiceUpdated` call signifying previously `ACCEPTED` payload as canonical one will trigger payload validation which, in its turn, induces a sync process if needed. * **Shallow-state clients.** Maintain only the most recent version of a state, i.e. a post-state of the head of the canonical chain. Every `newPayload` call submitting a payload that extends a side branch of the block tree is responded with `ACCEPTED` status. Validation of paylods from side branches happens only when they become canonical, i.e. the corresponding `forkchoiceUpdated` method call is received. Usually, this type of clients is capable of doing short re-orgs in a reasonable amount of time. We identify three possible scenarios of a re-org handling in a shallow-state client: * *Short range re-org.* Involves a few blocks and happens, say, under a sub-second time on a commodity hardware. In this scenario client software may *synchronously* i) revert state to a common ancestor and ii) execute a few blocks on top of it to reach the head of the chain that is designated by `forkchoiceUpdated`. The result of this method call will be either `VALID` or `INVALID` instantly informing CL of validity status of the payloads * *Long range re-org.* Invloves decent number of blocks and can't be done in a sub-second interval. In this scenario client software starts executing previosuly cached payloads *asynchronously* and responds with `SYNCING` status to the corresponding `forkchoiceUpdated` call, and engages CL to check status of these payloads later on * *Unknown range re-org.* This scenario hits when a client software is missing ancestors of a payload in question. In this case a sync process to pull required information from the network is started with `SYNCING` status in the response to the `forkchoiceUpdated` method call. CL is engaged to check the status later on as in the previous scenario. Note that shallow-state client implementation may not support *synchronous* short range re-orgs at all and do all types of re-orgs in an *asynchronous* fashion. From CL standpoint shallow-state clients that are supporting synchronous short-range re-orgs and deep-state clients has an important difference. Let's illustrate this difference on the following example: ``` A <- B <- C (a) \ <- B' <- C' (b) ``` CL is lock-stepping, (a) is the canonical branch at the beginning, and the network re-orgs to (b) after block `C'` is proposed and voted for. Behaviour of a node running different type of EL client looks as follows: * With a shallow-state client supporting synchronous short-range re-orgs a node applies blocks `B'` and `C'` to its fork choice state *optimistically*. EL validates payloads of `B'` and `C'` when processing the `forkchoiceUpdated(head: C')` call and syncrhonously responds with `VALID` to this call. * With a deep-state client a node applies blocks `B'` and `C'` to its fork choice state *non-optimistically* as EL validates payloads of these blocks on corresponding `newPayload` calls. EL switches the head to already validated block `C'` while processing the `forkchoiceUpdated(head: C')` call. In both cases a node re-orgs to (b) without turning optimistic mode, and VC served by this node keeps doing its duties seamlessly. The difference in this case, namely, applying a block to the fork choice state in an *optimistic* or *non-optimistic* way, doesn't matter that much after the Merge transition. But it matters a lot during the transition according to further analysis. ## Optimistic sync The optimistic sync spec gives the following definition to optimistically imported blocks: > blocks which have only received a `NOT_VALIDATED` designation from an execution engine (i.e., they are not known to be `INVALIDATED` or `VALID`). The spec allows for importing a block optimistically only if either of the following conditions are met: > 1. The justified checkpoint has execution enabled. > 2. The current slot (as per the system clock) is at least `SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY` ahead of the slot of the block being imported. If the first condition is met then we have transition block justified and for simplicity treat scenarios related to this case as a post-transition kind of scenarios. Though, post-transition scenarios requires transition block to be finalized, this simplification doesn't affect further analysis. Scenarios, when *only* the second condition or neither of these two conditions are met, belong to transition kind of scenarios. The Optimistic Spec has the following adverse effect if a node uses shallow-state client. *A node running a shallow-state EL client can't import a block from a side chain until either of optimistic block import conditions are met.* Simply, CL have to import every side chain block optimistically if it communicates with a shallow-state EL client. But it's forbidden by the Optimistic Sync spec if neither of the conditions above are met. ## Transition edge cases Let's remind us a property of a terminal block that is important to analysis of this edge cases. There may be several terminal blocks, in this case these terminal blocks will likely be children of the same pre-terminal block, but it also could be a more complicated case e.g. with a couple pre-terminal blocks and one grand-terminal block and so forth. Read Security Considerations section of the [EIP-3675](https://eips.ethereum.org/EIPS/eip-3675#ability-to-jump-between-terminal-pow-blocks) to get more explanation on the importance of re-orgs from one terminal block to another. ### Canonical transition block is missing data A transition block that extends the canonical chain contains a payload built atop of unknown or not yet executed terminal block. In this scenario both type of clients will respond with `ACCEPTED` status to the corresponding `newPayload` call and CL won't be able to import this block until `SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY` runs out or transition is justified. ### Transition payload is from a side chain There are two potential ways to end up in this scenario: * A payload of proposed transition block is built on terminal block `B` while terminal block `A` is the head of the canonical chain to an observation of a local EL client. * A payload of proposed transition block `A` is built on the canonical head to an observation of a local EL client. And then another transition block `B` gets proposed with a payload built on a tip of a side branch, and the network favours `B` over `A`. We assume that in both of these cases ancestors of terminal blocks `A` and `B` are known to local EL client, and a short-range re-org is enough to jump between these blocks. Deep-state clients will seamlessly re-org to `B` in this case. While shallow-state clients will not import `B` and stay at `A`'s chain until `SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY` runs out or `A`'s chain is justified. If `>= 2/3` of validators are running deep-state clients then the transition will be justified and by importing block `B` optimistically shallow-state clients will catch up with the canonical chain and pass the transition after a short period of time stick to a side chain resulting in validator penalties. If the majority of validators are running shallow-state clients the transition becomes highly dependent on the network conditions. In the worst case scenario there will be a chain split which resolves in the next `SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY` after nodes will import side chain blocks optimistically and converge at the same canonical chain eventually. Note that in this case mechanism preventing the [Fork Choice Poisoning](https://github.com/ethereum/consensus-specs/blob/dev/sync/optimistic.md#fork-choice-poisoning) does still work as a split at a transition block won't affect justification of a checkpoint existing before the split. But one another assumption must be made in order to make it work: > The chain must provide enough block space supply to accomodate attestations made on other forks to be able to justify an epoch in question in `SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY`. ## Post-transition edge cases ### Canonical payload is missing data If a payload extending the canonical chain can't be validated due to requisite data is missing then both types of client will respond with `SYNCING` status to the `newPayload` calls making a node *optimistic*. A CL client is engaged to periodically check for updates on the status until syncing process is finished. The default strategy for these checks is simply submitting `newPayload` and `forkchoiceUpdated` when subsequent payloads are received from the network and looking at the status in the responses. ### Re-org to a side chain The case when a payload or a several payloads in a row came from a side chain and then re-org is happening to this chain. Shallow-state clients will respond with `ACCEPTED` status to every `newPayload` call submitting payloads from a side branch. CL client will switch a node to optimistic mode by making a re-org. But next steps depend on EL client implementation and re-org depth: * In case of a long or unknown range re-org shallow-state client responds with `SYNCING` to the `forkchoiceUpdated` method call and leaves a node in optimistic mode with necessity to check for EL status updates * If a shallow-state client supports short-range re-orgs, i.e. doing them synchronously, then it will respond with `VALID/INVALID` status to the corresponding `forkchoiceUpdated` call, thus, a node will turn off an optimistic mode upon receiving the response to this call and VC served by a node will be able to continue doing its duties. There is a very little time of a node to be in an optimistic mode in this case. Literally the period between CL changes its head to a side chain block and receives a response to the corresponding `forkchoiceUpdated` call * If short-range re-orgs aren't supported then EL responds with `SYNCING` status as in case of long-range re-org leaving a node in an optimistic mode with inability to serve VC until the branch is validated. As an optimisation of handling this case, CL may poll a status update from EL on a sub-slot time interval by calling `forkchoiceUpdated` with the same data. Deep-state clients will respond with `VALID/INVALID` status to `newPayload` call if a parent state of a payload exists locally (payload `blockNumber` is in `[HEAD-N; N]` range), thus, making a node to re-org avoiding optimistic mode. In case of long-range (when `blockNumber` is lower than `HEAD-N` and paren state is missing) or unknown-rage (when ancestor blocks are missing) re-orgs deep-state client responds with `SYNCING` and CL will have to check for updates of EL status, and once EL responds with `VALID/INVALID` turn off optimistic mode.

    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