From a39fd5fa9543af412eae7f7e505660547c29b4b3 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Tue, 27 Jun 2023 17:58:39 +0100 Subject: [PATCH] fix(vms): fix VM commands --- packages/actions/src/helpers/vm.ts | 12 ++++++------ packages/backend/src/functions/ceremony.ts | 7 ++----- packages/backend/src/functions/circuit.ts | 21 ++++++++++++++------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/packages/actions/src/helpers/vm.ts b/packages/actions/src/helpers/vm.ts index 8aaac5f6..67ec8603 100644 --- a/packages/actions/src/helpers/vm.ts +++ b/packages/actions/src/helpers/vm.ts @@ -80,10 +80,10 @@ export const vmDependenciesAndCacheArtifactsCommand = (zKeyPath: string, potPath "sudo yum update -y", "sudo yum install -y nodejs", "npm install -g snarkjs", - "wget https://github.com/BLAKE3-team/BLAKE3/releases/download/1.4.0/b3sum_linux_x64_bin -O /var/tmp/blake3.bin", - "chmod +x /var/tmp/blake3.bin", `aws s3 cp s3://${zKeyPath} /var/tmp/genesisZkey.zkey`, - `aws s3 cp s3://${potPath} /var/tmp/pot.ptau` + `aws s3 cp s3://${potPath} /var/tmp/pot.ptau`, + "wget https://github.com/BLAKE3-team/BLAKE3/releases/download/1.4.0/b3sum_linux_x64_bin -O /var/tmp/blake3.bin", + "chmod +x /var/tmp/blake3.bin" ] /** @@ -99,11 +99,11 @@ export const vmContributionVerificationCommand = ( lastZkeyStoragePath: string, verificationTranscriptStoragePathAndFilename: string ): Array => [ - `aws s3 cp s3://${bucketName}/${lastZkeyStoragePath} /var/tmp/lastZKey.zkey > /dev/null`, + `aws s3 cp s3://${bucketName}/${lastZkeyStoragePath} /var/tmp/lastZKey.zkey &>/dev/null`, `snarkjs zkvi /var/tmp/genesisZkey.zkey /var/tmp/pot.ptau /var/tmp/lastZKey.zkey > /var/tmp/verification_transcript.log`, - `aws s3 cp /var/tmp/verification_transcript.log s3://${bucketName}/${verificationTranscriptStoragePathAndFilename} > /dev/null`, + `aws s3 cp /var/tmp/verification_transcript.log s3://${bucketName}/${verificationTranscriptStoragePathAndFilename} &>/dev/null`, `./var/tmp/blake3.bin /var/tmp/verification_transcript.log | awk '{print $1}'`, - `rm /var/tmp/lastZKey.zkey /var/tmp/verification_transcript.log > /dev/null` + `rm /var/tmp/lastZKey.zkey /var/tmp/verification_transcript.log &>/dev/null` ] /** diff --git a/packages/backend/src/functions/ceremony.ts b/packages/backend/src/functions/ceremony.ts index 3430b4b4..b016cadb 100644 --- a/packages/backend/src/functions/ceremony.ts +++ b/packages/backend/src/functions/ceremony.ts @@ -17,8 +17,7 @@ import { computeDiskSizeForVM, vmBootstrapCommand, vmDependenciesAndCacheArtifactsCommand, - vmBootstrapScriptFilename, - stopEC2Instance + vmBootstrapScriptFilename } from "@p0tion/actions" import { encode } from "html-entities" import { SetupCeremonyData } from "../types/index" @@ -161,6 +160,7 @@ export const setupCeremony = functions // Compute the VM disk space requirement (in GB). const vmDiskSize = computeDiskSizeForVM(circuit.zKeySizeInBytes!, circuit.metadata?.pot!) + printLog(startupCommand.join("\n"), LogLevel.DEBUG) // Configure and instantiate a new VM based on the coordinator input. const instance = await createEC2Instance( ec2Client, @@ -172,9 +172,6 @@ export const setupCeremony = functions // Get the VM instance identifier. vmInstanceId = instance.instanceId - // Stop the instance after creation. - await stopEC2Instance(ec2Client, vmInstanceId) - // Update the circuit document info accordingly. circuit = { ...circuit, diff --git a/packages/backend/src/functions/circuit.ts b/packages/backend/src/functions/circuit.ts index 241f1fc5..1d3ca3cc 100644 --- a/packages/backend/src/functions/circuit.ts +++ b/packages/backend/src/functions/circuit.ts @@ -483,15 +483,22 @@ export const verifycontribution = functionsV2.https.onCall( ) ) + // @todo check sleep + await sleep(1000) + // Wait until the command completes with a success status. const interval = setInterval(async () => { - const cmdStatus = await retrieveCommandStatus(ssm, commandId, vmInstanceId) - - // TODO: make an enum. - if (cmdStatus === "Success") clearInterval(interval) - else if (cmdStatus === "Failed" || cmdStatus === "AccessDenied") - // Refactoring error. - logAndThrowError(makeError("aborted", `Invalid command execution ${cmdStatus}`)) + try { + const cmdStatus = await retrieveCommandStatus(ssm, commandId, vmInstanceId) + printLog("CMD STATUS" + cmdStatus, LogLevel.DEBUG) + // TODO: make an enum. + if (cmdStatus === "Success") clearInterval(interval) + else if (cmdStatus === "Failed" || cmdStatus === "AccessDenied") + // Refactoring error. + logAndThrowError(makeError("aborted", `Invalid command execution ${cmdStatus}`)) + } catch (error: any) { + printLog(error.toString(), LogLevel.DEBUG) + } }, 60000) // TODO To be deleted