Skip to content

Commit

Permalink
add retry to contract deploy too
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Oct 13, 2023
1 parent 4ccd4ab commit 4664e56
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions packages/cli/src/deploy/ensureContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { deployer } from "./ensureDeployer";
import { salt } from "./common";
import { sendTransaction } from "@latticexyz/common";
import { debug } from "./debug";
import pRetry from "p-retry";
import { wait } from "@latticexyz/common/utils";

export async function ensureContract({
client,
Expand All @@ -24,10 +26,21 @@ export async function ensureContract({

debug("deploying", label, "at", address);
return [
await sendTransaction(client, {
chain: client.chain ?? null,
to: deployer,
data: concatHex([salt, bytecode]),
}),
await pRetry(
() =>
sendTransaction(client, {
chain: client.chain ?? null,
to: deployer,
data: concatHex([salt, bytecode]),
}),
{
retries: 3,
onFailedAttempt: async (error) => {
const delay = error.attemptNumber * 500;
debug(`failed to deploy ${label}, retrying in ${delay}ms...`);
await wait(delay);
},
}
),
];
}

0 comments on commit 4664e56

Please sign in to comment.