fix(drive): consolidate historical contract proof verification retry logic#3165
fix(drive): consolidate historical contract proof verification retry logic#3165thepastaclaw wants to merge 5 commits intodashpay:v3.1-devfrom
Conversation
…logic When contract_known_keeps_history is None, any result other than Ok((hash, Some(contract))) now triggers exactly one retry with history enabled. Previously, retry logic was scattered across multiple match arms and several failure paths bypassed it entirely. Refactored verify_contract_v0 and verify_contract_return_serialization_v0 to extract _given_history helpers containing the pure verification logic, with retry decisions made solely in the outer functions. Added regression test: test_contract_keeps_history_verify_with_unknown_history_flag
The previous commit incorrectly restricted retry to Err(_) only, but Ok(None) from the non-historical path is a legitimate trigger for historical retry — it means the contract exists in the historical path, not that it's absent. Restoring the _ catch-all preserves the original fix from a7fec8b. Test assertions now require contracts to be returned (not accept None) for cases where the contract definitely exists, eliminating tautological acceptance paths.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/rs-drive/tests/query_tests.rs`:
- Around line 4702-4703: Rename the test function
test_contract_keeps_history_verify_with_unknown_history_flag to follow the
repository convention by starting with "should_"; update the function signature
(fn test_contract_keeps_history_verify_with_unknown_history_flag) to a
descriptive name beginning with should_, e.g.
should_contract_keep_history_verify_with_unknown_history_flag, and update any
references or test runners expecting the old name so the test still compiles and
runs.
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/rs-drive/src/verify/contract/verify_contract/v0/mod.rspackages/rs-drive/src/verify/contract/verify_contract_return_serialization/v0/mod.rspackages/rs-drive/tests/query_tests.rs
| #[test] | ||
| fn test_contract_keeps_history_verify_with_unknown_history_flag() { |
There was a problem hiding this comment.
Rename the new test to follow the repository test naming rule.
The new test name should start with should_... to match the project’s test naming convention.
✏️ Suggested rename
- fn test_contract_keeps_history_verify_with_unknown_history_flag() {
+ fn should_verify_contract_keeps_history_when_history_flag_is_unknown() {As per coding guidelines: **/tests/**/*.{js,jsx,ts,tsx,rs}: Name tests descriptively, starting with 'should …'.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| #[test] | |
| fn test_contract_keeps_history_verify_with_unknown_history_flag() { | |
| #[test] | |
| fn should_verify_contract_keeps_history_when_history_flag_is_unknown() { |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/rs-drive/tests/query_tests.rs` around lines 4702 - 4703, Rename the
test function test_contract_keeps_history_verify_with_unknown_history_flag to
follow the repository convention by starting with "should_"; update the function
signature (fn test_contract_keeps_history_verify_with_unknown_history_flag) to a
descriptive name beginning with should_, e.g.
should_contract_keep_history_verify_with_unknown_history_flag, and update any
references or test runners expecting the old name so the test still compiles and
runs.
Issue
When
getDataContractis called for a contract withkeepsHistory: true, it returns "Data contract not found" even thoughgetDataContractHistorysucceeds for the same contract.Root cause: In
verify_contract_v0, whencontract_known_keeps_historyisNone(as it always is fromFromProof<GetDataContractRequest>), the code defaults to the non-historical path. If that returnsOk(None)(contract not found on the non-historical path), it never retries with the historical path — it only retried onErr(_).Changes
Core fix (both
verify_contractandverify_contract_return_serialization)_given_historyhelpers that perform verification with a known history flagcontract_known_keeps_historyisNone, retry withkeeps_history = trueif the first attempt returnsErr(_)orOk((_, None))Tests
test_contract_keeps_history_verify_with_unknown_history_flagregression test covering:None(unknown) — must succeed via retry for historical contractsSome(true)— direct historical verificationSome(false)— non-historical contract verificationverify_contract_return_serializationwithNone— parallel path coverageValidation
cargo test -p drive✅cargo clippy -p drive -- -D warnings✅Summary by CodeRabbit
Bug Fixes
Tests