Skip to content

Commit

Permalink
fix: missing pre-condition when resuming during computing step; wrong…
Browse files Browse the repository at this point in the history
… pre-condition on related cf
  • Loading branch information
0xjei committed Feb 23, 2023
1 parent 15788ea commit 90c8729
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
33 changes: 16 additions & 17 deletions packages/backend/src/functions/participant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,24 +282,23 @@ export const permanentlyStoreCurrentContributionTimeAndHash = functions.https.on

// Pre-condition: computing contribution step or finalizing (only for coordinator when finalizing ceremony).
if (
contributionStep !== ParticipantContributionStep.COMPUTING ||
(isCoordinator && status !== ParticipantStatus.FINALIZING)
)
logAndThrowError(SPECIFIC_ERRORS.SE_PARTICIPANT_CANNOT_STORE_PERMANENT_DATA)

// Send tx.
await participantDoc.ref.set(
{
contributions: [
...currentContributions,
{
hash: data.contributionHash,
computationTime: data.contributionComputationTime
}
]
},
{ merge: true }
contributionStep === ParticipantContributionStep.COMPUTING ||
(isCoordinator && status === ParticipantStatus.FINALIZING)
)
// Send tx.
await participantDoc.ref.set(
{
contributions: [
...currentContributions,
{
hash: data.contributionHash,
computationTime: data.contributionComputationTime
}
]
},
{ merge: true }
)
else logAndThrowError(SPECIFIC_ERRORS.SE_PARTICIPANT_CANNOT_STORE_PERMANENT_DATA)

printLog(
`Participant ${participantDoc.id} has successfully stored the contribution hash ${data.contributionHash} and computation time ${data.contributionComputationTime}`,
Expand Down
6 changes: 5 additions & 1 deletion packages/phase2cli/src/commands/contribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ const listenToParticipantDocumentChanges = async (
const {
contributionProgress: exContributionProgress,
status: exStatus,
contributions: exContributions,
contributionStep: exContributionStep,
tempContributionData: exTempContributionData
} = participant.data()!
Expand Down Expand Up @@ -730,6 +731,9 @@ const listenToParticipantDocumentChanges = async (

const noTemporaryContributionData = !exTempContributionData && !changedTempContributionData

const samePermanentContributionData =
(!exContributions && !changedContributions) || exContributions.length === changedContributions.length

const downloadingStep = changedContributionStep === ParticipantContributionStep.DOWNLOADING
const computingStep = changedContributionStep === ParticipantContributionStep.COMPUTING
const uploadingStep = changedContributionStep === ParticipantContributionStep.UPLOADING
Expand Down Expand Up @@ -764,7 +768,7 @@ const listenToParticipantDocumentChanges = async (
resumingAfterTimeoutExpiration ||
neverResumedContribution)) ||
// Pre-condition X => contribute / resume when contribution step = COMPUTING.
(computingStep && resumingContribution) ||
(computingStep && resumingContribution && samePermanentContributionData) ||
// Pre-condition Y => contribute / resume when contribution step = UPLOADING without any pre-uploaded chunk.
(uploadingStep && resumingContribution && noTemporaryContributionData) ||
// Pre-condition Z => contribute / resume when contribution step = UPLOADING w/ some pre-uploaded chunk.
Expand Down
4 changes: 2 additions & 2 deletions packages/phase2cli/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ export const handleStartOrResumeContribution = async (

// Advance to next contribution step (COMPUTING) if not finalizing.
if (!isFinalizing) {
spinner.text = `Preparing to contribution computation...`
spinner.text = `Preparing for contribution computation...`
spinner.start()

await progressToNextContributionStep(cloudFunctions, ceremony.id)
Expand Down Expand Up @@ -607,7 +607,7 @@ export const handleStartOrResumeContribution = async (

// Advance to next contribution step (UPLOADING) if not finalizing.
if (!isFinalizing) {
spinner.text = `Preparing to uploading the contribution...`
spinner.text = `Preparing for uploading the contribution...`
spinner.start()

await progressToNextContributionStep(cloudFunctions, ceremony.id)
Expand Down

0 comments on commit 90c8729

Please sign in to comment.