From 9bcc11ee96d89d4d45ded9be9d66574ae1c80505 Mon Sep 17 00:00:00 2001 From: Jacob Kaufmann Date: Thu, 17 Aug 2023 12:05:08 -0600 Subject: [PATCH] refactor: IntoIterator trait bounds in builder (#46) --- src/builder.rs | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index fc7b16b..3078b04 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -142,7 +142,7 @@ pub struct Job { } impl Job { - fn new>( + fn new>( config: JobConfig, client: Arc, pool: Arc, @@ -151,6 +151,7 @@ impl Job { invalidated: Fuse>, ) -> Self { let bundles = bundles + .into_iter() .map(|bundle| (bundle.id, BundleCompact(bundle.txs))) .collect(); let built_payloads = Vec::new(); @@ -233,7 +234,7 @@ where let pool = Arc::clone(&this.pool); let pending = task::spawn_blocking(move || { // TODO: come back to this - build(config, client, pool, bundles.into_iter()) + build(config, client, pool, bundles) }); this.pending_payloads.push_back(pending); @@ -311,7 +312,7 @@ where self.config.clone(), Arc::clone(&self.client), Arc::new(NoopTransactionPool::default()), - None.into_iter(), + None, )?; Ok(empty.inner) } @@ -326,7 +327,7 @@ where let client = Arc::clone(&self.client); let pool = Arc::new(NoopTransactionPool::default()); task::spawn_blocking(move || { - let payload = build(config, client, pool, None.into_iter()); + let payload = build(config, client, pool, None); let _ = tx.send(payload); }); @@ -503,7 +504,7 @@ where config, Arc::clone(&self.client), Arc::clone(&self.pool), - bundles.into_iter(), + bundles, incoming, invalidated, )) @@ -519,7 +520,7 @@ fn build( where Client: StateProviderFactory, P: TransactionPool, - I: Iterator, + I: IntoIterator, { let state = client.state_by_block_hash(config.parent.hash)?; let state = State::new(state); @@ -535,7 +536,7 @@ fn build_on_state( where S: StateProvider, P: TransactionPool, - I: Iterator, + I: IntoIterator, { let state = Arc::new(state); let mut db = CacheDB::new(Arc::clone(&state)); @@ -585,7 +586,7 @@ where &cfg_env, &block_env, cumulative_gas_used, - bundle.clone().into_iter(), + bundle.clone(), ); match execution { Ok(execution) => { @@ -621,7 +622,7 @@ where &cfg_env, &block_env, cumulative_gas_used, - Some(recovered_tx.clone()).into_iter(), + Some(recovered_tx.clone()), ); match execution { Ok(execution) => { @@ -670,7 +671,7 @@ where &cfg_env, &block_env, cumulative_gas_used, - Some(payment_tx.clone()).into_iter(), + Some(payment_tx.clone()), ) .map_err(PayloadBuilderError::EvmExecutionError)?; cumulative_gas_used = execution.cumulative_gas_used; @@ -723,7 +724,7 @@ fn execute( ) -> Result> where S: StateProvider, - I: Iterator, + I: IntoIterator, { let block_num = block_env.number.to::(); @@ -972,14 +973,8 @@ mod tests { ); // execute the transfer transaction - let execution = execute( - &mut db, - &cfg_env, - &block_env, - 0, - Some(transfer_tx).into_iter(), - ) - .expect("execution doesn't fail"); + let execution = execute(&mut db, &cfg_env, &block_env, 0, Some(transfer_tx)) + .expect("execution doesn't fail"); let Execution { post_state, cumulative_gas_used, @@ -1073,7 +1068,7 @@ mod tests { sender_nonce, ); - let execution = execute(&mut db, &cfg_env, &block_env, 0, Some(call_tx).into_iter()) + let execution = execute(&mut db, &cfg_env, &block_env, 0, Some(call_tx)) .expect("execution doesn't fail"); let Execution { post_state,