Skip to content

Commit

Permalink
Merge pull request #270 from privacy-scaling-explorations/268-avoid-d…
Browse files Browse the repository at this point in the history
…up-compute

feat(contribute.ts): avoid duplicate invocation of compute step
  • Loading branch information
NicoSerranoP authored Mar 8, 2024
2 parents c1f4cbe + 4ab581e commit 671e653
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions packages/phase2cli/src/commands/contribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ export const listenToCeremonyCircuitDocumentChanges = (
})
}

let contributionInProgress = false

/**
* Listen to current authenticated participant document changes.
* @dev this is the core business logic related to the execution of the contribute command.
Expand Down Expand Up @@ -711,6 +713,12 @@ export const listenToParticipantDocumentChanges = async (

// Scenario (3.B).
if (isCurrentContributor && hasResumableStep && startingOrResumingContribution) {
if (contributionInProgress) {
console.warn(
`\n${theme.symbols.warning} Received instruction to start/resume contribution but contribution is already in progress...[skipping]`
)
return
}
// Communicate resume / start of the contribution to participant.
await simpleLoader(
`${
Expand All @@ -720,18 +728,24 @@ export const listenToParticipantDocumentChanges = async (
3000
)

// Start / Resume the contribution for the participant.
await handleStartOrResumeContribution(
cloudFunctions,
firestoreDatabase,
ceremony,
circuit,
participant,
entropy,
providerUserId,
false, // not finalizing.
circuits.length
)
try {
contributionInProgress = true

// Start / Resume the contribution for the participant.
await handleStartOrResumeContribution(
cloudFunctions,
firestoreDatabase,
ceremony,
circuit,
participant,
entropy,
providerUserId,
false, // not finalizing.
circuits.length
)
} finally {
contributionInProgress = false
}
}
// Scenario (3.A).
else if (isWaitingForContribution)
Expand Down
Empty file modified packages/phase2cli/src/index.ts
100755 → 100644
Empty file.

0 comments on commit 671e653

Please sign in to comment.