dymensionxyz / dymint

Sequencing Engine for Dymension RollApps
Other
90 stars 61 forks source link

feat(p2p): block sync protocol #915

Open srene opened 2 weeks ago

srene commented 2 weeks ago

PR Standards

This PR is aimed at providing a new feature to be able to sync from P2P, retrieving blocks from other peers using the P2P network, mainly using available libp2p and IPFS libraries.

ADR is defined here https://www.notion.so/ADR-x-Rollapp-block-sync-protocol-6ee48b232a6a45e09989d67f1a6c0297?pvs=4

--

PR naming convention: https://hackmd.io/@nZpxHZ0CT7O5ngTp0TP9mg/HJP_jrm7A


Close #914

<-- Briefly describe the content of this pull request -->

For Author:


For Reviewer:


After reviewer approval:

Summary by CodeRabbit

coderabbitai[bot] commented 2 weeks ago

Walkthrough

The changes introduce a robust peer-to-peer (P2P) block syncing mechanism in the block and p2p modules. This enhancement includes new methods for event subscriptions, block caching, and synchronization processes, coupled with improved logging and error handling. Substantial updates to the configuration files ensure seamless integration.

Changes

Files / Groups Change Summary
block/block.go Added attemptCacheBlock function and updated applyBlock logic for block caching and height management.
block/manager.go Introduced new event subscriptions, enhanced syncing logic for sequencers and full-nodes, and added new functions for block production and submission loops.
block/manager_test.go Updated TestInitialState to use datastore.NewMapDatastore() for parameter setup.
block/p2p.go Added functions for handling and synchronizing gossiped blocks, refreshing block sync advertisements, and gossiping blocks.
block/produce.go Added a logging statement to ProduceBlockLoop to log the size of new blocks.
block/retriever.go Commented out or removed specific logging statements in the syncToTargetHeight and ProcessNextDABatch methods.
block/types.go Added new blocksyncBlock constant and updated CachedBlock struct to include a Source field.
config/defaults.go, config/p2p.go Introduced BlockSyncRetryTime field in P2PConfig with a default value of 30 * time.Second.
da/celestia/celestia.go, da/da.go, ... Refactored batch retrieval methods, changed Grpc constant order, and fixed a typo in a log message.
go.mod Updated dependencies including github.com/google/uuid, github.com/hashicorp/golang-lru, and go.opentelemetry.io/otel.
node/node.go Added datastore and leveldb imports, and updated NewNode function to initialize a datastore.Datastore instance.
p2p/block_sync.go, p2p/block_sync_dag.go Introduced BlockSync and BlockSyncDagService structs with methods for managing block synchronization, DAG services, and IPLD block data handling.
p2p/block_sync_test.go Added tests for block synchronization functionality in a P2P network environment.
p2p/client.go Added methods for handling block advertisements, adding and retrieving blocks, and managing block synchronization. Modified NewClient function to include a store parameter.
p2p/client_test.go Introduced a test for block advertisement and validation logic, and updated TestClientStartup to use datastore.NewMapDatastore().
p2p/events.go, p2p/validator.go Added EventNewBlockSyncBlock event and updated deserialization logic for gossiped blocks in the BlockValidator function.
p2p/validator_test.go Renamed GossipedBlock to P2PBlock, affecting the creation of gossiped block instances in TestValidator_BlockValidator.
testutil/p2p.go Updated StartTestNetwork function to take an additional datastore parameter.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Manager
    participant P2P Network
    participant Data Layer

    Client->>Manager: StartBlockSync
    Manager->>P2P Network: AdvertiseBlock
    P2P Network-->>Manager: NewBlockSyncBlockEvent
    Manager->>Client: AddBlock(block)
    Client-->>Data Layer: StoreBlock(block)
    Client-->>P2P Network: GetBlockId
    P2P Network-->>Manager: RequestBlock(blockId)
    Manager->>Client: SyncBlock(blockId)
    Client-->>Data Layer: RetrieveBlock(blockId)
    Data Layer-->>Client: BlockData
    Client-->>Manager: UpdateBlock(blockData)

Assessment against linked issues

Objective (Issue Number) Addressed Explanation
Implement robust P2P block syncing (#914)
Include improved error handling (#914)
Add and document necessary configurations (#914)
Introduce comprehensive logging (#914)
Test synchronization processes (#914)

Poem

In the network of blocks anew, P2P sync makes its debut, With caches and retries, it flows, Ensuring each block knows, The place where it belongs, Singing synchrony’s songs, A change both sure and true! 🌐


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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 generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@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 as 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 resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
codecov[bot] commented 1 week ago

Codecov Report

Attention: Patch coverage is 55.55556% with 168 lines in your changes missing coverage. Please review.

Project coverage is 39.64%. Comparing base (5a3478b) to head (c27c7e6). Report is 4 commits behind head on main.

:exclamation: Current head c27c7e6 differs from pull request most recent head d6a174b

Please upload reports for the commit d6a174b to get more accurate results.

Files Patch % Lines
p2p/client.go 56.00% 38 Missing and 6 partials :warning:
block/p2p.go 26.31% 40 Missing and 2 partials :warning:
p2p/block_sync_dag.go 56.62% 24 Missing and 12 partials :warning:
block/block.go 0.00% 22 Missing :warning:
block/manager.go 60.00% 4 Missing and 2 partials :warning:
node/node.go 33.33% 6 Missing :warning:
p2p/block_sync.go 88.67% 4 Missing and 2 partials :warning:
store/store.go 85.00% 2 Missing and 1 partial :warning:
block/retriever.go 0.00% 0 Missing and 1 partial :warning:
block/state.go 0.00% 1 Missing :warning:
... and 1 more
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #915 +/- ## ========================================== + Coverage 39.25% 39.64% +0.39% ========================================== Files 121 123 +2 Lines 18420 18722 +302 ========================================== + Hits 7230 7422 +192 - Misses 10149 10236 +87 - Partials 1041 1064 +23 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.