Skip to content

Commit

Permalink
fix(vms): fix VM commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlc03 committed Jun 27, 2023
1 parent b75b3d3 commit a39fd5f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
12 changes: 6 additions & 6 deletions packages/actions/src/helpers/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]

/**
Expand All @@ -99,11 +99,11 @@ export const vmContributionVerificationCommand = (
lastZkeyStoragePath: string,
verificationTranscriptStoragePathAndFilename: string
): Array<string> => [
`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`
]

/**
Expand Down
7 changes: 2 additions & 5 deletions packages/backend/src/functions/ceremony.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import {
computeDiskSizeForVM,
vmBootstrapCommand,
vmDependenciesAndCacheArtifactsCommand,
vmBootstrapScriptFilename,
stopEC2Instance
vmBootstrapScriptFilename
} from "@p0tion/actions"
import { encode } from "html-entities"
import { SetupCeremonyData } from "../types/index"
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
21 changes: 14 additions & 7 deletions packages/backend/src/functions/circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a39fd5f

Please sign in to comment.