lido
      • 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
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners 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
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- tags: Oracle, withdrawals title: Accounting oracle --- # Accounting oracle ## Data collection TODO ## Withdrawal requests finalisation Each oracle report, it decides how many requests to finalize and at what rate. Requests are finalized in the order in which they were created by moving the cursor to the last finalized request. Oracle must take two things into account: 1. Available ETH and share rate 2. Safe requests finalisation border ### Available ETH and rate The Oracle report has two parts: the report of the number of validators and their total balance and the finalization of requests in the Withdrawal Queue. The tricky part is that the finalization of requests requires data from the first part of the report. So to calculate them we simulate oracle report making static call to `handleOracleReport` in Lido contract, getting share rate and amount of ETH that can be withdrawn from Withdrawal Vault and Execution Layer Rewards Vault taking into account the limits. ```python def get_requests_finalization_data(report_data, ref_block_hash): (total_pooled_ether, total_shares, withdrawals, el_rewards) = simulate_oracle_report(report_data, ref_block_hash) reserved_buffer = get_reserved_buffer(ref_block_hash) available_eth = reserved_buffer + withdrawals + el_rewards share_rate = get_share_rate(total_pooled_ether, total_shares) return (available_eth, share_rate) def get_reserved_buffer(ref_block_hash): buffered_eth = lido_contract.get_buffered_ether(block_identifier=ref_block_hash) withdrawal_reserve = withdrawal_queue_contract.unfinalized_steth(block_identifier=ref_block_hash) return min(withdrawal_reserve, buffered_eth) def get_share_rate(total_pooled_ether, total_shares): return 1e27 * total_pooled_ether // total_shares def simulate_oracle_report(report_data, ref_block_hash): last_processing_ref_slot = oracle_contract.get_last_processing_ref_slot(block_identifier=ref_block_hash) slots_elapsed = report_data.ref_slot - last_processing_ref_slot seconds_elapsed_since_last_report = slots_elapsed * SECONDS_PER_SLOT return lido_contract.handle_oracle_report( seconds_elapsed_since_last_report, report_data.cl_validators, report_data.cl_balance_gwei * 1e9, report_data.withdrawal_vault_balance, report_data.el_rewards_vault_balance, request_id_to_finalize_up_to=0, finalization_share_rate=0 ).call(block_identifier=ref_block_hash) ``` ### Safe requests finalisation border The protocol can be in two states: Turbo and Bunker modes. Turbo mode is a usual state when requests are finalized as fast as possible, while Bunker mode assumes a more prudent requests finalization and is activated if it's necessary to mitigate undesirable factors. More datails in [Withdrawals Landscape](https://hackmd.io/@lido/SyaJQsZoj). **In Turbo mode**, there is only one border that does not allow to finalize requests created close to the reference slot to which the oracle report is performed. - New requests border **In Bunker mode** there are more safe borders. The protocol takes into account the impact of negative factors that occurred in a certain period and finalizes requests on which the negative effects have already been socialized. The safe border is considered to be the earliest of of the following: - New requests border - Associated slashing border - Negative rebase border Before we begin examining each border, let's introduce some notations that are used in the graphs below: <img style="margin: 0 0 15px 0" width="500" src="https://hackmd.io/_uploads/BJwAPuthj.png" /> #### New requests border The border is a constant interval near the reference epoch in which no requests can be finalized: <img style="margin: 0 0 15px 0" width="500" src="https://hackmd.io/_uploads/Bk8rFuF2o.png" /> ```python NEW_REQUESTS_BORDER = 8 # epochs ~50 min def get_new_requests_border_epoch(ref_epoch): return ref_epoch - NEW_REQUESTS_BORDER ``` #### Associated slashing border The border represents the latest epoch before the reference slot before which there are no incompleted associated slashings. <img style="margin: 0 0 15px 0" width="500" src="https://hackmd.io/_uploads/SyMwK_Fhs.png" /> In the image above there are 4 slashings on the timeline that start with `slashed_epoch` and end with `withdrawable_epoch` and some points in time: withrawal request and reference epoch relationship of the slashnings with which we want to analyze. ##### Completed non-associated <img style="margin: 0 0 15px 0" width="500" src="https://hackmd.io/_uploads/rJxOYdKhj.png" /> The slashing is non-associated with the withdrawal request since it started and ended before the request was created. It's completed since `withdrawable_epoch` is before `reference_epoch`. ##### Completed associated <img style="margin: 0 0 15px 0" width="500" src="https://hackmd.io/_uploads/SJhdKOt3i.png" /> The slashing is associated with withdrawal request, since the request is in its boundaries. In this case the slashing is completed since `withdrawable_epoch` is before `reference_epoch`, so all possible impact from it is accounted. This slashing should not block the finalization of this request. ##### Incompleted associated <img style="margin: 0 0 15px 0" width="500" src="https://hackmd.io/_uploads/Sk0KKOY3i.png" /> Slashing is associated with the withdrawal request and is still going on. The impact from it is still incomplete, so such a request cannot be finalized. ##### Incompleted non-associated <img style="margin: 0 0 15px 0" width="500" src="https://hackmd.io/_uploads/SyR9tdYho.png" /> Incompleted but non-associated slashing do not block finalization of the request. The impact of it is still incomplete, nevertheless we must allow users to unstake even in bad weather. ##### Computation of the border <img style="margin: 0 0 25px 0" width="500" src="https://hackmd.io/_uploads/H13Pf5F2s.png" /> The border is calculated as the earliest `slashed_epoch` among all incompleted slashings at the point of `reference_epoch` rounded to the start of the closest oracle report frame - `NEW_REQUESTS_BORDER`. ```python def get_associated_slashings_border_epoch(ref_epoch): earliest_slashed_epoch = get_earliest_slashed_epoch_among_incomplete_slashings(ref_epoch) if earliest_slashed_epoch is None: return ref_epoch rounded_epoch = round_epoch_down_to_report_frame(earliest_slashed_epoch) return rounded_epoch - NEW_REQUESTS_BORDER ``` [Detailed research of associated slashings](https://hackmd.io/@lido/r1Qkkiv3j) #### Negative rebase border Bunker mode can be enabled by a negative rebase in case of mass validator penalties. In this case the border is considered the reference slot of the previous oracle report from the moment the Bunker mode was activated - `NEW_REQUESTS_BORDER`. <img style="margin: 0 0 0 0" width="500" src="https://hackmd.io/_uploads/ByjuG5Kho.png" /> <img style="margin: 0 0 15px 0" width="500" src="https://hackmd.io/_uploads/rJ0wrqY2i.png" /> This border has a maximum length equal to two times the governance reaction time. ```python MAX_NEGATIVE_REBASE_BORDER = 1536 # epochs ~6.8 days def get_negative_rebase_border_epoch(ref_epoch): bunker_start_epoch = get_bunker_start_epoch_from_contract() if bunker_start_epoch is None: bunker_start_epoch = get_previous_report_epoch_from_contract() bunker_start_border_epoch = bunker_start_epoch - NEW_REQUESTS_BORDER earliest_allowable_epoch = ref_epoch - MAX_NEGATIVE_REBASE_BORDER return max(earliest_allowable_epoch, bunker_start_border_epoch) ``` #### Border union The safe border is chosen depending on the protocol mode and is always the longest of all. <img style="margin: 0 0 15px 0" width="500" src="https://hackmd.io/_uploads/r1NaSqYni.png" /> ```python def get_safe_border_epoch(ref_epoch): is_bunker = detect_bunker_mode() new_request_border_epoch = get_new_requests_border_epoch(ref_epoch) if not is_bunker: return new_request_border_epoch negative_rebase_border_epoch = get_negative_rebase_border_epoch(ref_epoch) associated_slashings_border_epoch = get_associated_slashings_border_epoch(ref_epoch) return min( new_request_border_epoch, negative_rebase_border_epoch, associated_slashings_border_epoch ) ``` ### Bunker mode Activation of Bunker mode assumes the presence of one of the following events: - CL rewards for the reporting period are negative - CL rewards for the last epoch are negative - The slashing midterm penalties can cause negative CL rewards in the future TODO: describe in details ### Finalization With the amount of available ETH, rate and safe border, the oracle can find the request id up to and including which requests can be finalized. ```python def find_request_id_to_finalize_up_to(): last_finalized_request_id = get_last_finalized_request_id() last_request_id = get_last_request_id() if last_finalized_request_id >= last_request_id: # Contract expects 0 in case no finalization is needed return 0 available_eth, share_rate = get_requests_finalization_data() safe_border_timestamp = get_safe_border_timestamp() start_request_id = last_finalized_request_id end_request_id = last_request_id request_id_to_finalize_up_to = 0 while start_request_id <= end_request_id: mid_request_id = (end_request_id + start_request_id) // 2 required_eth, request_timestamp, _ = withdrawal_queue_contract.finalization_batch( mid_request_id, share_rate ) if required_eth <= available_eth and request_timestamp < safe_border_timestamp: request_id_to_finalize_up_to = mid_request_id # Ignore left half start_request_id = mid_request_id + 1 else: # Ignore right half end_request_id = mid_request_id - 1 return request_id_to_finalize_up_to ```

    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