Skip to content

Commit f8a5cef

Browse files
refactor: avoid cloning immutable values (#1995)
1 parent f8b33ac commit f8a5cef

File tree

3 files changed

+34
-37
lines changed

3 files changed

+34
-37
lines changed

crates/cli/src/main.rs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -541,33 +541,33 @@ async fn main() -> Result<(), AlignedError> {
541541
let chain_id = get_chain_id(eth_rpc_url.as_str()).await?;
542542
wallet = wallet.with_chain_id(chain_id);
543543

544+
let used_network: Network = submit_args.network.clone().into();
545+
544546
let nonce = match &submit_args.nonce {
545547
Some(nonce) => U256::from_dec_str(nonce).map_err(|_| SubmitError::InvalidNonce)?,
546-
None => {
547-
get_nonce_from_batcher(submit_args.network.clone().into(), wallet.address())
548-
.await
549-
.map_err(|e| match e {
550-
aligned_sdk::common::errors::GetNonceError::EthRpcError(e) => {
551-
SubmitError::GetNonceError(e)
552-
}
553-
aligned_sdk::common::errors::GetNonceError::ConnectionFailed(e) => {
554-
SubmitError::GenericError(e)
555-
}
556-
aligned_sdk::common::errors::GetNonceError::InvalidRequest(e) => {
557-
SubmitError::GenericError(e)
558-
}
559-
aligned_sdk::common::errors::GetNonceError::SerializationError(e) => {
560-
SubmitError::GenericError(e)
561-
}
562-
aligned_sdk::common::errors::GetNonceError::ProtocolMismatch {
563-
current,
564-
expected,
565-
} => SubmitError::ProtocolVersionMismatch { current, expected },
566-
aligned_sdk::common::errors::GetNonceError::UnexpectedResponse(e) => {
567-
SubmitError::UnexpectedBatcherResponse(e)
568-
}
569-
})?
570-
}
548+
None => get_nonce_from_batcher(used_network.clone(), wallet.address())
549+
.await
550+
.map_err(|e| match e {
551+
aligned_sdk::common::errors::GetNonceError::EthRpcError(e) => {
552+
SubmitError::GetNonceError(e)
553+
}
554+
aligned_sdk::common::errors::GetNonceError::ConnectionFailed(e) => {
555+
SubmitError::GenericError(e)
556+
}
557+
aligned_sdk::common::errors::GetNonceError::InvalidRequest(e) => {
558+
SubmitError::GenericError(e)
559+
}
560+
aligned_sdk::common::errors::GetNonceError::SerializationError(e) => {
561+
SubmitError::GenericError(e)
562+
}
563+
aligned_sdk::common::errors::GetNonceError::ProtocolMismatch {
564+
current,
565+
expected,
566+
} => SubmitError::ProtocolVersionMismatch { current, expected },
567+
aligned_sdk::common::errors::GetNonceError::UnexpectedResponse(e) => {
568+
SubmitError::UnexpectedBatcherResponse(e)
569+
}
570+
})?,
571571
};
572572

573573
warn!("Nonce: {nonce}");
@@ -587,10 +587,10 @@ async fn main() -> Result<(), AlignedError> {
587587
info!("Submitting proofs to the Aligned batcher...");
588588

589589
let aligned_verification_data_vec = submit_multiple(
590-
submit_args.network.clone().into(),
590+
used_network.clone(),
591591
&verification_data_arr,
592592
max_fee_wei,
593-
wallet.clone(),
593+
wallet,
594594
nonce,
595595
)
596596
.await;
@@ -625,7 +625,7 @@ async fn main() -> Result<(), AlignedError> {
625625
}
626626

627627
for batch_merkle_root in unique_batch_merkle_roots {
628-
let base_url = match submit_args.network.clone().into() {
628+
let base_url = match used_network {
629629
Network::Holesky => "https://holesky.explorer.alignedlayer.com/batches/0x",
630630
Network::HoleskyStage => "https://stage.explorer.alignedlayer.com/batches/0x",
631631
Network::Mainnet => "https://explorer.alignedlayer.com/batches/0x",
@@ -725,7 +725,7 @@ async fn main() -> Result<(), AlignedError> {
725725
let chain_id = get_chain_id(eth_rpc_url.as_str()).await?;
726726
wallet = wallet.with_chain_id(chain_id);
727727

728-
let client = SignerMiddleware::new(eth_rpc_provider.clone(), wallet.clone());
728+
let client = SignerMiddleware::new(eth_rpc_provider, wallet);
729729

730730
match deposit_to_aligned(amount_wei, client, deposit_to_batcher_args.network.into())
731731
.await
@@ -777,8 +777,7 @@ async fn main() -> Result<(), AlignedError> {
777777
}
778778
GetUserNonceFromEthereum(args) => {
779779
let address = H160::from_str(&args.address).unwrap();
780-
let network = args.network.into();
781-
match get_nonce_from_ethereum(&args.eth_rpc_url, address, network).await {
780+
match get_nonce_from_ethereum(&args.eth_rpc_url, address, args.network.into()).await {
782781
Ok(nonce) => {
783782
info!(
784783
"Nonce for address {} in BatcherPaymentService contract is {}",

crates/sdk/src/verification_layer/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,7 @@ async fn _is_proof_verified(
470470
.flatten()
471471
.collect();
472472

473-
let verification_data_comm = aligned_verification_data
474-
.verification_data_commitment
475-
.clone();
473+
let verification_data_comm = &aligned_verification_data.verification_data_commitment;
476474

477475
let service_manager = aligned_service_manager(eth_rpc_provider, contract_address).await?;
478476

crates/task-sender/src/commands.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ pub async fn send_infinite_proofs(args: SendInfiniteProofsArgs) {
318318
let network: Network = args.network.into();
319319
info!("Starting senders!");
320320
for (i, sender) in senders.iter().enumerate() {
321+
// this clones are necessary because of the move
321322
let wallet = sender.wallet.clone();
322323
let verification_data = verification_data.clone();
323-
// this is necessary because of the move
324324
let network_clone = network.clone();
325325

326326
// a thread to send tasks from each loaded wallet:
@@ -347,11 +347,11 @@ pub async fn send_infinite_proofs(args: SendInfiniteProofsArgs) {
347347

348348
info!(
349349
"Sending {:?} Proofs to Aligned Batcher on {:?} from sender {}, nonce: {}, address: {:?}",
350-
args.burst_size, n.clone(), i, nonce, wallet.address(),
350+
args.burst_size, n, i, nonce, wallet.address(),
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)