Skip to content

Commit

Permalink
fix(mpc): allow exiting cli at any point
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-aitlahcen committed Jul 31, 2024
1 parent 723fad4 commit 3eb388b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/src/routes/ceremony/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import { createClient, type Provider } from "@supabase/supabase-js";
const apiKey =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImJmZmNvbHdjYWtxcmhsem55am5zIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjIwOTc5OTgsImV4cCI6MjAzNzY3Mzk5OH0.9dVeafP8atsYqwdtPVYmzIhqMr_DEkHKdfoN3eqxjC0";
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Ind3cXB5bGJyY3ByaXlhcXVnenNpIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjI0MzMyMjQsImV4cCI6MjAzODAwOTIyNH0.UQOmQ-wE63O32lyrLDO7ryowrM5LNA2UILHDA7hTH8E";
const supabase = createClient(
"https://bffcolwcakqrhlznyjns.supabase.co",
"https://wwqpylbrcpriyaqugzsi.supabase.co",
apiKey,
);
Expand Down
1 change: 1 addition & 0 deletions mpc/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["full"] }
tokio-util = "0.7"
22 changes: 12 additions & 10 deletions mpc/client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ use tokio::{
mpsc, oneshot, RwLock,
},
};
use tokio_util::sync::CancellationToken;
use types::Status;

const SUPABASE_PROJECT: &str = "https://bffcolwcakqrhlznyjns.supabase.co";
const SUPABASE_PROJECT: &str = "https://wwqpylbrcpriyaqugzsi.supabase.co";
const ENDPOINT: &str = "/contribute";

#[derive(PartialEq, Eq, Debug, Clone, Deserialize)]
Expand Down Expand Up @@ -376,9 +377,9 @@ async fn input_and_status_handling(
tokio::spawn(async move {
while let Ok(status) = rx_status.recv().await {
*latest_status.write().await = status.clone();
tx_ui_clone
.send(ui::Event::NewStatus(status))
.expect("impossible");
if let Err(_) = tx_ui_clone.send(ui::Event::NewStatus(status)) {
break;
}
}
});
tokio::spawn(async move {
Expand Down Expand Up @@ -410,8 +411,9 @@ async fn main() -> Result<(), DynError> {
let lock = Arc::new(AtomicBool::new(false));
let (tx_status, rx_status) = broadcast::channel(64);
let graceful = GracefulShutdown::new();
let (tx_shutdown, mut rx_shutdown) = oneshot::channel::<()>();
let status_clone = status.clone();
let token = CancellationToken::new();
let token_clone = token.clone();
let handle = tokio::spawn(async move {
let addr = SocketAddr::from(([127, 0, 0, 1], 0x1337));
let listener = TcpListener::bind(addr).await.unwrap();
Expand Down Expand Up @@ -440,12 +442,12 @@ async fn main() -> Result<(), DynError> {
}
});
}
_ = &mut rx_shutdown => {
graceful.shutdown().await;
break
_ = token_clone.cancelled() => {
break;
}
}
}
graceful.shutdown().await;
});
// Dispatch terminal
let (tx_ui, rx_ui) = mpsc::unbounded_channel();
Expand All @@ -462,7 +464,7 @@ async fn main() -> Result<(), DynError> {
ui::run_ui(&mut terminal, rx_ui).await?;
crossterm::terminal::disable_raw_mode()?;
terminal.clear()?;
tx_shutdown.send(()).expect("impossible");
token.cancel();
handle.await.expect("impossible");
Ok(())
std::process::exit(0);
}
2 changes: 1 addition & 1 deletion mpc/coordinator/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::{Parser, Subcommand};
use mpc_shared::{phase2_verify, supabase::SupabaseMPCApi};

const SUPABASE_PROJECT: &str = "https://bffcolwcakqrhlznyjns.supabase.co";
const SUPABASE_PROJECT: &str = "https://wwqpylbrcpriyaqugzsi.supabase.co";

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
Expand Down

0 comments on commit 3eb388b

Please sign in to comment.