Skip to content

Commit 690da25

Browse files
committed
fix(setup): revert transfer of object and add region to config
1 parent c407bee commit 690da25

File tree

10 files changed

+15
-208
lines changed

10 files changed

+15
-208
lines changed

packages/actions/src/helpers/functions.ts

+1-26
Original file line numberDiff line numberDiff line change
@@ -435,29 +435,4 @@ export const finalizeCeremony = async (functions: Functions, ceremonyId: string)
435435
await cf({
436436
ceremonyId
437437
})
438-
}
439-
440-
/**
441-
* Transfer an object between two buckets
442-
* @param functions <Functions> - the Firebase cloud functions object instance.
443-
* @param originBucketName <string> - the name of the origin bucket.
444-
* @param originObjectKey <string> - the key of the origin object.
445-
* @param destinationBucketName <string> - the name of the destination bucket.
446-
* @param destinationObjectKey <string> - the key of the destination object.
447-
*/
448-
export const transferObject = async (
449-
functions: Functions,
450-
originBucketName: string,
451-
originObjectKey: string,
452-
destinationBucketName: string,
453-
destinationObjectKey: string
454-
) => {
455-
const cf = httpsCallable(functions, commonTerms.cloudFunctionsNames.transferObject)
456-
457-
await cf({
458-
originBucketName,
459-
originObjectKey,
460-
destinationBucketName,
461-
destinationObjectKey
462-
})
463-
}
438+
}

packages/actions/src/helpers/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export const parseCeremonyFile = async (path: string, cleanup: boolean = false):
9999

100100
try {
101101
await s3.send(new HeadObjectCommand({
102-
Bucket: circuitData.artifacts.bucket,
102+
Bucket: artifacts.bucket,
103103
Key: r1csPath
104104
}))
105105
} catch (error: any) {

packages/actions/src/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ export {
8787
verifyContribution,
8888
checkAndPrepareCoordinatorForFinalization,
8989
finalizeCircuit,
90-
finalizeCeremony,
91-
transferObject
90+
finalizeCeremony
9291
} from "./helpers/functions"
9392
export { toHex, blake512FromPath, computeSHA256ToHex, compareHashes } from "./helpers/crypto"
9493
export {

packages/actions/test/data/artifacts/ceremonySetup.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
},
2323
"artifacts": {
2424
"bucket": "test-qfi-p0tion-development-environment",
25+
"region": "us-east-1",
2526
"r1csStoragePath": "circuits/circuit/circuit.r1cs",
2627
"wasmStoragePath": "circuits/circuit/circuit.wasm"
2728
},

packages/actions/test/unit/storage.test.ts

+2-56
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import {
1818
sleep,
1919
cleanUpRecursively,
2020
mockCeremoniesCleanup,
21-
generatePseudoRandomStringOfNumbers,
22-
uploadFileToS3
2321
} from "../utils/index"
2422
import { fakeCeremoniesData, fakeCircuitsData, fakeUsersData } from "../data/samples"
2523
import {
@@ -36,12 +34,12 @@ import {
3634
commonTerms,
3735
genesisZkeyIndex,
3836
checkIfObjectExist,
39-
generateGetObjectPreSignedUrl
37+
generateGetObjectPreSignedUrl,
4038
} from "../../src/index"
4139
import { TestingEnvironment } from "../../src/types/enums"
4240
import { ChunkWithUrl, ETagWithPartNumber } from "../../src/types/index"
4341
import { getChunksAndPreSignedUrls, getWasmStorageFilePath, uploadParts } from "../../src/helpers/storage"
44-
import { completeMultiPartUpload, openMultiPartUpload, transferObject } from "../../src/helpers/functions"
42+
import { completeMultiPartUpload, openMultiPartUpload } from "../../src/helpers/functions"
4543

4644
chai.use(chaiAsPromised)
4745

@@ -595,58 +593,6 @@ describe("Storage", () => {
595593
await cleanUpRecursively(adminFirestore, fakeCeremoniesData.fakeCeremonyOpenedFixed.uid)
596594
})
597595
})
598-
599-
describe("transferObject", () => {
600-
// we need two buckets - source and destination
601-
const sourceBucketName = randomBytes(10).toString()
602-
const destinationBucketName = randomBytes(10).toString()
603-
const objectKey = "test.txt"
604-
fs.writeFileSync(objectKey, "test")
605-
606-
beforeAll(async () => {
607-
// login as coordinator
608-
await signInWithEmailAndPassword(userAuth, users[1].data.email, passwords[1])
609-
// create the buckets and upload the file
610-
await createS3Bucket(userFunctions, sourceBucketName)
611-
await createS3Bucket(userFunctions, destinationBucketName)
612-
await uploadFileToS3(
613-
sourceBucketName,
614-
objectKey,
615-
objectKey
616-
)
617-
})
618-
619-
it("should successfully transfer an object between buckets", async () => {
620-
await expect(transferObject(
621-
userFunctions,
622-
sourceBucketName,
623-
objectKey,
624-
destinationBucketName,
625-
objectKey
626-
)).to.be.fulfilled
627-
})
628-
629-
it("should transfer an object between buckets in different regions", async () => {})
630-
it("should throw when trying to transfer an object that does not exist", async () => {
631-
await expect(transferObject(
632-
userFunctions,
633-
sourceBucketName,
634-
"i-dont-exist.txt",
635-
destinationBucketName,
636-
objectKey
637-
)).to.be.rejected
638-
})
639-
640-
afterAll(async () => {
641-
// delete the buckets
642-
await deleteObjectFromS3(sourceBucketName, objectKey)
643-
await deleteObjectFromS3(destinationBucketName, objectKey)
644-
await deleteBucket(sourceBucketName)
645-
await deleteBucket(destinationBucketName)
646-
647-
fs.unlinkSync(objectKey)
648-
})
649-
})
650596
}
651597

652598
describe("getR1csStorageFilePath", () => {

packages/backend/src/functions/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ export {
2929
generateGetObjectPreSignedUrl,
3030
startMultiPartUpload,
3131
generatePreSignedUrlsParts,
32-
completeMultiPartUpload,
33-
transferObject
32+
completeMultiPartUpload
3433
} from "./storage"
3534
export { checkAndRemoveBlockingContributor, resumeContributionAfterTimeoutExpiration } from "./timeout"
3635

packages/backend/src/functions/storage.ts

+1-57
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as functions from "firebase-functions"
22
import admin from "firebase-admin"
33
import {
4-
S3Client,
5-
CopyObjectCommand,
64
GetObjectCommand,
75
CreateMultipartUploadCommand,
86
UploadPartCommand,
@@ -32,8 +30,7 @@ import {
3230
CompleteMultiPartUploadData,
3331
CreateBucketData,
3432
GeneratePreSignedUrlsPartsData,
35-
StartMultiPartUploadData,
36-
TransferObjectData
33+
StartMultiPartUploadData
3734
} from "../types/index"
3835

3936
dotenv.config()
@@ -231,59 +228,6 @@ export const createBucket = functions
231228
}
232229
})
233230

234-
/**
235-
* Transfer a public object from one bucket to another.
236-
*/
237-
export const transferObject = functions
238-
.runWith({
239-
memory: "512MB"
240-
})
241-
.https.onCall(async (data: TransferObjectData, context: functions.https.CallableContext) => {
242-
// Check if the user has the coordinator claim.
243-
if (!context.auth || !context.auth.token.coordinator) logAndThrowError(COMMON_ERRORS.CM_NOT_COORDINATOR_ROLE)
244-
245-
if (
246-
!data.sourceBucketName ||
247-
!data.sourceObjectKey ||
248-
!data.destinationBucketName ||
249-
!data.destinationObjectKey ||
250-
!data.sourceRegion
251-
) logAndThrowError(COMMON_ERRORS.CM_MISSING_OR_WRONG_INPUT_DATA)
252-
253-
// Connect to S3 client.
254-
const S3 = await getS3Client()
255-
256-
const copyParams = {
257-
Bucket: data.destinationBucketName,
258-
CopySource: `${data.sourceBucketName}/${encodeURIComponent(data.sourceObjectKey)}`,
259-
Key: data.destinationObjectKey,
260-
}
261-
262-
const command = new CopyObjectCommand(copyParams)
263-
264-
try {
265-
// Execute S3 command.
266-
await S3.send(command)
267-
268-
printLog(
269-
`The object was copied from ${data.sourceBucketName} to ${data.destinationBucketName}`,
270-
LogLevel.LOG
271-
)
272-
} catch (error: any) {
273-
// eslint-disable-next-line @typescript-eslint/no-shadow
274-
if (error.$metadata.httpStatusCode === 403) logAndThrowError(SPECIFIC_ERRORS.SE_STORAGE_MISSING_PERMISSIONS)
275-
276-
if (error.$metadata.httpStatusCode !== 200) {
277-
const commonError = COMMON_ERRORS.CM_INVALID_REQUEST
278-
const additionalDetails = error.toString()
279-
280-
logAndThrowError(makeError(commonError.code, commonError.message, additionalDetails))
281-
}
282-
}
283-
284-
logAndThrowError(SPECIFIC_ERRORS.SE_STORAGE_TRASNSFER_FAILED)
285-
})
286-
287231
/**
288232
* Check if a specified object exist in a given AWS S3 bucket.
289233
* @returns <Promise<boolean>> - true if the object exist in the given bucket; otherwise false.

packages/backend/src/lib/errors.ts

-5
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,6 @@ export const SPECIFIC_ERRORS = {
115115
"Unable to delete the AWS S3 object from the provided ceremony bucket.",
116116
"This could happen if the local file or the bucket do not exist."
117117
),
118-
SE_STORAGE_TRASNSFER_FAILED: makeError(
119-
"failed-precondition",
120-
"Unable to transfer the circuit artifacts to the ceremony bucket.",
121-
"This could happen if the files or the bucket do not exist, or the permissions are not public."
122-
),
123118
SE_CONTRIBUTE_NO_CEREMONY_CIRCUITS: makeError(
124119
"not-found",
125120
"There is no circuit associated with the ceremony.",

packages/backend/src/types/index.ts

-17
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,6 @@ export type BucketAndObjectKeyData = {
3333
objectKey: string
3434
}
3535

36-
/**
37-
* Group all the necessary data needed for running the `transferObject` cloud function.
38-
* @typedef {Object} TransferObjectData
39-
* @property {string} sourceRegion - the region of the source bucket.
40-
* @property {string} sourceBucketName - the name of the source bucket.
41-
* @property {string} sourceObjectKey - the unique key to identify the object inside the given AWS S3 source bucket.
42-
* @property {string} destinationBucketName - the name of the destination bucket.
43-
* @property {string} destinationObjectKey - the unique key to identify the object inside the given AWS S3 destination bucket.
44-
*/
45-
export type TransferObjectData = {
46-
sourceRegion: string
47-
sourceBucketName: string
48-
sourceObjectKey: string
49-
destinationBucketName: string
50-
destinationObjectKey: string
51-
}
52-
5336
/**
5437
* Group all the necessary data needed for running the `startMultiPartUpload` cloud function.
5538
* @typedef {Object} StartMultiPartUploadData

packages/phase2cli/src/commands/setup.ts

+7-42
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
import { zKey } from "snarkjs"
44
import boxen from "boxen"
5-
import { createWriteStream, Dirent, renameSync, createReadStream } from "fs"
5+
import { createWriteStream, Dirent, renameSync } from "fs"
66
import { pipeline } from "node:stream"
77
import { promisify } from "node:util"
88
import fetch from "node-fetch"
99
import { Functions } from "firebase/functions"
1010
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3"
11-
import { getSignedUrl } from "@aws-sdk/s3-request-presigner"
1211
import {
1312
CeremonyTimeoutType,
1413
CircomCompilerData,
@@ -65,7 +64,6 @@ import {
6564
checkAndMakeNewDirectoryIfNonexistent
6665
} from "../lib/files.js"
6766
import { Readable } from "stream"
68-
import { transferObject } from "@p0tion/actions"
6967

7068
/**
7169
* Handle whatever is needed to obtain the input data for a circuit that the coordinator would like to add to the ceremony.
@@ -462,37 +460,6 @@ export const handleCircuitArtifactUploadToStorage = async (
462460
spinner.succeed(`Upload of (${theme.text.bold(completeFilename)}) file completed successfully`)
463461
}
464462

465-
/**
466-
* Transfer a file between two buckets
467-
* @param firebaseFunctions <Functions> - the Firebase Cloud Functions instance connected to the current application.
468-
* @param bucketName <string> - the ceremony bucket name.
469-
* @param storageFilePath <string> - the storage (bucket) path where the file should be uploaded.
470-
* @param sourceBucketName <string> - the source bucket name.
471-
* @param sourceObjectKey <string> - the source object key.
472-
* @param completeFilename <string> - the complete filename.
473-
*/
474-
export const handleCircuitArtifactTransferToStorage = async (
475-
firebaseFunctions: Functions,
476-
bucketName: string,
477-
storageFilePath: string,
478-
sourceBucketName: string,
479-
sourceObjectKey: string,
480-
completeFilename: string
481-
) => {
482-
const spinner = customSpinner(`Transfering ${theme.text.bold(completeFilename)} file to ceremony storage...`, `clock`)
483-
spinner.start()
484-
485-
await transferObject(
486-
firebaseFunctions,
487-
sourceBucketName,
488-
bucketName,
489-
sourceObjectKey,
490-
storageFilePath
491-
)
492-
493-
spinner.succeed(`Transfer of (${theme.text.bold(completeFilename)}) file completed successfully`)
494-
}
495-
496463
/**
497464
* Setup command.
498465
* @notice The setup command allows the coordinator of the ceremony to prepare the next ceremony by interacting with the CLI.
@@ -608,23 +575,21 @@ const setup = async (cmd: { template?: string, auth?: string}) => {
608575
circuit.files.potFilename
609576
)
610577

611-
// Move r1cs between buckets
612-
await handleCircuitArtifactTransferToStorage(
578+
// Upload r1cs to Storage.
579+
await handleCircuitArtifactUploadToStorage(
613580
firebaseFunctions,
614-
ceremonySetupData.circuitArtifacts[index].artifacts.bucket,
615-
ceremonySetupData.circuitArtifacts[index].artifacts.r1csStoragePath,
616581
bucketName,
617582
circuit.files.r1csStoragePath,
583+
r1csLocalPathAndFileName,
618584
circuit.files.r1csFilename
619585
)
620586

621-
// Move wasm between buckets.
622-
await handleCircuitArtifactTransferToStorage(
587+
// Upload wasm to Storage.
588+
await handleCircuitArtifactUploadToStorage(
623589
firebaseFunctions,
624-
ceremonySetupData.circuitArtifacts[index].artifacts.bucket,
625-
ceremonySetupData.circuitArtifacts[index].artifacts.wasmStoragePath,
626590
bucketName,
627591
circuit.files.wasmStoragePath,
592+
r1csLocalPathAndFileName,
628593
circuit.files.wasmFilename
629594
)
630595

0 commit comments

Comments
 (0)