Skip to content

Commit 0a6c1f1

Browse files
committed
fix: added retries and delay in contract verification
1 parent 7497d5e commit 0a6c1f1

File tree

1 file changed

+110
-44
lines changed

1 file changed

+110
-44
lines changed

circom/src/contract.rs

Lines changed: 110 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -208,54 +208,120 @@ pub async fn deploy_verifier_contract(payload: Payload) -> Result<String> {
208208

209209
if let Ok(_) = env::var("ETHERSCAN_API_KEY") {
210210
info!(LOG, "Verify contracts");
211-
if let Err(e) = run_command(
212-
"forge",
213-
&[
214-
"verify-contract",
215-
"--chain-id",
216-
payload.chain_id.to_string().as_str(),
217-
contract_addresses.get("ClientProofVerifier").unwrap(),
218-
"tmp/ClientProofVerifier.sol:ClientProofVerifier",
219-
],
220-
None,
221-
)
222-
.await
223-
{
224-
info!(LOG, "Warning: Failed to verify ClientProofVerifier: {}", e);
211+
212+
// Verify ClientProofVerifier with retries
213+
for attempt in 1..=3 {
214+
info!(
215+
LOG,
216+
"Attempting to verify ClientProofVerifier (attempt {}/3)", attempt
217+
);
218+
match run_command(
219+
"forge",
220+
&[
221+
"verify-contract",
222+
"--chain-id",
223+
payload.chain_id.to_string().as_str(),
224+
contract_addresses.get("ClientProofVerifier").unwrap(),
225+
"tmp/ClientProofVerifier.sol:ClientProofVerifier",
226+
],
227+
None,
228+
)
229+
.await
230+
{
231+
Ok(_) => {
232+
info!(LOG, "Successfully verified ClientProofVerifier");
233+
break;
234+
}
235+
Err(e) => {
236+
info!(
237+
LOG,
238+
"Attempt {}/3 failed to verify ClientProofVerifier: {}", attempt, e
239+
);
240+
if attempt < 3 {
241+
info!(LOG, "Waiting 10 seconds before retry...");
242+
tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;
243+
}
244+
}
245+
}
225246
}
226247

227-
if let Err(e) = run_command(
228-
"forge",
229-
&[
230-
"verify-contract",
231-
"--chain-id",
232-
payload.chain_id.to_string().as_str(),
233-
contract_addresses.get("ServerProofVerifier").unwrap(),
234-
"tmp/ServerProofVerifier.sol:ServerProofVerifier",
235-
],
236-
None,
237-
)
238-
.await
239-
{
240-
info!(LOG, "Warning: Failed to verify ServerProofVerifier: {}", e);
248+
// Delay between contract verifications
249+
info!(LOG, "Waiting 5 seconds before next verification...");
250+
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
251+
252+
// Verify ServerProofVerifier with retries
253+
for attempt in 1..=3 {
254+
info!(
255+
LOG,
256+
"Attempting to verify ServerProofVerifier (attempt {}/3)", attempt
257+
);
258+
match run_command(
259+
"forge",
260+
&[
261+
"verify-contract",
262+
"--chain-id",
263+
payload.chain_id.to_string().as_str(),
264+
contract_addresses.get("ServerProofVerifier").unwrap(),
265+
"tmp/ServerProofVerifier.sol:ServerProofVerifier",
266+
],
267+
None,
268+
)
269+
.await
270+
{
271+
Ok(_) => {
272+
info!(LOG, "Successfully verified ServerProofVerifier");
273+
break;
274+
}
275+
Err(e) => {
276+
info!(
277+
LOG,
278+
"Attempt {}/3 failed to verify ServerProofVerifier: {}", attempt, e
279+
);
280+
if attempt < 3 {
281+
info!(LOG, "Waiting 10 seconds before retry...");
282+
tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;
283+
}
284+
}
285+
}
241286
}
242287

243-
if let Err(e) = run_command(
244-
"forge",
245-
&[
246-
"verify-contract",
247-
"--chain-id",
248-
payload.chain_id.to_string().as_str(),
249-
"--constructor-args",
250-
&constructor_args,
251-
contract_addresses.get("Contract").unwrap(),
252-
"tmp/Contract.sol:Contract",
253-
],
254-
None,
255-
)
256-
.await
257-
{
258-
info!(LOG, "Warning: Failed to verify Contract: {}", e);
288+
// Delay between contract verifications
289+
info!(LOG, "Waiting 5 seconds before next verification...");
290+
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
291+
292+
// Verify Contract with retries
293+
for attempt in 1..=3 {
294+
info!(LOG, "Attempting to verify Contract (attempt {}/3)", attempt);
295+
match run_command(
296+
"forge",
297+
&[
298+
"verify-contract",
299+
"--chain-id",
300+
payload.chain_id.to_string().as_str(),
301+
"--constructor-args",
302+
&constructor_args,
303+
contract_addresses.get("Contract").unwrap(),
304+
"tmp/Contract.sol:Contract",
305+
],
306+
None,
307+
)
308+
.await
309+
{
310+
Ok(_) => {
311+
info!(LOG, "Successfully verified Contract");
312+
break;
313+
}
314+
Err(e) => {
315+
info!(
316+
LOG,
317+
"Attempt {}/3 failed to verify Contract: {}", attempt, e
318+
);
319+
if attempt < 3 {
320+
info!(LOG, "Waiting 10 seconds before retry...");
321+
tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;
322+
}
323+
}
324+
}
259325
}
260326
}
261327

0 commit comments

Comments
 (0)