Skip to content

Conversation

@shumkov
Copy link
Collaborator

@shumkov shumkov commented Feb 25, 2025

  • Introduced MasternodeListBuilder
  • Used Hash instead of byte array
  • Used BlockHash instead of byte array
  • Removed unnecessary vector allocations and sorting
  • Removed unused structure
  • Used macro to define encoding traits

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a flexible builder approach for configuring masternode lists, allowing for greater adaptability in setup.
  • Refactor

    • Improved the representation and handling of block identifiers and their associated computations for enhanced consistency.
    • Streamlined the verification and comparison processes for masternode data, leading to clearer and more reliable outputs.
    • Simplified hash calculation methods to enhance type specificity and consistency across the application.
  • Bug Fixes

    • Resolved issues with the processing of block hashes in verification statuses, ensuring accurate representation.
  • Chores

    • Removed redundant manual encoding and decoding implementations to enhance maintainability.
    • Deleted unused module to streamline the codebase.
    • Removed several redundant methods from the masternode list implementation to simplify functionality.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 25, 2025

Warning

Rate limit exceeded

@shumkov has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 24 minutes and 13 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 5b01626 and 06e802a.

📒 Files selected for processing (3)
  • dash/src/sml/masternode_list/apply_diff.rs (1 hunks)
  • dash/src/sml/masternode_list/builder.rs (1 hunks)
  • dash/src/sml/masternode_list/mod.rs (3 hunks)

Walkthrough

This pull request updates various parts of the masternode and quorum verification modules by replacing raw byte array representations with a more structured hash type (sha256d::Hash or BlockHash). It introduces a builder pattern for constructing masternode lists, simplifies comparison logic, and updates merkle root computations to enhance type specificity and consistency across the codebase.

Changes

File(s) Change Summary
dash/src/sml/llmq_entry_verification.rs Changed LLMQEntryVerificationSkipStatus::UnknownBlock from [u8; 32] to BlockHash and updated the Display implementation accordingly.
dash/src/sml/masternode_list/apply_diff.rs
dash/src/sml/masternode_list/builder.rs
dash/src/sml/masternode_list/mod.rs
Introduced MasternodeListBuilder to replace direct instantiation of MasternodeList, removed legacy creation methods, and updated module exports.
dash/src/sml/masternode_list/masternode_helpers.rs Removed several methods to streamline the MasternodeList implementation, simplifying masternode management.
dash/src/sml/masternode_list/merkle_roots.rs Updated merkle root functions and related methods to use sha256d::Hash instead of [u8; 32], adjusting internal processing and return types.
dash/src/sml/masternode_list_entry/hash.rs
dash/src/sml/masternode_list_entry/qualified_masternode_list_entry.rs
Modified hash calculation and field types in masternode list entry to return/use sha256d::Hash directly.
dash/src/sml/quorum_entry/qualified_quorum_entry.rs Updated update_quorum_status to pass block_hash directly to UnknownBlock, omitting the conversion to a byte array.
dash/src/network/message_sml.rs Removed manual Encodable and Decodable implementations for MnListDiff, replaced with macro impl_consensus_encoding!.
dash/src/sml/llmq_type/llmq_indexed_hash.rs Deleted the LLMQIndexedHash struct and its associated methods.
dash/src/sml/llmq_type/mod.rs Removed public declaration of the llmq_indexed_hash module, restricting its visibility.
dash/src/sml/masternode_list/debug_helpers.rs Updated the short_description method to directly access the length of the masternodes collection instead of calling a method.

Possibly related PRs

Poem

I'm a little rabbit, hopping with delight,
Code improvements shining oh so bright. 🐇
Block hashes now structured, neat and clear,
Masternode builders drawing ever near.
In every line and function, our changes cheer!
Hop along the code trail without any fear!
Happy coding, from my burrow to your terminal!


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.
  • @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.

@shumkov shumkov changed the title refactor: minor masternode list improvements based on #51 review refactor: masternode list improvements based on #51 review Feb 25, 2025
Copy link
Contributor

@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: 0

🧹 Nitpick comments (2)
dash/src/sml/masternode_list/masternode_helpers.rs (1)

81-81: Ensure you're not overlooking differences in keys
If the goal is to compare both the keys and the corresponding values, consider comparing the entire map instead of just the values. Otherwise, two maps with different keys but matching values in the same iteration order could incorrectly pass as equal.

Here is a potential fix:

-        self.masternodes.values().eq(list.masternodes.values())
+        self.masternodes == list.masternodes
dash/src/sml/masternode_list/builder.rs (1)

23-37: Good implementation of the new constructor.

Fields are properly initialized with None for the optional merkle roots. One small observation: the parameter order in the method signature (lines 23-28) doesn't match the field order in the struct initialization (lines 29-36). While this doesn't affect functionality, maintaining a consistent order would improve readability.

 Self {
-    quorums,
     block_hash,
     block_height,
     masternode_merkle_root: None,
     llmq_merkle_root: None,
     masternodes,
+    quorums,
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d634386 and 1cc06cc.

📒 Files selected for processing (9)
  • dash/src/sml/llmq_entry_verification.rs (3 hunks)
  • dash/src/sml/masternode_list/apply_diff.rs (2 hunks)
  • dash/src/sml/masternode_list/builder.rs (1 hunks)
  • dash/src/sml/masternode_list/masternode_helpers.rs (1 hunks)
  • dash/src/sml/masternode_list/merkle_roots.rs (6 hunks)
  • dash/src/sml/masternode_list/mod.rs (1 hunks)
  • dash/src/sml/masternode_list_entry/hash.rs (1 hunks)
  • dash/src/sml/masternode_list_entry/qualified_masternode_list_entry.rs (2 hunks)
  • dash/src/sml/quorum_entry/qualified_quorum_entry.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
dash/src/sml/masternode_list_entry/hash.rs (1)
Learnt from: QuantumExplorer
PR: dashpay/rust-dashcore#51
File: dash/src/sml/masternode_list_entry/hash.rs:7-12
Timestamp: 2025-02-25T06:19:32.230Z
Learning: The `consensus_encode` method on `MasternodeListEntry` writing to a `Vec` buffer cannot fail, so using `.expect()` is appropriate rather than propagating the error with the `?` operator.
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Tests (nightly, true, false, true)
  • GitHub Check: Tests (beta, true, false)
  • GitHub Check: Tests (stable, true, true, false)
  • GitHub Check: Tests (nightly, true, false, true)
  • GitHub Check: Tests (beta, true, false)
  • GitHub Check: Tests (stable, true, true, false)
🔇 Additional comments (23)
dash/src/sml/quorum_entry/qualified_quorum_entry.rs (1)

62-62: Use typed BlockHash for improved clarity
Switching from a raw byte array to a structured BlockHash is a welcome enhancement, as it promotes type safety and clarity in the code.

dash/src/sml/masternode_list/mod.rs (1)

11-15: Builder module introduction looks good
Re-exporting MasternodeListBuilder at the module level provides a clean entry point for users. This refactor nicely supports a more structured approach to constructing masternode lists.

dash/src/sml/masternode_list/apply_diff.rs (2)

4-4: Update imports to reflect the builder pattern addition

The import has been updated to include MasternodeListBuilder, which aligns with the refactoring to use the builder pattern instead of direct instantiation.


79-86: Improved code structure with builder pattern

The implementation now uses a builder pattern which provides better encapsulation and flexibility for object construction. This is a good improvement over direct instantiation.

dash/src/sml/masternode_list_entry/hash.rs (3)

1-1: Updated import for consistent hash type usage

The import has been updated to use sha256d from the hashes module, which aligns with the PR's goal of using structured hash types instead of raw byte arrays.


7-7: Return type improved to use sha256d::Hash

Changed the return type from raw byte array [u8; 32] to sha256d::Hash, enhancing type safety and consistency with other parts of the codebase.


11-11: Simplified hash calculation

Removed unnecessary to_byte_array() conversion, directly returning the hash. This aligns with the learnings from PR #51 where it was noted that this operation cannot fail, making .expect() appropriate.

dash/src/sml/masternode_list_entry/qualified_masternode_list_entry.rs (2)

5-5: Updated import for structured hash types

The import now includes sha256d from the hashes module, supporting the consistent use of structured hash types throughout the codebase.


21-21: Enhanced type safety with sha256d::Hash

Changed field type from raw byte array [u8; 32] to sha256d::Hash, improving type safety and consistency. This change aligns with the overall PR objective of using more structured hash types.

dash/src/sml/llmq_entry_verification.rs (3)

5-5: Updated import for BlockHash type

Added import for BlockHash type to support the enum variant type change.


16-16: Enhanced type safety in enum variant

Changed UnknownBlock variant from raw byte array [u8; 32] to BlockHash type, improving type safety and making the code more expressive and consistent with the rest of the codebase.


30-30: Simplified display formatting

Updated the Display implementation to directly use the block_hash without additional encoding, which is possible because the BlockHash type implements the necessary display traits.

dash/src/sml/masternode_list/builder.rs (5)

1-8: Good import organization.

All necessary dependencies are properly imported and well-organized.


9-16: Well-designed builder pattern structure.

The MasternodeListBuilder struct is properly designed with clear fields that match the MasternodeList requirements. Using public fields is appropriate for a builder pattern.


19-21: Clear and concise empty constructor.

The empty method provides a convenient way to create a builder with default empty collections while reusing the new method implementation.


39-47: Effective method chaining implementation.

The with_merkle_roots method follows the builder pattern correctly by taking ownership of self, modifying it, and returning it for method chaining.


49-65: Good build method with automatic merkle root calculation.

The build method effectively constructs the MasternodeList and conditionally calculates merkle roots if they weren't explicitly provided. This makes the builder both flexible and robust.

dash/src/sml/masternode_list/merkle_roots.rs (6)

23-23: Type-safe hash handling improvement.

Changing from raw byte arrays to the specific sha256d::Hash type enhances type safety and makes the code more semantically clear.


32-38: Improved hash processing with proper type usage.

The hash processing now properly uses the sha256d::Hash type's methods like as_byte_array() and hash() instead of working with raw byte arrays. This provides better type safety and clarity.


129-129: Consistent type conversion using from_raw_hash.

Using from_raw_hash consistently improves code clarity by making it explicit that you're working with hash types rather than raw byte arrays.


143-143: Consistent type conversion for quorum merkle roots.

Similar to the masternode merkle root, using from_raw_hash here maintains consistency and type safety.


157-159: Updated return type documentation.

The comments and return type have been correctly updated to reflect the change from raw byte arrays to the specific hash type.


183-188: Improved quorum merkle root hash handling.

The function now correctly returns and processes sha256d::Hash types, and uses the appropriate to_raw_hash() method when mapping quorum entries.

@shumkov shumkov self-assigned this Feb 25, 2025
@shumkov shumkov changed the title refactor: masternode list improvements based on #51 review refactor: minor masternode list improvements based on #51 review Feb 25, 2025
@QuantumExplorer QuantumExplorer merged commit a457fea into master Feb 27, 2025
6 of 25 checks passed
@github-project-automation github-project-automation bot moved this from In review / testing to Done in Platform team Feb 27, 2025
@QuantumExplorer QuantumExplorer deleted the refactor/sml branch February 27, 2025 02:52
shumkov added a commit that referenced this pull request Feb 28, 2025
* feat: add single node quorum type

* chore: update lazy_static

* revert: lazy_static version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants