Skip to content

feat(platform): query any element in Platform state #1816

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 9 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/dapi-grpc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
// Derive features for versioned messages
//
// "GetConsensusParamsRequest" is excluded as this message does not support proofs
const VERSIONED_REQUESTS: [&str; 17] = [
const VERSIONED_REQUESTS: [&str; 18] = [
"GetDataContractHistoryRequest",
"GetDataContractRequest",
"GetDataContractsRequest",
Expand All @@ -57,10 +57,11 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
"WaitForStateTransitionResultRequest",
"GetProtocolVersionUpgradeStateRequest",
"GetProtocolVersionUpgradeVoteStatusRequest",
"GetPathElementsRequest",
];

// "GetConsensusParamsResponse" is excluded as this message does not support proofs
const VERSIONED_RESPONSES: [&str; 18] = [
const VERSIONED_RESPONSES: [&str; 19] = [
"GetDataContractHistoryResponse",
"GetDataContractResponse",
"GetDataContractsResponse",
Expand All @@ -79,6 +80,7 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
"GetEpochsInfoResponse",
"GetProtocolVersionUpgradeStateResponse",
"GetProtocolVersionUpgradeVoteStatusResponse",
"GetPathElementsResponse",
];

// Derive VersionedGrpcMessage on requests
Expand Down
32 changes: 32 additions & 0 deletions packages/dapi-grpc/protos/platform/v0/platform.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ service Platform {
rpc getProtocolVersionUpgradeState(GetProtocolVersionUpgradeStateRequest) returns (GetProtocolVersionUpgradeStateResponse);
rpc getProtocolVersionUpgradeVoteStatus(GetProtocolVersionUpgradeVoteStatusRequest) returns (GetProtocolVersionUpgradeVoteStatusResponse);
rpc getEpochsInfo(GetEpochsInfoRequest) returns (GetEpochsInfoResponse);
rpc getPathElements(GetPathElementsRequest) returns (GetPathElementsResponse);
}

message Proof {
Expand Down Expand Up @@ -620,3 +621,34 @@ message GetEpochsInfoResponse {
GetEpochsInfoResponseV0 v0 = 1;
}
}

message GetPathElementsRequest {
message GetPathElementsRequestV0 {
repeated bytes path = 1;
repeated bytes keys = 2;
bool prove = 3;
}

oneof version {
GetPathElementsRequestV0 v0 = 1;
}
}

message GetPathElementsResponse {
message GetPathElementsResponseV0 {
message Elements {
repeated bytes elements = 1;
}

oneof result {
Elements elements = 1;
Proof proof = 2;
}
ResponseMetadata metadata = 3;
}

oneof version {
GetPathElementsResponseV0 v0 = 1;
}
}

176 changes: 176 additions & 0 deletions packages/dapi-grpc/src/platform/proto/org.dash.platform.dapi.v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2134,6 +2134,99 @@ pub mod get_epochs_info_response {
V0(GetEpochsInfoResponseV0),
}
}
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "snake_case")]
#[derive(::dapi_grpc_macros::VersionedGrpcMessage)]
#[grpc_versions(0)]
#[derive(::dapi_grpc_macros::Mockable)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetPathElementsRequest {
#[prost(oneof = "get_path_elements_request::Version", tags = "1")]
pub version: ::core::option::Option<get_path_elements_request::Version>,
}
/// Nested message and enum types in `GetPathElementsRequest`.
pub mod get_path_elements_request {
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "snake_case")]
#[derive(::dapi_grpc_macros::Mockable)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetPathElementsRequestV0 {
#[prost(bytes = "vec", repeated, tag = "1")]
pub path: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec<u8>>,
#[prost(bytes = "vec", repeated, tag = "2")]
pub keys: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec<u8>>,
#[prost(bool, tag = "3")]
pub prove: bool,
}
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "snake_case")]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Version {
#[prost(message, tag = "1")]
V0(GetPathElementsRequestV0),
}
}
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "snake_case")]
#[derive(
::dapi_grpc_macros::VersionedGrpcMessage,
::dapi_grpc_macros::VersionedGrpcResponse
)]
#[grpc_versions(0)]
#[derive(::dapi_grpc_macros::Mockable)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetPathElementsResponse {
#[prost(oneof = "get_path_elements_response::Version", tags = "1")]
pub version: ::core::option::Option<get_path_elements_response::Version>,
}
/// Nested message and enum types in `GetPathElementsResponse`.
pub mod get_path_elements_response {
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "snake_case")]
#[derive(::dapi_grpc_macros::Mockable)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetPathElementsResponseV0 {
#[prost(message, optional, tag = "3")]
pub metadata: ::core::option::Option<super::ResponseMetadata>,
#[prost(oneof = "get_path_elements_response_v0::Result", tags = "1, 2")]
pub result: ::core::option::Option<get_path_elements_response_v0::Result>,
}
/// Nested message and enum types in `GetPathElementsResponseV0`.
pub mod get_path_elements_response_v0 {
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "snake_case")]
#[derive(::dapi_grpc_macros::Mockable)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Elements {
#[prost(bytes = "vec", repeated, tag = "1")]
pub elements: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec<u8>>,
}
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "snake_case")]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Result {
#[prost(message, tag = "1")]
Elements(Elements),
#[prost(message, tag = "2")]
Proof(super::super::Proof),
}
}
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "snake_case")]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Version {
#[prost(message, tag = "1")]
V0(GetPathElementsResponseV0),
}
}
/// Generated client implementations.
pub mod platform_client {
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
Expand Down Expand Up @@ -2816,6 +2909,36 @@ pub mod platform_client {
);
self.inner.unary(req, path, codec).await
}
pub async fn get_path_elements(
&mut self,
request: impl tonic::IntoRequest<super::GetPathElementsRequest>,
) -> std::result::Result<
tonic::Response<super::GetPathElementsResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/org.dash.platform.dapi.v0.Platform/getPathElements",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"org.dash.platform.dapi.v0.Platform",
"getPathElements",
),
);
self.inner.unary(req, path, codec).await
}
}
}
/// Generated server implementations.
Expand Down Expand Up @@ -2965,6 +3088,13 @@ pub mod platform_server {
tonic::Response<super::GetEpochsInfoResponse>,
tonic::Status,
>;
async fn get_path_elements(
&self,
request: tonic::Request<super::GetPathElementsRequest>,
) -> std::result::Result<
tonic::Response<super::GetPathElementsResponse>,
tonic::Status,
>;
}
#[derive(Debug)]
pub struct PlatformServer<T: Platform> {
Expand Down Expand Up @@ -3989,6 +4119,52 @@ pub mod platform_server {
};
Box::pin(fut)
}
"/org.dash.platform.dapi.v0.Platform/getPathElements" => {
#[allow(non_camel_case_types)]
struct getPathElementsSvc<T: Platform>(pub Arc<T>);
impl<
T: Platform,
> tonic::server::UnaryService<super::GetPathElementsRequest>
for getPathElementsSvc<T> {
type Response = super::GetPathElementsResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::GetPathElementsRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
(*inner).get_path_elements(request).await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
let method = getPathElementsSvc(inner);
let codec = tonic::codec::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
_ => {
Box::pin(async move {
Ok(
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-dapi-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ offline-testing = []

[dependencies]
backon = "0.4.1"
dapi-grpc = { path = "../dapi-grpc" , features = ["core", "client", "serde"], default-features = false}
dapi-grpc = { path = "../dapi-grpc" }
futures = "0.3.28"
http = "0.2.9"
rand = { version = "0.8.5", features = ["small_rng"] }
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-dapi-grpc-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ heck = "0.5.0"

[dev-dependencies]

dapi-grpc = { path = "../dapi-grpc" , features = ["client", "serde"], default-features = false}
dapi-grpc = { path = "../dapi-grpc" }
2 changes: 1 addition & 1 deletion packages/rs-drive-abci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ tracing = { version = "0.1.37", default-features = false, features = [] }
clap = { version = "4.4.10", features = ["derive"] }
envy = { version = "0.4.2" }
dotenvy = { version = "0.15.7" }
dapi-grpc = { path = "../dapi-grpc", features = ["server"], default-features = false }
dapi-grpc = { path = "../dapi-grpc" }
tracing-subscriber = { version = "0.3.16", default-features = false, features = [
"env-filter",
"ansi",
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-drive-abci/src/query/proofs/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<C> Platform<C> {
})
.collect::<Result<Vec<_>, QueryError>>());

let proof = self.drive.prove_multiple(
let proof = self.drive.prove_multiple_state_transition_results(
&identity_requests,
&contract_ids,
&document_queries,
Expand Down
20 changes: 16 additions & 4 deletions packages/rs-drive-abci/src/query/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use dapi_grpc::platform::v0::{
GetIdentityByPublicKeyHashResponse, GetIdentityContractNonceRequest,
GetIdentityContractNonceResponse, GetIdentityKeysRequest, GetIdentityKeysResponse,
GetIdentityNonceRequest, GetIdentityNonceResponse, GetIdentityRequest, GetIdentityResponse,
GetProofsRequest, GetProofsResponse, GetProtocolVersionUpgradeStateRequest,
GetProtocolVersionUpgradeStateResponse, GetProtocolVersionUpgradeVoteStatusRequest,
GetProtocolVersionUpgradeVoteStatusResponse, WaitForStateTransitionResultRequest,
WaitForStateTransitionResultResponse,
GetPathElementsRequest, GetPathElementsResponse, GetProofsRequest, GetProofsResponse,
GetProtocolVersionUpgradeStateRequest, GetProtocolVersionUpgradeStateResponse,
GetProtocolVersionUpgradeVoteStatusRequest, GetProtocolVersionUpgradeVoteStatusResponse,
WaitForStateTransitionResultRequest, WaitForStateTransitionResultResponse,
};
use dapi_grpc::tonic::{Request, Response, Status};
use dpp::version::PlatformVersion;
Expand Down Expand Up @@ -388,6 +388,18 @@ impl PlatformService for QueryService {
)
.await
}

async fn get_path_elements(
&self,
request: Request<GetPathElementsRequest>,
) -> Result<Response<GetPathElementsResponse>, Status> {
self.handle_blocking_query(
request,
Platform::<DefaultCoreRPC>::query_path_elements,
"get_path_elements",
)
.await
}
}

fn query_error_into_status(error: QueryError) -> Status {
Expand Down
1 change: 1 addition & 0 deletions packages/rs-drive-abci/src/query/system/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod epoch_infos;
mod path_elements;
mod version_upgrade_state;
mod version_upgrade_vote_status;
Loading