Skip to content

Conversation

@UdjinM6
Copy link

@UdjinM6 UdjinM6 commented Apr 4, 2025

Issue being fixed or feature implemented

Before this PR you could get baseBlockHash as all 0s for some cases. Also, a known baseBlockHash that matched the cycleHash was ignored which means that results included quorum changes from an older known baseBlockHash till the cycleHash(which is the same as the baseBlockHash in question) i.e. these changes were already known to the requester.

What was done?

Pls see individual commits

How Has This Been Tested?

Run tests

Breaking Changes

n/a, results should simply be a bit more meaningful and compact

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@UdjinM6 UdjinM6 added this to the 23 milestone Apr 4, 2025
@coderabbitai
Copy link

coderabbitai bot commented Apr 4, 2025

Walkthrough

The changes update the logic for obtaining the last valid base block hash and expand the testing of quorum rotation. In the block snapshot module, the GetLastBaseBlockHash function now initializes the hash variable to the genesis block's hash, ensuring a valid return even if no other base block is found. Additionally, the loop condition was modified to only consider base blocks with a strictly greater height than the reference block, altering the selection criteria for the last valid base block hash.

In parallel, the test framework for quorum rotation was enhanced by adding a new scenario that verifies the output of the "quorum rotationinfo" RPC call. The test retrieves multiple block hashes and validates the structure and consistency of the returned RPC data, confirming correct block hash associations and quorum list content. No changes were made to public or exported entity declarations.


📜 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 4f57afa and 8b9a728.

📒 Files selected for processing (1)
  • test/functional/feature_llmq_rotation.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/functional/feature_llmq_rotation.py
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: x86_64-w64-mingw32 / Build depends
  • GitHub Check: x86_64-apple-darwin / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_nowallet / Build depends
  • GitHub Check: x86_64-pc-linux-gnu / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_multiprocess / Build depends
  • GitHub Check: arm-linux-gnueabihf / Build depends

🪧 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.

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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1549daa and 275ed8e.

📒 Files selected for processing (2)
  • src/llmq/snapshot.cpp (1 hunks)
  • test/functional/feature_llmq_rotation.py (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Clang Diff Format Check
src/llmq/snapshot.cpp

[error] 399-399: Clang format differences found. Please run 'clang-format' to fix formatting issues.

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: x86_64-apple-darwin / Build depends
  • GitHub Check: x86_64-w64-mingw32 / Build depends
  • GitHub Check: x86_64-pc-linux-gnu / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_multiprocess / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_nowallet / Build depends
  • GitHub Check: arm-linux-gnueabihf / Build depends
🔇 Additional comments (1)
test/functional/feature_llmq_rotation.py (1)

234-249: Good test coverage for quorum rotationinfo RPC.

This test ensures that the changes to the GetLastBaseBlockHash function are properly validated. The assertions verify that:

  1. Block hashes are correctly passed through the rotation info response
  2. The base block hash hierarchy is maintained (tip → H → HMinusC)
  3. The HMinusC base block hash matches the provided hmc_base_blockhash
  4. Empty quorum lists are correctly returned for HMinusC
  5. The genesis block hash is correctly used as the fallback for the oldest blocks

These tests directly address the issues fixed in the GetLastBaseBlockHash function, ensuring the rotation info results are meaningful and compact.

Comment on lines +399 to +400
// default to genesis block
uint256 hash{Params().GenesisBlock().GetHash()};
Copy link

@coderabbitai coderabbitai bot Apr 4, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Good addition of a sensible default value.

Initializing the hash variable to the genesis block hash ensures the function always returns a valid hash, even if no valid base blocks are found in the loop. This addresses an issue where baseBlockHash could incorrectly return all zeros in some edge cases.

However, there is a Clang format issue reported in the pipeline:

[error] 399-399: Clang format differences found. Please run 'clang-format' to fix formatting issues.

Please run clang-format to fix this formatting issue.

🧰 Tools
🪛 GitHub Actions: Clang Diff Format Check

[error] 399-399: Clang format differences found. Please run 'clang-format' to fix formatting issues.

Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we need to set genesis block here? Is it still possible situation when hash can be default?

Copy link

Choose a reason for hiding this comment

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

@knst The genesis block initialization ensures the function always returns a valid hash rather than an uninitialized value.

This change prevents undefined behavior that could occur in two scenarios:

  1. When baseBlockIndexes is empty
  2. When all base blocks have heights greater than the target block's height

In either case, the loop would finish without assigning anything to hash, potentially returning all zeros or garbage data. By defaulting to the genesis block hash, we ensure a meaningful fallback value is always returned.

After this change, there's no possibility of the hash remaining in an uninitialized state.


🧬 Code Definitions Used
### Relevant Code Snippets for `src/llmq/snapshot.cpp`

1. **Function: `GetLastBaseBlockHash`**
   - **Filename:** `src/llmq/snapshot.cpp`
   - **Line Range:** 215-216
   - **Description:**
     ```cpp
     uint256 GetLastBaseBlockHash(Span<const CBlockIndex*> baseBlockIndexes, const CBlockIndex* blockIndex,
                                  bool use_legacy_construction)
     ```
     - **Parameters:**
       - `baseBlockIndexes`: A span of pointers to `CBlockIndex` representing base block indexes.
       - `blockIndex`: A pointer to the `CBlockIndex` for which the last base block hash is to be determined.
       - `use_legacy_construction`: A boolean indicating whether to use legacy construction logic.
     - **Returns:** The hash of the last base block as a `uint256`.
     - **Exceptions/Error Handling:** None specified; assumes valid inputs.

2. **Function: `BuildQuorumRotationInfo`**
   - **Filename:** `src/llmq/snapshot.cpp`
   - **Line Range:** 48-48
   - **Description:**
     ```cpp
     bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotManager& qsnapman,
                                  const ChainstateManager& chainman, const CQuorumManager& qman,
                                  const CQuorumBlockProcessor& qblockman, const CGetQuorumRotationInfo& request,
                                  bool use_legacy_construction, CQuorumRotationInfo& response, std::string& errorRet)
     ```
     - **Parameters:**
       - `dmnman`: A reference to a `CDeterministicMNManager` instance.
       - `qsnapman`: A reference to a `CQuorumSnapshotManager` instance.
       - `chainman`: A reference to a `ChainstateManager` instance.
       - `qman`: A reference to a `CQuorumManager` instance.
       - `qblockman`: A reference to a `CQuorumBlockProcessor` instance.
       - `request`: A `CGetQuorumRotationInfo` request object.
       - `use_legacy_construction`: A boolean indicating whether to use legacy construction logic.
       - `response`: A reference to a `CQuorumRotationInfo` object to populate with the response.
       - `errorRet`: A string to capture any error messages.
     - **Returns:** `true` if successful, `false` otherwise.
     - **Exceptions/Error Handling:** Populates `errorRet` with error messages for various failure conditions.

3. **Function: `GetSnapshotForBlock`**
   - **Filename:** `src/llmq/snapshot.h`
   - **Line Range:** 231-231
   - **Description:**
     ```cpp
     std::optional<CQuorumSnapshot> GetSnapshotForBlock(const Consensus::LLMQType llmqType, const CBlockIndex* pindex)
     ```
     - **Parameters:**
       - `llmqType`: The type of the LLMQ (Long-Living Masternode Quorum).
       - `pindex`: A pointer to the `CBlockIndex` for which the snapshot is requested.
     - **Returns:** An optional `CQuorumSnapshot` if found, otherwise `std::nullopt`.
     - **Exceptions/Error Handling:** None specified; assumes valid inputs.

4. **Function: `StoreSnapshotForBlock`**
   - **Filename:** `src/llmq/snapshot.h`
   - **Line Range:** 232-232
   - **Description:**
     ```cpp
     void StoreSnapshotForBlock(const Consensus::LLMQType llmqType, const CBlockIndex* pindex, const CQuorumSnapshot& snapshot)
     ```
     - **Parameters:**
       - `llmqType`: The type of the LLMQ.
       - `pindex`: A pointer to the `CBlockIndex` for which the snapshot is being stored.
       - `snapshot`: The `CQuorumSnapshot` to store.
     - **Returns:** None.
     - **Exceptions/Error Handling:** None specified; assumes valid inputs.

Comment on lines +399 to +400
// default to genesis block
uint256 hash{Params().GenesisBlock().GetHash()};
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we need to set genesis block here? Is it still possible situation when hash can be default?

Copy link
Collaborator

@knst knst left a comment

Choose a reason for hiding this comment

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

LGTM 8b9a728

Copy link
Member

@PastaPastaPasta PastaPastaPasta left a comment

Choose a reason for hiding this comment

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

utACK 8b9a728

@UdjinM6 UdjinM6 modified the milestones: 23, 22.1.2 Apr 6, 2025
@PastaPastaPasta PastaPastaPasta merged commit bcd14b0 into dashpay:develop Apr 7, 2025
34 checks passed
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Apr 7, 2025
…edge cases, add tests

8b9a728 chore: drop redundant debug logging in tests (UdjinM6)
4f57afa chore: fix clang format (UdjinM6)
275ed8e test: a few trivial checks for `quorum rotationinfo` RPC (UdjinM6)
9c98f99 fix: off-by-one: do not ignore the base block which matches the requested block (UdjinM6)
422a695 fix: default to genesis block as the last base block (UdjinM6)

Pull request description:

  ## Issue being fixed or feature implemented
  Before this PR you could get `baseBlockHash` as all 0s for some cases. Also, a known `baseBlockHash` that matched the `cycleHash` was ignored which means that results included quorum changes from an older known `baseBlockHash` till the `cycleHash`(which is the same as the `baseBlockHash` in question) i.e. these changes were already known to the requester.

  ## What was done?
  Pls see individual commits

  ## How Has This Been Tested?
  Run tests

  ## Breaking Changes
  n/a, results should simply be a bit more meaningful and compact

  ## Checklist:
  - [ ] I have performed a self-review of my own code
  - [ ] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [ ] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

ACKs for top commit:
  PastaPastaPasta:
    utACK 8b9a728

Tree-SHA512: 88e5463ca0a40e3decb5cfcab948d7be2febc3583f7a24d455a5a93eb730e34c25246a1384fcfeea887a91348651e6250e226afa02b73f4403d8d10624a84d55
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Apr 14, 2025
…edge cases, add tests

8b9a728 chore: drop redundant debug logging in tests (UdjinM6)
4f57afa chore: fix clang format (UdjinM6)
275ed8e test: a few trivial checks for `quorum rotationinfo` RPC (UdjinM6)
9c98f99 fix: off-by-one: do not ignore the base block which matches the requested block (UdjinM6)
422a695 fix: default to genesis block as the last base block (UdjinM6)

Pull request description:

  ## Issue being fixed or feature implemented
  Before this PR you could get `baseBlockHash` as all 0s for some cases. Also, a known `baseBlockHash` that matched the `cycleHash` was ignored which means that results included quorum changes from an older known `baseBlockHash` till the `cycleHash`(which is the same as the `baseBlockHash` in question) i.e. these changes were already known to the requester.

  ## What was done?
  Pls see individual commits

  ## How Has This Been Tested?
  Run tests

  ## Breaking Changes
  n/a, results should simply be a bit more meaningful and compact

  ## Checklist:
  - [ ] I have performed a self-review of my own code
  - [ ] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [ ] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

ACKs for top commit:
  PastaPastaPasta:
    utACK 8b9a728

Tree-SHA512: 88e5463ca0a40e3decb5cfcab948d7be2febc3583f7a24d455a5a93eb730e34c25246a1384fcfeea887a91348651e6250e226afa02b73f4403d8d10624a84d55
PastaPastaPasta added a commit that referenced this pull request Apr 15, 2025
8b4ab03 fix: suppress MIN_MASTERNODE_PROTO_VERSION bump in 6608 (pasta)
aca04d1 chore: bump build to 22.1.2 (pasta)
d9d8c24 docs: add release notes for 22.1.2 (pasta)
fb45240 Merge #6608: fix: `cycleHash` should represent a cycle starting block of the signing quorum (pasta)
9d1498c Merge #6625: fix: adjust quorum rotation data results in some edge cases, add tests (pasta)
dfc1119 Merge #6622: fix: efficient build mnlistdiffs in rotation info (pasta)
6fd626b Merge #6586: fix: revert deployment images back to Ubuntu 22.04 LTS (`jammy`), pin QEMU to avoid segfault (pasta)
affa9d1 Merge #6599: fix: follow-up #6546 to bump copyright year in COPYING and debian's package (pasta)
f6163a2 Merge #6593: fix: resolve potential deadlock in coinjoin_tests (pasta)
243e0ab Merge #6585: fix: Do not assert special tx type for cbtx in simplified mn list diff output (pasta)
497f95c Merge #6581: perf: speedup of CBLSLazyPublicKey::operator== when comparing to the default / null object; speedup CDeterministicMNList::AddMN by avoiding check to IsValid when a nullcheck is sufficient (pasta)

Pull request description:

  ## Issue being fixed or feature implemented
  Backports for a new version, v22.1.2

  ## What was done?
  See release notes

  ## How Has This Been Tested?

  ## Breaking Changes
  None

  ## Checklist:
    _Go over all the following points, and put an `x` in all the boxes that apply._
  - [ ] I have performed a self-review of my own code
  - [ ] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

ACKs for top commit:
  UdjinM6:
    utACK 8b4ab03
  knst:
    utACK 8b4ab03

Tree-SHA512: 9f2f65e315940197cc2b75a6b0a858d624256cbe668272ff6dfa216eceda1ba9338484d47afc569202b3b5cc75b4dcb825209efe3a3d3ccec57c741f75c40577
PastaPastaPasta added a commit that referenced this pull request Apr 23, 2025
8b4ab03 fix: suppress MIN_MASTERNODE_PROTO_VERSION bump in 6608 (pasta)
aca04d1 chore: bump build to 22.1.2 (pasta)
d9d8c24 docs: add release notes for 22.1.2 (pasta)
fb45240 Merge #6608: fix: `cycleHash` should represent a cycle starting block of the signing quorum (pasta)
9d1498c Merge #6625: fix: adjust quorum rotation data results in some edge cases, add tests (pasta)
dfc1119 Merge #6622: fix: efficient build mnlistdiffs in rotation info (pasta)
6fd626b Merge #6586: fix: revert deployment images back to Ubuntu 22.04 LTS (`jammy`), pin QEMU to avoid segfault (pasta)
affa9d1 Merge #6599: fix: follow-up #6546 to bump copyright year in COPYING and debian's package (pasta)
f6163a2 Merge #6593: fix: resolve potential deadlock in coinjoin_tests (pasta)
243e0ab Merge #6585: fix: Do not assert special tx type for cbtx in simplified mn list diff output (pasta)
497f95c Merge #6581: perf: speedup of CBLSLazyPublicKey::operator== when comparing to the default / null object; speedup CDeterministicMNList::AddMN by avoiding check to IsValid when a nullcheck is sufficient (pasta)
4298d73 chore: bump to 22.1.1 (pasta)
fc65a16 chore: release notes for 22.1.1 (pasta)
38762f7 Merge #6574: fix: ReconnectionInfo should also store Dash-specific flags (pasta)
580b74c Merge #6566: fix(qt): avoid leaking balance and CJ info in GUI when in discreet mode (pasta)

Pull request description:

  ## Issue being fixed or feature implemented

  ## What was done?
  ff-ed `master` 21.1.0 -> 21.1.2, merging it back into `develop` now

  ## How Has This Been Tested?

  ## Breaking Changes

  ## Checklist:
  - [ ] I have performed a self-review of my own code
  - [ ] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [ ] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

ACKs for top commit:
  PastaPastaPasta:
    utACK 73fa780; gonna merge as this changes docs only

Tree-SHA512: f04fe461edc05c38771d684bd5d60327076251b8004723027276b104989ea6d84f7f77cce31f310f058e81f2c25411ab5a15b563cd3db66091ccaf33da459e3c
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.

3 participants