Skip to content

Commit 1f1138b

Browse files
authored
Merge pull request #505 from kvinwang/fix/deploy-verify-retry
fix(auth-eth): retry verifyDeployment for public RPC latency
2 parents adad69b + 710bb9b commit 1f1138b

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

kms/auth-eth/lib/deployment-helpers.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,34 @@ export async function estimateDeploymentCost(
110110
}
111111

112112
/**
113-
* Verify contract deployment
113+
* Verify contract deployment with retry logic for public RPCs.
114+
*
115+
* Public RPC endpoints may return stale data immediately after a transaction
116+
* is mined, causing `getCode()` to return `'0x'` even though the contract was
117+
* deployed successfully. We retry a few times with exponential back-off
118+
* before giving up.
114119
*/
115120
export async function verifyDeployment(
116121
hre: HardhatRuntimeEnvironment,
117122
contractAddress: string,
118123
quiet: boolean = false
119124
) {
120-
// Verify that contract was deployed successfully
121-
const code = await hre.ethers.provider.getCode(contractAddress);
122-
if (code === '0x') {
123-
throw new Error('Contract deployment failed - no code at address');
125+
const maxRetries = 5;
126+
const baseDelayMs = 2000;
127+
128+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
129+
const code = await hre.ethers.provider.getCode(contractAddress);
130+
if (code !== '0x') {
131+
break;
132+
}
133+
if (attempt === maxRetries) {
134+
throw new Error('Contract deployment failed - no code at address after ' + maxRetries + ' attempts');
135+
}
136+
const delay = baseDelayMs * attempt;
137+
if (!quiet) {
138+
console.log(`Waiting for contract code at ${contractAddress} (attempt ${attempt}/${maxRetries}, next retry in ${delay}ms)...`);
139+
}
140+
await new Promise(resolve => setTimeout(resolve, delay));
124141
}
125142

126143
// Get implementation contract address

0 commit comments

Comments
 (0)