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

feat: allow interrupts on proof generation #324

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion service/api
Submodule api updated 94 files
+2 −2 .github/workflows/ci.yml
+2 −0 .gitignore
+17 −5 Makefile
+9 −0 buf.gen.yaml
+7 −2 buf.lock
+3 −0 buf.yaml
+4 −0 post/v1/service.proto
+9 −11 release/go/go.mod
+18 −27 release/go/go.sum
+31 −27 release/go/post/v1/service.pb.go
+2 −10 release/go/post/v1/service.pb.gw.go
+27 −24 release/go/spacemesh/v1/activation.pb.go
+4 −20 release/go/spacemesh/v1/activation.pb.gw.go
+1 −1 release/go/spacemesh/v1/activation_types.pb.go
+37 −34 release/go/spacemesh/v1/admin.pb.go
+5 −25 release/go/spacemesh/v1/admin.pb.gw.go
+516 −159 release/go/spacemesh/v1/admin_types.pb.go
+59 −48 release/go/spacemesh/v1/debug.pb.go
+84 −35 release/go/spacemesh/v1/debug.pb.gw.go
+37 −0 release/go/spacemesh/v1/debug_grpc.pb.go
+483 −113 release/go/spacemesh/v1/debug_types.pb.go
+77 −74 release/go/spacemesh/v1/global_state.pb.go
+12 −60 release/go/spacemesh/v1/global_state.pb.gw.go
+1 −1 release/go/spacemesh/v1/global_state_types.pb.go
+117 −113 release/go/spacemesh/v1/mesh.pb.go
+24 −120 release/go/spacemesh/v1/mesh.pb.gw.go
+1 −1 release/go/spacemesh/v1/mesh_types.pb.go
+56 −52 release/go/spacemesh/v1/node.pb.go
+8 −40 release/go/spacemesh/v1/node.pb.gw.go
+1 −1 release/go/spacemesh/v1/node_types.pb.go
+40 −25 release/go/spacemesh/v1/post.pb.go
+131 −0 release/go/spacemesh/v1/post.pb.gw.go
+90 −0 release/go/spacemesh/v1/post_grpc.pb.go
+284 −30 release/go/spacemesh/v1/post_types.pb.go
+152 −139 release/go/spacemesh/v1/smesher.pb.go
+84 −75 release/go/spacemesh/v1/smesher.pb.gw.go
+42 −0 release/go/spacemesh/v1/smesher_grpc.pb.go
+247 −184 release/go/spacemesh/v1/smesher_types.pb.go
+57 −51 release/go/spacemesh/v1/tx.pb.go
+11 −43 release/go/spacemesh/v1/tx.pb.gw.go
+1 −1 release/go/spacemesh/v1/tx_types.pb.go
+40 −30 release/go/spacemesh/v1/types.pb.go
+426 −0 release/go/spacemesh/v2alpha1/account.pb.go
+163 −0 release/go/spacemesh/v2alpha1/account.pb.gw.go
+107 −0 release/go/spacemesh/v2alpha1/account_grpc.pb.go
+674 −0 release/go/spacemesh/v2alpha1/activation.pb.go
+348 −0 release/go/spacemesh/v2alpha1/activation.pb.gw.go
+259 −0 release/go/spacemesh/v2alpha1/activation_grpc.pb.go
+158 −0 release/go/spacemesh/v2alpha1/block.pb.go
+552 −0 release/go/spacemesh/v2alpha1/layer.pb.go
+271 −0 release/go/spacemesh/v2alpha1/layer.pb.gw.go
+222 −0 release/go/spacemesh/v2alpha1/layer_grpc.pb.go
+298 −0 release/go/spacemesh/v2alpha1/network.pb.go
+163 −0 release/go/spacemesh/v2alpha1/network.pb.gw.go
+107 −0 release/go/spacemesh/v2alpha1/network_grpc.pb.go
+340 −0 release/go/spacemesh/v2alpha1/node.pb.go
+163 −0 release/go/spacemesh/v2alpha1/node.pb.gw.go
+107 −0 release/go/spacemesh/v2alpha1/node_grpc.pb.go
+574 −0 release/go/spacemesh/v2alpha1/reward.pb.go
+271 −0 release/go/spacemesh/v2alpha1/reward.pb.gw.go
+222 −0 release/go/spacemesh/v2alpha1/reward_grpc.pb.go
+2,187 −0 release/go/spacemesh/v2alpha1/tx.pb.go
+502 −0 release/go/spacemesh/v2alpha1/tx.pb.gw.go
+333 −0 release/go/spacemesh/v2alpha1/tx_grpc.pb.go
+159 −0 release/go/spacemesh/v2alpha1/v2alpha1.pb.go
+10 −0 release/openapi/swagger/index.html
+4,137 −0 release/openapi/swagger/package-lock.json
+26 −0 release/openapi/swagger/package.json
+1,249 −0 release/openapi/swagger/src/api.swagger.json
+7 −0 release/openapi/swagger/src/index.js
+41 −0 release/openapi/swagger/webpack.config.js
+2 −0 spacemesh/v1/activation.proto
+2 −0 spacemesh/v1/admin.proto
+43 −9 spacemesh/v1/admin_types.proto
+4 −0 spacemesh/v1/debug.proto
+31 −1 spacemesh/v1/debug_types.proto
+3 −0 spacemesh/v1/global_state.proto
+3 −0 spacemesh/v1/mesh.proto
+3 −0 spacemesh/v1/node.proto
+11 −0 spacemesh/v1/post.proto
+36 −0 spacemesh/v1/post_types.proto
+11 −0 spacemesh/v1/smesher.proto
+4 −0 spacemesh/v1/smesher_types.proto
+9 −1 spacemesh/v1/tx.proto
+2 −0 spacemesh/v1/types.proto
+34 −0 spacemesh/v2alpha1/account.proto
+59 −0 spacemesh/v2alpha1/activation.proto
+9 −0 spacemesh/v2alpha1/block.proto
+51 −0 spacemesh/v2alpha1/layer.proto
+25 −0 spacemesh/v2alpha1/network.proto
+28 −0 spacemesh/v2alpha1/node.proto
+52 −0 spacemesh/v2alpha1/reward.proto
+180 −0 spacemesh/v2alpha1/tx.proto
+29 −0 spacemesh/v2alpha1/v2alpha1.proto
21 changes: 20 additions & 1 deletion service/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,6 +47,8 @@ pub trait PostService {
proof: &post::prove::Proof<'a>,
challenge: &[u8],
) -> eyre::Result<()>;

fn interrupt_proof(&self) -> eyre::Result<()>;
}

impl<T: PostService + ?Sized> PostService for std::sync::Arc<T> {
Expand All @@ -60,6 +63,10 @@ impl<T: PostService + ?Sized> PostService for std::sync::Arc<T> {
fn get_metadata(&self) -> &PostMetadata {
self.as_ref().get_metadata()
}

fn interrupt_proof(&self) -> eyre::Result<()> {
self.as_ref().interrupt_proof()
}
}

impl<S: PostService> ServiceClient<S> {
Expand Down Expand Up @@ -148,6 +155,10 @@ impl<S: PostService> ServiceClient<S> {
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 {
Expand Down Expand Up @@ -235,6 +246,14 @@ impl<S: PostService> ServiceClient<S> {
})),
}
}

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 {
Expand Down
10 changes: 9 additions & 1 deletion service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Arc doesn't need to be cloned here

Suggested change
self.stop.clone().store(true, Ordering::Relaxed);
self.stop.store(true, Ordering::Relaxed);

Ok(())
}
}

impl crate::operator::Service for PostService {
Expand Down
Loading