diff --git a/service/api b/service/api index 10baa944..4d3acf29 160000 --- a/service/api +++ b/service/api @@ -1 +1 @@ -Subproject commit 10baa9442c3416da98e9da57be96c759d725c916 +Subproject commit 4d3acf29394fc895975c1dd9c2dd9e7f0b84f4f0 diff --git a/service/src/client.rs b/service/src/client.rs index b31f3302..9609de95 100644 --- a/service/src/client.rs +++ b/service/src/client.rs @@ -10,7 +10,8 @@ use post::metadata::PostMetadata; pub(crate) use spacemesh_v1::post_service_client::PostServiceClient; use spacemesh_v1::{node_request, service_response}; use spacemesh_v1::{ - GenProofRequest, GenProofResponse, GenProofStatus, Proof, ProofMetadata, ServiceResponse, + GenProofRequest, GenProofResponse, GenProofStatus, InterruptProofResponse, Proof, + ProofMetadata, ServiceResponse, }; use tokio::sync::mpsc; use tokio::time::sleep; @@ -46,6 +47,8 @@ pub trait PostService { proof: &post::prove::Proof<'a>, challenge: &[u8], ) -> eyre::Result<()>; + + fn interrupt_proof(&self) -> eyre::Result<()>; } impl PostService for std::sync::Arc { @@ -60,6 +63,10 @@ impl PostService for std::sync::Arc { fn get_metadata(&self) -> &PostMetadata { self.as_ref().get_metadata() } + + fn interrupt_proof(&self) -> eyre::Result<()> { + self.as_ref().interrupt_proof() + } } impl ServiceClient { @@ -148,6 +155,10 @@ impl ServiceClient { let resp = self.generate_and_verify_proof(req); tx.send(resp).await?; } + Some(node_request::Kind::Interrupt(_)) => { + let resp = self.interrupt_proof(); + tx.send(resp).await?; + } None => { log::warn!("Got a request with no kind"); tx.send(ServiceResponse { @@ -235,6 +246,14 @@ impl ServiceClient { })), } } + + fn interrupt_proof(&self) -> ServiceResponse { + self.service.interrupt_proof().unwrap(); + log::info!("received proof interrupt"); + ServiceResponse { + kind: Some(service_response::Kind::Interrupt(InterruptProofResponse {})), + } + } } fn convert_metadata(meta: PostMetadata) -> spacemesh_v1::Metadata { diff --git a/service/src/service.rs b/service/src/service.rs index 4f958ca0..47ae7360 100644 --- a/service/src/service.rs +++ b/service/src/service.rs @@ -3,7 +3,10 @@ use std::{ ops::{Range, RangeInclusive}, path::PathBuf, - sync::{atomic::AtomicBool, Arc, Mutex}, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, Mutex, + }, }; use eyre::Context; @@ -213,6 +216,11 @@ impl crate::client::PostService for PostService { fn get_metadata(&self) -> &PostMetadata { &self.metadata } + + fn interrupt_proof(&self) -> eyre::Result<()> { + self.stop.clone().store(true, Ordering::Relaxed); + Ok(()) + } } impl crate::operator::Service for PostService {