-
Notifications
You must be signed in to change notification settings - Fork 57
refactor(sdk)!: extract transport-free query core into dash-platform-queries #4388
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7277935
refactor(sdk)!: extract transport-free query core into dash-platform-…
PastaPastaPasta bdaa619
docs(sdk): document the transport-free consumption path
PastaPastaPasta 63e2e8a
ci: cover the transport-free feature cuts
PastaPastaPasta 7087bd2
build(docker): add dash-platform-queries to Dockerfile COPY lists
PastaPastaPasta 7aa98a2
docs(dash-platform-queries): correct migration notes in README
PastaPastaPasta 30265ca
docs(dash-platform-queries): deduplicate module docs and tighten phra…
PastaPastaPasta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| [package] | ||
| name = "dash-platform-queries" | ||
| description = "Transport-free query building and proof decoding core shared by Dash Platform SDK embedders" | ||
| version.workspace = true | ||
| edition = "2021" | ||
| rust-version.workspace = true | ||
| license = "MIT" | ||
|
|
||
| [features] | ||
| default = [] | ||
| mocks = [ | ||
| "dep:serde", | ||
| "dep:serde_json", | ||
| "dapi-grpc/mocks", | ||
| "drive/serde", | ||
| "dpp/serde-conversion", | ||
| ] | ||
|
|
||
| [dependencies] | ||
| dapi-grpc = { path = "../dapi-grpc", default-features = false, features = [ | ||
| "platform", | ||
| "client", | ||
| ] } | ||
| dash-context-provider = { path = "../rs-context-provider", default-features = false } | ||
| dash-platform-macros = { path = "../rs-dash-platform-macros" } | ||
| dpp = { path = "../rs-dpp", default-features = false, features = [ | ||
| "platform-value-cbor", | ||
| "state-transitions", | ||
| "state-transition-validation", | ||
| ] } | ||
| drive = { path = "../rs-drive", default-features = false, features = [ | ||
| "verify", | ||
| ] } | ||
| drive-proof-verifier = { path = "../rs-drive-proof-verifier", default-features = false } | ||
| hex = { version = "0.4.3" } | ||
| serde = { version = "1.0.219", default-features = false, features = [ | ||
| "rc", | ||
| ], optional = true } | ||
| serde_json = { version = "1.0", optional = true } | ||
| thiserror = "2.0.17" | ||
| tracing = { version = "0.1.41" } | ||
|
|
||
| [dev-dependencies] | ||
| dpp = { path = "../rs-dpp", default-features = false, features = [ | ||
| "fixtures-and-mocks", | ||
| ] } | ||
|
|
||
| [package.metadata.cargo-machete] | ||
| ignored = [ | ||
| # Used inside the `dash_platform_macros::Mockable` derive expansion under | ||
| # the `mocks` feature; machete cannot see through proc-macro output. | ||
| "serde_json", | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # dash-platform-queries | ||
|
|
||
| Transport-free query core of the Dash Platform SDK. | ||
|
|
||
| This crate carries the pieces of `dash-sdk` that build queries, encode them | ||
| onto the wire format, and decode/verify proved responses — with **no | ||
| transport implementation**: no `rs-dapi-client` and no tonic native | ||
| channel/TLS stack. Shared generated types and context-provider utilities | ||
| remain dependencies. `dash-sdk` depends on it and re-exports every moved | ||
| item at its historical path, so most imports keep compiling unchanged — but | ||
| the extraction is not fully source-compatible. Depending on what it uses, | ||
| downstream code may need to: | ||
|
|
||
| - import the `dash_sdk::platform::DocumentQuerySdk` extension trait to keep | ||
| calling `DocumentQuery::new_with_data_contract_id`, which fetches the | ||
| contract and therefore needs `&Sdk`; | ||
| - handle `dash_platform_queries::Error` — `DocumentQuery`'s fallible | ||
| methods now return it instead of `dash_sdk::Error`. `?` call sites keep | ||
| compiling via `From`; explicit return types and direct variant matches | ||
| need a conversion; | ||
| - implement the `dash_sdk::platform::WireQuery` marker trait | ||
| (`impl WireQuery for MyCustomRequest {}`) for custom `TransportRequest` | ||
| types used with the blanket `Query` impl. | ||
|
|
||
| ## Who this is for | ||
|
|
||
| Embedders that bring their own transport and trust context and only need the | ||
| verification/query layer: | ||
|
|
||
| - **Dash Core's platform GUI** — fetches over its own gRPC-Web transport, | ||
| serves quorum keys from its locally synced LLMQ state via a | ||
| [`ContextProvider`](../rs-context-provider), and verifies every response | ||
| proof with [`drive-proof-verifier`](../rs-drive-proof-verifier). | ||
| - Block explorers, Electrum-style servers, hardware-wallet tooling — anything | ||
| that talks to DAPI its own way but must not trust responses. | ||
|
|
||
| If you want networking, retries, and a managed connection pool, use | ||
| `dash-sdk` — it consumes this crate internally. | ||
|
|
||
| ## What's here | ||
|
|
||
| - `DocumentQuery` — rich document query builder with wire | ||
| encoding for both request versions. | ||
| - Aggregate proof helpers (count/sum/average/ranked) shared with `dash-sdk`. | ||
| - DPNS username helpers — label normalization/validation and the | ||
| convertibility/contested checks shared with `dash-sdk`. | ||
| - `transition::validation` — structural validation for state transitions | ||
| ahead of signing. | ||
|
|
||
| Wire-request decoding (`DocumentQuery::try_from_request`), request-driven | ||
| proof verification, and pure DPNS/DashPay document builders arrive in the | ||
| next slice of this series. | ||
|
|
||
| ## Feature flags | ||
|
|
||
| - `mocks` — serde support for the types used in dump/replay test vectors | ||
| (forwarded by `dash-sdk`'s `mocks`). | ||
|
|
||
| The dependency tree is checked in CI to stay free of the transport stack | ||
| (`hyper`, `rustls`, `tower`); see the "Check transport-free feature cuts" | ||
| step in `.github/workflows/tests-rs-workspace.yml`. | ||
|
|
||
| "Transport-free" means no networking stack, not an async-runtime-free graph: | ||
| `tokio` is still reachable on native targets through | ||
| `dash-context-provider` → `dash-async`, exactly as it already was for | ||
| `drive-proof-verifier` before this crate existed. `tonic` is present too, but | ||
| only for `dapi-grpc`'s generated message/client types — its transport feature | ||
| stays off, which is what the `hyper`/`rustls`/`tower` assertions prove. On | ||
| `wasm32-unknown-unknown` none of that is pulled in; the wasm assertions in the | ||
| same CI step also ban `mio`. |
47 changes: 47 additions & 0 deletions
47
packages/dash-platform-queries/src/block_info_from_metadata.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| use crate::Error; | ||
| use dapi_grpc::platform::v0::ResponseMetadata; | ||
| use dpp::block::block_info::BlockInfo; | ||
| use dpp::block::epoch::MAX_EPOCH; | ||
| use drive::error::proof::ProofError; | ||
|
|
||
| /// Constructs a `BlockInfo` structure from the provided response metadata. This function | ||
| /// translates metadata received from a platform response into a format that is specific to the | ||
| /// application's needs, particularly focusing on block-related information. It ensures that | ||
| /// the epoch value from the metadata does not exceed `MAX_EPOCH`, | ||
| /// as this is a constraint for the `Epoch` type used in the `BlockInfo` structure. | ||
| /// | ||
| /// # Parameters | ||
| /// - `response_metadata`: A reference to `ResponseMetadata` obtained from a platform response. | ||
| /// This metadata includes various block-related information such as time in milliseconds, | ||
| /// height, core chain locked height, and epoch. | ||
| /// | ||
| /// # Returns | ||
| /// If successful, returns `Ok(BlockInfo)` where `BlockInfo` contains: | ||
| /// - `time_ms`: The timestamp of the block in milliseconds. | ||
| /// - `height`: The height of the block. | ||
| /// - `core_height`: The core chain locked height, indicating the height of the block in the core blockchain that is considered final and securely linked to this block. | ||
| /// - `epoch`: The epoch number, converted to an `Epoch` struct via a 16-bit number. | ||
| /// | ||
| /// # Errors | ||
| /// Returns an error if: | ||
| /// - The `epoch` value in the response metadata exceeds `MAX_EPOCH`. This is considered a data validity error as it indicates Platform returned an unexpectedly high epoch number. | ||
| /// | ||
| /// The function encapsulates errors into the application's own `Error` type, providing a unified interface for error handling across the application. | ||
| pub fn block_info_from_metadata(response_metadata: &ResponseMetadata) -> Result<BlockInfo, Error> { | ||
| if response_metadata.epoch > MAX_EPOCH as u32 { | ||
| return Err( | ||
| drive::error::Error::Proof(ProofError::InvalidMetadata(format!( | ||
| "platform returned an epoch {} that was higher than the maximum allowed epoch", | ||
| response_metadata.epoch | ||
| ))) | ||
| .into(), | ||
| ); | ||
| } | ||
|
|
||
| Ok(BlockInfo { | ||
| time_ms: response_metadata.time_ms, | ||
| height: response_metadata.height, | ||
| core_height: response_metadata.core_chain_locked_height, | ||
| epoch: (response_metadata.epoch as u16).try_into()?, | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.