Skip to content

Conversation

pshenmic
Copy link
Collaborator

@pshenmic pshenmic commented Aug 17, 2025

Issue being fixed or feature implemented

There is a optional contract_known_keeps_history param in the verify_contract_v0 method, which may be passed if you know that specific setting for you data contract, or you can simply pass None, and in that case verification will be made for both values.

The logic relies on on catching error and retrying again with flag enabled, in case there was a error during verification with flag disabled:

Err(e) => {
    if contract_known_keeps_history.is_some() {
        // just return error
        Err(e)
    } else {
        tracing::debug!(?path_query,error=?e, "retry contract verification with history enabled");
        Self::verify_contract(
            proof,
            Some(true),
            is_proof_subset,
            in_multiple_contract_proof_form,
            contract_id,
            platform_version,
        )
    }
}

However, this never happens, because verification function does not throw a error if contract wasn't found, and it returns Option) which resolves to None instead, and it goes in separate match and this case is not handled, leading to receiving false negative result when querying data contract with option of keep history ommited.

This PR adds an additional check on None in Ok match body of result of verification function that now correctly retries in both cases (error or none)

What was done?

Added additional check to verify_contract_v0 function for better handling when contract_known_keeps_history is None

How Has This Been Tested?

In production in dash-platform-sdk

Breaking Changes

No

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 added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • Bug Fixes
    • Improved contract verification reliability by automatically retrying with historical data when a current version isn’t found.
    • Reduced false negatives and intermittent verification failures, especially for contracts that retain history.
    • Preserved existing behavior for successful lookups and error handling; no public API changes or configuration updates required.

@pshenmic pshenmic added this to the v2.1 milestone Aug 17, 2025
Copy link
Contributor

coderabbitai bot commented Aug 17, 2025

Walkthrough

Adds a fallback in verify_contract_v0: when a non-historical lookup returns None and the contract isn’t known to keep history, it retries verification with history enabled. Behavior for successful Some(contract) and for errors remains as before, including retry-on-error when history wasn’t specified.

Changes

Cohort / File(s) Summary
Contract verification fallback
packages/rs-drive/src/verify/contract/verify_contract/v0/mod.rs
Adjusted Ok branch to treat contract as Option; if None and history not confirmed, retry with contract_known_keeps_history=Some(true). Preserved existing return on Some(contract) and existing Err retry behavior when history flag wasn’t set. No public signatures changed.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant VerifyV0 as verify_contract_v0
  participant Store as ContractStore

  Caller->>VerifyV0: verify_contract(contract_id, history_flag=None/false)
  VerifyV0->>Store: fetch(contract_id, historical=history_flag)
  Store-->>VerifyV0: (root_hash, Option<DataContract>)
  alt Contract found (Some)
    VerifyV0-->>Caller: return (root_hash, contract)
  else Not found (None) and history not confirmed
    VerifyV0->>VerifyV0: retry with history_flag=Some(true)
    VerifyV0->>Store: fetch(contract_id, historical=true)
    Store-->>VerifyV0: (root_hash, Option<DataContract>)
    VerifyV0-->>Caller: return result
  else Not found (None) but history confirmed
    VerifyV0-->>Caller: return (root_hash, None)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • lklimek
  • QuantumExplorer

Poem

A nibble of code, a hop through time,
I toggled history—oh how sublime!
First burrow’s empty? Try the old trail;
Second hop finds the contract’s tale.
With whiskers twitching, I press “re-run,”
Now carrots and contracts—both well done! 🥕🐇

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/drive-verify-contract

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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
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)
packages/rs-drive/src/verify/contract/verify_contract/v0/mod.rs (2)

133-144: Nit: Use idiomatic boolean negation and add a debug log for parity with the Err(e) path

Make the condition more idiomatic and emit a debug log when retrying due to a None result to aid observability.

-                        if contract_known_keeps_history.unwrap_or_default() != true {
+                        if !contract_known_keeps_history.unwrap_or(false) {
+                            tracing::debug!(?path_query, "retry contract verification with history enabled on None result");
                             Self::verify_contract(
                                 proof,
                                 Some(true),
                                 is_proof_subset,
                                 in_multiple_contract_proof_form,
                                 contract_id,
                                 platform_version,
                             )
-                        } else{
+                        } else {
                             Ok((root_hash, contract))
                         }

131-147: Confirm test coverage for the Ok(None) fallback path

Please ensure there are tests asserting:

  • Non-historical lookup returns None and triggers historical retry when contract_known_keeps_history is None (both subset and multi-contract proof forms).
  • No retry occurs when contract_known_keeps_history is Some(true) and the result is None.

I can help add/adjust these if gaps remain.

📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bcdda30 and f45f15c.

📒 Files selected for processing (1)
  • packages/rs-drive/src/verify/contract/verify_contract/v0/mod.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
  • GitHub Check: Rust packages (drive-abci) / Check each feature
  • GitHub Check: Rust packages (drive-abci) / Formatting
  • GitHub Check: Rust packages (drive-abci) / Unused dependencies
  • GitHub Check: Rust packages (drive-abci) / Linting
  • GitHub Check: Rust packages (drive-abci) / Tests
  • GitHub Check: Rust packages (drive) / Tests
  • GitHub Check: Rust packages (drive) / Linting
  • GitHub Check: Rust packages (drive) / Formatting
  • GitHub Check: Rust packages (drive) / Unused dependencies
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Check each feature
  • GitHub Check: Rust packages (dash-sdk) / Unused dependencies
  • GitHub Check: Rust packages (dash-sdk) / Linting
  • GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: build-and-test-wasm-sdk
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • GitHub Check: Build JS packages / Build JS
  • GitHub Check: build-wasm-sdk
🔇 Additional comments (1)
packages/rs-drive/src/verify/contract/verify_contract/v0/mod.rs (1)

131-147: Fallback on Ok(None) matches intended semantics — LGTM

The added retry on Ok(None) when contract_known_keeps_history is None closes the false-negative gap and mirrors the existing Err(e) fallback. No risk of infinite recursion since the second call sets Some(true). Behavior for Some(contract) remains unchanged.

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