fix(drive): fix verification data contract verification logic with keeps history
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<DataContract>) 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:
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have added or updated relevant unit/integration/functional/e2e tests
- [x] I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
- [x] I have made corresponding changes to the documentation if needed
For repository code-owners and collaborators only
- [x] 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.
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 fallbackpackages/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
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.
🪧 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
@coderabbitaiin a new review comment at the desired location with your query. - PR comments: Tag
@coderabbitaiin 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 ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.
@pshenmic there's a linting issue here.