From 58f101e45ad50e064779cbc441246a22b70efa07 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 20 Sep 2024 13:14:42 +0000 Subject: [PATCH] feat(cli): quieter automine (#3212) --- .changeset/flat-bulldogs-smash.md | 5 ++++ packages/cli/src/runDeploy.ts | 4 +-- packages/cli/src/utils/enableAutomine.ts | 31 +++++++++++------------- 3 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 .changeset/flat-bulldogs-smash.md diff --git a/.changeset/flat-bulldogs-smash.md b/.changeset/flat-bulldogs-smash.md new file mode 100644 index 0000000000..99d5aad382 --- /dev/null +++ b/.changeset/flat-bulldogs-smash.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/cli": patch +--- + +Reduced the log noise from enabling/disabling automine on non-Anvil chains. diff --git a/packages/cli/src/runDeploy.ts b/packages/cli/src/runDeploy.ts index fb3fb3ebba..078a6b0e80 100644 --- a/packages/cli/src/runDeploy.ts +++ b/packages/cli/src/runDeploy.ts @@ -138,7 +138,7 @@ export async function runDeploy(opts: DeployOptions): Promise { console.log("Deploying from", client.account.address); // Attempt to enable automine for the duration of the deploy. Noop if automine is not available. - const { reset: resetMiningMode } = await enableAutomine(client); + const automine = await enableAutomine(client); const startTime = Date.now(); const worldDeploy = await deploy({ @@ -165,7 +165,7 @@ export async function runDeploy(opts: DeployOptions): Promise { } // Reset mining mode after deploy - await resetMiningMode(); + await automine?.reset(); console.log(chalk.green("Deployment completed in", (Date.now() - startTime) / 1000, "seconds")); diff --git a/packages/cli/src/utils/enableAutomine.ts b/packages/cli/src/utils/enableAutomine.ts index 15c7a2e498..ca40a91be4 100644 --- a/packages/cli/src/utils/enableAutomine.ts +++ b/packages/cli/src/utils/enableAutomine.ts @@ -1,5 +1,5 @@ import { getAutomine, getBlock, setAutomine, setIntervalMining } from "viem/actions"; -import { debug, error } from "../debug"; +import { debug } from "../debug"; import { Client } from "viem"; import { getAction } from "viem/utils"; @@ -12,24 +12,21 @@ type MiningMode = blockTime: number; }; -export type EnableAutomineResult = { reset: () => Promise }; +export type EnableAutomineResult = undefined | { reset: () => Promise }; export async function enableAutomine(client: Client): Promise { - try { - debug("Enabling automine"); - const prevMiningMode = await getMiningMode(client); - await setMiningMode(client, { type: "automine" }); - return { - reset: () => { - debug("Disabling automine"); - return setMiningMode(client, prevMiningMode); - }, - }; - } catch (e) { - debug("Skipping automine"); - error(e); - return { reset: async () => void 0 }; - } + const miningMode = await getMiningMode(client).catch(() => undefined); + // doesn't support automine or is already in automine + if (!miningMode || miningMode.type === "automine") return; + + debug("Enabling automine"); + await setMiningMode(client, { type: "automine" }); + return { + reset: () => { + debug("Disabling automine"); + return setMiningMode(client, miningMode); + }, + }; } async function getMiningMode(client: Client): Promise {