Repository navigation
feat(platform): add getDataContractsLatestVersions query for cheap contract staleness checks - #4739
Conversation
|
Warning Review limit reachedNext included review available in 50 minutes. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (32)
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 |
|
🕓 Queued for automated review — 8th in line, estimated start in ~40 min (commit 6a1d08a)
|
Codecov Report❌ Patch coverage is 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
🚀 New features to boost your workflow:
|
…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>
5e5655d to
6a1d08a
Compare
Issue being fixed or feature implemented
Clients that hold data contracts locally have no cheap way to check that they are still current:
getDataContractsreads each contract from state, serializes it and sends the whole thing back, only for the client to compare one integer per contract. This addsgetDataContractsLatestVersions, 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?
platform.proto):getDataContractsLatestVersionswithGetDataContractsLatestVersionsRequest { ids, include_contracts, prove }and a response carrying oneDataContractLatestVersionEntry { identifier, optional version, optional data_contract }per requested id, or a proof. An id no contract has gets an entry withoutversion. Registered indapi-grpc/build.rs, the gRPC coverage cache and the DAPI endpoint list.query/data_contract_based_queries/data_contracts_latest_versions):idsis bounded bymax_returned_elementsand must not be empty, likegetDataContracts. The unproved form answers from Drive's contract cache throughget_contracts_with_fetch_info, so a hit is a map lookup and the response is oneu32per contract; contracts are serialized only wheninclude_contractsis set. The proved form reusesprove_contracts. Version bounds added asdata_contract_based_queries.data_contracts_latest_versionsin query versions V0 and V1 (plus the v2 test mock). No new rs-drive methods.drive_method!passthrough and metrics entry, rs-dapi-client transport impl.types::data_contracts_latest_versions::{DataContractLatestVersion { version, data_contract: Option<DataContract> }, DataContractsLatestVersions(RetrievedObjects<Identifier, DataContractLatestVersion>)}with aFromProofimpl (verifies withDrive::verify_contractsand readsversion()off each verified contract, keeping contracts only on request) and aFromUnprovedimpl for the fast path.platform/data_contracts_latest_versions.rs):DataContractLatestVersion::fetch_many(sdk, ids)(proved, viaFetchMany<Identifier, DataContractsLatestVersions>) andDataContractsLatestVersions::fetch_unproved(sdk, ids)(the fast path);Queryimpls forVec<Identifier>and forDataContractsLatestVersionsQuery { ids, include_contracts }. Mock support and the wire-query registration are included.getDataContractsLatestVersions({ contractIds, includeContracts? })and theWithProofInfovariant returning aMap<string, DataContractLatestVersion | undefined>;contracts.getLatestVersions/getLatestVersionsWithProoffacade 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
getDataContractsproof whateverinclude_contractssays. 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.rsandunproved.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 withscripts/generate_test_vectors.sh.wasm-sdk/tests/functional/contracts.spec.tsandjs-evo-sdk/tests/unit/facades/contracts.spec.tsextended; ESLint passes. The js-evo-sdk unit test andtscwere not run locally because they need a built@dashevo/wasm-sdk.cargo clippy --all-targets -- -D warningson 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:
For repository code-owners and collaborators only
🤖 Generated with Claude Code