Anton Nashatyrev
    • 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
      • Invitee
    • 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
    • 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 Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync 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
Invitee
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
# Incremental diff SSZ storage ## Goal Improve Ethereum Consensus Layer node 'cold' or archive beacon state database: - reduce DB size - increase load speed ## Highlights - The LevelDB database took **8.6 Gb** per 65K epoch states starting from the Altair hardfork (which is **~10Gb per year**) - It takes **~190ms** on average (~280ms in the worst case) to read a random `BeaconState` instance from DB ## Idea Many back up systems use incremental schema. I.e. they store initial full snapshot and then write only changes with some time period. To make the process of backup and recovery more effective the changes are organized into hierarchical structure. E.g. every month the system stores changes relative to the initial full snapshot and then every day the system stores changes relative to the monthly state. That way restoring backup for some specific date requires: - Load initial full snapshot - Load and apply monthly diff - Load and apply daily diff to the previous result The similar approach was tested with respect to the binary SSZ representation of CL `BeaconState` ![](https://i.imgur.com/6AOm4pP.png =500x) SSZ diffs are basically arranged to a tree like structure. To get an arbitrary epoch state SSZ we need to get corresponding yearly state SSZ snapshot and then incrementally apply monthly, weekly, ..., every-16-epochs, and finally epoch diffs ## Idea improvements ### Compression Many `BeaconState` fields could be compressed pretty well. E.g. the whole state could be compressed (with Gzip) to about 60% of its original size. Thus all the diffs are stored compressed #### Full snapshot compression note While optimizing load performance it was noted that `Snappy` compressor significantly outperforms `Gzip` on decompressing speed while still yields quite affordable compression rate ### State `balances` field It was noticed that a `balances` diff for neighbor epoch states contain >95% of equal values and thus is a good candidate for compression. E.g. for some state (with ~400K validators): - **3170**Kb: raw field SSZ size - **3170**Kb: the same size for regular binary diff - **1760**Kb: compressed regular binary diff - **35**Kb: compressed `balances` `UInt64` values diff relative to the previous epoch state Since we want to save a lot of space by storing balance diffs between neighbor epoch states we need to slightly redesign the diff schema for the last `EpochX1` step: we want to make diff as usual with the exception of the SSZ part corresponding to the `balances` field. So this is kind of 'composite' diff We would also need to perform more steps when recreating a state SSZ: ![](https://i.imgur.com/rsRCx2m.png =300x) ### From Tree to DAG The improved schema saves a lot of space however requires much more diffs to be loaded and applied. The further idea for improvement is to separate `balances` diff and the rest of the whole binary diff. Thus to restore a state the original schema is used for everything except `balances` SSZ. For `balances` part we use the 'iterative' approach. The final step is merging both `Rest Diff` and `Balances Diff` results ![](https://i.imgur.com/9TmChWr.png =500x) Worth to mention that prior to this scheme applying any diff at any stage resulted in a complete beacon state SSZ (the white graph vertices), however after splitting the schema applying `Balances Diff` results in just that part of SSZ where `balances` are serialized. Applying `Rest Diff` results in SSZ with 'nothing' in place of `balances`. Such results appear as yellow vertices and are represented with a `SparseBytes` structure which is effectively just a byte array where some bytes are 'missing' This DAG approach looks pretty flexible and potentially allows to combine different diff approaches throughout any levels ## The schema which was tested Below is the summary of the actual schema used for testing: | Name | Period (epochs) | Diff type | Sparse result | Compression | |-------------------------------|-----------------|----------------------------------|---------------|------------------| | eearSchema | 65536 | Snapshot | No | Snappy | | eonthSchema | 8192 | Simple binary diff | No | Gzip | | eekSchema | 2048 | Simple binary diff | No | Gzip | | eaySchema | 256 | Simple binary diff | No | Gzip | | epochX64Schema | 64 | Composite(UInt64, Simple binary) | No | Gzip | | epochX16Schema | 16 | Composite(UInt64, Simple binary) | No | Gzip | | epochX1MergeSchema | 1 | | No | | | \\--->epochX1BalancesSchema | 1 | UInt64 diff | Yes | Gzip | | \\--->epochX1RestSchema | 1 | Simple binary diff | Yes | Gzip | ## Size details | Name | Count | Size(Mb) | Diff size | |-------------------------------|-------|----------|-----------| | eearSchema | 2 | 51 | 25496666 | | eonthSchema | 8 | 98 | 12189263 | | eekSchema | 32 | 163 | 5083683 | | eaySchema | 255 | 1066 | 4181279 | | epochX64Schema | 1004 | 1159 | 1154297 | | epochX16Schema | 3796 | 2023 | 532831 | | epochX1MergeSchema | | | | | \\---> epochX1BalancesSchema | 61681 | 3435 | 55694 | | \\---> epochX1RestSchema | 61681 | 1656 | 26853 | ## Drawbacks - No `hash_tree_root` is stored. I.e. obtaining hash of any element of a freshly loaded state would required full rehashing - Next hardfork spec changes might potentially introduce much more entropy to state diffs so the disk space gain would become less impressive ## Potential improvements - Include slot grained states which would allow to load _any_ state without replaying state transitions. Implementing this would increase DB size x2-x3 for post Altair states according to very rough estimations - Saving state performance optimization. It is now implemented naively and takes around 1000ms - Further optimize DB space and load performance - It's possible to implement 'partial' SSZ load. This could potentially be useful to optimize access to just a part of a state ## Proof of Concept Prototype source: https://github.com/Nashatyrev/heku-tools/tree/master/apps/state-db Modified Teku (modify SSZ Writer to annotate data chunks with their GIndexes): https://github.com/Nashatyrev/teku/tree/hack/state-db

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