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(rollup): sync finalized batches from L1 #515

Merged
merged 78 commits into from
Oct 27, 2023

Conversation

colinlyguo
Copy link
Member

@colinlyguo colinlyguo commented Sep 14, 2023

1. Purpose or design rationale of this PR

This PR adds a service to ensure the integrity and consistency of L2 data with the L1 data. When starting the node, it is initiated as a background process, guaranteeing the start procedure does not be blocked by rollupSyncService.

Ref link (see the last requirement of stage0): https://l2beat.com/scaling/projects/arbitrum#stage

Usage: --rollup.verify to enable.

L1 state: Syncing with ScrollChain Contract

  1. Event types: CommitBatch, RevertBatch, and FinalizeBatch.
  2. Calldata of CommitBatch event: get batch -> chunk range -> block ranges for each chunk.
  3. Event topics: get BatchIndex, BatchHash, StateRoot, WithdrawRoot.

L2 state: Reconstruct Batch Header to get Batch Hash

  1. Blocks: get from node state.
  2. Block/chunk range of the batch: get from commitBatch calldata.
  3. Parent batch hash and total l1 message popped before: store in db (after passing validation check).

Consistency check

  1. Compare locally StateRoot, and WithdrawRoot with L1's.
  2. Compare locally computed Batch Hash with L1's.
  3. Close the node and shutdown once inconsistent.

DB:

  1. Graceful Restart: Upon restarting, the sync service resumes from the last synchronized block height, preventing redundancy by syncing processed blocks.
  2. Batch Meta Information: To construct the batch header, the database stores the hash of successfully reconciled batches along with the total count of L1 messages that have been processed.
  3. Batch Chunk Ranges: For the construction of the batch header, the database saves the chunk ranges associated with each batch.

Unit tests:

  1. accessors_rollup_event.go: read/write, read non-existing value, over-write.
  2. rollup_sync_service.go: get/decode chunk ranges from calldata, new/start/stop (without rollup event data), validate batch.
  3. l1client.go: test with mockEthClient (without rollup event data).
  4. abi.go, block.go, chunk.go, batch_header.go: tested in scroll repo, consider moving them to a common repo.

2. PR title

Your PR title must follow conventional commits (as we are doing squash merge for each PR), so it must start with one of the following types:

  • feat: A new feature

3. Deployment tag versioning

Has the version in params/version.go been updated?

  • This PR doesn't involve a new deployment, git tag, docker image tag, and it doesn't affect traces
  • Yes

4. Breaking change label

Does this PR have the breaking-change label?

  • This PR is not a breaking change
  • Yes

@colinlyguo colinlyguo force-pushed the feat-sync-finalized-batches-from-L1 branch from 97dfaa9 to ada6676 Compare September 14, 2023 09:38
@colinlyguo colinlyguo changed the title feat(rollup): sync finalized batches from L1 [WIP] feat(rollup): sync finalized batches from L1 Sep 14, 2023
@colinlyguo colinlyguo force-pushed the feat-sync-finalized-batches-from-L1 branch 7 times, most recently from 935b1e1 to 8733519 Compare September 15, 2023 06:42
@colinlyguo colinlyguo marked this pull request as ready for review September 15, 2023 06:43
@colinlyguo colinlyguo force-pushed the feat-sync-finalized-batches-from-L1 branch 6 times, most recently from ac753b7 to 8fecbed Compare September 15, 2023 12:29
@colinlyguo colinlyguo force-pushed the feat-sync-finalized-batches-from-L1 branch from 8fecbed to 21cbf3a Compare September 17, 2023 12:03
@colinlyguo colinlyguo force-pushed the feat-sync-finalized-batches-from-L1 branch 4 times, most recently from 81304ba to 8c09411 Compare September 18, 2023 05:57
@colinlyguo colinlyguo self-assigned this Sep 18, 2023
@colinlyguo colinlyguo force-pushed the feat-sync-finalized-batches-from-L1 branch 5 times, most recently from ff6f255 to f7ca600 Compare September 18, 2023 07:49
@colinlyguo
Copy link
Member Author

colinlyguo commented Oct 26, 2023

sync looks good in Mainnet so far:
INFO [10-26|16:16:37.527] finalized batch progress batch index=900 finalized l2 block height=109,683

RevertBatch needs to be tested in Sepolia (has been tested previously), and will run later.

updated: also tested.

core/rawdb/schema.go Outdated Show resolved Hide resolved
params/version.go Outdated Show resolved Hide resolved
Thegaram
Thegaram previously approved these changes Oct 26, 2023
@colinlyguo colinlyguo force-pushed the feat-sync-finalized-batches-from-L1 branch from e95cb9e to a4682ba Compare October 26, 2023 18:06
@0xmountaintop 0xmountaintop merged commit 4412122 into develop Oct 27, 2023
5 checks passed
@0xmountaintop 0xmountaintop deleted the feat-sync-finalized-batches-from-L1 branch October 27, 2023 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants