starcoinorg / starcoin

Starcoin - A Move smart contract blockchain network that scales by layering
Apache License 2.0
1.38k stars 289 forks source link

Make the sync faster by sync the selected state #4182

Closed jackzhhuang closed 3 months ago

jackzhhuang commented 3 months ago

Pull request type

Please check the type of change your PR introduces:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

-

-

Other information

Summary by CodeRabbit

coderabbitai[bot] commented 3 months ago

Walkthrough

The recent changes enhance the efficiency and maintainability of the blockchain verification and synchronization processes. Key modifications include simplifications in the verification of parent blocks, improved error handling, and the adoption of constants for configurable parameters. These updates streamline control flow, increase logging visibility, and reduce code complexity, contributing to a more robust and adaptable architecture.

Changes

File Path Change Summary
chain/src/verifier/mod.rs Simplified parent block verification in DagVerifier, reducing complexity and enhancing readability.
flexidag/src/blockdag.rs Added filtering for parent blocks, improved error handling, and ensured robust block processing.
sync/src/block_connector/write_block_chain.rs Streamlined parent hash validation by checking a single parent hash instead of iterating.
sync/src/tasks/accumulator_sync_task.rs Changed logging level from debug! to info!, enhancing visibility of task information.
sync/src/tasks/block_sync_task.rs Improved logging for block fetching and execution; refined parent block checks for efficiency.
sync/src/tasks/inner_sync_task.rs Replaced hardcoded block request sizes with imported constants for configurability.
sync/src/tasks/mod.rs Modified FindAncestorTask instantiation to use a constant instead of a hardcoded value.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BlockVerifier
    participant BlockDAG
    participant Logger

    User->>BlockVerifier: Request block verification
    BlockVerifier->>BlockDAG: Check parent block existence
    BlockDAG-->>BlockVerifier: Return parent block status
    BlockVerifier->>Logger: Log verification result

🐇 In fields so green and wide,
With blocks we hop, with joy and pride.
Simplified paths we now explore,
With constants set, we leap for more!
Let logs declare our swift success,
In this code, we find our zest! 🌱✨


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 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](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.
github-actions[bot] commented 3 months ago

Benchmark for ec91013

Click to view benchmark | Test | Base | PR | % | |------|--------------|------------------|---| | accumulator_append | **737.3±56.08µs** | 801.4±145.52µs | **+8.69%** | | block_apply/block_apply_10 | 373.9±20.14ms | 364.9±10.69ms | -2.41% | | block_apply/block_apply_1000 | 40.2±0.66s | **39.7±2.29s** | **-1.24%** | | get_with_proof/db_store | 46.2±3.76µs | 45.8±1.07µs | -0.87% | | get_with_proof/mem_store | 39.6±7.88µs | 37.9±2.66µs | -4.29% | | put_and_commit/db_store/1 | 120.4±7.86µs | 120.1±11.36µs | -0.25% | | put_and_commit/db_store/10 | 1111.9±200.22µs | **1035.1±68.89µs** | **-6.91%** | | put_and_commit/db_store/100 | 9.7±0.35ms | 9.7±1.21ms | 0.00% | | put_and_commit/db_store/5 | 547.0±30.95µs | 521.1±40.80µs | -4.73% | | put_and_commit/db_store/50 | 4.9±0.22ms | 5.0±0.29ms | +2.04% | | put_and_commit/mem_store/1 | 71.4±6.29µs | 71.4±7.41µs | 0.00% | | put_and_commit/mem_store/10 | 703.9±125.27µs | 670.7±55.99µs | -4.72% | | put_and_commit/mem_store/100 | 6.4±0.30ms | 6.5±0.65ms | +1.56% | | put_and_commit/mem_store/5 | 349.4±57.51µs | 359.3±62.76µs | +2.83% | | put_and_commit/mem_store/50 | **3.3±0.17ms** | 3.9±1.14ms | **+18.18%** | | query_block/query_block_in(10)_times(100) | 4.4±0.15ms | 4.5±0.19ms | +2.27% | | query_block/query_block_in(10)_times(1000) | **45.0±1.23ms** | 47.2±1.49ms | **+4.89%** | | query_block/query_block_in(10)_times(10000) | **452.7±11.77ms** | 467.6±14.23ms | **+3.29%** | | query_block/query_block_in(1000)_times(100) | **1093.8±16.55µs** | 1121.7±19.30µs | **+2.55%** | | query_block/query_block_in(1000)_times(1000) | 11.8±1.41ms | 11.5±0.33ms | -2.54% | | query_block/query_block_in(1000)_times(10000) | 113.0±4.43ms | 114.5±10.68ms | +1.33% | | storage_transaction | 1101.9±433.09µs | 1145.8±473.59µs | +3.98% | | vm/transaction_execution/1 | **414.0±6.85ms** | 439.8±21.30ms | **+6.23%** | | vm/transaction_execution/10 | 132.9±7.87ms | 138.6±7.33ms | +4.29% | | vm/transaction_execution/20 | **123.8±4.95ms** | 137.0±19.56ms | **+10.66%** | | vm/transaction_execution/5 | **157.0±2.19ms** | 167.7±7.71ms | **+6.82%** | | vm/transaction_execution/50 | 143.2±8.90ms | 140.6±5.09ms | -1.82% |