Skip to content
This repository was archived by the owner on Aug 3, 2026. It is now read-only.

Commit 9322071

Browse files
committed
refactor: clean up and optimize code structure
- Removed unused BatchMetadata and BatchProofRequest structs from interfaces.rs. - Simplified various function implementations and improved readability across multiple files. - Adjusted logging statements for better clarity and consistency. - Enhanced type handling and reduced complexity in preflight and provider modules. Made-with: Cursor
1 parent 429ef1f commit 9322071

46 files changed

Lines changed: 372 additions & 1216 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ballot/src/poisson.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ impl PoissionDrawer {
2020
let mut last_draw_time = HashMap::new();
2121

2222
for (ptype, (_rate, per_day)) in config {
23+
#[allow(clippy::clone_on_copy)]
2324
per_day_limit.insert(ptype.clone(), per_day as usize);
2425
let interval = if per_day == 0 {
2526
0
@@ -60,7 +61,7 @@ impl PoissionDrawer {
6061
.get(proof_type)
6162
.cloned()
6263
.unwrap_or_default();
63-
let delta = now.signed_duration_since(&last_time).num_seconds();
64+
let delta = now.signed_duration_since(last_time).num_seconds();
6465
if delta <= 0 {
6566
return false;
6667
}

core/src/interfaces.rs

Lines changed: 5 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -378,122 +378,6 @@ pub struct ProofRequest {
378378
pub cached_event_data: Option<raiko_lib::input::BlockProposedFork>,
379379
}
380380

381-
#[serde_as]
382-
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
383-
pub struct BatchMetadata {
384-
pub batch_id: u64,
385-
pub l1_inclusion_block_number: u64,
386-
}
387-
388-
impl std::str::FromStr for BatchMetadata {
389-
type Err = anyhow::Error;
390-
391-
fn from_str(s: &str) -> Result<Self, Self::Err> {
392-
let parts: Vec<&str> = s.split(':').collect();
393-
let [batch_id_str, l1_str] = parts.as_slice() else {
394-
return Err(anyhow::anyhow!(
395-
"Invalid BatchMetadata format. Expected 'batch_id:l1_inclusion_block_number'"
396-
));
397-
};
398-
Ok(Self {
399-
batch_id: batch_id_str.parse().map_err(|_| anyhow::anyhow!("Invalid batch_id"))?,
400-
l1_inclusion_block_number: l1_str
401-
.parse()
402-
.map_err(|_| anyhow::anyhow!("Invalid l1_inclusion_block_number"))?,
403-
})
404-
}
405-
}
406-
407-
impl std::fmt::Display for BatchMetadata {
408-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
409-
write!(f, "{}:{}", self.batch_id, self.l1_inclusion_block_number)
410-
}
411-
}
412-
413-
#[serde_as]
414-
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
415-
pub struct BatchProofRequest {
416-
pub batches: Vec<BatchMetadata>,
417-
pub aggregate: bool,
418-
pub proof_type: ProofType,
419-
420-
pub network: String,
421-
pub l1_network: String,
422-
pub graffiti: B256,
423-
#[serde_as(as = "DisplayFromStr")]
424-
pub prover: Address,
425-
pub blob_proof_type: BlobProofType,
426-
#[serde(flatten)]
427-
pub prover_args: ProverSpecificOpts,
428-
}
429-
430-
#[serde_as]
431-
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
432-
pub struct BatchProofRequestOpt {
433-
// Required fields
434-
pub batches: Vec<BatchMetadata>,
435-
pub aggregate: Option<bool>,
436-
pub proof_type: String,
437-
438-
// Optional fields, if not provided, the default values will be used
439-
pub network: Option<String>,
440-
pub l1_network: Option<String>,
441-
pub graffiti: Option<String>,
442-
pub prover: Option<String>,
443-
pub blob_proof_type: Option<String>,
444-
#[serde(flatten)]
445-
pub prover_args: Option<ProverSpecificOpts>,
446-
}
447-
448-
impl TryFrom<BatchProofRequestOpt> for BatchProofRequest {
449-
type Error = RaikoError;
450-
451-
fn try_from(value: BatchProofRequestOpt) -> Result<Self, Self::Error> {
452-
Ok(Self {
453-
batches: value.batches,
454-
aggregate: value.aggregate.unwrap_or(false),
455-
proof_type: value
456-
.proof_type
457-
.parse()
458-
.map_err(|_| RaikoError::InvalidRequestConfig("Invalid proof_type".to_string()))?,
459-
460-
network: value.network.ok_or(RaikoError::InvalidRequestConfig(
461-
"Missing network".to_string(),
462-
))?,
463-
l1_network: value.l1_network.ok_or(RaikoError::InvalidRequestConfig(
464-
"Missing l1_network".to_string(),
465-
))?,
466-
graffiti: value
467-
.graffiti
468-
.ok_or(RaikoError::InvalidRequestConfig(
469-
"Missing graffiti".to_string(),
470-
))?
471-
.parse()
472-
.map_err(|_| RaikoError::InvalidRequestConfig("Invalid graffiti".to_string()))?,
473-
prover: value
474-
.prover
475-
.ok_or(RaikoError::InvalidRequestConfig(
476-
"Missing prover".to_string(),
477-
))?
478-
.parse()
479-
.map_err(|_| RaikoError::InvalidRequestConfig("Invalid prover".to_string()))?,
480-
blob_proof_type: value
481-
.blob_proof_type
482-
.unwrap_or("proof_of_equivalence".to_string())
483-
.parse()
484-
.map_err(|_| {
485-
RaikoError::InvalidRequestConfig("Invalid blob_proof_type".to_string())
486-
})?,
487-
prover_args: value
488-
.prover_args
489-
.ok_or(RaikoError::InvalidRequestConfig(
490-
"Missing prover_args".to_string(),
491-
))?
492-
.into(),
493-
})
494-
}
495-
}
496-
497381
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
498382
pub struct ShastaProposalCheckpoint {
499383
pub block_number: u64,
@@ -504,7 +388,7 @@ pub struct ShastaProposalCheckpoint {
504388
impl From<ShastaProposalCheckpoint> for Checkpoint {
505389
fn from(value: ShastaProposalCheckpoint) -> Self {
506390
Checkpoint {
507-
blockNumber: value.block_number.into(),
391+
blockNumber: value.block_number,
508392
blockHash: value.block_hash,
509393
stateRoot: value.state_root,
510394
}
@@ -526,9 +410,7 @@ impl std::fmt::Display for ShastaProposal {
526410
write!(
527411
f,
528412
"{}:{:?}:{}",
529-
self.proposal_id,
530-
self.checkpoint,
531-
self.l1_inclusion_block_number
413+
self.proposal_id, self.checkpoint, self.l1_inclusion_block_number
532414
)
533415
}
534416
}
@@ -602,12 +484,9 @@ impl TryFrom<ShastaProofRequestOpt> for ShastaProofRequest {
602484
.map_err(|_| {
603485
RaikoError::InvalidRequestConfig("Invalid blob_proof_type".to_string())
604486
})?,
605-
prover_args: value
606-
.prover_args
607-
.ok_or(RaikoError::InvalidRequestConfig(
608-
"Missing prover_args".to_string(),
609-
))?
610-
.into(),
487+
prover_args: value.prover_args.ok_or(RaikoError::InvalidRequestConfig(
488+
"Missing prover_args".to_string(),
489+
))?,
611490
})
612491
}
613492
}

core/src/lib.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ impl Raiko {
5959
prover_data: TaikoProverData {
6060
graffiti: self.request.graffiti,
6161
actual_prover: self.request.prover,
62-
checkpoint: self.request.checkpoint.clone().map(ShastaProposalCheckpoint::into),
62+
checkpoint: self
63+
.request
64+
.checkpoint
65+
.clone()
66+
.map(ShastaProposalCheckpoint::into),
6367
last_anchor_block_number: self.request.last_anchor_block_number,
6468
},
6569
blob_proof_type: self.request.blob_proof_type.clone(),
@@ -74,9 +78,7 @@ impl Raiko {
7478
//TODO: read fork from config
7579
let preflight_data = self.get_batch_preflight_data();
7680
info!("Generating batch input for batch {}", self.request.batch_id);
77-
batch_preflight(provider, preflight_data)
78-
.await
79-
.map_err(Into::<RaikoError>::into)
81+
batch_preflight(provider, preflight_data).await
8082
}
8183

8284
pub fn get_output(&self, input: &GuestInput) -> RaikoResult<GuestOutput> {
@@ -98,7 +100,10 @@ impl Raiko {
98100
})?;
99101

100102
debug!("Verifying final state using provider data ...");
101-
debug!("Final block hash derived successfully. {}", header.hash_slow());
103+
debug!(
104+
"Final block hash derived successfully. {}",
105+
header.hash_slow()
106+
);
102107
debug!("Final block header derived successfully. {header:?}");
103108
check_header(&input.block.header, &header)?;
104109

@@ -161,8 +166,15 @@ impl Raiko {
161166
})?;
162167

163168
let header = &block.header;
164-
debug!("Verifying final block {} state using provider data ...", header.number);
165-
debug!("Final block {} hash derived successfully. {}", header.number, header.hash_slow());
169+
debug!(
170+
"Verifying final block {} state using provider data ...",
171+
header.number
172+
);
173+
debug!(
174+
"Final block {} hash derived successfully. {}",
175+
header.number,
176+
header.hash_slow()
177+
);
166178
debug!("Final block derived successfully. {block:?}");
167179
check_header(&input.block.header, header)?;
168180

@@ -528,5 +540,4 @@ mod tests {
528540
let aggregated_proof = aggregate_single_shasta_proof(&proof_request, &proof).await;
529541
println!("aggregated shasta proof: {aggregated_proof:?}");
530542
}
531-
532543
}

core/src/preflight/lru.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![cfg(feature = "statedb_lru")]
21
use lazy_static::lazy_static;
32
use std::{collections::HashMap, num::NonZeroUsize, sync::Mutex};
43

core/src/preflight/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ use tracing::{debug, info};
2525

2626
use util::{execute_txs, get_batch_blocks_and_parent_data, prepare_taiko_chain_batch_input};
2727

28-
pub use util::{
29-
parse_l1_batch_proposal_tx_for_shasta_fork,
30-
};
28+
pub use util::parse_l1_batch_proposal_tx_for_shasta_fork;
3129

3230
#[cfg(feature = "statedb_lru")]
3331
use lru::{load_state_db, save_state_db};
@@ -146,6 +144,7 @@ pub async fn batch_preflight<BDP: BlockDataProvider>(
146144
.unwrap_or(PREFETCH_CHUNK_SIZE_DEFAULT);
147145

148146
let mut handles = Vec::new();
147+
#[allow(clippy::type_complexity)]
149148
let tasks: Vec<(
150149
(reth_primitives::Block, alloy_rpc_types::Block),
151150
(Vec<TransactionSigned>, bool),

core/src/preflight/util.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ use raiko_lib::{
1717
inplace_print,
1818
input::{
1919
shasta::{Proposed as ShastaProposed, ShastaEventData},
20-
BlobProofType, BlockProposedFork, InputDataSource, TaikoGuestBatchInput,
21-
TaikoProverData,
20+
BlobProofType, BlockProposedFork, InputDataSource, TaikoGuestBatchInput, TaikoProverData,
2221
},
2322
primitives::eip4844::{self, commitment_to_version_hash, KZG_SETTINGS},
2423
utils::shasta_rules::anchor_max_offset_for_chain,
@@ -36,8 +35,8 @@ use crate::{
3635
};
3736

3837
/// Optimize data gathering by executing the transactions multiple times so data can be requested in batches
39-
pub async fn execute_txs<'a, BDP>(
40-
builder: &mut RethBlockBuilder<ProviderDb<'a, BDP>>,
38+
pub async fn execute_txs<BDP>(
39+
builder: &mut RethBlockBuilder<ProviderDb<'_, BDP>>,
4140
pool_txs: Vec<reth_primitives::TransactionSigned>,
4241
) -> RaikoResult<()>
4342
where
@@ -126,6 +125,7 @@ pub async fn parse_l1_batch_proposal_tx_for_shasta_fork(
126125
}
127126

128127
/// Prepare Shasta batch input
128+
#[allow(clippy::too_many_arguments)]
129129
async fn prepare_shasta_batch_input(
130130
shasta_event_data: raiko_lib::input::shasta::ShastaEventData,
131131
batch_id: u64,
@@ -200,6 +200,7 @@ async fn prepare_shasta_batch_input(
200200
})
201201
}
202202

203+
#[allow(clippy::too_many_arguments)]
203204
async fn prepare_taiko_chain_batch_input_shasta(
204205
l1_chain_spec: &ChainSpec,
205206
taiko_chain_spec: &ChainSpec,
@@ -258,6 +259,7 @@ async fn prepare_taiko_chain_batch_input_shasta(
258259
}
259260

260261
/// Prepare the input for a Taiko chain
262+
#[allow(clippy::too_many_arguments)]
261263
pub async fn prepare_taiko_chain_batch_input(
262264
l1_chain_spec: &ChainSpec,
263265
taiko_chain_spec: &ChainSpec,
@@ -422,8 +424,8 @@ pub async fn filter_block_proposed_event(
422424
let l1_address = chain_spec
423425
.l1_contract
424426
.get(&fork)
425-
.ok_or_else(|| anyhow!("L1 contract address not found for fork {fork:?}"))?
426-
.clone();
427+
.copied()
428+
.ok_or_else(|| anyhow!("L1 contract address not found for fork {fork:?}"))?;
427429

428430
// Get the event signature (value can differ between chains)
429431
let event_signature = match fork {
@@ -508,11 +510,6 @@ pub async fn filter_block_proposed_event(
508510
.expect("couldn't query the propose tx")
509511
.expect("Could not find the propose tx");
510512

511-
let block_propose_event = match block_propose_event {
512-
BlockProposedFork::Shasta(event_data) => BlockProposedFork::Shasta(event_data),
513-
_ => block_propose_event,
514-
};
515-
516513
return Ok((log.block_number.unwrap(), tx, block_propose_event));
517514
} else {
518515
info!("block_or_batch_id: {block_or_batch_id} != block_num_or_batch_id: {block_num_or_batch_id}");

core/src/prover.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,12 @@ impl Prover for NativeProver {
142142
proofs: input
143143
.proofs
144144
.iter()
145-
.map(|proof| RawProof {
146-
input: proof.input.clone().unwrap(),
147-
proof: Default::default(),
145+
.map(|proof| {
146+
#[allow(clippy::clone_on_copy)]
147+
RawProof {
148+
input: proof.input.clone().unwrap(),
149+
proof: Default::default(),
150+
}
148151
})
149152
.collect(),
150153
proof_carry_data_vec: input

core/src/provider/db.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ impl<'a, BDP: BlockDataProvider> ProviderDb<'a, BDP> {
6060
let absent_block_numbers = all_init_block_numbers
6161
.into_iter()
6262
.filter(|(block_number, _)| {
63-
!provider_db.initial_db.block_hashes.contains_key(block_number)
63+
!provider_db
64+
.initial_db
65+
.block_hashes
66+
.contains_key(block_number)
6467
})
6568
.collect::<Vec<(u64, bool)>>();
6669
let initial_history_blocks = provider_db
@@ -163,7 +166,7 @@ impl<'a, BDP: BlockDataProvider> ProviderDb<'a, BDP> {
163166
}
164167
}
165168

166-
impl<'a, BDP: BlockDataProvider> Database for ProviderDb<'a, BDP> {
169+
impl<BDP: BlockDataProvider> Database for ProviderDb<'_, BDP> {
167170
type Error = ProviderError;
168171

169172
fn basic(&mut self, address: Address) -> Result<Option<AccountInfo>, Self::Error> {
@@ -299,13 +302,13 @@ impl<'a, BDP: BlockDataProvider> Database for ProviderDb<'a, BDP> {
299302
}
300303
}
301304

302-
impl<'a, BDP: BlockDataProvider> DatabaseCommit for ProviderDb<'a, BDP> {
305+
impl<BDP: BlockDataProvider> DatabaseCommit for ProviderDb<'_, BDP> {
303306
fn commit(&mut self, changes: HashMap<Address, Account>) {
304307
self.current_db.commit(changes);
305308
}
306309
}
307310

308-
impl<'a, BDP: BlockDataProvider> OptimisticDatabase for ProviderDb<'a, BDP> {
311+
impl<BDP: BlockDataProvider> OptimisticDatabase for ProviderDb<'_, BDP> {
309312
async fn fetch_data(&mut self) -> bool {
310313
let valid_run = self.is_valid_run();
311314

core/src/provider/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ pub async fn get_task_data(
5757
.hash
5858
.ok_or_else(|| RaikoError::RPC("No block hash for requested block".to_string()))?;
5959
Ok((taiko_chain_spec.chain_id, blockhash))
60-
}
60+
}

core/src/provider/rpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl BlockDataProvider for RpcBlockDataProvider {
297297
let mut requests = Vec::new();
298298

299299
let mut batch_size = 0;
300-
while !accounts.is_empty() && batch_size < PROOF_BATCH_LIMIT {
300+
while !accounts.is_empty() && batch_size < PROOF_BATCH_LIMIT {
301301
let mut address_to_remove = None;
302302

303303
if let Some((address, keys)) = accounts.iter_mut().next() {

0 commit comments

Comments
 (0)