Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): speed up deployment by decreasing polling interval when waiting for transactions to confirm #3198

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions .changeset/few-olives-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@latticexyz/cli": patch
---

Significantly improved the deployment performance for large projects with public libraries by implementing a more efficient algorithm to resolve public libraries during deployment.
The local deployment time on a large reference project was reduced from over 10 minutes to 4 seconds.
10 changes: 2 additions & 8 deletions packages/cli/src/deploy/deployWorld.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Account, Chain, Client, Hex, Transport } from "viem";
import { waitForTransactionReceipt } from "viem/actions";
import { ensureWorldFactory } from "./ensureWorldFactory";
import WorldFactoryAbi from "@latticexyz/world/out/WorldFactory.sol/WorldFactory.abi.json" assert { type: "json" };
import { writeContract } from "@latticexyz/common";
import { debug } from "./debug";
import { logsToWorldDeploy } from "./logsToWorldDeploy";
import { WorldDeploy } from "./common";
import { waitForTransactions } from "./waitForTransactions";

export async function deployWorld(
client: Client<Transport, Chain | undefined, Account>,
Expand All @@ -24,13 +24,7 @@ export async function deployWorld(
args: [salt],
});

debug("waiting for world deploy");
const receipt = await waitForTransactionReceipt(client, { hash: tx });
if (receipt.status !== "success") {
console.error("world deploy failed", receipt);
throw new Error("world deploy failed");
}

const [receipt] = await waitForTransactions({ client, hashes: [tx], debugLabel: "world deploy" });
const deploy = logsToWorldDeploy(receipt.logs);
debug("deployed world to", deploy.address, "at block", deploy.deployBlock);

Expand Down
20 changes: 16 additions & 4 deletions packages/cli/src/deploy/waitForTransactions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client, Transport, Chain, Account, Hex } from "viem";
import { Client, Transport, Chain, Account, Hex, TransactionReceipt } from "viem";
import { debug } from "./debug";
import { waitForTransactionReceipt } from "viem/actions";

Expand All @@ -10,15 +10,27 @@ export async function waitForTransactions({
readonly client: Client<Transport, Chain | undefined, Account>;
readonly hashes: readonly Hex[];
readonly debugLabel: string;
}): Promise<void> {
if (!hashes.length) return;
}): Promise<TransactionReceipt[]> {
if (!hashes.length) return [];

debug(`waiting for ${debugLabel} to confirm`);
const receipts: TransactionReceipt[] = [];
// wait for each tx separately/serially, because parallelizing results in RPC errors
for (const hash of hashes) {
const receipt = await waitForTransactionReceipt(client, { hash });
const receipt = await waitForTransactionReceipt(client, {
hash,
pollingInterval: 100,
retryCount: 8,
retryDelay: ({ count }) => {
console.log("retry", count);
return ~~(1 << count) * 400;
},
});
if (receipt.status === "reverted") {
throw new Error(`Transaction reverted: ${hash}`);
}
receipts.push(receipt);
}

return receipts;
}
Loading