Skip to content

Commit f4ae99d

Browse files
committed
fix(vm): bug fix
1 parent 0ebe401 commit f4ae99d

File tree

6 files changed

+37
-41
lines changed

6 files changed

+37
-41
lines changed

packages/actions/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@p0tion/actions",
3-
"version": "0.4.2",
3+
"version": "0.4.4",
44
"description": "A set of actions and helpers for CLI commands",
55
"repository": "git@github.com:privacy-scaling-explorations/p0tion.git",
66
"homepage": "https://github.com/privacy-scaling-explorations/p0tion",

packages/actions/src/helpers/ec2.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ export const generateVMCommand = (zKeyPath: string, ptauPath: string): string[]
9494
"sudo yum update -y",
9595
"sudo yum install -y nodejs",
9696
"npm install -g snarkjs",
97-
`aws s3 cp s3://${zKeyPath} ./var/tmp/genesisZkey.zkey`,
98-
`aws s3 cp s3://${ptauPath} ./var/tmp/pot.ptau`
97+
`aws s3 cp s3://${zKeyPath} /var/tmp/genesisZkey.zkey`,
98+
`aws s3 cp s3://${ptauPath} /var/tmp/pot.ptau`
9999
]
100100

101101
return command

packages/actions/test/data/samples.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ const fakeCircuitSmallNoContributors = generateFakeCircuit({
285285
data: {
286286
name: "Circuit Small",
287287
description: "Short description of Circuit Small",
288-
prefix: "circuit-small",
288+
prefix: "circuit_small",
289289
sequencePosition: 1,
290290
fixedTimeWindow: 10,
291291
zKeySizeInBytes: 45020,

packages/actions/test/unit/ec2.test.ts

+18-19
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe("VMs", () => {
4444
// instance = await createEC2Instance(ec2, [
4545
// "echo 'hello world' > hello.txt",
4646
// "aws s3 cp hello.txt s3://p0tion-test-bucket/hello.txt"
47-
// ], "t2.micro", amiId, keyName, roleArn)
47+
// ], "t2.micro", amiId, keyName, roleArn, 8)
4848
// expect(instance).to.not.be.undefined
4949
// // give it time to actually spin up
5050
// await sleep(250000)
@@ -96,7 +96,7 @@ describe("VMs", () => {
9696
// "aws s3 cp s3://p0tion-test-bucket/script_test.sh script_test.sh",
9797
// "chmod +x script_test.sh && bash script_test.sh"
9898
// ]
99-
// ssmTestInstance = await createEC2Instance(ec2, userData, "t2.small", amiId, keyName, roleArn)
99+
// ssmTestInstance = await createEC2Instance(ec2, userData, "t2.small", amiId, keyName, roleArn, 8)
100100
// await sleep(250000)
101101
// })
102102
// it("should run my commands", async () => {
@@ -191,7 +191,6 @@ describe("VMs", () => {
191191

192192
// 1 create a bucket for the ceremony
193193
await signInWithEmailAndPassword(userAuth, users[1].data.email, passwords[1])
194-
console.log("LOGGED IN")
195194
await createS3Bucket(userFunctions, ceremonyBucket)
196195

197196
// zkey upload
@@ -201,20 +200,22 @@ describe("VMs", () => {
201200
})
202201

203202
afterAll(async () => {
204-
for (const instanceId of instancesToTerminate) {
205-
await terminateEC2Instance(ec2, instanceId)
206-
}
203+
// for (const instanceId of instancesToTerminate) {
204+
// await terminateEC2Instance(ec2, instanceId)
205+
// }
207206

208-
for (const objectToDelete of objectsToDelete) {
209-
await deleteObjectFromS3(ceremonyBucket, objectToDelete)
210-
}
211-
await deleteBucket(ceremonyBucket)
207+
// for (const objectToDelete of objectsToDelete) {
208+
// await deleteObjectFromS3(ceremonyBucket, objectToDelete)
209+
// }
210+
// await deleteBucket(ceremonyBucket)
212211

213212
await cleanUpMockUsers(adminAuth, adminFirestore, users)
214-
// await cleanUpRecursively(adminFirestore, ceremonyId)
213+
await cleanUpRecursively(adminFirestore, ceremonyId)
214+
215+
fs.rmdirSync(`${outputDirectory}`, { recursive: true })
215216
})
216217

217-
it("should create a ceremony and two VMs should spin up", async () => {
218+
it.only("should create a ceremony and two VMs should spin up", async () => {
218219
// 1. setup ceremony
219220
ceremonyId = await setupCeremony(userFunctions, ceremony.data, ceremony.data.prefix!, [circuit.data])
220221

@@ -229,16 +230,14 @@ describe("VMs", () => {
229230

230231
for (const circuit of circuits) {
231232
const { vmInstanceId } = circuit.data
232-
// instancesToTerminate.push(vmInstanceId)
233-
// check VM status
234-
const status = await checkEC2Status(ec2, vmInstanceId)
235-
expect(status).to.be.eq(true)
233+
expect(vmInstanceId).to.not.be.null
234+
instancesToTerminate.push(vmInstanceId)
236235
}
237236
})
238237

239-
it.skip("should verify a contribution", async () => {
240-
// 1. login as user 2
241-
await signInWithEmailAndPassword(userAuth, users[2].data.email, passwords[2])
238+
it("should verify a contribution", async () => {
239+
// 1. login
240+
await signInWithEmailAndPassword(userAuth, users[0].data.email, passwords[0])
242241
await sleep(500)
243242
// 2. get circuits for ceremony
244243
const circuits = await getCeremonyCircuits(userFirestore, ceremonyId)

packages/backend/src/functions/ceremony.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,9 @@ import {
2727
htmlEncodeCircuitData,
2828
createEC2Client,
2929
getAWSVariables,
30-
sleep,
31-
uploadFileToBucket,
32-
createTemporaryLocalPath,
3330
uploadFileToBucketNoFile
3431
} from "../lib/utils"
3532
import { LogLevel } from "../types/enums"
36-
import { writeFileSync, unlinkSync } from "fs"
3733
import { determineVMSpecs } from "@p0tion/actions"
3834

3935
dotenv.config()
@@ -149,8 +145,8 @@ export const setupCeremony = functions
149145
const ec2Client = await createEC2Client()
150146
// generate the commands for startup
151147
const vmCommands = generateVMCommand(
152-
circuit.files?.initialZkeyStoragePath!,
153-
circuit.files?.potStoragePath!
148+
`${bucketName}/${circuit.files?.initialZkeyStoragePath!}`,
149+
`${bucketName}/circuit.files?.potStoragePath!`
154150
)
155151

156152
// upload the instructions file the bucket and clean up
@@ -163,7 +159,7 @@ export const setupCeremony = functions
163159
const instance = await createEC2Instance(
164160
ec2Client,
165161
userData,
166-
"t3.xlarge",
162+
vmSpecs.vm,
167163
amiId,
168164
keyName,
169165
roleArn,

packages/backend/src/functions/circuit.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,12 @@ export const verifycontribution = functionsV2.https.onCall(
436436
// get ec2 client
437437
const ec2Client = await createEC2Client()
438438

439+
440+
441+
// Prepare timer. (@todo check where to move this)
442+
const verificationTaskTimer = new Timer({ label: `${ceremonyId}-${circuitId}-${participantDoc.id}` })
443+
verificationTaskTimer.start()
444+
439445
// start vm and give it time to start
440446
await startEC2Instance(ec2Client, instanceId)
441447
await sleep(200000)
@@ -446,16 +452,6 @@ export const verifycontribution = functionsV2.https.onCall(
446452
console.log("DEBUG Not running yet")
447453
}
448454

449-
// Prepare timer. (@todo check where to move this)
450-
const verificationTaskTimer = new Timer({ label: `${ceremonyId}-${circuitId}-${participantDoc.id}` })
451-
verificationTaskTimer.start()
452-
453-
// Step (1.A.3).
454-
verificationTaskTimer.stop()
455-
verifyCloudFunctionExecutionTime = verificationTaskTimer.ms()
456-
457-
printLog(`The contribution has been verified - Result ${isContributionValid}`, LogLevel.DEBUG)
458-
459455
const commands = [
460456
`aws s3 cp s3://${bucketName}/${lastZkeyStoragePath} /var/tmp/lastZKey.zkey`,
461457
`snarkjs zkvi /var/tmp/genesisZkey.zkey /var/tmp/pot.ptau /var/tmp/lastZKey.zkey | tee /var/tmp/verification_transcript.log`,
@@ -470,10 +466,15 @@ export const verifycontribution = functionsV2.https.onCall(
470466
const commandOutput = await retrieveCommandOutput(ssmClient, commandId, instanceId)
471467
if (commandOutput.includes("ZKey Ok!")) isContributionValid = true
472468
console.log("dEBUG output", commandOutput)
473-
469+
printLog(`The contribution has been verified - Result ${isContributionValid}`, LogLevel.DEBUG)
470+
474471
// stop the VM
475472
await stopEC2Instance(ec2Client, instanceId)
476473

474+
// Step (1.A.3).
475+
verificationTaskTimer.stop()
476+
verifyCloudFunctionExecutionTime = verificationTaskTimer.ms()
477+
477478
// Step (1.A.2).
478479

479480
// Compute contribution hash. (@todo compute on VM api)

0 commit comments

Comments
 (0)