Skip to content

Commit 44664ae

Browse files
author
Naohiro Yoshida
committed
add inspector
1 parent aa82b66 commit 44664ae

File tree

8 files changed

+115
-64
lines changed

8 files changed

+115
-64
lines changed

Makefile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,9 @@ test:
6161
L2_GETH_PORT=$$(jq -r '.l2GethPort' hostPort.json);\
6262
L2_ROLLUP_ADDR=http://localhost:$$L2_ROLLUP_PORT L2_GETH_ADDR=http://localhost:$$L2_GETH_PORT cargo test --manifest-path=./server/Cargo.toml
6363

64-
.PHONY: test-ignored
65-
test-ignored:
66-
@L2_ROLLUP_PORT=$$(jq -r '.l2RollupPort' hostPort.json);\
67-
L2_GETH_PORT=$$(jq -r '.l2GethPort' hostPort.json);\
68-
REQUEST_PATH=$(CURDIR)/tool/body.json L2_ROLLUP_PORT=$$L2_ROLLUP_PORT L2_GETH_PORT=$$L2_GETH_PORT cargo test --manifest-path=./server/Cargo.toml -- --ignored
64+
.PHONY: inspect
65+
inspect:
66+
cargo test --manifest-path=./server/Cargo.toml -- --ignored
6967

7068
.PHONY: devnet-down
7169
devnet-down:

server/src/client/beacon_client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ where
6161
E: serde::de::Error,
6262
{
6363
v.parse::<u64>()
64-
.map_err(|e| E::custom(format!("invalid u64 string: {}", e)))
64+
.map_err(|e| E::custom(format!("invalid u64 string: {e}")))
6565
}
6666

6767
fn visit_string<E>(self, v: String) -> Result<Self::Value, E>
@@ -83,7 +83,7 @@ impl BeaconClient {
8383
pub async fn get_raw_light_client_finality_update(&self) -> anyhow::Result<String> {
8484
let client = reqwest::Client::new();
8585
let response = client
86-
.get(&format!(
86+
.get(format!(
8787
"{}/eth/v1/beacon/light_client/finality_update",
8888
self.beacon_addr
8989
))
@@ -93,7 +93,7 @@ impl BeaconClient {
9393
response
9494
.text()
9595
.await
96-
.map_err(|e| anyhow::anyhow!("Failed to get finality update: {:?}", e))
96+
.map_err(|e| anyhow::anyhow!("Failed to get finality update: {e:?}"))
9797
}
9898

9999
async fn check_response(&self, response: Response) -> anyhow::Result<Response> {

server/src/collector.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ impl<T: PreimageRepository, F: FinalizedL1Repository> PreimageCollector<T, F> {
116116
}
117117

118118
for batch in batches {
119-
match self
120-
.parallel_collect(l1_head_hash.clone(), batch.to_vec())
121-
.await
122-
{
119+
match self.parallel_collect(l1_head_hash, batch.to_vec()).await {
123120
Ok(end) => latest_l2 = end.unwrap_or(latest_l2),
124121
Err(e) => {
125122
error!(

server/src/data/file_finalized_l1_repository.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl FileFinalizedL1Repository {
2020
}
2121

2222
fn path(&self, l1_head_hash: &B256) -> String {
23-
format!("{}/{}.json", self.dir, l1_head_hash.to_string())
23+
format!("{}/{}.json", self.dir, l1_head_hash)
2424
}
2525

2626
async fn entries(dir: &str) -> anyhow::Result<Vec<DirEntry>> {

server/tests/e2e.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! These tests are required to run the preimage server.
2+
13
use optimism_derivation::derivation::Derivation;
24
use optimism_derivation::oracle::MemoryOracleClient;
35
use optimism_derivation::types::Preimages;
@@ -9,22 +11,19 @@ use optimism_preimage_maker::web::{
911
};
1012
use prost::Message;
1113
use std::env;
12-
use tracing::metadata;
1314
use tracing_subscriber::filter;
1415
use tracing_subscriber::layer::SubscriberExt;
1516
use tracing_subscriber::util::SubscriberInitExt;
1617

17-
/// These tests are required to run the preimage server.
18-
19-
fn init() {
18+
pub fn init() {
2019
let filter = filter::EnvFilter::from_default_env().add_directive("info".parse().unwrap());
2120
let _ = tracing_subscriber::registry()
2221
.with(tracing_subscriber::fmt::layer())
2322
.with(filter)
2423
.try_init();
2524
}
2625

27-
fn get_l2_client() -> L2Client {
26+
pub fn get_l2_client() -> L2Client {
2827
let op_node_addr = env::var("L2_ROLLUP_ADDR").unwrap();
2928
let op_geth_addr = env::var("L2_GETH_ADDR").unwrap();
3029
tracing::info!(
@@ -62,7 +61,7 @@ pub async fn test_derivation_success() {
6261
.json()
6362
.await
6463
.unwrap();
65-
assert!(metadata_list.len() > 0, "No metadata found");
64+
assert!(!metadata_list.is_empty(), "No metadata found");
6665

6766
for metadata in metadata_list {
6867
assert!(metadata.claimed > 100);

server/tests/inspect.rs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
use optimism_preimage_maker::derivation::host::single::config::Config;
2+
use optimism_preimage_maker::derivation::host::single::handler::{
3+
Derivation, DerivationConfig, DerivationRequest,
4+
};
5+
use serde_json::Value;
6+
use serial_test::serial;
7+
use std::env;
8+
use std::sync::Arc;
9+
use tracing::info;
10+
11+
mod e2e;
12+
use e2e::get_l2_client;
13+
use e2e::init;
14+
use optimism_preimage_maker::client::l2_client::{Block, RpcResult};
15+
16+
#[derive(Debug, Clone, serde::Serialize, Default)]
17+
struct RpcRequest {
18+
jsonrpc: String,
19+
method: String,
20+
params: Vec<Value>,
21+
id: i64,
22+
}
23+
24+
async fn get_block_by_number(number: u64, l1_geth_addr: &str) -> anyhow::Result<Block> {
25+
let client = reqwest::Client::new();
26+
let body = RpcRequest {
27+
method: "eth_getBlockByNumber".into(),
28+
params: vec![format!("0x{number:X}").into(), false.into()],
29+
..Default::default()
30+
};
31+
let response = client
32+
.post(l1_geth_addr)
33+
.header("Content-Type", "application/json")
34+
.json(&body)
35+
.send()
36+
.await?;
37+
let result: RpcResult<Block> = response.json().await?;
38+
Ok(result.result)
39+
}
40+
41+
/*
42+
ex)
43+
export L2_ROLLUP_ADDR=http://localhost:9545
44+
export L2_GETH_ADDR=http://localhost:8546
45+
export L1_GETH_ADDR=http://localhost:8545
46+
export L1_BEACON_ADDR=http://localhost:9596
47+
export CLAIMED=104
48+
export AGREED=103
49+
*/
50+
#[serial]
51+
#[tokio::test(flavor = "multi_thread")]
52+
#[ignore]
53+
async fn test_derivation() {
54+
init();
55+
let claimed: u64 = env::var("CLAIMED").unwrap().parse().unwrap();
56+
let agreed: u64 = env::var("AGREED").unwrap().parse().unwrap();
57+
let l2_client = get_l2_client();
58+
let chain_id = l2_client.chain_id().await.unwrap();
59+
60+
let op_geth_addr = env::var("L2__ADDR").unwrap();
61+
let op_node_addr = env::var("L2_ROLLUP_ADDR").unwrap();
62+
let l1_geth_addr = env::var("L1_GETH_ADDR").unwrap();
63+
let l1_beacon_addr = env::var("L1_BEACON_ADDR").unwrap();
64+
65+
let claimed_output = l2_client.output_root_at(claimed).await.unwrap();
66+
let agreed_output = l2_client.output_root_at(agreed).await.unwrap();
67+
let l1_hash = get_block_by_number(
68+
claimed_output.block_ref.l1_origin.number + 100,
69+
&l1_geth_addr,
70+
)
71+
.await
72+
.unwrap()
73+
.hash;
74+
let request = DerivationRequest {
75+
l1_head_hash: l1_hash,
76+
agreed_l2_head_hash: agreed_output.block_ref.hash,
77+
agreed_l2_output_root: agreed_output.output_root,
78+
l2_output_root: claimed_output.output_root,
79+
l2_block_number: claimed,
80+
};
81+
82+
let config = Arc::new(DerivationConfig {
83+
config: Config {
84+
l2_node_address: op_geth_addr.to_string(),
85+
l1_node_address: l1_geth_addr.to_string(),
86+
l1_beacon_address: l1_beacon_addr.to_string(),
87+
l2_rollup_address: op_node_addr.to_string(),
88+
..Default::default()
89+
},
90+
rollup_config: None,
91+
l2_chain_id: chain_id,
92+
l1_chain_config: None,
93+
});
94+
95+
info!("derivation start : {:?}", &request);
96+
let derivation = Derivation { config, request };
97+
let result = derivation.start().await;
98+
match result {
99+
Ok(_) => info!("derivation success"),
100+
Err(e) => panic!("derivation failed: {e:?}"),
101+
}
102+
}

tool/derive.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

tool/output.sh

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)