-
Notifications
You must be signed in to change notification settings - Fork 44
fix(drive): fix verification data contract verification logic with keeps history #2727
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
base: v2.1-dev
Are you sure you want to change the base?
Conversation
WalkthroughAdds 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
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
Poem
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 unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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) pathMake 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 pathPlease 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.
📒 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 — LGTMThe 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.
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:
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:
For repository code-owners and collaborators only
Summary by CodeRabbit