From 34f02c9343803dd63f02dca9bb3b122cefe463f8 Mon Sep 17 00:00:00 2001 From: Geoff Lamperd Date: Wed, 23 Mar 2022 14:45:36 +1000 Subject: [PATCH] feat: issue #11 circuit-specific file names --- client/src/api/FileApi.ts | 12 ++++++------ client/src/state/Compute.tsx | 7 ++++--- client/src/state/ComputeStateManager.tsx | 4 ++-- client/src/types/ceremony.d.ts | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/client/src/api/FileApi.ts b/client/src/api/FileApi.ts index cfc9287..359a3ce 100644 --- a/client/src/api/FileApi.ts +++ b/client/src/api/FileApi.ts @@ -3,16 +3,16 @@ import "firebase/storage"; import { resolve } from 'path'; import fetchStream from 'fetch-readablestream'; -const formatParamsFileName = (index: number): string => { +const formatParamsFileName = (prefix: string, index: number): string => { var tmp = "000" + index.toString(); var padIndex = tmp.substr(tmp.length-4); - return `ph2_${padIndex}.zkey`; + return `${prefix}_${padIndex}.zkey`; }; -export const getParamsFile = async (ceremonyId: string, index: number, progressCallback: (p: number) => void): Promise => { +export const getParamsFile = async (ceremonyId: string, circuitPrefix: string, index: number, progressCallback: (p: number) => void): Promise => { const storage = firebase.storage(); - const fileRef = storage.ref(`/ceremony_data/${ceremonyId}/${formatParamsFileName(index)}`); + const fileRef = storage.ref(`/ceremony_data/${ceremonyId}/${formatParamsFileName(circuitPrefix, index)}`); const metadata = await fileRef.getMetadata() .catch((err: any) => { console.log(`Expected params file doesn't exist? ${err.message}`); @@ -52,9 +52,9 @@ export const getParamsFile = async (ceremonyId: string, index: number, progressC return chunks; }; -export const uploadParams = async (ceremonyId: string, index: number, params: Uint8Array, progressCallback: (p: number) => void): Promise => { +export const uploadParams = async (ceremonyId: string, circuitPrefix: string, index: number, params: Uint8Array, progressCallback: (p: number) => void): Promise => { const storage = firebase.storage(); - const fileRef = storage.ref(`/ceremony_data/${ceremonyId}/${formatParamsFileName(index)}`); + const fileRef = storage.ref(`/ceremony_data/${ceremonyId}/${formatParamsFileName(circuitPrefix, index)}`); const executor = (resolve: (val: string) => void, reject: (reason: any) => void) => { const uploadTask = fileRef.put(params); diff --git a/client/src/state/Compute.tsx b/client/src/state/Compute.tsx index 9f1ff7a..ce62c5e 100644 --- a/client/src/state/Compute.tsx +++ b/client/src/state/Compute.tsx @@ -6,11 +6,11 @@ import { Dispatch } from "react"; import { getParticipantContributions } from '../api/FirestoreApi'; import { zKey } from 'snarkjs'; -export const startDownload = (ceremonyId: string, index: number, dispatch: Dispatch) => { +export const startDownload = (ceremonyId: string, circuitPrefix: string, index: number, dispatch: Dispatch) => { // DATA DOWNLOAD console.debug(`getting data ${ceremonyId} ${index}`); const progressCb = (progress: number) => dispatch({type: 'PROGRESS_UPDATE', data: progress}) - getParamsFile(ceremonyId, index, progressCb).then( paramData => { + getParamsFile(ceremonyId, circuitPrefix, index, progressCb).then( paramData => { //setTimeout(() => { console.debug(`downloaded ${paramData?.length}`); dispatch({ @@ -56,9 +56,10 @@ export const startComputation = (params: Uint8Array, entropy: Uint8Array, partic } }; -export const startUpload = (ceremonyId: string, index: number, data: Uint8Array, dispatch: Dispatch) => { +export const startUpload = (ceremonyId: string, circuitPrefix: string, index: number, data: Uint8Array, dispatch: Dispatch) => { uploadParams( ceremonyId, + circuitPrefix, index, data, (progress) => dispatch({type: 'PROGRESS_UPDATE', data: progress}) diff --git a/client/src/state/ComputeStateManager.tsx b/client/src/state/ComputeStateManager.tsx index aeb3d4f..22d26e8 100644 --- a/client/src/state/ComputeStateManager.tsx +++ b/client/src/state/ComputeStateManager.tsx @@ -240,7 +240,7 @@ export const computeStateReducer = (state: any, action: any):any => { updateContribution(action.ceremonyId, contribution); newState.contributionState = {...state.contributionState, startTime: Date.now()}; newState.computeStatus = {...state.computeStatus, running: true, downloading: true}; - startDownload(state.contributionState.ceremony.id, state.contributionState.lastValidIndex, action.dispatch); + startDownload(state.contributionState.ceremony.id, state.contributionState.ceremony.zkeyPrefix, state.contributionState.lastValidIndex, action.dispatch); newState.progress = {count: 0, total: 0}; return newState; } @@ -305,7 +305,7 @@ export const computeStateReducer = (state: any, action: any):any => { newState.paramData = new Uint8Array(); //const msg = `Computation completed.`; //newState = addMessage(newState, msg); - startUpload(state.contributionState.ceremony.id, state.contributionState.queueIndex, action.newParams, action.dispatch); + startUpload(state.contributionState.ceremony.id, state.contributionState.ceremony.zkeyPrefix, state.contributionState.queueIndex, action.newParams, action.dispatch); return newState; } case 'UPLOADED': { diff --git a/client/src/types/ceremony.d.ts b/client/src/types/ceremony.d.ts index 425a0bb..acb15f5 100644 --- a/client/src/types/ceremony.d.ts +++ b/client/src/types/ceremony.d.ts @@ -34,7 +34,6 @@ export interface Ceremony { adminAddr: string; lastSummaryUpdate: Date; - // fetched from mpc server, cached by zkp server for when / if mpc server is disconnected ceremonyState: CeremonyState; startTime: Date | string; endTime: Date | string | undefined; @@ -54,6 +53,7 @@ export interface Ceremony { hash?: string; // Participant's own hash isCompleted?: boolean; // Participant has completed this circuit highestQueueIndex: number; + zkeyPrefix: string; } export interface Participant {