HackMD
    • Sharing Link copied
    • /edit
    • View mode
      • Edit mode
      • View mode
      • Book mode
      • Slide mode
      Edit mode View mode Book mode Slide mode
    • 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
    • More (Comment, Invitee)
    • Publishing
    • Commenting Enable
      Disabled Forbidden Owners Signed-in users Everyone
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Invitee
    • No invitee
    • Options
    • Versions and GitHub Sync
    • Transfer ownership
    • Delete this note
    • Template
    • Save as template
    • Insert from template
    • Export
    • Google Drive Export to Google Drive
    • Gist
    • Import
    • Google Drive Import from Google Drive
    • Gist
    • Clipboard
    • Download
    • Markdown
    • HTML
    • Raw HTML
Menu Sharing Help
Menu
Options
Versions and GitHub Sync Transfer ownership Delete this note
Export
Google Drive Export to Google Drive Gist
Import
Google Drive Import from Google Drive Gist Clipboard
Download
Markdown HTML Raw HTML
Back
Sharing
Sharing Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
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
More (Comment, Invitee)
Publishing
More (Comment, Invitee)
Commenting Enable
Disabled Forbidden Owners Signed-in users Everyone
Permission
Owners
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Invitee
No invitee
   owned this note    owned this note      
Published Linked with GitHub
Like BookmarkBookmarked
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# More efficient snap After we complete a snap sync, we need to go through the entire trie (at root `X`) and generate the snapshot base layer (for root `X`). This is problematic. Here's from one of the bootnodes: ``` Jan 22 11:25:07 bootnode-aws-ap-southeast-1-001 geth INFO [01-22|10:25:07.548] Resuming state snapshot generation root="bad86c…809831" in="0a2f1a…987b1a" at="f496f8…838431" accounts=4581561 slots=18608062 storage=1.63GiB elapsed=16h29m49.102s eta=398h11m43.786s ``` It has been generating for `16h`, and estimates another `~400h` to complete the generation. It will probably go a lot faster than that, but it's safe to say it's a matter of several days. ``` Jan 24 07:24:55 bootnode-aws-ap-southeast-1-001 geth INFO [01-24|06:24:55.010] Resuming state snapshot generation root="4d056b…703e42" in="0ef08c…34bc7d" at="efb101…ee8cb2" accounts=6722662 slots=36128084 storage=2.95GiB elapsed=60h29m36.564s eta=976h5m59.624s ``` After `60` hours, it estimates a further `976` hours until completion. ## How to not solve it There's a naive way to avoid that: storing the snapshot data upon receiption. During the heal-phase, as before, we write the new values into the trie, and also make sure to update the base-layer with any new changes. The naive way suffers from two problems: 1. If an account has been selfdestructed from the time we first got it, to the time we do the trie-heal, then we won't successfully delete it from the base layer. 2. If a storage value has been changed in the same interval, then - We will successfully update the `storageRoot` of the account object, but not successfully update the slot-value in the base layer. Can we work around these limitations? ## SELFDESTRUCTS handling When healing, we obtain knowledge of all paths that were modified, starting with root. Let's say we have root `X`, wich we fetch. We then discover that we indeed already have path `0` (the leftmost 1/16th part of the trie). We can now say, with certainty, that any keys `0x0xxxx` in our snap db are correct. ### Phase 0 What we can do, is create a `healtrie`. The `healtrie` is constructed during the healing-phase, and contains everything that was healed. Any parts of the `healtrie` which already existed, remains unresolved. This means that a `hash` in the `healtrie` represents a path-subset where our snab-db is correct. Any non-hash node represents a path-subset where the snapdb was changed. It's not a requirement to go "all the way", but we can choose to abort the tracking after a certain level (for example it might be good to stop once we reach the first shortnode, but experimentation will tell) Note: The `healTrie` does not need to be a Merkle-Patricia trie: based on the cryptographic hash of the children. It can be a regular trie (prefix tree) with two types of leaves that just differentiates between "was present" (`hash`) and "had to be resolved" (`node`). Note 2: the `healtrie` does not _have_ to include any/all leaf-data, such as actual accounts. After the trie healing is done, we now have a `healtrie` of paths where things were modified. Perform these steps: We can now traverse the healtrie, along the outer perimemeter. - From the baselayer, delete all items that in the keyspaces for those paths. - For each sub-path, iterate the trie, and fill the leaves into the baselayer. ### Phase 1 - Start at root. This path `0` marks the beginning of a delete-section. Traverse to the first `hash`, at path `pN`. This segment can be deleted. - Continue from `pN+1`. Continue until the next `hash`, at path `pM`. Delete this segment. - Continue until the trie is done. ### Phase 2 Our original state was: > we have a base layer which is 99.9% correct, but it has some extra elements which are not present in the trie. Our state after the deletion is: > We now have a base layer which is 99.9% correct, but it has some missing elements. So filling from the trie is a matter of iterating maybe only `1%` of the trie, instead of the whole thing. Do the same iteration as phase 1, once again, but instead of deleting, fill the snap-db from the trie. ### Phase 1 + 2 In practice, I think phase 1+2 can be more optimally performed in one step (one iteration), but it's simpler to reason about as two separate phases. ## Storage modification handling I haven't yet thought this fully through, but I think it can be handled analogous to the case above.

Import from clipboard

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 lost 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?

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

Sign in via SAML

or

Sign in via GitHub

Help

  • English
  • 中文
  • 日本語

Documents

Tutorials

Book Mode Tutorial

Slide Example

YAML Metadata

Resources

Releases

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

Versions and GitHub Sync

Sign in to link this note to GitHub Learn more
This note is not linked with GitHub Learn more
 
Add badge Pull Push GitHub Link Settings
Upgrade now

Version named by    

More Less
  • Edit
  • Delete

Note content is identical to the latest version.
Compare with
    Choose a version
    No search result
    Version not found

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. Learn more

       Sign in to GitHub

      HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.

      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
      Available push count

      Upgrade

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Upgrade

      Danger Zone

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

      Syncing

      Push failed

      Push successfully