From a1b32b7cbcefbd18e1458fc08e7e0f16d9ed3266 Mon Sep 17 00:00:00 2001 From: tomyrd Date: Fri, 26 Jul 2024 13:05:49 -0300 Subject: [PATCH] fix: address suggestions --- CHANGELOG.md | 2 +- crates/proto/src/generated/responses.rs | 2 +- crates/proto/src/generated/rpc.rs | 74 ++++++++++++------------- crates/proto/src/generated/store.rs | 70 +++++++++++------------ crates/rpc-proto/proto/responses.proto | 2 +- crates/rpc-proto/proto/rpc.proto | 2 +- crates/rpc-proto/proto/store.proto | 2 +- crates/store/src/db/mod.rs | 1 + crates/store/src/db/sql.rs | 6 +- proto/responses.proto | 2 +- proto/rpc.proto | 2 +- proto/store.proto | 2 +- 12 files changed, 85 insertions(+), 82 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13a5cf5b3..2255961f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,12 +4,12 @@ ### Enhancements -- Added `CheckNullifiersByPrefix` endpoint (#419). - [BREAKING] Configuration files with unknown properties are now rejected (#401). - [BREAKING] Removed redundant node configuration properties (#401). - Improve type safety of the transaction inputs nullifier mapping (#406). - Embed the faucet's static website resources (#411). - Added warning on CI for `CHANGELOG.md` (#413). +- Added `CheckNullifiersByPrefix` endpoint (#419). ## 0.4.0 (2024-07-04) diff --git a/crates/proto/src/generated/responses.rs b/crates/proto/src/generated/responses.rs index b429edb77..1ace4f108 100644 --- a/crates/proto/src/generated/responses.rs +++ b/crates/proto/src/generated/responses.rs @@ -12,7 +12,7 @@ pub struct CheckNullifiersResponse { #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct CheckNullifiersByPrefixResponse { - /// List of nullifiers matching the 16-bit prefixes specified in the request. + /// List of nullifiers matching the prefixes specified in the request. #[prost(message, repeated, tag = "1")] pub nullifiers: ::prost::alloc::vec::Vec, } diff --git a/crates/proto/src/generated/rpc.rs b/crates/proto/src/generated/rpc.rs index edad10be9..d080eeb22 100644 --- a/crates/proto/src/generated/rpc.rs +++ b/crates/proto/src/generated/rpc.rs @@ -84,13 +84,13 @@ pub mod api_client { self.inner = self.inner.max_encoding_message_size(limit); self } - pub async fn check_nullifiers_by_prefix( + pub async fn check_nullifiers( &mut self, request: impl tonic::IntoRequest< - super::super::requests::CheckNullifiersByPrefixRequest, + super::super::requests::CheckNullifiersRequest, >, ) -> std::result::Result< - tonic::Response, + tonic::Response, tonic::Status, > { self.inner @@ -103,21 +103,18 @@ pub mod api_client { ) })?; let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static( - "/rpc.Api/CheckNullifiersByPrefix", - ); + let path = http::uri::PathAndQuery::from_static("/rpc.Api/CheckNullifiers"); let mut req = request.into_request(); - req.extensions_mut() - .insert(GrpcMethod::new("rpc.Api", "CheckNullifiersByPrefix")); + req.extensions_mut().insert(GrpcMethod::new("rpc.Api", "CheckNullifiers")); self.inner.unary(req, path, codec).await } - pub async fn check_nullifiers( + pub async fn check_nullifiers_by_prefix( &mut self, request: impl tonic::IntoRequest< - super::super::requests::CheckNullifiersRequest, + super::super::requests::CheckNullifiersByPrefixRequest, >, ) -> std::result::Result< - tonic::Response, + tonic::Response, tonic::Status, > { self.inner @@ -130,9 +127,12 @@ pub mod api_client { ) })?; let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static("/rpc.Api/CheckNullifiers"); + let path = http::uri::PathAndQuery::from_static( + "/rpc.Api/CheckNullifiersByPrefix", + ); let mut req = request.into_request(); - req.extensions_mut().insert(GrpcMethod::new("rpc.Api", "CheckNullifiers")); + req.extensions_mut() + .insert(GrpcMethod::new("rpc.Api", "CheckNullifiersByPrefix")); self.inner.unary(req, path, codec).await } pub async fn get_account_details( @@ -292,6 +292,13 @@ pub mod api_server { /// Generated trait containing gRPC methods that should be implemented for use with ApiServer. #[async_trait] pub trait Api: Send + Sync + 'static { + async fn check_nullifiers( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; async fn check_nullifiers_by_prefix( &self, request: tonic::Request< @@ -301,13 +308,6 @@ pub mod api_server { tonic::Response, tonic::Status, >; - async fn check_nullifiers( - &self, - request: tonic::Request, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - >; async fn get_account_details( &self, request: tonic::Request, @@ -434,15 +434,15 @@ pub mod api_server { fn call(&mut self, req: http::Request) -> Self::Future { let inner = self.inner.clone(); match req.uri().path() { - "/rpc.Api/CheckNullifiersByPrefix" => { + "/rpc.Api/CheckNullifiers" => { #[allow(non_camel_case_types)] - struct CheckNullifiersByPrefixSvc(pub Arc); + struct CheckNullifiersSvc(pub Arc); impl< T: Api, > tonic::server::UnaryService< - super::super::requests::CheckNullifiersByPrefixRequest, - > for CheckNullifiersByPrefixSvc { - type Response = super::super::responses::CheckNullifiersByPrefixResponse; + super::super::requests::CheckNullifiersRequest, + > for CheckNullifiersSvc { + type Response = super::super::responses::CheckNullifiersResponse; type Future = BoxFuture< tonic::Response, tonic::Status, @@ -450,13 +450,12 @@ pub mod api_server { fn call( &mut self, request: tonic::Request< - super::super::requests::CheckNullifiersByPrefixRequest, + super::super::requests::CheckNullifiersRequest, >, ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { - ::check_nullifiers_by_prefix(&inner, request) - .await + ::check_nullifiers(&inner, request).await }; Box::pin(fut) } @@ -468,7 +467,7 @@ pub mod api_server { let inner = self.inner.clone(); let fut = async move { let inner = inner.0; - let method = CheckNullifiersByPrefixSvc(inner); + let method = CheckNullifiersSvc(inner); let codec = tonic::codec::ProstCodec::default(); let mut grpc = tonic::server::Grpc::new(codec) .apply_compression_config( @@ -484,15 +483,15 @@ pub mod api_server { }; Box::pin(fut) } - "/rpc.Api/CheckNullifiers" => { + "/rpc.Api/CheckNullifiersByPrefix" => { #[allow(non_camel_case_types)] - struct CheckNullifiersSvc(pub Arc); + struct CheckNullifiersByPrefixSvc(pub Arc); impl< T: Api, > tonic::server::UnaryService< - super::super::requests::CheckNullifiersRequest, - > for CheckNullifiersSvc { - type Response = super::super::responses::CheckNullifiersResponse; + super::super::requests::CheckNullifiersByPrefixRequest, + > for CheckNullifiersByPrefixSvc { + type Response = super::super::responses::CheckNullifiersByPrefixResponse; type Future = BoxFuture< tonic::Response, tonic::Status, @@ -500,12 +499,13 @@ pub mod api_server { fn call( &mut self, request: tonic::Request< - super::super::requests::CheckNullifiersRequest, + super::super::requests::CheckNullifiersByPrefixRequest, >, ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { - ::check_nullifiers(&inner, request).await + ::check_nullifiers_by_prefix(&inner, request) + .await }; Box::pin(fut) } @@ -517,7 +517,7 @@ pub mod api_server { let inner = self.inner.clone(); let fut = async move { let inner = inner.0; - let method = CheckNullifiersSvc(inner); + let method = CheckNullifiersByPrefixSvc(inner); let codec = tonic::codec::ProstCodec::default(); let mut grpc = tonic::server::Grpc::new(codec) .apply_compression_config( diff --git a/crates/proto/src/generated/store.rs b/crates/proto/src/generated/store.rs index 999b961c6..5eb445f8e 100644 --- a/crates/proto/src/generated/store.rs +++ b/crates/proto/src/generated/store.rs @@ -106,13 +106,13 @@ pub mod api_client { req.extensions_mut().insert(GrpcMethod::new("store.Api", "ApplyBlock")); self.inner.unary(req, path, codec).await } - pub async fn check_nullifiers_by_prefix( + pub async fn check_nullifiers( &mut self, request: impl tonic::IntoRequest< - super::super::requests::CheckNullifiersByPrefixRequest, + super::super::requests::CheckNullifiersRequest, >, ) -> std::result::Result< - tonic::Response, + tonic::Response, tonic::Status, > { self.inner @@ -126,20 +126,19 @@ pub mod api_client { })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static( - "/store.Api/CheckNullifiersByPrefix", + "/store.Api/CheckNullifiers", ); let mut req = request.into_request(); - req.extensions_mut() - .insert(GrpcMethod::new("store.Api", "CheckNullifiersByPrefix")); + req.extensions_mut().insert(GrpcMethod::new("store.Api", "CheckNullifiers")); self.inner.unary(req, path, codec).await } - pub async fn check_nullifiers( + pub async fn check_nullifiers_by_prefix( &mut self, request: impl tonic::IntoRequest< - super::super::requests::CheckNullifiersRequest, + super::super::requests::CheckNullifiersByPrefixRequest, >, ) -> std::result::Result< - tonic::Response, + tonic::Response, tonic::Status, > { self.inner @@ -153,10 +152,11 @@ pub mod api_client { })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static( - "/store.Api/CheckNullifiers", + "/store.Api/CheckNullifiersByPrefix", ); let mut req = request.into_request(); - req.extensions_mut().insert(GrpcMethod::new("store.Api", "CheckNullifiers")); + req.extensions_mut() + .insert(GrpcMethod::new("store.Api", "CheckNullifiersByPrefix")); self.inner.unary(req, path, codec).await } pub async fn get_account_details( @@ -419,6 +419,13 @@ pub mod api_server { tonic::Response, tonic::Status, >; + async fn check_nullifiers( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; async fn check_nullifiers_by_prefix( &self, request: tonic::Request< @@ -428,13 +435,6 @@ pub mod api_server { tonic::Response, tonic::Status, >; - async fn check_nullifiers( - &self, - request: tonic::Request, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - >; async fn get_account_details( &self, request: tonic::Request, @@ -636,15 +636,15 @@ pub mod api_server { }; Box::pin(fut) } - "/store.Api/CheckNullifiersByPrefix" => { + "/store.Api/CheckNullifiers" => { #[allow(non_camel_case_types)] - struct CheckNullifiersByPrefixSvc(pub Arc); + struct CheckNullifiersSvc(pub Arc); impl< T: Api, > tonic::server::UnaryService< - super::super::requests::CheckNullifiersByPrefixRequest, - > for CheckNullifiersByPrefixSvc { - type Response = super::super::responses::CheckNullifiersByPrefixResponse; + super::super::requests::CheckNullifiersRequest, + > for CheckNullifiersSvc { + type Response = super::super::responses::CheckNullifiersResponse; type Future = BoxFuture< tonic::Response, tonic::Status, @@ -652,13 +652,12 @@ pub mod api_server { fn call( &mut self, request: tonic::Request< - super::super::requests::CheckNullifiersByPrefixRequest, + super::super::requests::CheckNullifiersRequest, >, ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { - ::check_nullifiers_by_prefix(&inner, request) - .await + ::check_nullifiers(&inner, request).await }; Box::pin(fut) } @@ -670,7 +669,7 @@ pub mod api_server { let inner = self.inner.clone(); let fut = async move { let inner = inner.0; - let method = CheckNullifiersByPrefixSvc(inner); + let method = CheckNullifiersSvc(inner); let codec = tonic::codec::ProstCodec::default(); let mut grpc = tonic::server::Grpc::new(codec) .apply_compression_config( @@ -686,15 +685,15 @@ pub mod api_server { }; Box::pin(fut) } - "/store.Api/CheckNullifiers" => { + "/store.Api/CheckNullifiersByPrefix" => { #[allow(non_camel_case_types)] - struct CheckNullifiersSvc(pub Arc); + struct CheckNullifiersByPrefixSvc(pub Arc); impl< T: Api, > tonic::server::UnaryService< - super::super::requests::CheckNullifiersRequest, - > for CheckNullifiersSvc { - type Response = super::super::responses::CheckNullifiersResponse; + super::super::requests::CheckNullifiersByPrefixRequest, + > for CheckNullifiersByPrefixSvc { + type Response = super::super::responses::CheckNullifiersByPrefixResponse; type Future = BoxFuture< tonic::Response, tonic::Status, @@ -702,12 +701,13 @@ pub mod api_server { fn call( &mut self, request: tonic::Request< - super::super::requests::CheckNullifiersRequest, + super::super::requests::CheckNullifiersByPrefixRequest, >, ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { - ::check_nullifiers(&inner, request).await + ::check_nullifiers_by_prefix(&inner, request) + .await }; Box::pin(fut) } @@ -719,7 +719,7 @@ pub mod api_server { let inner = self.inner.clone(); let fut = async move { let inner = inner.0; - let method = CheckNullifiersSvc(inner); + let method = CheckNullifiersByPrefixSvc(inner); let codec = tonic::codec::ProstCodec::default(); let mut grpc = tonic::server::Grpc::new(codec) .apply_compression_config( diff --git a/crates/rpc-proto/proto/responses.proto b/crates/rpc-proto/proto/responses.proto index ff2c64554..2c985ce81 100644 --- a/crates/rpc-proto/proto/responses.proto +++ b/crates/rpc-proto/proto/responses.proto @@ -18,7 +18,7 @@ message CheckNullifiersResponse { } message CheckNullifiersByPrefixResponse { - // List of nullifiers matching the 16-bit prefixes specified in the request. + // List of nullifiers matching the prefixes specified in the request. repeated NullifierUpdate nullifiers = 1; } diff --git a/crates/rpc-proto/proto/rpc.proto b/crates/rpc-proto/proto/rpc.proto index 4e66a0ea8..d67d622f0 100644 --- a/crates/rpc-proto/proto/rpc.proto +++ b/crates/rpc-proto/proto/rpc.proto @@ -6,8 +6,8 @@ import "requests.proto"; import "responses.proto"; service Api { - rpc CheckNullifiersByPrefix(requests.CheckNullifiersByPrefixRequest) returns (responses.CheckNullifiersByPrefixResponse) {} rpc CheckNullifiers(requests.CheckNullifiersRequest) returns (responses.CheckNullifiersResponse) {} + rpc CheckNullifiersByPrefix(requests.CheckNullifiersByPrefixRequest) returns (responses.CheckNullifiersByPrefixResponse) {} rpc GetAccountDetails(requests.GetAccountDetailsRequest) returns (responses.GetAccountDetailsResponse) {} rpc GetBlockByNumber(requests.GetBlockByNumberRequest) returns (responses.GetBlockByNumberResponse) {} rpc GetBlockHeaderByNumber(requests.GetBlockHeaderByNumberRequest) returns (responses.GetBlockHeaderByNumberResponse) {} diff --git a/crates/rpc-proto/proto/store.proto b/crates/rpc-proto/proto/store.proto index 551a08665..0a94ee9d2 100644 --- a/crates/rpc-proto/proto/store.proto +++ b/crates/rpc-proto/proto/store.proto @@ -9,8 +9,8 @@ import "responses.proto"; service Api { rpc ApplyBlock(requests.ApplyBlockRequest) returns (responses.ApplyBlockResponse) {} - rpc CheckNullifiersByPrefix(requests.CheckNullifiersByPrefixRequest) returns (responses.CheckNullifiersByPrefixResponse) {} rpc CheckNullifiers(requests.CheckNullifiersRequest) returns (responses.CheckNullifiersResponse) {} + rpc CheckNullifiersByPrefix(requests.CheckNullifiersByPrefixRequest) returns (responses.CheckNullifiersByPrefixResponse) {} rpc GetAccountDetails(requests.GetAccountDetailsRequest) returns (responses.GetAccountDetailsResponse) {} rpc GetBlockByNumber(requests.GetBlockByNumberRequest) returns (responses.GetBlockByNumberResponse) {} rpc GetBlockHeaderByNumber(requests.GetBlockHeaderByNumberRequest) returns (responses.GetBlockHeaderByNumberResponse) {} diff --git a/crates/store/src/db/mod.rs b/crates/store/src/db/mod.rs index f001c5a0a..099b74f03 100644 --- a/crates/store/src/db/mod.rs +++ b/crates/store/src/db/mod.rs @@ -164,6 +164,7 @@ impl Db { } /// Loads the nullifiers that match the prefixes from the DB. + #[instrument(target = "miden-store", skip_all, ret(level = "debug"), err)] pub async fn select_nullifiers_by_prefix( &self, prefix_len: u32, diff --git a/crates/store/src/db/sql.rs b/crates/store/src/db/sql.rs index cebe23969..eecfd544f 100644 --- a/crates/store/src/db/sql.rs +++ b/crates/store/src/db/sql.rs @@ -312,7 +312,7 @@ pub fn select_nullifiers_by_block_range( /// /// Each value of the `nullifier_prefixes` is only the `prefix_len` most significant bits /// of the nullifier of interest to the client. This hides the details of the specific -/// nullifier being requested. +/// nullifier being requested. Currently the only supported prefix length is 16 bits. /// /// # Returns /// @@ -320,9 +320,11 @@ pub fn select_nullifiers_by_block_range( /// created, or an error. pub fn select_nullifiers_by_prefix( conn: &mut Connection, - _prefix_len: u32, + prefix_len: u32, nullifier_prefixes: &[u32], ) -> Result> { + assert_eq!(prefix_len, 16, "Only 16-bit prefixes are supported"); + let nullifier_prefixes: Vec = nullifier_prefixes.iter().copied().map(u32_to_value).collect(); diff --git a/proto/responses.proto b/proto/responses.proto index ff2c64554..2c985ce81 100644 --- a/proto/responses.proto +++ b/proto/responses.proto @@ -18,7 +18,7 @@ message CheckNullifiersResponse { } message CheckNullifiersByPrefixResponse { - // List of nullifiers matching the 16-bit prefixes specified in the request. + // List of nullifiers matching the prefixes specified in the request. repeated NullifierUpdate nullifiers = 1; } diff --git a/proto/rpc.proto b/proto/rpc.proto index 4e66a0ea8..d67d622f0 100644 --- a/proto/rpc.proto +++ b/proto/rpc.proto @@ -6,8 +6,8 @@ import "requests.proto"; import "responses.proto"; service Api { - rpc CheckNullifiersByPrefix(requests.CheckNullifiersByPrefixRequest) returns (responses.CheckNullifiersByPrefixResponse) {} rpc CheckNullifiers(requests.CheckNullifiersRequest) returns (responses.CheckNullifiersResponse) {} + rpc CheckNullifiersByPrefix(requests.CheckNullifiersByPrefixRequest) returns (responses.CheckNullifiersByPrefixResponse) {} rpc GetAccountDetails(requests.GetAccountDetailsRequest) returns (responses.GetAccountDetailsResponse) {} rpc GetBlockByNumber(requests.GetBlockByNumberRequest) returns (responses.GetBlockByNumberResponse) {} rpc GetBlockHeaderByNumber(requests.GetBlockHeaderByNumberRequest) returns (responses.GetBlockHeaderByNumberResponse) {} diff --git a/proto/store.proto b/proto/store.proto index 551a08665..0a94ee9d2 100644 --- a/proto/store.proto +++ b/proto/store.proto @@ -9,8 +9,8 @@ import "responses.proto"; service Api { rpc ApplyBlock(requests.ApplyBlockRequest) returns (responses.ApplyBlockResponse) {} - rpc CheckNullifiersByPrefix(requests.CheckNullifiersByPrefixRequest) returns (responses.CheckNullifiersByPrefixResponse) {} rpc CheckNullifiers(requests.CheckNullifiersRequest) returns (responses.CheckNullifiersResponse) {} + rpc CheckNullifiersByPrefix(requests.CheckNullifiersByPrefixRequest) returns (responses.CheckNullifiersByPrefixResponse) {} rpc GetAccountDetails(requests.GetAccountDetailsRequest) returns (responses.GetAccountDetailsResponse) {} rpc GetBlockByNumber(requests.GetBlockByNumberRequest) returns (responses.GetBlockByNumberResponse) {} rpc GetBlockHeaderByNumber(requests.GetBlockHeaderByNumberRequest) returns (responses.GetBlockHeaderByNumberResponse) {}