Skip to content

Cmd sync optimization #4464

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

Merged
merged 4 commits into from
Apr 10, 2025
Merged

Cmd sync optimization #4464

merged 4 commits into from
Apr 10, 2025

Conversation

jackzhhuang
Copy link
Collaborator

@jackzhhuang jackzhhuang commented Apr 10, 2025

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Other information

Summary by CodeRabbit

  • New Features
    • Block info retrieval now accepts a flexible input, allowing users to specify either a block hash or a block number.
    • A new CLI command has been introduced to fetch ghost DAG data using a block hash.
    • RPC API and client methods have been expanded to support block information retrieval by hash and ghost DAG data access.
    • A retry mechanism has been added to improve the reliability of block event broadcasts.

@jackzhhuang jackzhhuang marked this pull request as draft April 10, 2025 04:12
Copy link

coderabbitai bot commented Apr 10, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request modifies the block retrieval functionality by updating the GetBlockInfoOpt structure to accept either a hash or a block number. A new ghost DAG data command has been added along with its module integration. The RPC schema, API trait, and server implementation now include methods for retrieving block information by hash. Additionally, the RPC client gains two new methods for block info and ghost DAG data, the block sync task introduces a retry mechanism for event broadcasting, and the test harness is extended with a method for fetching block info by hash.

Changes

Files Change Summary
cmd/starcoin/src/chain/get_block_info_cmd.rs Updated GetBlockInfoOpt: replaced number with hash_or_number; modified run method to match and handle hash vs number input.
cmd/starcoin/src/chain/get_ghost_dag_data.rs, cmd/starcoin/src/chain/mod.rs Added new file for ghost DAG data command and registered a new module to support it.
rpc/api/generated_rpc_schema/chain.json, rpc/api/src/chain/mod.rs, rpc/server/src/module/chain_rpc.rs Introduced new RPC method chain.get_block_info_by_hash including schema definition, trait alteration, and server implementation.
rpc/client/src/lib.rs Added two public methods: chain_get_block_info_by_hash and get_ghost_dag_data with synchronous error handling.
sync/src/tasks/block_sync_task.rs Implemented a retry mechanism for broadcasting BlockConnectedEvent with exponential backoff.
vm/starcoin-transactional-test-harness/src/fork_chain.rs Extended MockChainApi with a new asynchronous method get_block_info_by_hash.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Command
    participant ChainService
    User->>Command: Provide hash or number input
    alt Input is Hash
        Command->>ChainService: chain_get_block_info_by_hash(hash)
    else Input is Number
        Command->>ChainService: chain_get_block_info_by_number(number)
    end
    ChainService-->>Command: Return BlockInfo or error message
    Command-->>User: Display result
Loading
sequenceDiagram
    participant RpcClient
    participant RpcServer
    participant ChainApi
    RpcClient->>RpcServer: Request get_block_info_by_hash(id)
    RpcServer->>ChainApi: Execute get_block_info_by_hash(id)
    ChainApi-->>RpcServer: Return BlockInfoView or None
    RpcServer-->>RpcClient: Send response
Loading

Suggested reviewers

  • jolestar
  • nkysg
  • sanlee42
  • yourmoonlight

Poem

I'm a rabbit in the codefield, hopping by,
With hash or number, I give it a try.
Ghost DAG data twirls like a playful dance,
RPC calls and retries lead to a chance.
My little paws tap keys with glee,
Carrots and code—hoppy as can be!
🥕🐇 Happy changes in our chain, you see!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 54af0b8 and bc70c93.

📒 Files selected for processing (9)
  • cmd/starcoin/src/chain/get_block_info_cmd.rs (2 hunks)
  • cmd/starcoin/src/chain/get_ghost_dag_data.rs (1 hunks)
  • cmd/starcoin/src/chain/mod.rs (1 hunks)
  • rpc/api/generated_rpc_schema/chain.json (1 hunks)
  • rpc/api/src/chain/mod.rs (1 hunks)
  • rpc/client/src/lib.rs (2 hunks)
  • rpc/server/src/module/chain_rpc.rs (1 hunks)
  • sync/src/tasks/block_sync_task.rs (2 hunks)
  • vm/starcoin-transactional-test-harness/src/fork_chain.rs (1 hunks)
✨ 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@jackzhhuang jackzhhuang removed the request for review from jolestar April 10, 2025 04:24
@jackzhhuang jackzhhuang self-assigned this Apr 10, 2025
@jackzhhuang jackzhhuang marked this pull request as ready for review April 10, 2025 09:18
@jackzhhuang jackzhhuang merged commit 5962e2f into dag-master Apr 10, 2025
3 of 6 checks passed
@jackzhhuang jackzhhuang deleted the cmd-sync-optimization branch April 10, 2025 09:19
sanlee42 pushed a commit that referenced this pull request Apr 17, 2025
* add cmd to get block info by id

* add cmd to get the ghostdata

* retry the block connect message

* add chain.json in rpc/api
jackzhhuang added a commit that referenced this pull request Apr 21, 2025
* add cmd to get block info by id

* add cmd to get the ghostdata

* retry the block connect message

* add chain.json in rpc/api
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.

2 participants