Skip to content

Commit

Permalink
Merge pull request #63 from ethereum-optimism/refcell/from-l2
Browse files Browse the repository at this point in the history
fix(opdn): Implement from-l2 subcommand with generated fixture
  • Loading branch information
refcell authored Aug 16, 2024
2 parents b805aba + 67de1ef commit 75f4fa6
Show file tree
Hide file tree
Showing 24 changed files with 276,852 additions and 462 deletions.
296 changes: 168 additions & 128 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = ["crates/*", "bin/*"]
default-members = ["bin/opt8n", "bin/opd8n", "bin/range-finder"]
default-members = ["bin/opt8n", "bin/opdn", "bin/range-finder"]
resolver = "2"

[workspace.package]
Expand All @@ -25,6 +25,7 @@ clap = { version = "4", features = ["derive"] }
shellwords = "1"
reqwest = "0.12"
tracing-subscriber = "0.3.18"
hashbrown = "0.14.5"

# Alloy Dependencies
op-alloy-rpc-types = "0.1.4"
Expand All @@ -35,17 +36,17 @@ alloy-eips = { version = "0.2" }
alloy-rpc-types = { version = "0.2" }

# Foundry Dependencies
foundry-common = { git = "https://github.com/foundry-rs/foundry", default-features = true, rev = "26a7559758c192911dd39ce7d621a18ef0d419e6" }
foundry-compilers = { git = "https://github.com/foundry-rs/foundry", default-features = true, rev = "26a7559758c192911dd39ce7d621a18ef0d419e6" }
anvil = { git = "https://github.com/foundry-rs/foundry", default-features = true, rev = "26a7559758c192911dd39ce7d621a18ef0d419e6" }
anvil-core = { git = "https://github.com/foundry-rs/foundry", default-features = true, rev = "26a7559758c192911dd39ce7d621a18ef0d419e6" }
cast = { git = "https://github.com/foundry-rs/foundry", rev = "26a7559758c192911dd39ce7d621a18ef0d419e6" }
forge-script = { git = "https://github.com/foundry-rs/foundry", rev = "26a7559758c192911dd39ce7d621a18ef0d419e6" }
foundry-common = { git = "https://github.com/foundry-rs/foundry", default-features = true, rev = "c600237f3e54604274bfdcba627f347493fd21d2" }
foundry-compilers = { git = "https://github.com/foundry-rs/foundry", default-features = true, rev = "c600237f3e54604274bfdcba627f347493fd21d2" }
anvil = { git = "https://github.com/foundry-rs/foundry", default-features = true, rev = "c600237f3e54604274bfdcba627f347493fd21d2" }
anvil-core = { git = "https://github.com/foundry-rs/foundry", default-features = true, rev = "c600237f3e54604274bfdcba627f347493fd21d2" }
cast = { git = "https://github.com/foundry-rs/foundry", rev = "c600237f3e54604274bfdcba627f347493fd21d2" }
forge-script = { git = "https://github.com/foundry-rs/foundry", rev = "c600237f3e54604274bfdcba627f347493fd21d2" }
revm = { version = "12.1", features = ["alloydb", "optimism"] }

# Kona + OP Types
superchain-registry = "0.2.2"
kona-derive = { git = "https://github.com/ethereum-optimism/kona", rev = "6f7c119d93c854d31de27feadbe11362bafe9cfc", features = ["online"] }
kona-derive = { git = "https://github.com/ethereum-optimism/kona", rev = "4e57dd35ea08b31d0baa293c7a12165f28e6cd92", features = ["online"] }

# Internal
op-test-vectors = { path = "crates/op-test-vectors" }
168 changes: 0 additions & 168 deletions bin/opd8n/src/cmd/from_l1.rs

This file was deleted.

23 changes: 0 additions & 23 deletions bin/opd8n/src/cmd/from_l2.rs

This file was deleted.

3 changes: 2 additions & 1 deletion bin/opd8n/Cargo.toml → bin/opdn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "opd8n"
name = "opdn"
version = "0.2.0"
edition.workspace = true
authors.workspace = true
Expand All @@ -10,6 +10,7 @@ publish = false

[dependencies]
# Core
hashbrown.workspace = true
serde.workspace = true
tracing.workspace = true
serde_json.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion bin/opd8n/README.md → bin/opdn/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `opd8n`
# `opdn`

A CLI-tool for creating derivation test fixtures.
10 changes: 8 additions & 2 deletions bin/opd8n/src/cmd/blobs.rs → bin/opdn/src/cmd/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use alloy_primitives::{Address, TxKind};
use color_eyre::Result;
use tracing::warn;

use kona_derive::online::{OnlineBeaconClient, OnlineBlobProvider, SimpleSlotDerivation};
use kona_derive::online::{
OnlineBeaconClient, OnlineBlobProviderWithFallback, SimpleSlotDerivation,
};
use kona_derive::traits::BlobProvider;
use kona_derive::types::{Blob, BlockInfo, IndexedBlobHash};

Expand All @@ -15,7 +17,11 @@ pub async fn load(
txs: &[TxEnvelope],
batcher_address: Address,
signer: Address,
provider: &mut OnlineBlobProvider<OnlineBeaconClient, SimpleSlotDerivation>,
provider: &mut OnlineBlobProviderWithFallback<
OnlineBeaconClient,
OnlineBeaconClient,
SimpleSlotDerivation,
>,
) -> Result<Vec<Box<Blob>>> {
let blob_hashes = extract_blob_data(batcher_address, signer, txs);

Expand Down
68 changes: 68 additions & 0 deletions bin/opdn/src/cmd/fixtures.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//! Logic for building the derivation fixture blocks.

use crate::cmd::blobs;
use alloy_eips::eip2718::Encodable2718;
use alloy_primitives::Address;
use color_eyre::eyre::{eyre, Result};
use kona_derive::online::{
AlloyChainProvider, OnlineBeaconClient, OnlineBlobProviderWithFallback, SimpleSlotDerivation,
};
use kona_derive::traits::ChainProvider;
use op_test_vectors::derivation::FixtureBlock;

/// Constructs [FixtureBlock]s for the given L1 blocks.
pub async fn build_fixture_blocks(
batcher_address: Address,
signer: Address,
blocks: &[u64],
l1_provider: &mut AlloyChainProvider,
blob_provider: &mut OnlineBlobProviderWithFallback<
OnlineBeaconClient,
OnlineBeaconClient,
SimpleSlotDerivation,
>,
) -> Result<Vec<FixtureBlock>> {
let mut fixtures = Vec::with_capacity(blocks.len());
for b in blocks {
let block_info = l1_provider
.block_info_by_number(*b)
.await
.map_err(|e| eyre!(e))?;
let block_header = l1_provider
.header_by_hash(block_info.hash)
.await
.map_err(|e| eyre!(e))?;
let (_, txs) = l1_provider
.block_info_and_transactions_by_hash(block_info.hash)
.await
.map_err(|e| eyre!(e))?;
let mut transactions = Vec::with_capacity(txs.len());
for tx in txs.as_slice() {
let mut out = Vec::new();
tx.encode_2718(&mut out);
transactions.push(out.into());
}
let receipts = l1_provider
.receipts_by_hash(block_info.hash)
.await
.map_err(|e| eyre!(e))?;

let blobs = blobs::load(
&block_info,
txs.as_slice(),
batcher_address,
signer,
blob_provider,
)
.await?;

let fixture = FixtureBlock {
header: block_header,
transactions,
blobs,
receipts,
};
fixtures.push(fixture);
}
Ok(fixtures)
}
Loading

0 comments on commit 75f4fa6

Please sign in to comment.