risc0 / zeth

A "Type 0" zkEVM. Prove validity of Ethereum blocks using RISC Zero's zkVM
Apache License 2.0
381 stars 68 forks source link

fix: update fs write and thread sleep to async versions #26

Closed austinabell closed 1 year ago

austinabell commented 1 year ago

I was skimming code and noticed this. Doesn't matter now since nothing is being executed async (didn't look in depth), but it is a good future proof if there is in order not to block the executor.

Alternatively, since it seems like nothing needs to be async, this could be done to remove the runtime until it's needed:

diff --git a/host/src/main.rs b/host/src/main.rs
index d0809fc..8b97021 100644
--- a/host/src/main.rs
+++ b/host/src/main.rs
@@ -82,8 +82,7 @@ fn cache_file_path(cache_path: &String, network: &String, block_no: u64, ext: &s
     format!("{}/{}/{}.{}", cache_path, network, block_no, ext)
 }

-#[tokio::main]
-async fn main() -> Result<()> {
+fn main() -> Result<()> {
     env_logger::init();
     let args = Args::parse();

@@ -93,11 +92,8 @@ async fn main() -> Result<()> {
         .as_ref()
         .map(|dir| cache_file_path(dir, &args.network.to_string(), args.block_no, "json.gz"));

-    let init = tokio::task::spawn_blocking(move || {
-        zeth_lib::host::get_initial_data(rpc_cache, args.rpc_url, args.block_no)
-            .expect("Could not init")
-    })
-    .await?;
+    let init = zeth_lib::host::get_initial_data(rpc_cache, args.rpc_url, args.block_no)
+        .expect("Could not init");

     let input: Input = init.clone().into();

I'm assuming this was made to be async because maybe there is a plan to change the bonsai HTTP calls to async or have more logic be handled in parallel in the future, which is why I suggested the change I PRed.

Feel free to close; this change doesn't matter right now. I just figured I'd point it out!

austinabell commented 1 year ago

We actually kinda use async for RPC calls, but then we do block_on to make it blocking

Oh, I did definitely skim over that detail, I didn't see the provider nested in the get_initial_data call. My alternate suggestion in the diff is obviously not valid then, I did not expect that :D