Skip to content

Commit

Permalink
Introduce op-info tool (#48)
Browse files Browse the repository at this point in the history
* Introduce op-info tool

* Whitespace

* Update host/Cargo.toml

Co-authored-by: Wolfgang Welz <[email protected]>

* Update Cargo.lock

---------

Co-authored-by: Wolfgang Welz <[email protected]>
  • Loading branch information
intoverflow and Wollac authored Oct 26, 2023
1 parent 2f12782 commit 69402de
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
alloy-sol-types = "0.4"
anyhow = "1.0"
bincode = "1.3.3"
bonsai-sdk = { workspace = true }
Expand Down
96 changes: 96 additions & 0 deletions host/src/bin/op-info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright 2023 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use alloy_sol_types::{sol, SolInterface};
use anyhow::Result;
use clap::Parser;
use zeth_lib::host::provider::{new_provider, BlockQuery};

sol! {
#[derive(Debug)]
interface OpSystemInfo {
function setL1BlockValues(
uint64 _number,
uint64 _timestamp,
uint256 _basefee,
bytes32 _hash,
uint64 _sequenceNumber,
bytes32 _batcherHash,
uint256 _l1FeeOverhead,
uint256 _l1FeeScalar
);
}
}

#[derive(Parser, Debug, Clone)]
#[clap(author, version, about, long_about = None)]
struct Args {
#[clap(long, require_equals = true)]
/// URL of the L2 RPC node.
op_rpc_url: Option<String>,

#[clap(short, long, require_equals = true, num_args = 0..=1, default_missing_value = "host/testdata")]
/// Use a local directory as a cache for RPC calls. Accepts a custom directory.
/// [default: host/testdata]
cache: Option<String>,

#[clap(long, require_equals = true)]
/// L2 block number to begin from
block_no: u64,
}

fn cache_file_path(cache_path: &String, network: &str, block_no: u64, ext: &str) -> String {
format!("{}/{}/{}.{}", cache_path, network, block_no, ext)
}

fn op_cache_path(args: &Args, block_no: u64) -> Option<String> {
args.cache
.as_ref()
.map(|dir| cache_file_path(dir, "optimism", block_no, "json.gz"))
}

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

let op_block = tokio::task::spawn_blocking(move || {
let mut provider =
new_provider(op_cache_path(&args, args.block_no), args.op_rpc_url.clone())
.expect("Could not create provider");

let op_block = provider
.get_full_block(&BlockQuery {
block_no: args.block_no,
})
.expect("Could not fetch OP block");
provider.save().expect("Could not save cache");

op_block
})
.await?;

let system_tx_data = op_block
.transactions
.first()
.expect("No transactions")
.input
.to_vec();
let set_l1_block_values = OpSystemInfo::OpSystemInfoCalls::abi_decode(&system_tx_data, true)
.expect("Could not decode call data");

println!("{:?}", set_l1_block_values);

Ok(())
}

0 comments on commit 69402de

Please sign in to comment.