Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: merk state sync chunking #267

Closed
wants to merge 8 commits into from
Closed

Conversation

iammadab
Copy link
Contributor

@iammadab iammadab commented Aug 25, 2023

State sync specification required us to make changes to how we handle previously handled chunking.
Before, a single trunk of height = h / 2 is first sent, the node hash values for subsequent chunks are gotten and then each chunk is retrieved and applied sequentially.

Problems with this:

  • The trunk height might be larger than the max chunk size (no progress can be made, stalling state sync)
  • Sequential, doesn't take advantage of connection to multiple nodes (so slow)

This work addresses those problems:

  • Each chunk now has a minimum height of 2 and maximum height of 3
  • Can produce single chunk + multi chunk given some limit
  • When producing multi-chunk, the chunk size expands to fill available data up to some limit (this means no proof size overhead)

Issue being fixed or feature implemented

What was done?

How Has This Been Tested?

Breaking Changes

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

    finalize multi chunk with limit

    implement chunk op

    test chunk op encoding

    convert chunk op chunk id to string

    implement traversal instruction to string

    add chunking error + devoid multi subtree chunk from encoding work

    multi-subtree-chunk skeleton + return encoding length in multichunk

    make chunks fixed size height 2

    test height proof

    implement height proof verifier

    update documentation

    verify height proof generation

    add documentation

    test no of chunk under chunk id fn

    implement number of chunks under chunk id function

    extract chunk layer function from chunk height

    seperate number_of_chunk into height and layer_height functions

    return multi chunk result

    enforce limit without storage overhead

    add test for encoding length check

    implement iterator for chunk producer

    remove cost from chunks

    fix the error type

    implement random chunk access

    fixes

    implement chunk height function

    add traverse then build chunk function to ref walker

    update comment

    implement chunk producer length

    init chunk producer struct

    implement merk tree height function

    update traversal generation instruction

    add instruction traversal test

    fix documentation

    implement binary range function

    clean up number of chunks function

    given a subtree of a given height return the exit node count

    documentation fixes

    implement chunk_height_per_layer

    verify that chunks produce expected root hash

    implement and test variable depth chunk creation

    restart chunking v2
@iammadab iammadab changed the title Feat/merk state sync feat: merk state sync chunking Aug 25, 2023
@iammadab iammadab changed the base branch from master to develop August 25, 2023 07:56
    remove bad test

    rename files

    update documentation

    wip

    wip

    implement merk verifier + state building

    implement replication from multichunk

    fix chunk verification

    fixed implementation of chunkid from traversal instructions

    fix some tests

    make chunk_id from traversal instruction test resistant to changes in underlying chunking scheme

    add restoration logic test function

    returning the next chunk id when you call chunk

    use strings as communication interface between producer and restorer

    implement chunk id from traversal instruction

    add traversal instruction generation to direct string

    chunk producer returns next index as string for multi chunk

    clean up rewrite parent links

    restoration done successfully

    rough implementation of rewrite parent

    implement function to extract sum from node type

    wip

    chunk write logic + restorer finalization + parent key tracking

    new visit ref function that keeps track of traversal path

    implement instruction string to traversal instruction

    test child to link functionality for basic and sum merks

    implement node to link include sum

    wip

    implement and test chunk verification

    Fix layer iter function

    Previous implementation made a key assumption that nodes are unique
    including hash nodes, this made the layer iteration functionality
    depend on the contents of the tree, which shouldn't be the case.

    This adds a simpler implementation of the layer iter logic using breadth
    first search.

    add test to ensure chunks only contain hash and kvfeaturetype

    test for avl tree during proof op execution

    remove chunk_height_per_layer_lin_comb every chunk now has fixed height of 2
@iammadab iammadab marked this pull request as ready for review October 2, 2023 07:40

// generate as many subtree chunks as we can
// until we have exhausted all or hit a limit restriction
while current_index.is_some() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is while let syntax in Rust to cleanup some expects later

}

/// Returns the chunk at the given index
/// Assumes index and traversal_instructions represents the same information
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a sign of a new type needed, to ensure two field are in sync to have an invariant

@iammadab iammadab mentioned this pull request Jan 4, 2024
1 task
@ogabrielides
Copy link
Collaborator

Already included in #292

@ogabrielides ogabrielides deleted the feat/merk-state-sync branch May 1, 2024 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants