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

Feature/partial tree #66

Merged
merged 13 commits into from
Dec 22, 2022
Merged

Feature/partial tree #66

merged 13 commits into from
Dec 22, 2022

Conversation

EvgenKor
Copy link
Collaborator

@EvgenKor EvgenKor commented Dec 9, 2022

Supporting for partial tree sync, state rollbacking and wiping, self-healing approach to restore corrupted state

  • Integrated birthindex optional parameter in ClientConfig (which is used in ZkBobClient initialization). If it was set during init process, the state will sync from the specified index (need relayer support for siblings). If birthindex < 0 - the library will convert it to the actual tree next_index - 128 (new account case)
  • Added support for specified index in routines ZkBobClient::{getLocalState, getPoolState}
  • ZkBobClient::{getLeftSiblings, getFirstIndex} - for testing purposes on the console tool
  • ZkBobClient::{rollbackState, cleanState} - to support self-healing
  • history storage rollback implemented as well
  • requesting partial tree if birthindex was specified. Partial tree sync conditions:
    • the pool should contain greater than PARTIAL_TREE_USAGE_THRESHOLD txs (500 currently)
    • the client birthindex should exist
    • relayer should return siblings for birthindex with correct format (/siblings?index=... method, format was discussed with @LyzeOfKiel )
  • local tree root verify and restore routines. Self-healing logic (occured after the each state updating):
    • we look for the current state's next_index value and last verified index. In case of equality - skip the checks
    • get local root and compare it with the one from pool contract (direct web3 request)
    • if roots are match each other - save current next_index as last verified index and finish check routine
    • if roots are different - attempt to restore tree:
      • rollback to the last verified index and start state sync again (number of possible rollbacks are limited by CORRUPT_STATE_ROLLBACK_ATTEMPTS constant: 2 currently)
      • wipe all user state and retry sync (number of possible rollbacks are limited by CORRUPT_STATE_WIPE_ATTEMPTS constant: 5 currently). After the first wiping in case of state unrestored - begin to ignore birthindex in the synchronization process
      • throw InternalError('Unable to synchronize pool state') in case of exhausting all rollback/wipes attempts

Depends on zkBob/libzkbob-rs#33 and zkBob/zeropool-relayer#113

The library can be tested along libzkbob-rs library and zkbob-console tool with associated branches.

@EvgenKor
Copy link
Collaborator Author

EvgenKor commented Dec 9, 2022

Build with Actions was failed due to libzkbob-rs-wasm-web dependency is currently corrupted (because it wasn;t published yet)

@EvgenKor EvgenKor mentioned this pull request Dec 9, 2022
Copy link

@AllFi AllFi left a comment

Choose a reason for hiding this comment

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

It looks good to me but we'll need to merge it carefully with #65.

# Conflicts:
#	package.json
#	src/client.ts
#	src/index.ts
#	src/utils.ts
#	src/worker.ts
#	yarn.lock
Copy link

@r0wdy1 r0wdy1 left a comment

Choose a reason for hiding this comment

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

lgtm

@akolotov
Copy link

zkBob/zeropool-relayer#113 has been merged. This PR can be tested now together with the new relayer. @EvgenKor could you post here results of the testing so we can merge the PR. Thanks!

@EvgenKor
Copy link
Collaborator Author

Local tests have passed successfully. Few issues were found and fixed. Library is ready to publish now.
@akolotov Can you please review the latest changes and merge PR to the develop? After that please merge the develop branch into the main branch. It will cause library publishing process to be started. After library publishing I'll start staging console deploying

@akolotov akolotov merged commit 3dfe98d into develop Dec 22, 2022
@akolotov akolotov deleted the feature/partial_tree branch December 22, 2022 13:27
akolotov added a commit that referenced this pull request Dec 22, 2022
This merge contains the following set of changes:
- Fix issue which prevents tracking history records for simple deposit via approve(#59)
- Introduction of simple stats collecting(#60)
- Introduction of cold storage for pool transactions (#64)
- Add iOS/Safari support(#65)
- Introduction of getting partial tree (#66)
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