Skip to content

feat(platform): add getDataContractsLatestVersions query for cheap contract staleness checks - #4739

Merged
QuantumExplorer merged 1 commit into
v4.2-devfrom
claude/latest-contract-version-query-86ede3
Sep 14, 2026
Merged

QuantumExplorer merged 1 commit into
v4.2-devfrom
claude/latest-contract-version-query-86ede3

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

Clients that hold data contracts locally have no cheap way to check that they are still current: getDataContracts reads each contract from state, serializes it and sends the whole thing back, only for the client to compare one integer per contract. This adds getDataContractsLatestVersions, which takes a list of contract ids and returns each contract's current version number and nothing else unless the caller asks for the contracts too.

What was done?

  • Proto (platform.proto): getDataContractsLatestVersions with GetDataContractsLatestVersionsRequest { ids, include_contracts, prove } and a response carrying one DataContractLatestVersionEntry { identifier, optional version, optional data_contract } per requested id, or a proof. An id no contract has gets an entry without version. Registered in dapi-grpc/build.rs, the gRPC coverage cache and the DAPI endpoint list.
  • drive-abci (query/data_contract_based_queries/data_contracts_latest_versions): ids is bounded by max_returned_elements and must not be empty, like getDataContracts. The unproved form answers from Drive's contract cache through get_contracts_with_fetch_info, so a hit is a map lookup and the response is one u32 per contract; contracts are serialized only when include_contracts is set. The proved form reuses prove_contracts. Version bounds added as data_contract_based_queries.data_contracts_latest_versions in query versions V0 and V1 (plus the v2 test mock). No new rs-drive methods.
  • DAPI plumbing: rs-dapi drive_method! passthrough and metrics entry, rs-dapi-client transport impl.
  • Proof verifier: types::data_contracts_latest_versions::{DataContractLatestVersion { version, data_contract: Option<DataContract> }, DataContractsLatestVersions(RetrievedObjects<Identifier, DataContractLatestVersion>)} with a FromProof impl (verifies with Drive::verify_contracts and reads version() off each verified contract, keeping contracts only on request) and a FromUnproved impl for the fast path.
  • rs-sdk (platform/data_contracts_latest_versions.rs): DataContractLatestVersion::fetch_many(sdk, ids) (proved, via FetchMany<Identifier, DataContractsLatestVersions>) and DataContractsLatestVersions::fetch_unproved(sdk, ids) (the fast path); Query impls for Vec<Identifier> and for DataContractsLatestVersionsQuery { ids, include_contracts }. Mock support and the wire-query registration are included.
  • wasm-sdk / js-evo-sdk: getDataContractsLatestVersions({ contractIds, includeContracts? }) and the WithProofInfo variant returning a Map<string, DataContractLatestVersion | undefined>; contracts.getLatestVersions / getLatestVersionsWithProof facade methods; README line.

Note on proofs: a GroveDB item proof always carries the item's value, so the proved form is the same size as a getDataContracts proof whatever include_contracts says. The saving is on the unproved path. A smaller proof would need a storage change that keeps the version as its own element, which is out of scope here.

Swift/Kotlin FFI exposure is left for a follow-up PR, as was done for getDataContractsByRange (#4734).

How Has This Been Tested?

  • rs-drive-abci/.../data_contracts_latest_versions/v0/mod.rs: invalid id, empty and oversized id lists, missing contract entry without version, absence proof, versions without contracts in id order, contracts on request, proof for stored contracts, and a warm-cache read followed by a contract update that must report the new version (cargo test -p drive-abci --lib data_contracts_latest_versions).
  • rs-drive-proof-verifier/src/proof/data_contracts_latest_versions.rs and unproved.rs: request validation errors, unproved parsing with and without contracts and with a missing id, proof-where-values-expected and missing-metadata rejection (cargo test -p drive-proof-verifier --lib data_contracts_latest_versions).
  • rs-sdk/tests/fetch/data_contracts_latest_versions.rs: proved read with a known and an unknown id, read with contracts, and unproved agreement; gated as ignored in offline mode until vectors are recorded with scripts/generate_test_vectors.sh.
  • wasm-sdk/tests/functional/contracts.spec.ts and js-evo-sdk/tests/unit/facades/contracts.spec.ts extended; ESLint passes. The js-evo-sdk unit test and tsc were not run locally because they need a built @dashevo/wasm-sdk.
  • cargo clippy --all-targets -- -D warnings on drive-abci, drive-proof-verifier, dash-sdk, rs-dapi and rs-dapi-client; cargo check -p wasm-sdk --target wasm32-unknown-unknown; check-grpc-coverage.py.

Breaking Changes

None. This is a new read-only query; no state, consensus or existing endpoint changes.

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

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 50 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 3eb8a91e-c917-4057-95bb-07b32640d8d7

📥 Commits

Reviewing files that changed from the base of the PR and between 5659f3d and 6a1d08a.

📒 Files selected for processing (32)
  • .github/grpc-queries-cache.json
  • packages/dapi-grpc/build.rs
  • packages/dapi-grpc/protos/platform/v0/platform.proto
  • packages/dapi/doc/endpoints/index.md
  • packages/js-evo-sdk/src/contracts/facade.ts
  • packages/js-evo-sdk/tests/unit/facades/contracts.spec.ts
  • packages/rs-dapi-client/src/transport/grpc.rs
  • packages/rs-dapi/src/metrics.rs
  • packages/rs-dapi/src/services/platform_service/mod.rs
  • packages/rs-drive-abci/src/query/data_contract_based_queries/data_contracts_latest_versions/mod.rs
  • packages/rs-drive-abci/src/query/data_contract_based_queries/data_contracts_latest_versions/v0/mod.rs
  • packages/rs-drive-abci/src/query/data_contract_based_queries/mod.rs
  • packages/rs-drive-abci/src/query/service.rs
  • packages/rs-drive-proof-verifier/src/proof.rs
  • packages/rs-drive-proof-verifier/src/proof/data_contracts_latest_versions.rs
  • packages/rs-drive-proof-verifier/src/types.rs
  • packages/rs-drive-proof-verifier/src/types/data_contracts_latest_versions.rs
  • packages/rs-drive-proof-verifier/src/unproved.rs
  • packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_query_versions/mod.rs
  • packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_query_versions/v0.rs
  • packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_query_versions/v1.rs
  • packages/rs-platform-version/src/version/mocks/v2_test.rs
  • packages/rs-sdk/src/mock/requests.rs
  • packages/rs-sdk/src/mock/sdk.rs
  • packages/rs-sdk/src/platform.rs
  • packages/rs-sdk/src/platform/data_contracts_latest_versions.rs
  • packages/rs-sdk/src/platform/query.rs
  • packages/rs-sdk/tests/fetch/data_contracts_latest_versions.rs
  • packages/rs-sdk/tests/fetch/mod.rs
  • packages/wasm-sdk/README.md
  • packages/wasm-sdk/src/queries/data_contract.rs
  • packages/wasm-sdk/tests/functional/contracts.spec.ts

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.

@github-actions github-actions Bot added this to the v4.2.0 milestone Sep 14, 2026
@thepastaclaw

thepastaclaw commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

🕓 Queued for automated review — 8th in line, estimated start in ~40 min (commit 6a1d08a)
Estimated review time once started: ~10 min (two-phase automated review; median of recent runs).

  • Request priority review — tick this box and the review moves to the front of the queue.

@codecov

codecov Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.09945% with 101 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.18%. Comparing base (66efe32) to head (6a1d08a).
⚠️ Report is 15 commits behind head on v4.2-dev.

Files with missing lines Patch % Lines
...rifier/src/proof/data_contracts_latest_versions.rs 0.00% 47 Missing ⚠️
...ased_queries/data_contracts_latest_versions/mod.rs 0.00% 41 Missing ⚠️
...rifier/src/types/data_contracts_latest_versions.rs 0.00% 11 Missing ⚠️
...d_queries/data_contracts_latest_versions/v0/mod.rs 99.23% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           v4.2-dev    #4739      +/-   ##
============================================
+ Coverage     83.15%   83.18%   +0.03%     
============================================
  Files          2836     2843       +7     
  Lines        389307   390298     +991     
============================================
+ Hits         323718   324681     +963     
- Misses        65589    65617      +28     
Components Coverage Δ
dpp 83.66% <ø> (-0.02%) ⬇️
drive 84.35% <ø> (+0.25%) ⬆️
drive-abci 86.02% <85.85%> (-0.23%) ⬇️
sdk ∅ <ø> (∅)
dapi-client ∅ <ø> (∅)
platform-version ∅ <ø> (∅)
platform-value 70.53% <ø> (ø)
platform-wallet ∅ <ø> (∅)
drive-proof-verifier 34.63% <0.00%> (-0.48%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@thephez thephez added the dapi-endpoint DAPI endpoint addition or modification label Sep 14, 2026
…ntract staleness checks

Adds a query that returns the current version number of each requested
data contract without the contracts themselves unless `include_contracts`
is set. The unproved form is answered from Drive's contract cache with one
integer per contract, so a client can check that the contracts it holds are
still current at the cost of a map lookup each. Every requested id gets an
entry; an id no contract has gets an entry without a version. The proved
form reuses the multi-contract proof, which carries the contracts because
GroveDB proves an item with its value; the verifier reads the versions off
the verified contracts.

Wired through proto, rs-dapi, rs-dapi-client, drive-abci (with query
version bounds), the proof verifier (proved and unproved parsers), rs-sdk
(FetchMany and FetchUnproved), wasm-sdk and js-evo-sdk, mirroring the
getDataContracts layout.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@QuantumExplorer
QuantumExplorer force-pushed the claude/latest-contract-version-query-86ede3 branch from 5e5655d to 6a1d08a Compare September 14, 2026 15:20
@QuantumExplorer QuantumExplorer changed the title feat(platform): add getDataContractLatestVersion query for cheap contract staleness checks feat(platform): add getDataContractsLatestVersions query for cheap contract staleness checks Sep 14, 2026
@QuantumExplorer
QuantumExplorer merged commit 51189ad into v4.2-dev Sep 14, 2026
46 of 48 checks passed
@QuantumExplorer
QuantumExplorer deleted the claude/latest-contract-version-query-86ede3 branch September 14, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dapi-endpoint DAPI endpoint addition or modification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants