Skip to content

Commit

Permalink
Merge pull request #16 from Layr-Labs/jb/fix-state-machine
Browse files Browse the repository at this point in the history
[1.1.1] Minor fixes to state machine
  • Loading branch information
jbrower95 authored Jan 15, 2025
2 parents a1aa82a + 0eea4d6 commit effdf91
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

**[Current]**
1.1.1:
- Minor patches to the zeus state machine to make errors more legible.

1.1.0:
- Complete rewrite of the ledger integration, with an emphasis on viem+ledger. Multisig ledger phases now work properly.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@layr-labs/zeus",
"version": "1.1.0",
"version": "1.1.1",
"description": "web3 deployer / metadata manager",
"main": "src/index.ts",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion src/commands/deploy/cmd/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { configs, getRepoRoot } from '../../configs';
import { getActiveDeploy, phaseType, formatNow, blankDeploy } from "./utils";
import { join, normalize } from 'path';
import { existsSync, lstatSync } from "fs";
import { HaltDeployError, TExecuteOptions } from "../../../signing/strategy";
import { HaltDeployError, PauseDeployError, TExecuteOptions } from "../../../signing/strategy";
import chalk from "chalk";
import { canonicalPaths } from "../../../metadata/paths";
import { createTestClient, http, TestClient, toHex } from "viem";
Expand Down Expand Up @@ -274,6 +274,10 @@ const executeOrContinueDeploy = async (deploy: SavebleDocument<TDeploy>, _user:
}
}
} catch (e) {
if (e instanceof PauseDeployError) {
chalk.gray(`The deploy stopped: ${e.message}`);
return;
}
if (e instanceof HaltDeployError) {
if (e.complete) {
chalk.gray(`The deploy completed: ${e.message}`);
Expand Down
10 changes: 6 additions & 4 deletions src/deploy/handlers/gnosis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createPublicClient, http } from "viem";
const {default: SafeApiKit} = await import(`@safe-global/api-kit`)
import { SafeMultisigTransactionResponse} from '@safe-global/types-kit';
import { SavebleDocument, Transaction } from "../../metadata/metadataStore";
import { HaltDeployError, TGnosisRequest, TStrategyOptions } from "../../signing/strategy";
import { HaltDeployError, PauseDeployError, TGnosisRequest, TStrategyOptions } from "../../signing/strategy";
import { GnosisSigningStrategy } from "../../signing/strategies/gnosis/gnosis";
import { GnosisOnchainStrategy } from "../../signing/strategies/gnosis/onchain/onchain";
import { MultisigMetadata, TDeploy, TDeployStateMutations, TMutation, TTestOutput } from "../../metadata/schema";
Expand Down Expand Up @@ -135,7 +135,7 @@ export async function executeMultisigPhase(deploy: SavebleDocument<TDeploy>, met
console.error(`\tShare the following URI: ${multisigBaseUrl(deploy._.chainId)}/transactions/queue?safe=${multisigDeploy._.safeAddress}`)
console.error(`Run the following to continue: `);
console.error(`\t\tzeus deploy run --resume --env ${deploy._.env}`);
throw new HaltDeployError(deploy, `Waiting on multisig signers.`);
throw new PauseDeployError(deploy, `Waiting on multisig signers.`);
}
break;
}
Expand Down Expand Up @@ -204,7 +204,7 @@ export async function executeMultisigPhase(deploy: SavebleDocument<TDeploy>, met
console.log(chalk.bold(`To continue running this upgrade, re-run with --resume. Deploy will resume from phase: ${deploy._.segments[deploy._.segmentId].filename}`))
console.error(`\t\tzeus deploy run --resume --env ${deploy._.env}`);
await metatxn.commit(`[deploy ${deploy._.name}] multisig transaction success`);
throw new HaltDeployError(deploy, `Waiting to begin next phase.`)
throw new PauseDeployError(deploy, `Waiting to begin next phase.`)
}
break;
} else {
Expand All @@ -227,7 +227,9 @@ export async function executeMultisigPhase(deploy: SavebleDocument<TDeploy>, met
console.error(e);
throw new HaltDeployError(deploy, `Transaction (${multisigTxn._.transactionHash}) might have not landed in a block yet.`)
}
}
} else {
throw new PauseDeployError(deploy, `Transaction is waiting for execution.`);
}
break;
}
default:
Expand Down
8 changes: 4 additions & 4 deletions src/deploy/handlers/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { advance, updateLatestDeploy } from "../../commands/deploy/cmd/utils";
import { SavebleDocument, Transaction } from "../../metadata/metadataStore";
import { canonicalPaths } from "../../metadata/paths";
import { TDeploy, TDeployedContractsManifest, TDeployStateMutations, TEnvironmentManifest, TUpgrade } from "../../metadata/schema";
import { HaltDeployError, TStrategyOptions } from "../../signing/strategy";
import { HaltDeployError, PauseDeployError, TStrategyOptions } from "../../signing/strategy";
import { PhaseTypeHandler } from "./base";

export async function executeSystemPhase(deploy: SavebleDocument<TDeploy>, metatxn: Transaction, _options: TStrategyOptions): Promise<void> {
Expand Down Expand Up @@ -91,22 +91,22 @@ export async function executeSystemPhase(deploy: SavebleDocument<TDeploy>, metat
deploy.save();
await metatxn.commit(`Deploy ${deploy._.name} completed!`);
await waitIfAnvil();
throw new HaltDeployError(deploy, 'Deploy completed', true /* complete */);
throw new PauseDeployError(deploy, 'Deploy completed');
}
case "failed": {
console.error(`The deploy failed. ❌`);
await updateLatestDeploy(metatxn, deploy._.env, undefined, true);
await metatxn.commit(`Deploy ${deploy._.name} failed.`);
await waitIfAnvil();
throw new HaltDeployError(deploy, 'Deploy failed', true /* complete */);
throw new PauseDeployError(deploy, 'Deploy failed');
}
case "cancelled":
console.log(`Deploy was cancelled. ❌`);
await updateLatestDeploy(metatxn, deploy._.env, undefined, true);
await deploy.save();
await metatxn.commit(`Deploy ${deploy._.name} cancelled.`);
await waitIfAnvil();
throw new HaltDeployError(deploy, 'Deploy cancelled.', true /* complete */);
throw new PauseDeployError(deploy, 'Deploy cancelled.');
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/signing/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ class CachedArg<T> implements ICachedArg<T> {
}
}

export class PauseDeployError extends Error {
readonly phase: string;
readonly segmentId: number;
readonly deploy: string;

constructor(deploy: SavebleDocument<TDeploy>, reason: string) {
super(`The deploy stopped: ${reason}`);
this.phase = deploy._.phase;
this.deploy = deploy._.name;
this.segmentId = deploy._.segmentId;
}
}

export class HaltDeployError extends Error {
readonly phase: string;
Expand Down
8 changes: 4 additions & 4 deletions src/tests/deploy/system.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('system steps', () => {
mockFiles[canonicalPaths.deployParameters('', deploy._.env)] = deployParameters;

const txn = mockStatefulTransaction(mockFiles);
await expect(executeSystemPhase(deploy, txn, {})).rejects.toThrowError(`The deploy halted: Deploy completed`);
await expect(executeSystemPhase(deploy, txn, {})).rejects.toThrowError(`The deploy stopped: Deploy completed`);

await expectNoOngoingDeploy(txn);
const updatedEnvManifest = await txn.getJSONFile<TEnvironmentManifest>(canonicalPaths.environmentManifest(deploy._.env));
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('system steps', () => {
mockFiles[canonicalPaths.deployParameters('', deploy._.env)] = deployParameters;

const txn = mockStatefulTransaction(mockFiles);
await expect(executeSystemPhase(deploy, txn, {})).rejects.toThrowError(`The deploy halted: Deploy completed`);
await expect(executeSystemPhase(deploy, txn, {})).rejects.toThrowError(`The deploy stopped: Deploy completed`);

await expectNoOngoingDeploy(txn);
const updatedEnvManifest = await txn.getJSONFile<TEnvironmentManifest>(canonicalPaths.environmentManifest(deploy._.env));
Expand All @@ -173,7 +173,7 @@ describe('system steps', () => {
deploy._.phase = 'failed'
})
it("should fail the deploy", async () => {
await expect(executeSystemPhase(deploy, metatxn, {})).rejects.toThrowError(`The deploy halted: Deploy failed`)
await expect(executeSystemPhase(deploy, metatxn, {})).rejects.toThrowError(`The deploy stopped: Deploy failed`)
await expectNoOngoingDeploy(metatxn);
})
})
Expand All @@ -183,7 +183,7 @@ describe('system steps', () => {
deploy._.phase = 'cancelled'
})
it("should cancel the deploy", async () => {
await expect(executeSystemPhase(deploy, metatxn, {})).rejects.toThrowError(`The deploy halted: Deploy cancelled.`)
await expect(executeSystemPhase(deploy, metatxn, {})).rejects.toThrowError(`The deploy stopped: Deploy cancelled.`)
await expectNoOngoingDeploy(metatxn);
})
})
Expand Down

0 comments on commit effdf91

Please sign in to comment.