diff --git a/bin/opd8n/src/cli.rs b/bin/opd8n/src/cli.rs index b4fc7e9..86557b9 100644 --- a/bin/opd8n/src/cli.rs +++ b/bin/opd8n/src/cli.rs @@ -27,13 +27,29 @@ pub enum Commands { #[command(flatten)] l1_args: L1Args, }, + /// Gets the L2 block info including the l1 origin for the l2 block number. + #[command(visible_alias = "i")] + Info { + /// The L2 Chain ID + #[clap(short, long, help = "L2 chain ID")] + l2_chain_id: u64, + /// The L2 block number to get info for + #[clap(short, long, help = "L2 block number")] + l2_block: u64, + /// The rpc url to fetch L2 block info from. + #[clap(long, help = "RPC url to fetch L2 block info from")] + rpc_url: String, + }, } #[derive(Parser, Clone, Debug)] pub struct L1Args { - /// A list of L1 blocks to fetch data from. - #[clap(short, long, help = "L1 block number")] - pub blocks: Vec, + /// The L1 block number to start from + #[clap(short, long, help = "Starting L1 block number")] + pub start_block: u64, + /// The L1 block number to end at + #[clap(short, long, help = "Ending L1 block number")] + pub end_block: u64, /// A list of L2 output root hashes to assert against. #[clap(short, long, help = "L2 output root hashes")] pub outputs: Vec, @@ -58,6 +74,11 @@ impl Cli { match self.command { Commands::FromL2 { input } => Self::load(input).await, Commands::FromL1 { l1_args } => crate::from_l1::run(l1_args).await, + Commands::Info { + l2_chain_id, + l2_block, + rpc_url, + } => crate::info::run(l2_chain_id, l2_block, rpc_url).await, } } diff --git a/bin/opd8n/src/from_l1.rs b/bin/opd8n/src/from_l1.rs index 644ea42..90692c3 100644 --- a/bin/opd8n/src/from_l1.rs +++ b/bin/opd8n/src/from_l1.rs @@ -22,8 +22,8 @@ use crate::cli::L1Args; /// data associated with this block. pub async fn run(args: L1Args) -> Result<()> { ensure!( - !args.blocks.is_empty(), - "Must provide at least one L1 block number" + args.end_block > args.start_block, + "End block must come after the start block" ); let outputs = if args.derive { derive(&args).await? @@ -34,17 +34,10 @@ pub async fn run(args: L1Args) -> Result<()> { !outputs.is_empty(), "Must provide at least one L2 output root" ); - let min = args - .blocks - .iter() - .min() - .ok_or_else(|| eyre!("No minimum block number"))?; - let max = args - .blocks - .iter() - .max() - .ok_or_else(|| eyre!("No maximum block number"))?; - trace!(target: "from-l1", "Producing derivation fixture for L1 block range [{}, {}]", min, max); + trace!(target: "from-l1", "Producing derivation fixture for L1 block range [{}, {}]", args.start_block, args.end_block); + + // Construct a sequential list of block numbers from [start_block, end_block]. + let blocks = (args.start_block..=args.end_block).collect::>(); // Construct the providers let l1_rpc_url = Url::parse(&args.rpc_url).map_err(|e| eyre!("Invalid L1 RPC URL: {}", e))?; @@ -72,7 +65,7 @@ pub async fn run(args: L1Args) -> Result<()> { let fixture_blocks = build_fixture_blocks( batcher_address, signer, - &args.blocks, + &blocks, &mut l1_provider, &mut blob_provider, ) diff --git a/bin/opd8n/src/info.rs b/bin/opd8n/src/info.rs new file mode 100644 index 0000000..e586cea --- /dev/null +++ b/bin/opd8n/src/info.rs @@ -0,0 +1,23 @@ +//! Info Module + +use color_eyre::eyre::{eyre, Result}; +use kona_derive::online::AlloyL2ChainProvider; +use kona_derive::traits::L2ChainProvider; +use reqwest::Url; +use std::sync::Arc; +use superchain_registry::ROLLUP_CONFIGS; + +pub async fn run(l2_chain_id: u64, block: u64, rpc_url: String) -> Result<()> { + let url = Url::parse(&rpc_url).map_err(|e| eyre!("Invalid RPC URL: {}", e))?; + let rollup_config = ROLLUP_CONFIGS + .get(&l2_chain_id) + .ok_or_else(|| eyre!("No rollup config found for chain id: {}", l2_chain_id))?; + let rollup_config = Arc::new(rollup_config.clone()); + let mut provider = AlloyL2ChainProvider::new_http(url, rollup_config); + let info = provider + .l2_block_info_by_number(block) + .await + .map_err(|e| eyre!("Failed to fetch block info: {}", e))?; + println!("{:#?}", info); + Ok(()) +} diff --git a/bin/opd8n/src/main.rs b/bin/opd8n/src/main.rs index bb964fa..52e9279 100644 --- a/bin/opd8n/src/main.rs +++ b/bin/opd8n/src/main.rs @@ -4,6 +4,7 @@ use color_eyre::eyre::Result; pub mod blobs; pub mod cli; pub mod from_l1; +pub mod info; #[tokio::main] async fn main() -> Result<()> { diff --git a/fixtures/derivation/.gitkeep b/fixtures/derivation/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/fixtures/derivation/Block1000000.json b/fixtures/derivation/Block1000000.json new file mode 100644 index 0000000..ccbfeed --- /dev/null +++ b/fixtures/derivation/Block1000000.json @@ -0,0 +1,52 @@ +{ + "l1Blocks": [ + { + "number": 1000000, + "hash": "0xf2f366c335a21d93f415bd4fbb15503e66909dd1d29acdcc1361bcaabe552c25", + "timestamp": 1639128595, + "transactions": [ + "0xf8ab83053152830f42408307a1209425e1c58040f27ecf20bbd4ca83a09290326896b380b844202ee0ed000000000000000000000000000000000000000000000000000000000000f87d0000000000000000000000000000000000000000000000000000005f625aa20037a0aa428b8edc295c6fe45ac547d0ea0d7b5d21cddffa540a0efe2c3919faafba2ca0074d95c243613761482ba8de82d35b35e4c2c7036f52e91eda0c1ef1375a3dd4" + ], + "blobs": [] + }, + { + "number": 1000001, + "hash": "0x3461f55097bad77c0a272eddf68a49fc6baf89b0d005e65a6fa73872cb95e9ee", + "timestamp": 1639128595, + "transactions": [ + "0xf8ab83034cfb830f42408307a120942e4a187732166a0282e52527b931c96146ac7c5880b844202ee0ed0000000000000000000000000000000000000000000000000000000000019de90000000000000000000000000000000000000000000000000000000021989dee38a004f4b36800df92a4ce2ad303b02529488e75cb2d25724047e0d85d0d6e996b34a01415643e528c0360f16a22e5d51ec2299bffc82c937ad0e8c4f02ec18696ee11" + ], + "blobs": [] + }, + { + "number": 1000002, + "hash": "0xcb884ef66577a707544a25945a01fa2135d047d7fb89089ef227b8dafa8e0e4a", + "timestamp": 1639128595, + "transactions": [ + "0xf8ab83053153830f42408307a120942e4a187732166a0282e52527b931c96146ac7c5880b844202ee0ed0000000000000000000000000000000000000000000000000000000000019de900000000000000000000000000000000000000000000000000000000216b64d938a0784693b8703f496918f6ec86570c2b6c612ffd2d04de9e95acceaa193c3e1894a02d0bcdc6885f12f16beb09e0a997ae07c1120e5f3bb086a76face876956b6d2a" + ], + "blobs": [] + }, + { + "number": 1000003, + "hash": "0x9a30d7d3487f54d099a9f0aaf3b5b70f5ed0eb02cf7e27e0abef69c71576108f", + "timestamp": 1639128595, + "transactions": [ + "0xf8ab8304c91e830f42408307a120942e4a187732166a0282e52527b931c96146ac7c5880b844202ee0ed0000000000000000000000000000000000000000000000000000000000019de900000000000000000000000000000000000000000000000000000000216275b538a0d7c0fa6c5addd96ef7d1401cfff00ac93e456512319e943100520d581852bd0fa01a91ce34ab319bd85fbe063ce85c0344d491dda07bf4ec53c8e2e911421aae46" + ], + "blobs": [] + }, + { + "number": 1000004, + "hash": "0x077eebe1973ffc700426c5b9b286decd18a90e055298b268e5d5378265ea5922", + "timestamp": 1639128595, + "transactions": [ + "0xf8ab830475a8830f42408307a120942e4a187732166a0282e52527b931c96146ac7c5880b844202ee0ed0000000000000000000000000000000000000000000000000000000000019de900000000000000000000000000000000000000000000000000000000215ddec038a039a12a6bfae4354eec9f03fd917de52a67d03b2b510c741e6693aab230849680a044bc938dd8cd9151a2554f35c190ad3cfdec16c492a3b793b3ebb70425cb3de9" + ], + "blobs": [] + } + ], + "l2OutputRoots": [ + "0x0000000000000000000000000000000000000000000000000000000000000000" + ] +} \ No newline at end of file