Skip to content

Commit

Permalink
feat: issue #11 circuit-specific file names
Browse files Browse the repository at this point in the history
  • Loading branch information
glamperd committed Mar 23, 2022
1 parent 6fe6a55 commit 34f02c9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
12 changes: 6 additions & 6 deletions client/src/api/FileApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uint8Array> => {
export const getParamsFile = async (ceremonyId: string, circuitPrefix: string, index: number, progressCallback: (p: number) => void): Promise<Uint8Array> => {
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}`);
Expand Down Expand Up @@ -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<string> => {
export const uploadParams = async (ceremonyId: string, circuitPrefix: string, index: number, params: Uint8Array, progressCallback: (p: number) => void): Promise<string> => {
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);

Expand Down
7 changes: 4 additions & 3 deletions client/src/state/Compute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>) => {
export const startDownload = (ceremonyId: string, circuitPrefix: string, index: number, dispatch: Dispatch<any>) => {
// 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({
Expand Down Expand Up @@ -56,9 +56,10 @@ export const startComputation = (params: Uint8Array, entropy: Uint8Array, partic
}
};

export const startUpload = (ceremonyId: string, index: number, data: Uint8Array, dispatch: Dispatch<any>) => {
export const startUpload = (ceremonyId: string, circuitPrefix: string, index: number, data: Uint8Array, dispatch: Dispatch<any>) => {
uploadParams(
ceremonyId,
circuitPrefix,
index,
data,
(progress) => dispatch({type: 'PROGRESS_UPDATE', data: progress})
Expand Down
4 changes: 2 additions & 2 deletions client/src/state/ComputeStateManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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': {
Expand Down
2 changes: 1 addition & 1 deletion client/src/types/ceremony.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down

0 comments on commit 34f02c9

Please sign in to comment.