platform icon indicating copy to clipboard operation
platform copied to clipboard

feat(drive-abci): state sync - faster sync of new nodes

Open ogabrielides opened this issue 10 months ago • 1 comments

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 added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • [ ] I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • [ ] I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Introduced state sync and snapshot management, enabling creation, listing, loading, and application of database snapshots for improved state synchronization and recovery.
    • Added new configuration options and environment variables for checkpoint and snapshot paths.
    • Enhanced platform state serialization with reduced state storage and retrieval.
    • Expanded versioning support to include state sync and reduced platform state methods.
  • Improvements

    • Updated dependencies and Docker image versions for improved compatibility.
    • Enhanced error handling with new error types related to snapshots and state sync.
    • Improved internal logging and debugging for platform state and snapshots.
  • Bug Fixes

    • Adjusted test expectations to reflect updated calculations for identity balances.
  • Documentation

    • Added and updated comments to clarify voting and snapshot-related logic in tests.

ogabrielides avatar Mar 07 '25 08:03 ogabrielides

[!WARNING]

Rate limit exceeded

@lklimek has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 43 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between d36184f69aee0528a8b8437bca7ef9abc9385779 and 3fdf661870470a23ed7266dc172e2596895abe5e.

⛔ Files ignored due to path filters (1)
  • packages/dashmate/templates/platform/drive/tenderdash/config.toml.dot is excluded by !**/*.dot
📒 Files selected for processing (31)
  • Dockerfile (3 hunks)
  • packages/dashmate/configs/defaults/getBaseConfigFactory.js (2 hunks)
  • packages/dashmate/configs/defaults/getLocalConfigFactory.js (1 hunks)
  • packages/dashmate/configs/getConfigFileMigrationsFactory.js (1 hunks)
  • packages/dashmate/docker-compose.yml (4 hunks)
  • packages/dashmate/src/config/configJsonSchema.js (2 hunks)
  • packages/rs-dpp/src/reduced_platform_state/mod.rs (1 hunks)
  • packages/rs-dpp/src/reduced_platform_state/v0/mod.rs (1 hunks)
  • packages/rs-drive-abci/.env.local (1 hunks)
  • packages/rs-drive-abci/.env.mainnet (1 hunks)
  • packages/rs-drive-abci/.env.testnet (1 hunks)
  • packages/rs-drive-abci/src/abci/app/check_tx.rs (4 hunks)
  • packages/rs-drive-abci/src/abci/app/consensus.rs (4 hunks)
  • packages/rs-drive-abci/src/abci/app/full.rs (4 hunks)
  • packages/rs-drive-abci/src/abci/config.rs (3 hunks)
  • packages/rs-drive-abci/src/abci/handler/apply_snapshot_chunk.rs (1 hunks)
  • packages/rs-drive-abci/src/abci/handler/finalize_block.rs (3 hunks)
  • packages/rs-drive-abci/src/abci/handler/prepare_proposal.rs (1 hunks)
  • packages/rs-drive-abci/src/config.rs (4 hunks)
  • packages/rs-drive-abci/src/execution/engine/run_block_proposal/v1/mod.rs (1 hunks)
  • packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_core_info/mod.rs (3 hunks)
  • packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_core_info/v0/mod.rs (4 hunks)
  • packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_masternode_list/mod.rs (2 hunks)
  • packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_masternode_list/v0/mod.rs (2 hunks)
  • packages/rs-drive-abci/src/execution/storage/fetch_reduced_platform_state/v0/mod.rs (1 hunks)
  • packages/rs-drive-abci/src/execution/storage/mod.rs (1 hunks)
  • packages/rs-drive-abci/src/execution/storage/store_reduced_platform_state/mod.rs (1 hunks)
  • packages/rs-drive-abci/src/execution/storage/store_reduced_platform_state/v0/mod.rs (1 hunks)
  • packages/rs-drive-abci/src/logging/level.rs (1 hunks)
  • packages/rs-drive-abci/src/platform_types/platform_state/mod.rs (2 hunks)
  • packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs (5 hunks)

Walkthrough

This update introduces comprehensive enhancements centered on state synchronization, snapshot management, and versioned storage for platform and block state within the system. New modules and traits are added to support the serialization, deserialization, fetching, and storing of reduced platform state and last block information. Snapshot management is integrated into the ABCI application, including snapshot creation, listing, loading, and application during state sync. Configuration structures and environment variables are extended to support these new features. Versioning structures are updated throughout the platform to accommodate the new methods and structures, ensuring compatibility and extensibility for state sync and snapshot operations.

Changes

File(s) / Path(s) Change Summary
.github/actions/sccache/action.yaml, Dockerfile Updated default sccache version to 0.9.1; added checkpoint-related env vars and directory setup in Dockerfile.
packages/dapi-grpc/Cargo.toml Reordered tenderdash-proto dependency.
packages/dashmate/configs/defaults/getBaseConfigFactory.js Updated tenderdash Docker image reference to a feature branch.
packages/rs-dpp/src/lib.rs, packages/rs-dpp/src/block/block_info/mod.rs Added FeeMultiplier type and new ExtendedBlockInfo struct.
packages/rs-dpp/src/reduced_platform_state/mod.rs, packages/rs-dpp/src/reduced_platform_state/v0/mod.rs Introduced versioned reduced platform state struct and deserialization logic.
packages/rs-dpp/src/serialization/serialization_traits.rs Added traits for reduced serialization and deserialization.
packages/rs-drive-abci/.env.local Added env vars for checkpoints and GroveDB latest state file.
packages/rs-drive-abci/Cargo.toml, packages/rs-drive-proof-verifier/Cargo.toml Updated dependencies and features for tenderdash-abci and serde_json.
packages/rs-drive-abci/src/abci/app/check_tx.rs, src/abci/app/consensus.rs, src/abci/app/full.rs Integrated snapshot manager and state sync session handling into ABCI applications.
packages/rs-drive-abci/src/abci/app/mod.rs Added new traits for snapshot and state sync application interfaces; updated trait lifetimes.
packages/rs-drive-abci/src/abci/config.rs, src/config.rs Introduced state sync configuration struct and integrated into platform config.
packages/rs-drive-abci/src/abci/error.rs Added new error variants for state sync errors.
packages/rs-drive-abci/src/abci/handler/apply_snapshot_chunk.rs, list_snapshots.rs, load_snapshot_chunk.rs, offer_snapshot.rs Implemented handlers for snapshot chunk application, listing, loading, and offering.
packages/rs-drive-abci/src/abci/handler/finalize_block.rs, info.rs Enhanced block finalization with snapshot creation and added tracing.
packages/rs-drive-abci/src/abci/handler/mod.rs Registered new snapshot handler modules and public exports.
packages/rs-drive-abci/src/execution/engine/run_block_proposal/mod.rs, v1/mod.rs Added versioned block proposal processing logic.
packages/rs-drive-abci/src/execution/mod.rs, platform_events/mod.rs, core_based_updates/mod.rs, update_quorum_info/mod.rs Broadened visibility of platform events and quorum update modules.
packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs Optimized public key assignment (no clone).
packages/rs-drive-abci/src/execution/platform_events/protocol_upgrade/perform_events_on_first_block_of_protocol_change/v0/mod.rs Refactored and reorganized protocol upgrade transition logic.
packages/rs-drive-abci/src/execution/storage/mod.rs, fetch_last_block_info/mod.rs, fetch_last_block_info/v0/mod.rs, fetch_reduced_platform_state/mod.rs, fetch_reduced_platform_state/v0/mod.rs, store_last_block_info/mod.rs, store_last_block_info/v0/mod.rs, store_reduced_platform_state/mod.rs, store_reduced_platform_state/v0/mod.rs Added modules for fetching and storing reduced platform state and last block info, with version checks.
packages/rs-drive-abci/src/platform_types/mod.rs, snapshot/mod.rs Introduced snapshot management module with structs for snapshot, manager, and fetching session.
packages/rs-drive-abci/src/platform_types/platform_state/mod.rs, v0/mod.rs Implemented reduced serialization for platform state and conversion logic.
packages/rs-drive-abci/tests/strategy_tests/voting_tests.rs, withdrawal_tests.rs Added comments and updated test assertions for expected values.
packages/rs-drive/src/drive/platform_state/mod.rs, fetch_last_block_info_bytes/mod.rs, fetch_last_block_info_bytes/v0/mod.rs, fetch_reduced_platform_state_bytes/mod.rs, fetch_reduced_platform_state_bytes/v0/mod.rs, store_last_block_info_bytes/mod.rs, store_last_block_info_bytes/v0/mod.rs, store_reduced_platform_state_bytes/mod.rs, store_reduced_platform_state_bytes/v0/mod.rs Added methods and modules for versioned fetch/store of platform state and block info bytes.
packages/rs-drive/src/error/drive.rs Added snapshot error variant to DriveError.
packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_method_versions/mod.rs, v1.rs, v2.rs, v3.rs, v4.rs, v5.rs, v6.rs Added method versions for reduced platform state and last block info storage.
packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_structure_versions/mod.rs, v1.rs Added structure version for reduced platform state for saving.
packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_state_sync_versions/mod.rs, v1.rs, mod.rs, v1.rs Introduced drive ABCI state sync versioning.
packages/rs-platform-version/src/version/drive_versions/mod.rs, v1.rs, v2.rs, v3.rs, v4.rs Added method versions for reduced platform state and last block info in Drive.
packages/rs-platform-version/src/version/mocks/v2_test.rs, v3_test.rs Updated test mocks with new method versions and state sync.
packages/rs-dpp/src/block/block_info/mod.rs Added new ExtendedBlockInfo struct.

Sequence Diagram(s)

sequenceDiagram
    participant Node
    participant ABCI_App
    participant SnapshotManager
    participant GroveDB

    Node->>ABCI_App: Request State Sync (OfferSnapshot)
    ABCI_App->>SnapshotManager: Start Snapshot Fetching Session
    Note right of SnapshotManager: Wipe DB, prepare session

    Node->>ABCI_App: LoadSnapshotChunk (chunk N)
    ABCI_App->>SnapshotManager: Apply Chunk to Session
    SnapshotManager->>GroveDB: Store Chunk Data
    SnapshotManager-->>ABCI_App: Chunk Applied

    Node->>ABCI_App: Finalize Block
    ABCI_App->>SnapshotManager: Create Snapshot (if enabled)
    SnapshotManager->>GroveDB: Save Snapshot Metadata and Data
    SnapshotManager-->>ABCI_App: Snapshot Created

    Node->>ABCI_App: ListSnapshots
    ABCI_App->>SnapshotManager: Get Snapshots
    SnapshotManager-->>ABCI_App: Return Snapshots List
    ABCI_App-->>Node: Snapshots List

    Node->>ABCI_App: LoadSnapshotChunk (by height/id)
    ABCI_App->>SnapshotManager: Get Snapshot at Height
    SnapshotManager->>GroveDB: Fetch Chunk Data
    SnapshotManager-->>ABCI_App: Chunk Data
    ABCI_App-->>Node: Return Chunk

Possibly related PRs

  • dashpay/platform#2189: Modifies protocol upgrade logic in the same area (transition_to_version_4), directly related to protocol upgrade handling.
  • dashpay/platform#2227: Adds new versions and fixes deserialization for platform state serialization, related to serialization improvements.

Suggested labels

cleanup

Poem

A snapshot here, a chunk over there,
State sync bunnies now hop everywhere!
With versioned bytes and configs anew,
The platform leaps forward, fresh as dew.
Snapshots are managed, blocks safely stored—
This rabbit’s delighted (and never bored)!
Onward we bound, with state in our paws,
Hopping through code, earning applause!

((\
( -.-)
o_(")(")

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Mar 07 '25 08:03 coderabbitai[bot]