Simplify signature_checker code
@@ -185,8 +185,8 @@ async fn verify_eth_signature_txs_batch(
if signers.len() == batch_sign_data.signatures.len() {
return Err(TxAddError::IncorrectEthSignature);
}
- // This block will return `true` at the first match or `false` if there's none.
- let sender_correct = async {
+ // This block will set the `sender_correct` variable to `true` at the first match.
+ let mut sender_correct = false;
for signature in &batch_sign_data.signatures {
match signature {
TxEthSignature::EthereumSignature(packed_signature) => {
@@ -195,9 +195,9 @@ async fn verify_eth_signature_txs_batch(
.or(Err(TxAddError::IncorrectEthSignature))?;
// Always cache it as it's correct one.
signers.insert(signer_account);
-
if sender == &signer_account {
- return Ok(true);
+ sender_correct = true;
+ break;
}
}
TxEthSignature::EIP1271Signature(signature) => {
@@ -209,24 +209,19 @@ async fn verify_eth_signature_txs_batch(
)
.await
.expect("Unable to check EIP1271 signature");
-
if signature_correct {
signers.insert(*sender);
- return Ok(true);
+ sender_correct = true;
+ break;
}
}
}
}
// No signature for this transaction found, return error.
- Ok(false)
- }
- .await?;
-
if !sender_correct {
return Err(TxAddError::IncorrectEthSignature);
}
}
-
metrics::histogram!(
"signature_checker.verify_eth_signature_txs_batch",
start.elapsed()
