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(scripts): Add finalized block check #211

Merged
merged 2 commits into from
Nov 7, 2024
Merged
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
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.

19 changes: 5 additions & 14 deletions scripts/prove/bin/multi.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alloy_eips::BlockId;
use anyhow::Result;
use clap::Parser;
use op_succinct_host_utils::{
block_range::get_validated_block_range,
fetcher::{CacheMode, OPSuccinctDataFetcher},
get_proof_stdin,
stats::ExecutionStats,
Expand Down Expand Up @@ -61,20 +61,11 @@ async fn main() -> Result<()> {
CacheMode::DeleteCache
};

// If the end block is not provided, use the latest finalized block.
let l2_end_block = match args.end {
Some(end) => end,
None => {
let header = data_fetcher.get_l2_header(BlockId::finalized()).await?;
header.number
}
};
const DEFAULT_RANGE: u64 = 5;

// If the start block is not provided, use the end block - 5.
let l2_start_block = match args.start {
Some(start) => start,
None => l2_end_block - 5,
};
// If the end block is provided, check that it is less than the latest finalized block. If the end block is not provided, use the latest finalized block.
let (l2_start_block, l2_end_block) =
get_validated_block_range(&data_fetcher, args.start, args.end, DEFAULT_RANGE).await?;

let host_cli = data_fetcher
.get_host_cli_args(l2_start_block, l2_end_block, ProgramType::Multi, cache_mode)
Expand Down
20 changes: 4 additions & 16 deletions scripts/utils/bin/cost_estimator.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use alloy::eips::BlockId;
use anyhow::Result;
use clap::Parser;
use futures::StreamExt;
use kona_host::HostCli;
use log::info;
use op_succinct_host_utils::{
block_range::get_validated_block_range,
fetcher::{CacheMode, OPSuccinctDataFetcher},
get_proof_stdin,
stats::ExecutionStats,
Expand Down Expand Up @@ -279,23 +279,11 @@ async fn main() -> Result<()> {
utils::setup_logger();

let data_fetcher = OPSuccinctDataFetcher::new_with_rollup_config().await?;

let l2_chain_id = data_fetcher.get_l2_chain_id().await?;

// If the end block is not provided, use the latest finalized block.
let l2_end_block = match args.end {
Some(end) => end,
None => {
let header = data_fetcher.get_l2_header(BlockId::finalized()).await?;
header.number
}
};

// If the start block is not provided, use the start block - 5.
let l2_start_block = match args.start {
Some(start) => start,
None => l2_end_block - 5,
};
const DEFAULT_RANGE: u64 = 5;
let (l2_start_block, l2_end_block) =
get_validated_block_range(&data_fetcher, args.start, args.end, DEFAULT_RANGE).await?;

let split_ranges = split_range(l2_start_block, l2_end_block, l2_chain_id, args.batch_size);

Expand Down
1 change: 1 addition & 0 deletions utils/host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ alloy-rlp.workspace = true
alloy-primitives.workspace = true
alloy-consensus.workspace = true
alloy-sol-types.workspace = true
alloy-eips.workspace = true

# kona
kona-host.workspace = true
Expand Down
44 changes: 44 additions & 0 deletions utils/host/src/block_range.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use crate::fetcher::OPSuccinctDataFetcher;
use alloy_eips::BlockId;
use anyhow::{bail, Result};

/// Get the start and end block numbers for a range, with validation.
pub async fn get_validated_block_range(
data_fetcher: &OPSuccinctDataFetcher,
start: Option<u64>,
end: Option<u64>,
default_range: u64,
) -> Result<(u64, u64)> {
let header = data_fetcher.get_l2_header(BlockId::finalized()).await?;

// If end block not provided, use latest finalized block
let l2_end_block = match end {
Some(end) => {
if end > header.number {
bail!(
"The end block ({}) is greater than the latest finalized block ({})",
end,
header.number
);
}
end
}
None => header.number,
};

// If start block not provided, use end block - default_range
let l2_start_block = match start {
Some(start) => start,
None => l2_end_block.saturating_sub(default_range),
};

if l2_start_block >= l2_end_block {
bail!(
"Start block ({}) must be less than end block ({})",
l2_start_block,
l2_end_block
);
}

Ok((l2_start_block, l2_end_block))
}
1 change: 1 addition & 0 deletions utils/host/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod block_range;
pub mod fetcher;
pub mod helpers;
pub mod rollup_config;
Expand Down
Loading