Skip to content

Commit effdf91

Browse files
authored
Merge pull request #16 from Layr-Labs/jb/fix-state-machine
[1.1.1] Minor fixes to state machine
2 parents a1aa82a + 0eea4d6 commit effdf91

File tree

7 files changed

+35
-14
lines changed

7 files changed

+35
-14
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11

22
**[Current]**
3+
1.1.1:
4+
- Minor patches to the zeus state machine to make errors more legible.
5+
36
1.1.0:
47
- Complete rewrite of the ledger integration, with an emphasis on viem+ledger. Multisig ledger phases now work properly.
58

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@layr-labs/zeus",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "web3 deployer / metadata manager",
55
"main": "src/index.ts",
66
"scripts": {

src/commands/deploy/cmd/run.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { configs, getRepoRoot } from '../../configs';
55
import { getActiveDeploy, phaseType, formatNow, blankDeploy } from "./utils";
66
import { join, normalize } from 'path';
77
import { existsSync, lstatSync } from "fs";
8-
import { HaltDeployError, TExecuteOptions } from "../../../signing/strategy";
8+
import { HaltDeployError, PauseDeployError, TExecuteOptions } from "../../../signing/strategy";
99
import chalk from "chalk";
1010
import { canonicalPaths } from "../../../metadata/paths";
1111
import { createTestClient, http, TestClient, toHex } from "viem";
@@ -274,6 +274,10 @@ const executeOrContinueDeploy = async (deploy: SavebleDocument<TDeploy>, _user:
274274
}
275275
}
276276
} catch (e) {
277+
if (e instanceof PauseDeployError) {
278+
chalk.gray(`The deploy stopped: ${e.message}`);
279+
return;
280+
}
277281
if (e instanceof HaltDeployError) {
278282
if (e.complete) {
279283
chalk.gray(`The deploy completed: ${e.message}`);

src/deploy/handlers/gnosis.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { createPublicClient, http } from "viem";
77
const {default: SafeApiKit} = await import(`@safe-global/api-kit`)
88
import { SafeMultisigTransactionResponse} from '@safe-global/types-kit';
99
import { SavebleDocument, Transaction } from "../../metadata/metadataStore";
10-
import { HaltDeployError, TGnosisRequest, TStrategyOptions } from "../../signing/strategy";
10+
import { HaltDeployError, PauseDeployError, TGnosisRequest, TStrategyOptions } from "../../signing/strategy";
1111
import { GnosisSigningStrategy } from "../../signing/strategies/gnosis/gnosis";
1212
import { GnosisOnchainStrategy } from "../../signing/strategies/gnosis/onchain/onchain";
1313
import { MultisigMetadata, TDeploy, TDeployStateMutations, TMutation, TTestOutput } from "../../metadata/schema";
@@ -135,7 +135,7 @@ export async function executeMultisigPhase(deploy: SavebleDocument<TDeploy>, met
135135
console.error(`\tShare the following URI: ${multisigBaseUrl(deploy._.chainId)}/transactions/queue?safe=${multisigDeploy._.safeAddress}`)
136136
console.error(`Run the following to continue: `);
137137
console.error(`\t\tzeus deploy run --resume --env ${deploy._.env}`);
138-
throw new HaltDeployError(deploy, `Waiting on multisig signers.`);
138+
throw new PauseDeployError(deploy, `Waiting on multisig signers.`);
139139
}
140140
break;
141141
}
@@ -204,7 +204,7 @@ export async function executeMultisigPhase(deploy: SavebleDocument<TDeploy>, met
204204
console.log(chalk.bold(`To continue running this upgrade, re-run with --resume. Deploy will resume from phase: ${deploy._.segments[deploy._.segmentId].filename}`))
205205
console.error(`\t\tzeus deploy run --resume --env ${deploy._.env}`);
206206
await metatxn.commit(`[deploy ${deploy._.name}] multisig transaction success`);
207-
throw new HaltDeployError(deploy, `Waiting to begin next phase.`)
207+
throw new PauseDeployError(deploy, `Waiting to begin next phase.`)
208208
}
209209
break;
210210
} else {
@@ -227,7 +227,9 @@ export async function executeMultisigPhase(deploy: SavebleDocument<TDeploy>, met
227227
console.error(e);
228228
throw new HaltDeployError(deploy, `Transaction (${multisigTxn._.transactionHash}) might have not landed in a block yet.`)
229229
}
230-
}
230+
} else {
231+
throw new PauseDeployError(deploy, `Transaction is waiting for execution.`);
232+
}
231233
break;
232234
}
233235
default:

src/deploy/handlers/system.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { advance, updateLatestDeploy } from "../../commands/deploy/cmd/utils";
33
import { SavebleDocument, Transaction } from "../../metadata/metadataStore";
44
import { canonicalPaths } from "../../metadata/paths";
55
import { TDeploy, TDeployedContractsManifest, TDeployStateMutations, TEnvironmentManifest, TUpgrade } from "../../metadata/schema";
6-
import { HaltDeployError, TStrategyOptions } from "../../signing/strategy";
6+
import { HaltDeployError, PauseDeployError, TStrategyOptions } from "../../signing/strategy";
77
import { PhaseTypeHandler } from "./base";
88

99
export async function executeSystemPhase(deploy: SavebleDocument<TDeploy>, metatxn: Transaction, _options: TStrategyOptions): Promise<void> {
@@ -91,22 +91,22 @@ export async function executeSystemPhase(deploy: SavebleDocument<TDeploy>, metat
9191
deploy.save();
9292
await metatxn.commit(`Deploy ${deploy._.name} completed!`);
9393
await waitIfAnvil();
94-
throw new HaltDeployError(deploy, 'Deploy completed', true /* complete */);
94+
throw new PauseDeployError(deploy, 'Deploy completed');
9595
}
9696
case "failed": {
9797
console.error(`The deploy failed. ❌`);
9898
await updateLatestDeploy(metatxn, deploy._.env, undefined, true);
9999
await metatxn.commit(`Deploy ${deploy._.name} failed.`);
100100
await waitIfAnvil();
101-
throw new HaltDeployError(deploy, 'Deploy failed', true /* complete */);
101+
throw new PauseDeployError(deploy, 'Deploy failed');
102102
}
103103
case "cancelled":
104104
console.log(`Deploy was cancelled. ❌`);
105105
await updateLatestDeploy(metatxn, deploy._.env, undefined, true);
106106
await deploy.save();
107107
await metatxn.commit(`Deploy ${deploy._.name} cancelled.`);
108108
await waitIfAnvil();
109-
throw new HaltDeployError(deploy, 'Deploy cancelled.', true /* complete */);
109+
throw new PauseDeployError(deploy, 'Deploy cancelled.');
110110
}
111111
}
112112

src/signing/strategy.ts

+12
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ class CachedArg<T> implements ICachedArg<T> {
120120
}
121121
}
122122

123+
export class PauseDeployError extends Error {
124+
readonly phase: string;
125+
readonly segmentId: number;
126+
readonly deploy: string;
127+
128+
constructor(deploy: SavebleDocument<TDeploy>, reason: string) {
129+
super(`The deploy stopped: ${reason}`);
130+
this.phase = deploy._.phase;
131+
this.deploy = deploy._.name;
132+
this.segmentId = deploy._.segmentId;
133+
}
134+
}
123135

124136
export class HaltDeployError extends Error {
125137
readonly phase: string;

src/tests/deploy/system.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('system steps', () => {
9494
mockFiles[canonicalPaths.deployParameters('', deploy._.env)] = deployParameters;
9595

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

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

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

156156
await expectNoOngoingDeploy(txn);
157157
const updatedEnvManifest = await txn.getJSONFile<TEnvironmentManifest>(canonicalPaths.environmentManifest(deploy._.env));
@@ -173,7 +173,7 @@ describe('system steps', () => {
173173
deploy._.phase = 'failed'
174174
})
175175
it("should fail the deploy", async () => {
176-
await expect(executeSystemPhase(deploy, metatxn, {})).rejects.toThrowError(`The deploy halted: Deploy failed`)
176+
await expect(executeSystemPhase(deploy, metatxn, {})).rejects.toThrowError(`The deploy stopped: Deploy failed`)
177177
await expectNoOngoingDeploy(metatxn);
178178
})
179179
})
@@ -183,7 +183,7 @@ describe('system steps', () => {
183183
deploy._.phase = 'cancelled'
184184
})
185185
it("should cancel the deploy", async () => {
186-
await expect(executeSystemPhase(deploy, metatxn, {})).rejects.toThrowError(`The deploy halted: Deploy cancelled.`)
186+
await expect(executeSystemPhase(deploy, metatxn, {})).rejects.toThrowError(`The deploy stopped: Deploy cancelled.`)
187187
await expectNoOngoingDeploy(metatxn);
188188
})
189189
})

0 commit comments

Comments
 (0)