Skip to content

Commit b8ececc

Browse files
Receive network as a reference in the sdk functions since is never modified
1 parent 2909fb3 commit b8ececc

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

crates/sdk/src/communication/batch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ pub fn process_batcher_response(
3838
pub async fn await_batch_verification(
3939
aligned_verification_data: &AlignedVerificationData,
4040
rpc_url: &str,
41-
network: Network,
41+
network: &Network,
4242
) -> Result<(), errors::SubmitError> {
4343
for _ in 0..RETRIES {
44-
if is_proof_verified(aligned_verification_data, network.clone(), rpc_url)
44+
if is_proof_verified(aligned_verification_data, network, rpc_url)
4545
.await
4646
.is_ok_and(|r| r)
4747
{

crates/sdk/src/verification_layer/mod.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,21 @@ use std::path::PathBuf;
8282
#[allow(clippy::too_many_arguments)] // TODO: Refactor this function, use NoncedVerificationData
8383
pub async fn submit_multiple_and_wait_verification(
8484
eth_rpc_url: &str,
85-
network: Network,
85+
network: &Network,
8686
verification_data: &[VerificationData],
8787
max_fee: U256,
8888
wallet: Wallet<SigningKey>,
8989
nonce: U256,
9090
) -> Vec<Result<AlignedVerificationData, errors::SubmitError>> {
9191
let mut aligned_verification_data =
92-
submit_multiple(network.clone(), verification_data, max_fee, wallet, nonce).await;
92+
submit_multiple(network, verification_data, max_fee, wallet, nonce).await;
9393

9494
// TODO: open issue: use a join to .await all at the same time, avoiding the loop
9595
// And await only once per batch, no need to await multiple proofs if they are in the same batch.
9696
let mut error_awaiting_batch_verification: Option<errors::SubmitError> = None;
9797
for aligned_verification_data_item in aligned_verification_data.iter().flatten() {
9898
if let Err(e) =
99-
await_batch_verification(aligned_verification_data_item, eth_rpc_url, network.clone())
100-
.await
99+
await_batch_verification(aligned_verification_data_item, eth_rpc_url, network).await
101100
{
102101
error_awaiting_batch_verification = Some(e);
103102
break;
@@ -230,7 +229,7 @@ async fn fetch_gas_price(
230229
/// * `ProofQueueFlushed` if there is an error in the batcher and the proof queue is flushed.
231230
/// * `GenericError` if the error doesn't match any of the previous ones.
232231
pub async fn submit_multiple(
233-
network: Network,
232+
network: &Network,
234233
verification_data: &[VerificationData],
235234
max_fee: U256,
236235
wallet: Wallet<SigningKey>,
@@ -263,7 +262,7 @@ pub async fn submit_multiple(
263262
async fn _submit_multiple(
264263
ws_write: Arc<Mutex<SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, Message>>>,
265264
mut ws_read: SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>,
266-
network: Network,
265+
network: &Network,
267266
verification_data: &[VerificationData],
268267
max_fee: U256,
269268
wallet: Wallet<SigningKey>,
@@ -351,7 +350,7 @@ async fn _submit_multiple(
351350
#[allow(clippy::too_many_arguments)] // TODO: Refactor this function, use NoncedVerificationData
352351
pub async fn submit_and_wait_verification(
353352
eth_rpc_url: &str,
354-
network: Network,
353+
network: &Network,
355354
verification_data: &VerificationData,
356355
max_fee: U256,
357356
wallet: Wallet<SigningKey>,
@@ -406,7 +405,7 @@ pub async fn submit_and_wait_verification(
406405
/// * `ProofQueueFlushed` if there is an error in the batcher and the proof queue is flushed.
407406
/// * `GenericError` if the error doesn't match any of the previous ones.
408407
pub async fn submit(
409-
network: Network,
408+
network: &Network,
410409
verification_data: &VerificationData,
411410
max_fee: U256,
412411
wallet: Wallet<SigningKey>,
@@ -442,7 +441,7 @@ pub async fn submit(
442441
/// * `HexDecodingError` if there is an error decoding the Aligned service manager contract address.
443442
pub async fn is_proof_verified(
444443
aligned_verification_data: &AlignedVerificationData,
445-
network: Network,
444+
network: &Network,
446445
eth_rpc_url: &str,
447446
) -> Result<bool, errors::VerificationError> {
448447
let eth_rpc_provider =
@@ -455,10 +454,10 @@ pub async fn is_proof_verified(
455454

456455
async fn _is_proof_verified(
457456
aligned_verification_data: &AlignedVerificationData,
458-
network: Network,
457+
network: &Network,
459458
eth_rpc_provider: Provider<Http>,
460459
) -> Result<bool, errors::VerificationError> {
461-
let contract_address = network.clone().get_aligned_service_manager_address();
460+
let contract_address = network.get_aligned_service_manager_address();
462461
let payment_service_addr = network.get_batcher_payment_service_address();
463462

464463
// All the elements from the merkle proof have to be concatenated
@@ -532,7 +531,7 @@ pub fn get_vk_commitment(
532531
/// # Errors
533532
/// * `EthRpcError` if the batcher has an error in the Ethereum call when retrieving the nonce if not already cached.
534533
pub async fn get_nonce_from_batcher(
535-
network: Network,
534+
network: &Network,
536535
address: Address,
537536
) -> Result<U256, GetNonceError> {
538537
let (ws_stream, _) = connect_async(network.get_batcher_url())
@@ -608,7 +607,7 @@ pub async fn get_nonce_from_batcher(
608607
pub async fn get_nonce_from_ethereum(
609608
eth_rpc_url: &str,
610609
submitter_addr: Address,
611-
network: Network,
610+
network: &Network,
612611
) -> Result<U256, GetNonceError> {
613612
let eth_rpc_provider = Provider::<Http>::try_from(eth_rpc_url)
614613
.map_err(|e| GetNonceError::EthRpcError(e.to_string()))?;

crates/task-sender/src/commands.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ pub async fn send_infinite_proofs(args: SendInfiniteProofsArgs) {
328328
loop {
329329
let n = network_clone.clone();
330330
let mut result = Vec::with_capacity(args.burst_size);
331-
let nonce = get_nonce_from_batcher(n.clone(), wallet.address())
331+
let nonce = get_nonce_from_batcher(&n, wallet.address())
332332
.await
333333
.inspect_err(|e| {
334334
error!(
@@ -351,7 +351,7 @@ pub async fn send_infinite_proofs(args: SendInfiniteProofsArgs) {
351351
);
352352

353353
let aligned_verification_data = submit_multiple(
354-
n.clone(),
354+
&n,
355355
&verification_data_to_send.clone(),
356356
max_fee,
357357
wallet.clone(),

0 commit comments

Comments
 (0)