Skip to content
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

add(scan): Add ClearResults and DeleteKeys gRPC methods #8237

Merged
merged 5 commits into from
Feb 6, 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
21 changes: 21 additions & 0 deletions zebra-grpc/proto/scanner.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,31 @@ message Empty {}
service Scanner {
// Get information about the scanner service.
rpc GetInfo (Empty) returns (InfoReply);

// Clear results for a set of keys without removing the keys from the scanner.
// This request does not stop the scanner from scanning blocks for these keys, it
// only clears past results.
rpc ClearResults(ClearResultsRequest) returns (Empty);

// Deletes a set of keys and their results from the scanner.
// This request stop the scanner from scanning blocks for the these keys.
rpc DeleteKeys(DeleteKeysRequest) returns (Empty);
}

// A response to a GetInfo call.
message InfoReply {
// The minimum sapling height allowed.
uint32 min_sapling_birthday_height = 1;
}

// A request for clearing past results from the scanner cache.
message ClearResultsRequest {
// Keys for which to clear results.
repeated string keys = 1;
}

// A request to delete keys, delete their results, and stop scanning for their results.
message DeleteKeysRequest {
// Keys to delete from scanner.
repeated string keys = 1;
}
56 changes: 55 additions & 1 deletion zebra-grpc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tonic::{transport::Server, Response, Status};
use tower::ServiceExt;

use scanner::scanner_server::{Scanner, ScannerServer};
use scanner::{Empty, InfoReply};
use scanner::{ClearResultsRequest, DeleteKeysRequest, Empty, InfoReply};

use zebra_node_services::scan_service::{
request::Request as ScanServiceRequest, response::Response as ScanServiceResponse,
Expand Down Expand Up @@ -67,6 +67,60 @@ where

Ok(Response::new(reply))
}

async fn clear_results(
&self,
request: tonic::Request<ClearResultsRequest>,
) -> Result<Response<Empty>, Status> {
let keys = request.into_inner().keys;

if keys.is_empty() {
let msg = "must provide at least 1 key for which to clear results";
return Err(Status::invalid_argument(msg));
}

let ScanServiceResponse::ClearedResults = self
.scan_service
.clone()
.ready()
.and_then(|service| service.call(ScanServiceRequest::ClearResults(keys)))
.await
.map_err(|err| Status::unknown(format!("scan service returned error: {err}")))?
else {
return Err(Status::unknown(
"scan service returned an unexpected response",
));
};

Ok(Response::new(Empty {}))
oxarbitrage marked this conversation as resolved.
Show resolved Hide resolved
}

async fn delete_keys(
&self,
request: tonic::Request<DeleteKeysRequest>,
) -> Result<Response<Empty>, Status> {
let keys = request.into_inner().keys;

if keys.is_empty() {
let msg = "must provide at least 1 key to delete";
return Err(Status::invalid_argument(msg));
}

let ScanServiceResponse::DeletedKeys = self
.scan_service
.clone()
.ready()
.and_then(|service| service.call(ScanServiceRequest::DeleteKeys(keys)))
.await
.map_err(|err| Status::unknown(format!("scan service returned error: {err}")))?
else {
return Err(Status::unknown(
"scan service returned an unexpected response",
));
};

Ok(Response::new(Empty {}))
oxarbitrage marked this conversation as resolved.
Show resolved Hide resolved
}
}

/// Initializes the zebra-scan gRPC server
Expand Down
Loading