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

Reload k with epoch #4396

Open
wants to merge 2 commits into
base: dag-master
Choose a base branch
from
Open

Reload k with epoch #4396

wants to merge 2 commits into from

Conversation

sanlee42
Copy link
Member

@sanlee42 sanlee42 commented Feb 13, 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

    • Introduced a dynamic update mechanism for a core block processing parameter, enabling the system to adjust validation settings based on current conditions.
    • Added a new struct to enhance the management of a key parameter, improving modularity and thread-safety.
  • Refactor

    • Restructured the configuration management for block processing to improve modularity, thread-safety, and overall system reliability.

@sanlee42 sanlee42 requested a review from nkysg as a code owner February 13, 2025 07:00
@sanlee42 sanlee42 requested review from jackzhhuang and removed request for nkysg February 13, 2025 07:00
Copy link

coderabbitai bot commented Feb 13, 2025

Walkthrough

The changes update ghost DAG management by integrating a new KStore structure to encapsulate the k parameter. In the blockchain execution flow, a new call is added in the execute_dag_block method to update the ghost DAG manager's k with the current epoch's max uncles value. In parallel, the FlexiDAG modules are modified to instantiate and utilize KStore (via an Arc<KStore>) in both the BlockDAG and GhostdagManager, adjusting method signatures and internal logic accordingly without altering existing public interfaces.

Changes

File(s) Change Summary
chain/.../chain.rs Added a call in execute_dag_block to update the ghost DAG manager’s k parameter based on the epoch’s max uncles value.
flexidag/.../blockdag.rs and flexidag/.../ghostdag/protocol.rs Introduced the KStore struct to encapsulate the k parameter; updated instantiation and methods in both BlockDAG and GhostdagManager to use an Arc<KStore> instead of a primitive type.

Sequence Diagram(s)

sequenceDiagram
    participant BC as BlockChain
    participant DAG as DAG Instance
    participant GDM as GhostdagManager
    participant KS as KStore

    BC->>DAG: execute_dag_block()
    DAG->>GDM: update_k(new_k)
    GDM->>KS: update_k(new_k)
    KS-->>GDM: k updated
Loading

Suggested reviewers

  • jolestar
  • nkysg
  • welbon
  • simonjiao
  • yourmoonlight

Poem

I'm a hopping rabbit in the realm of code,
Updating ghost DAGs on a fresh, safe road.
With KStore tucked tight in each line,
Our k values now dance in perfect time.
Hoppy changes prevail—let's hit the upgrade mode! 🐇✨


📜 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 9c08be0 and 9325d54.

📒 Files selected for processing (1)
  • flexidag/src/ghostdag/protocol.rs (11 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • flexidag/src/ghostdag/protocol.rs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: run benchmark

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
🪧 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. (Beta)
  • @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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5c5275c and 9c08be0.

📒 Files selected for processing (3)
  • chain/src/chain.rs (1 hunks)
  • flexidag/src/blockdag.rs (2 hunks)
  • flexidag/src/ghostdag/protocol.rs (11 hunks)
🔇 Additional comments (4)
flexidag/src/ghostdag/protocol.rs (3)

13-33: LGTM! Thread-safe implementation of KStore.

The implementation provides safe concurrent access to the k value using Arc<RwLock<KType>> with a clean API.


42-42: LGTM! Consistent changes to GhostdagManager.

The changes to use Arc<KStore> maintain thread safety and are consistently applied to both the field and constructor.

Also applies to: 57-57


149-150: LGTM! Consistent updates to k value usage.

All usages of k have been correctly updated to use k_store.get_k(), and a new update_k method has been added to support dynamic updates to the k value.

Also applies to: 207-209, 348-349, 371-372, 376-377, 426-428, 514-519

flexidag/src/blockdag.rs (1)

17-17: LGTM! Proper integration of KStore in BlockDAG.

The changes correctly initialize and integrate the new KStore struct, maintaining thread safety with Arc.

Also applies to: 73-74

Comment on lines +667 to +669
self.dag()
.ghost_dag_manager()
.update_k(epoch.max_uncles_per_block().try_into().unwrap());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for the type conversion.

The try_into().unwrap() could panic if the epoch's max uncles value cannot be converted to KType. Consider using proper error handling.

Apply this diff to handle the conversion safely:

-            .update_k(epoch.max_uncles_per_block().try_into().unwrap());
+            .update_k(epoch.max_uncles_per_block().try_into().map_err(|e| {
+                format_err!("Failed to convert max_uncles_per_block to KType: {}", e)
+            })?);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self.dag()
.ghost_dag_manager()
.update_k(epoch.max_uncles_per_block().try_into().unwrap());
self.dag()
.ghost_dag_manager()
.update_k(epoch.max_uncles_per_block().try_into().map_err(|e| {
format_err!("Failed to convert max_uncles_per_block to KType: {}", e)
})?);

Copy link

Benchmark for d09ee1e

Click to view benchmark
Test Base PR %
accumulator_append 784.3±83.71µs 747.2±66.62µs -4.73%
block_apply/block_apply_10 405.1±30.64ms 360.4±8.08ms -11.03%
block_apply/block_apply_1000 39.3±0.88s 40.6±2.03s +3.31%
get_with_proof/db_store 44.0±3.57µs 46.0±2.93µs +4.55%
get_with_proof/mem_store 35.6±3.96µs 36.0±1.53µs +1.12%
put_and_commit/db_store/1 120.7±10.25µs 121.6±8.00µs +0.75%
put_and_commit/db_store/10 1033.3±112.54µs 1005.6±48.89µs -2.68%
put_and_commit/db_store/100 9.4±0.52ms 9.7±0.90ms +3.19%
put_and_commit/db_store/5 516.2±28.20µs 534.5±21.83µs +3.55%
put_and_commit/db_store/50 4.9±0.28ms 4.9±0.45ms 0.00%
put_and_commit/mem_store/1 87.3±23.63µs 71.9±7.59µs -17.64%
put_and_commit/mem_store/10 673.2±62.84µs 681.7±62.63µs +1.26%
put_and_commit/mem_store/100 6.5±0.41ms 6.6±0.64ms +1.54%
put_and_commit/mem_store/5 340.7±54.86µs 351.3±39.99µs +3.11%
put_and_commit/mem_store/50 3.2±0.13ms 3.2±0.14ms 0.00%
query_block/query_block_in(10)_times(100) 8.3±0.43ms 8.5±0.36ms +2.41%
query_block/query_block_in(10)_times(1000) 83.7±4.45ms 85.4±3.56ms +2.03%
query_block/query_block_in(10)_times(10000) 842.2±27.01ms 844.9±28.74ms +0.32%
query_block/query_block_in(1000)_times(100) 1202.6±15.82µs 1234.0±60.54µs +2.61%
query_block/query_block_in(1000)_times(1000) 11.9±0.28ms 13.2±1.32ms +10.92%
query_block/query_block_in(1000)_times(10000) 119.3±4.24ms 121.1±4.14ms +1.51%
storage_transaction 1112.9±425.37µs 1060.3±396.10µs -4.73%
vm/transaction_execution/1 399.7±16.93ms 388.6±5.73ms -2.78%
vm/transaction_execution/10 126.1±5.63ms 125.2±4.29ms -0.71%
vm/transaction_execution/20 122.2±4.25ms 118.3±4.34ms -3.19%
vm/transaction_execution/5 156.2±3.45ms 157.8±6.43ms +1.02%
vm/transaction_execution/50 133.1±4.81ms 133.6±4.81ms +0.38%

Copy link

Benchmark for 6030bf6

Click to view benchmark
Test Base PR %
accumulator_append 763.7±98.47µs 757.0±65.06µs -0.88%
block_apply/block_apply_10 369.0±17.22ms 409.1±55.09ms +10.87%
block_apply/block_apply_1000 39.9±0.89s 40.3±0.31s +1.00%
get_with_proof/db_store 45.3±3.43µs 44.9±1.84µs -0.88%
get_with_proof/mem_store 37.5±2.32µs 36.7±1.51µs -2.13%
put_and_commit/db_store/1 119.0±11.17µs 119.6±9.82µs +0.50%
put_and_commit/db_store/10 1055.2±67.17µs 1029.4±67.54µs -2.45%
put_and_commit/db_store/100 10.0±0.52ms 9.6±0.95ms -4.00%
put_and_commit/db_store/5 547.2±31.73µs 559.2±39.32µs +2.19%
put_and_commit/db_store/50 5.0±0.46ms 4.9±0.41ms -2.00%
put_and_commit/mem_store/1 70.7±6.83µs 72.4±7.98µs +2.40%
put_and_commit/mem_store/10 662.7±62.91µs 656.0±61.01µs -1.01%
put_and_commit/mem_store/100 6.4±0.58ms 6.4±0.35ms 0.00%
put_and_commit/mem_store/5 330.5±32.19µs 336.0±29.96µs +1.66%
put_and_commit/mem_store/50 3.2±0.16ms 3.3±0.22ms +3.13%
query_block/query_block_in(10)_times(100) 8.6±0.51ms 8.6±0.37ms 0.00%
query_block/query_block_in(10)_times(1000) 86.3±9.70ms 82.2±2.59ms -4.75%
query_block/query_block_in(10)_times(10000) 843.0±31.49ms 848.6±27.03ms +0.66%
query_block/query_block_in(1000)_times(100) 1228.8±39.50µs 1199.3±51.24µs -2.40%
query_block/query_block_in(1000)_times(1000) 12.6±0.62ms 12.0±0.55ms -4.76%
query_block/query_block_in(1000)_times(10000) 121.9±4.39ms 120.8±4.94ms -0.90%
storage_transaction 1108.0±435.74µs 1116.1±455.92µs +0.73%
vm/transaction_execution/1 404.9±16.61ms 402.3±14.88ms -0.64%
vm/transaction_execution/10 128.4±7.62ms 133.5±6.87ms +3.97%
vm/transaction_execution/20 118.2±4.49ms 120.3±5.66ms +1.78%
vm/transaction_execution/5 155.0±7.43ms 158.4±8.12ms +2.19%
vm/transaction_execution/50 133.5±5.54ms 134.7±7.40ms +0.90%

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.

1 participant