diff --git a/src/main/kotlin/org/cryptobiotic/eg/cli/RunBatchEncryption.kt b/src/main/kotlin/org/cryptobiotic/eg/cli/RunBatchEncryption.kt index bd938a5..f5112d9 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/cli/RunBatchEncryption.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/cli/RunBatchEncryption.kt @@ -296,9 +296,9 @@ class RunBatchEncryption { logger.info { " wrote ${invalidBallots.size} invalid ballots to $useInvalidDir" } } - logger.debug { "Encryption with nthreads = $nthreads ${stopwatch.tookPer(count, "ballot")}" } + logger.info { "Encryption with nthreads = $nthreads ${stopwatch.tookPer(count, "ballot")}" } val encryptionPerBallot = if (count == 0) 0 else (countEncryptions / count) - logger.debug { + logger.info { " $countEncryptions total encryptions = $encryptionPerBallot per ballot ${ stopwatch.tookPer( countEncryptions, diff --git a/src/main/kotlin/org/cryptobiotic/eg/cli/RunExampleEncryption.kt b/src/main/kotlin/org/cryptobiotic/eg/cli/RunExampleEncryption.kt index afdb09a..0ea56a2 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/cli/RunExampleEncryption.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/cli/RunExampleEncryption.kt @@ -11,6 +11,7 @@ import org.cryptobiotic.eg.input.ManifestInputValidation import org.cryptobiotic.eg.input.RandomBallotProvider import org.cryptobiotic.eg.publish.makeConsumer import org.cryptobiotic.eg.publish.makePublisher +import org.cryptobiotic.util.Stopwatch import kotlin.random.Random import kotlin.system.exitProcess @@ -90,6 +91,10 @@ class RunExampleEncryption { val publisher = makePublisher(plaintextBallotDir) var allOk = true + val styleCount = ManifestInputValidation(manifest).countEncryptions() + var countEncryptions = 0 + val stopwatch = Stopwatch() // start timing here + val ballotProvider = RandomBallotProvider(manifest) repeat(nballots) { val pballot = ballotProvider.getFakeBallot(manifest, null, "ballot$it") @@ -97,8 +102,7 @@ class RunExampleEncryption { val pballotFilename = "$plaintextBallotDir/pballot-${pballot.ballotId}.json" val deviceIdx = if (devices.size == 1) 0 else Random.nextInt(devices.size) val device = devices[deviceIdx] - // val eballotDir = if (chaining || !noDeviceNameInDir) "$encryptBallotDir/$device" else encryptBallotDir - // createDirectories(eballotDir) + countEncryptions += styleCount[pballot.ballotStyle] ?: 0 val retval = RunEncryptBallot.encryptBallot( consumerIn, @@ -126,6 +130,9 @@ class RunExampleEncryption { } else { if (!noexit) exitProcess(3) } + logger.info { "RunExampleEncryption ${stopwatch.tookPer(nballots, "ballot")}" } + logger.info { "RunExampleEncryption ${stopwatch.tookPer(countEncryptions, "encryptions")}" } + } catch (t: Throwable) { logger.error { "Exception= ${t.message} ${t.stackTraceToString()}" } if (!noexit) exitProcess(-1) diff --git a/src/main/kotlin/org/cryptobiotic/eg/cli/RunTrustedBallotDecryption.kt b/src/main/kotlin/org/cryptobiotic/eg/cli/RunTrustedBallotDecryption.kt index 3773032..1a0ffa6 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/cli/RunTrustedBallotDecryption.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/cli/RunTrustedBallotDecryption.kt @@ -40,7 +40,7 @@ class RunTrustedBallotDecryption { companion object { private val logger = KotlinLogging.logger("RunTrustedBallotDecryption") - private const val debug = true + private const val debug = false @JvmStatic fun main(args: Array) { diff --git a/src/main/kotlin/org/cryptobiotic/eg/cli/RunTrustedTallyDecryption.kt b/src/main/kotlin/org/cryptobiotic/eg/cli/RunTrustedTallyDecryption.kt index 5ec6311..d0321eb 100644 --- a/src/main/kotlin/org/cryptobiotic/eg/cli/RunTrustedTallyDecryption.kt +++ b/src/main/kotlin/org/cryptobiotic/eg/cli/RunTrustedTallyDecryption.kt @@ -17,6 +17,7 @@ import org.cryptobiotic.eg.decrypt.TallyDecryptor import org.cryptobiotic.eg.election.* import org.cryptobiotic.eg.publish.* import org.cryptobiotic.util.ErrorMessages +import org.cryptobiotic.util.Stopwatch import org.cryptobiotic.util.mergeErrorMessages import kotlin.system.exitProcess @@ -168,6 +169,7 @@ class RunTrustedTallyDecryption { } result.unwrap() } + val stopwatch = Stopwatch() // start timing here val errs = ErrorMessages("RunTrustedTallyDecryption") val decryptedTally = decryptor.decrypt(encryptedTally, errs) @@ -175,6 +177,9 @@ class RunTrustedTallyDecryption { logger.error { " encryptedTally.decrypt $inputDir has error=${errs}" } return 5 } + val countEncryptions = countEncryptions(decryptedTally) + println( "runDecryptTally ${stopwatch.tookPer(countEncryptions, "encryptions")}") + val publisher = makePublisher(outputDir, false) if (tallyResult != null) { publisher.writeDecryptionResult( @@ -198,3 +203,10 @@ class RunTrustedTallyDecryption { } } } + + +fun countEncryptions(tally: DecryptedTallyOrBallot): Int { + return tally.contests.map { contest -> + 1 + contest.selections.size + }.sum() +} diff --git a/src/test/kotlin/org/cryptobiotic/eg/decrypt/RunDecryptBallotsTest.kt b/src/test/kotlin/org/cryptobiotic/eg/decrypt/RunDecryptBallotsTest.kt index 14297ec..d9aca0f 100644 --- a/src/test/kotlin/org/cryptobiotic/eg/decrypt/RunDecryptBallotsTest.kt +++ b/src/test/kotlin/org/cryptobiotic/eg/decrypt/RunDecryptBallotsTest.kt @@ -36,6 +36,23 @@ class RunDecryptBallotsTest { assertEquals(42, n) } + @Test + fun testDecryptBallotsAllSingleThreaded() { + val inputDir = "src/test/data/workflow/allAvailableEc" + val trusteeDir = "$inputDir/private_data/trustees" + val outputDir = "${Testing.testOut}/decrypt/testDecryptBallotsAll" + println("\ntestDecryptBallotsAll") + val (retval, n) = runDecryptBallots( + inputDir, + outputDir, + readDecryptingTrustees(inputDir, trusteeDir), + "ALL", + 1, + ) + assertEquals(0, retval) + assertEquals(42, n) + } + @Test fun testDecryptBallotsSomeFromList() { val inputDir = "src/test/data/workflow/someAvailableEc" diff --git a/src/test/kotlin/org/cryptobiotic/eg/tally/RunTallyAccumulationTest.kt b/src/test/kotlin/org/cryptobiotic/eg/tally/RunTallyAccumulationTest.kt index 434fa86..6537123 100644 --- a/src/test/kotlin/org/cryptobiotic/eg/tally/RunTallyAccumulationTest.kt +++ b/src/test/kotlin/org/cryptobiotic/eg/tally/RunTallyAccumulationTest.kt @@ -14,8 +14,10 @@ import org.cryptobiotic.eg.decrypt.TallyDecryptor import org.cryptobiotic.eg.election.DecryptedTallyOrBallot import org.cryptobiotic.eg.election.ElectionInitialized import org.cryptobiotic.eg.election.EncryptedBallot.BallotState +import org.cryptobiotic.eg.input.ManifestInputValidation import org.cryptobiotic.eg.publish.makeConsumer import org.cryptobiotic.util.ErrorMessages +import org.cryptobiotic.util.Stopwatch import org.cryptobiotic.util.Testing import kotlin.test.* @@ -65,16 +67,22 @@ class RunTallyAccumulationTest { val initResult = consumerIn.readElectionInitialized() val electionInit = initResult.unwrap() val manifest = consumerIn.makeManifest(electionInit.config.manifestBytes) + val styleCount = ManifestInputValidation(manifest).countEncryptions() val accum = AccumulateTally(group, manifest, "name", electionInit.extendedBaseHash, electionInit.jointPublicKey) + val stopwatch = Stopwatch() // start timing here + var countEncryptions = 0 val errs = ErrorMessages("addCastBallots") consumerIn.iterateAllCastBallots().forEach { eballot -> accum.addCastBallot(eballot, errs) + countEncryptions += styleCount[eballot.ballotStyleId] ?: 0 } assertFalse(errs.hasErrors()) val etally: EncryptedTally = accum.build() + println( "testAccumulateTally ${stopwatch.tookPer(countEncryptions, "encryptions")}") + val tally = decryptTally(group, etally, electionInit, readDecryptingTrustees(inputDir, trusteeDir)) val decryptResult = consumerIn.readDecryptionResult() diff --git a/src/test/kotlin/org/cryptobiotic/eg/verifier/VerifierTest.kt b/src/test/kotlin/org/cryptobiotic/eg/verifier/VerifierTest.kt index 70d56a4..908b88a 100644 --- a/src/test/kotlin/org/cryptobiotic/eg/verifier/VerifierTest.kt +++ b/src/test/kotlin/org/cryptobiotic/eg/verifier/VerifierTest.kt @@ -24,6 +24,12 @@ class VerifierTest { assertEquals(0, RunVerifier.runVerifier("src/test/data/workflow/someAvailableEc", 11, true)) } + @Test + fun verificationEcSingle() { + assertEquals(0, RunVerifier.runVerifier("src/test/data/workflow/allAvailableEc", 1, true)) + assertEquals(0, RunVerifier.runVerifier("src/test/data/workflow/someAvailableEc", 1, true)) + } + @Test fun verificationInteger() { assertEquals(0, RunVerifier.runVerifier("src/test/data/workflow/allAvailable", 11, true))