Skip to content

fix(drive): consolidate historical contract proof verification retry logic#3165

Draft
thepastaclaw wants to merge 5 commits intodashpay:v3.1-devfrom
thepastaclaw:fix/verify-contract-history-retry
Draft

fix(drive): consolidate historical contract proof verification retry logic#3165
thepastaclaw wants to merge 5 commits intodashpay:v3.1-devfrom
thepastaclaw:fix/verify-contract-history-retry

Conversation

@thepastaclaw
Copy link
Contributor

@thepastaclaw thepastaclaw commented Feb 28, 2026

Issue

When getDataContract is called for a contract with keepsHistory: true, it returns "Data contract not found" even though getDataContractHistory succeeds for the same contract.

Root cause: In verify_contract_v0, when contract_known_keeps_history is None (as it always is from FromProof<GetDataContractRequest>), the code defaults to the non-historical path. If that returns Ok(None) (contract not found on the non-historical path), it never retries with the historical path — it only retried on Err(_).

Changes

Core fix (both verify_contract and verify_contract_return_serialization)

  • Extracted _given_history helpers that perform verification with a known history flag
  • Consolidated retry logic into the entry point: when contract_known_keeps_history is None, retry with keeps_history = true if the first attempt returns Err(_) or Ok((_, None))
  • Removed scattered retry logic from deep inside the function body

Tests

  • Added test_contract_keeps_history_verify_with_unknown_history_flag regression test covering:
    1. None (unknown) — must succeed via retry for historical contracts
    2. Some(true) — direct historical verification
    3. Some(false) — non-historical contract verification
    4. verify_contract_return_serialization with None — parallel path coverage

Validation

  • cargo test -p drive
  • cargo clippy -p drive -- -D warnings

Summary by CodeRabbit

  • Bug Fixes

    • Improved contract verification logic to better handle cases where contract history state is unknown, with automatic retry capability when needed.
  • Tests

    • Added regression tests validating contract verification behavior across different history state scenarios.

…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.
@github-actions github-actions bot added this to the v3.1.0 milestone Feb 28, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 28, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 78184f6 and f992ab4.

📒 Files selected for processing (3)
  • packages/rs-drive/src/verify/contract/verify_contract/v0/mod.rs
  • packages/rs-drive/src/verify/contract/verify_contract_return_serialization/v0/mod.rs
  • packages/rs-drive/tests/query_tests.rs

Comment on lines +4702 to +4703
#[test]
fn test_contract_keeps_history_verify_with_unknown_history_flag() {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
#[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.

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.

2 participants