Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit 7e1d201

Browse files
committed
lint
1 parent 2b08e85 commit 7e1d201

File tree

5 files changed

+30
-50
lines changed

5 files changed

+30
-50
lines changed

bin/opt8n/src/cli/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use alloy_primitives::Address;
44
use clap::{ArgAction, Parser};
55
use color_eyre::eyre::{eyre, Result};
6-
use t8n::T8n;
76
use std::path::PathBuf;
7+
use t8n::T8n;
88
use tokio::sync::broadcast::{self};
99
use tracing::Level;
1010

bin/opt8n/src/cli/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl<'a> StateCapture<'a> {
9393
};
9494

9595
let l1_info_tx = transactions
96-
.get(0)
96+
.first()
9797
.ok_or(eyre!("L1 info transaction not present"))?;
9898
let raw_tx = l2_provider
9999
.raw_request::<[B256; 1], Bytes>("debug_getRawTransaction".into(), [*l1_info_tx])

bin/opt8n/src/cli/t8n.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! The `opt8n` application.
22
33
use super::{deposits::DepositCapture, state::StateCapture, Cli};
4-
use crate::generator::STF;
4+
use crate::generator::StateTransition;
55
use alloy_genesis::Genesis;
66
use alloy_primitives::Bytes;
77
use color_eyre::{eyre::ensure, owo_colors::OwoColorize, Result};
@@ -32,8 +32,8 @@ impl<'a> T8n<'a> {
3232
Self {
3333
cli,
3434
interrupt: interrupt.clone(),
35-
state_cfg: StateCapture::new(&cli),
36-
deposits: DepositCapture::new(&cli, interrupt),
35+
state_cfg: StateCapture::new(cli),
36+
deposits: DepositCapture::new(cli, interrupt),
3737
transactions: Default::default(),
3838
}
3939
}
@@ -85,7 +85,7 @@ impl<'a> T8n<'a> {
8585
let genesis: Genesis =
8686
serde_json::from_slice(&std::fs::read(&self.cli.l2_genesis)?)?;
8787

88-
let mut stf = STF::new(genesis, self.state_cfg.allocs.clone())?;
88+
let mut stf = StateTransition::new(genesis, self.state_cfg.allocs.clone())?;
8989

9090
// Sanity check that the pre-state root is correct before proceeding.
9191
ensure!(

bin/opt8n/src/generator/mod.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ use revm::{
2525
use std::{collections::BTreeMap, sync::Arc};
2626
use tracing::info;
2727

28-
/// The database for [STF].
29-
type STFDB = CacheDB<EmptyDBTyped<ProviderError>>;
28+
/// The database for [StateTransition].
29+
type StfDb = CacheDB<EmptyDBTyped<ProviderError>>;
3030

3131
/// The execution fixture generator for `opt8n`.
32-
pub(crate) struct STF {
32+
pub(crate) struct StateTransition {
3333
/// Inner cache database.
34-
pub(crate) db: STFDB,
34+
pub(crate) db: StfDb,
3535
/// The [ChainSpec] for the devnet chain.
3636
pub(crate) chain_spec: Arc<ChainSpec>,
3737
}
3838

39-
impl STF {
39+
impl StateTransition {
4040
/// Create a new execution fixture generator.
4141
pub(crate) fn new(genesis: Genesis, state_dump: DumpBlockResponse) -> Result<Self> {
4242
let mut db = CacheDB::default();
@@ -59,7 +59,7 @@ impl STF {
5959
.storage
6060
.as_ref()
6161
.unwrap_or(&BTreeMap::new())
62-
.into_iter()
62+
.iter()
6363
.map(|(k, v)| ((*k).into(), (*v).into()))
6464
.collect(),
6565
account_state: AccountState::None,
@@ -79,11 +79,7 @@ impl STF {
7979
};
8080
db.insert_contract(&mut info);
8181

82-
let entry = db
83-
.accounts
84-
.entry(*k)
85-
.or_insert_with(|| DbAccount::default());
86-
82+
let entry = db.accounts.entry(*k).or_default();
8783
entry.info = info;
8884
if let Some(storage) = &account.storage {
8985
storage.iter().for_each(|(k, v)| {
@@ -99,7 +95,7 @@ impl STF {
9995
}
10096

10197
/// Grab the block executor with the current state.
102-
pub(crate) fn executor(&mut self) -> OpBlockExecutor<OptimismEvmConfig, STFDB> {
98+
pub(crate) fn executor(&mut self) -> OpBlockExecutor<OptimismEvmConfig, StfDb> {
10399
// Construct an ephemeral state with the current database.
104100
let state = State::builder()
105101
.with_database(self.db.clone())
@@ -178,11 +174,7 @@ impl STF {
178174
let mut info = account.info.clone().unwrap_or_default();
179175
self.db.insert_contract(&mut info);
180176

181-
let db_account = self
182-
.db
183-
.accounts
184-
.entry(*address)
185-
.or_insert_with(|| DbAccount::default());
177+
let db_account = self.db.accounts.entry(*address).or_default();
186178
if account.is_info_changed() {
187179
db_account.info = info;
188180
}
@@ -225,7 +217,12 @@ impl STF {
225217
current_number: U256::from(header.number),
226218
current_timestamp: U256::from(header.timestamp),
227219
parent_beacon_block_root: header.parent_beacon_block_root,
228-
block_hashes: Default::default(),
220+
block_hashes: Some(
221+
[(U256::from(header.number - 1), header.parent_hash)]
222+
.iter()
223+
.cloned()
224+
.collect::<HashMap<_, _>>(),
225+
),
229226
},
230227
transactions: encoded_txs,
231228
result: ExecutionResult {
@@ -281,11 +278,10 @@ impl STF {
281278
.code
282279
.as_ref()
283280
.map(|code| match code {
284-
Bytecode::LegacyRaw(code) => Some(keccak256(code)),
285-
Bytecode::LegacyAnalyzed(code) => Some(keccak256(code.bytecode())),
281+
Bytecode::LegacyRaw(code) => keccak256(code),
282+
Bytecode::LegacyAnalyzed(code) => keccak256(code.bytecode()),
286283
_ => panic!("Unsupported bytecode type"),
287284
})
288-
.flatten()
289285
.unwrap_or(KECCAK_EMPTY),
290286
};
291287

@@ -313,8 +309,8 @@ impl STF {
313309
Ok(hb.root())
314310
}
315311

316-
/// Transforms a [STFDB] into a map of [Address]es to [GenesisAccount]s.
317-
fn gen_allocs(db: STFDB) -> HashMap<Address, GenesisAccount> {
312+
/// Transforms a [StfDb] into a map of [Address]es to [GenesisAccount]s.
313+
fn gen_allocs(db: StfDb) -> HashMap<Address, GenesisAccount> {
318314
db.accounts
319315
.iter()
320316
.map(|(address, account)| {
Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
11
{
2-
"stateRoot": "0x1c99b01120e7a2fa1301b3505f20100e72362e5ac3f96854420e56ba8984d716",
3-
"txRoot": "0xb5eee60b45801179cbde3781b9a5dee9b3111554618c9cda3d6f7e351fd41e0b",
4-
"receiptRoot": "0x86ceb80cb6bef8fe4ac0f1c99409f67cb2554c4432f374e399b94884eb3e6562",
2+
"stateRoot": "0xadff407345f10f9ca555978665f414508b0ae6f75bb3e021db66a43329d35bdd",
3+
"txRoot": "0x23e4973bf3a2315801178524b870d66a00a0e9e312f24c150d56f42faa8521de",
4+
"receiptRoot": "0xf171a9e908a0720088e1b71d26079b7bf3702f02b38e0dec0c57e7aa41087aa3",
55
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
66
"receipts": [
7-
{
8-
"root": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
9-
"status": "0x1",
10-
"type": "0x0",
11-
"from": "0x25ace71c97b33cc4729cf772ae268934f7ab5fa1",
12-
"to": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
13-
"cumulativeGasUsed": "0xa878",
14-
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
15-
"logs": [],
16-
"transactionHash": "0x4e6549e2276d1bc256b2a56ead2d9705a51a8bf54e3775fbd2e98c91fb0e4494",
17-
"contractAddress": "0x0000000000000000000000000000000000000000",
18-
"blockNumber": "0x76976ad",
19-
"gasUsed": "0xa878",
20-
"effectiveGasPrice": "0x1",
21-
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
22-
"transactionIndex": "0x0"
23-
}
7+
"0xca7e0182b5eac08203a901"
248
]
25-
}
9+
}

0 commit comments

Comments
 (0)