Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log timing results #87

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/kotlin/org/cryptobiotic/eg/cli/RunBatchEncryption.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions src/main/kotlin/org/cryptobiotic/eg/cli/RunExampleEncryption.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -90,15 +91,18 @@ 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")
publisher.writePlaintextBallot(plaintextBallotDir, listOf(pballot))
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,
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -168,13 +169,17 @@ class RunTrustedTallyDecryption {
}
result.unwrap()
}
val stopwatch = Stopwatch() // start timing here

val errs = ErrorMessages("RunTrustedTallyDecryption")
val decryptedTally = decryptor.decrypt(encryptedTally, errs)
if (decryptedTally == null) {
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(
Expand All @@ -198,3 +203,10 @@ class RunTrustedTallyDecryption {
}
}
}


fun countEncryptions(tally: DecryptedTallyOrBallot): Int {
return tally.contests.map { contest ->
1 + contest.selections.size
}.sum()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand Down Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions src/test/kotlin/org/cryptobiotic/eg/verifier/VerifierTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading