Skip to content

fix: Harden prover #75

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions bin/cli/tests/devnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ async fn proposer_validator() {
bypass_chain_registry: true,
skip_derivation_proof: false,
skip_await_proof: false,
clear_cache_data: true,
hokulea: Default::default(),
hana: Default::default(),
},
Expand Down Expand Up @@ -325,6 +326,7 @@ async fn proposer_validator() {
bypass_chain_registry: true,
skip_derivation_proof: false,
skip_await_proof: false,
clear_cache_data: true,
hokulea: Default::default(),
hana: Default::default(),
},
Expand Down Expand Up @@ -452,6 +454,7 @@ async fn prover() {
bypass_chain_registry: false,
skip_derivation_proof: false,
skip_await_proof: false,
clear_cache_data: true,
hokulea: Default::default(),
hana: Default::default(),
},
Expand Down
3 changes: 3 additions & 0 deletions crates/prover/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ pub struct ProvingArgs {
/// Whether to skip waiting for the proof generation process to complete
#[clap(long, env, default_value_t = false)]
pub skip_await_proof: bool,
/// Whether to keep cache data after successful completion
#[clap(long, env, default_value_t = false)]
pub clear_cache_data: bool,

#[clap(flatten)]
pub hokulea: HokuleaArgs,
Expand Down
25 changes: 24 additions & 1 deletion crates/prover/src/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use opentelemetry::trace::{TraceContextExt, Tracer};
use std::collections::BinaryHeap;
use std::env::set_var;
use tempfile::tempdir;
use tokio::fs::remove_dir_all;
use tracing::{error, info, warn};

pub async fn prove(mut args: ProveArgs) -> anyhow::Result<()> {
Expand Down Expand Up @@ -338,7 +339,7 @@ pub async fn prove(mut args: ProveArgs) -> anyhow::Result<()> {
if proofs.len() > 1 {
info!("Composing {} proofs together.", proofs.len());
// construct a proving instruction with no blocks to derive
let mut base_args = args;
let mut base_args = args.clone();
{
// set last block as starting point
base_args.kona.agreed_l2_output_root = base_args.kona.claimed_l2_output_root;
Expand Down Expand Up @@ -380,6 +381,28 @@ pub async fn prove(mut args: ProveArgs) -> anyhow::Result<()> {
}
}

// Cleanup cached data
drop(disk_kv_store);
cleanup_cache_data(&args).await;

info!("Exiting prover program.");
Ok(())
}

pub async fn cleanup_cache_data(args: &ProveArgs) {
let Some(data_dir) = args.kona.data_dir.as_ref() else {
return;
};
if !args.proving.clear_cache_data {
warn!("Cache data directory {} was persisted.", data_dir.display());
return;
}
if let Err(err) = remove_dir_all(data_dir).await {
error!(
"Failed to cleanup cache directory {}: {err:?}",
data_dir.display()
);
} else {
info!("Cache data directory {} was removed.", data_dir.display());
}
}
4 changes: 2 additions & 2 deletions crates/sync/src/provider/beacon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl BlobProvider {
debug!("genesis {:?}", &genesis);
let genesis_time = genesis["data"]["genesis_time"]
.as_str()
.unwrap()
.ok_or_else(|| anyhow::anyhow!("genesis time is None"))?
.parse::<u64>()?;
let spec = await_tel!(
context,
Expand All @@ -71,7 +71,7 @@ impl BlobProvider {
debug!("spec {:?}", &spec);
let seconds_per_slot = spec["data"]["SECONDS_PER_SLOT"]
.as_str()
.unwrap()
.ok_or_else(|| anyhow::anyhow!("seconds per slot is None"))?
.parse::<u64>()?;
Ok(Self {
cl_node_endpoint,
Expand Down
12 changes: 8 additions & 4 deletions crates/sync/src/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::await_tel;
use crate::provider::beacon::BlobProvider;
use crate::provider::optimism::OpNodeProvider;
use crate::{await_tel, retry_res_ctx};
use alloy::providers::RootProvider;
use anyhow::Context;
use opentelemetry::trace::{FutureExt, TraceContextExt, Tracer};

pub mod beacon;
Expand Down Expand Up @@ -58,8 +57,13 @@ impl SyncProvider {
let tracer = opentelemetry::global::tracer("kailua");
let context = opentelemetry::Context::current_with_span(tracer.start("SyncProvider::new"));

let da_provider = await_tel!(context, BlobProvider::new(args.beacon_rpc_url.clone()))
.context("BlobProvider::new")?;
let da_provider = await_tel!(
context,
tracer,
"BlobProvider::new",
retry_res_ctx!(BlobProvider::new(args.beacon_rpc_url.clone()))
);

let l1_provider = RootProvider::new_http(args.eth_rpc_url.as_str().try_into()?);
let op_provider = OpNodeProvider(RootProvider::new_http(
args.op_node_url.as_str().try_into()?,
Expand Down
Loading