Skip to content

Commit

Permalink
Fix the voting-benchmark test
Browse files Browse the repository at this point in the history
This PR follows updates to Dela to make the benchmark test run again.
  • Loading branch information
ineiti committed Jan 19, 2024
1 parent a5e99b6 commit a4c7a6c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
)

replace (
go.dedis.ch/dela => github.com/c4dt/dela v0.0.0-20231121144634-18760d54394e
go.dedis.ch/dela => github.com/c4dt/dela v0.0.0-20231208150034-8c94bd32e18a
go.dedis.ch/dela-apps => github.com/c4dt/dela-apps v0.0.0-20231121155105-f3a8a6f4b3b8
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/c4dt/dela v0.0.0-20231121144634-18760d54394e h1:fziIs5dB/cYete4q4FveEefw0i4gbhbSjkTTJrfd4hQ=
github.com/c4dt/dela v0.0.0-20231121144634-18760d54394e/go.mod h1:Oh/WK8JMO0POQg7nR3u436u+HwsZwPqPzDWAasgmFAU=
github.com/c4dt/dela v0.0.0-20231208150034-8c94bd32e18a h1:MU7JHdKZssVjSeQttHPPa4fUMwqEO/xBQpdQ15H/AUo=
github.com/c4dt/dela v0.0.0-20231208150034-8c94bd32e18a/go.mod h1:Oh/WK8JMO0POQg7nR3u436u+HwsZwPqPzDWAasgmFAU=
github.com/c4dt/dela-apps v0.0.0-20231121155105-f3a8a6f4b3b8 h1:ELho4tnVG7lM3c2I42Q5IGNyuk/2FQCterA2zVQGvms=
github.com/c4dt/dela-apps v0.0.0-20231121155105-f3a8a6f4b3b8/go.mod h1:Rky9YH7R02zSOirr2BhhdJs/9VH4+rxqkQxHU3UTQRA=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down
43 changes: 34 additions & 9 deletions integration/performance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ import (
"golang.org/x/xerrors"
)

// Check the shuffled votes versus the casted votes and a few nodes
// Check the shuffled votes versus the cast votes and a few nodes
func BenchmarkIntegration_CustomVotesScenario(b *testing.B) {

numNodes := 3
numVotes := 3
numVotes := 200
numChunksPerBallot := 3

adminID := "I am an admin"
Expand Down Expand Up @@ -80,8 +79,11 @@ func BenchmarkIntegration_CustomVotesScenario(b *testing.B) {
form, err := getForm(formFac, formID, nodes[0].GetOrdering())
require.NoError(b, err)

b.ResetTimer()
castedVotes, err := castVotesNChunks(m, actor, form, numVotes)
require.NoError(b, err)
durationCasting := b.Elapsed()
b.Logf("Casting %d votes took %v", numVotes, durationCasting)

// ##### CLOSE FORM #####
err = closeForm(m, formID, adminID)
Expand All @@ -91,7 +93,7 @@ func BenchmarkIntegration_CustomVotesScenario(b *testing.B) {

// ##### SHUFFLE BALLOTS ####

//b.ResetTimer()
b.ResetTimer()

b.Logf("initializing shuffle")
sActor, err := initShuffle(nodes)
Expand All @@ -101,20 +103,35 @@ func BenchmarkIntegration_CustomVotesScenario(b *testing.B) {
err = sActor.Shuffle(formID)
require.NoError(b, err)

//b.StopTimer()
durationShuffling := b.Elapsed()

b.Logf("submitting public shares")

b.ResetTimer()

_, err = getForm(formFac, formID, nodes[0].GetOrdering())
require.NoError(b, err)
err = actor.ComputePubshares()
require.NoError(b, err)

err = waitForStatus(types.PubSharesSubmitted, formFac, formID, nodes,
numNodes, 6*time.Second*time.Duration(numNodes))
require.NoError(b, err)

durationPubShares := b.Elapsed()

// ##### DECRYPT BALLOTS #####
time.Sleep(time.Second * 1)

b.Logf("decrypting")

//b.ResetTimer()

form, err = getForm(formFac, formID, nodes[0].GetOrdering())
require.NoError(b, err)

b.ResetTimer()
err = decryptBallots(m, actor, form)
require.NoError(b, err)
durationDecrypt := b.Elapsed()

//b.StopTimer()

Expand All @@ -130,6 +147,11 @@ func BenchmarkIntegration_CustomVotesScenario(b *testing.B) {
fmt.Println("Number of decrypted ballots : " + strconv.Itoa(len(form.DecryptedBallots)))
fmt.Println("Chunks per ballot : " + strconv.Itoa(form.ChunksPerBallot()))

b.Logf("Casting %d votes took %v", numVotes, durationCasting)
b.Logf("Shuffling took: %v", durationShuffling)
b.Logf("Submitting shares took: %v", durationPubShares)
b.Logf("Decryption took: %v", durationDecrypt)

require.Len(b, form.DecryptedBallots, len(castedVotes))

for _, ballot := range form.DecryptedBallots {
Expand Down Expand Up @@ -213,10 +235,10 @@ func castVotesNChunks(m txManager, actor dkg.Actor, form types.Form,
ballotBuilder.Write([]byte(encodeID("bb")))
ballotBuilder.Write([]byte(":"))

textSize := 29*form.ChunksPerBallot() - ballotBuilder.Len() - 3
ballotBuilder.Write([]byte("\n\n"))

textSize := 29*form.ChunksPerBallot() - ballotBuilder.Len() - 3
ballotBuilder.Write([]byte(strings.Repeat("=", textSize)))
ballotBuilder.Write([]byte("\n\n"))

vote := ballotBuilder.String()

Expand All @@ -227,6 +249,7 @@ func castVotesNChunks(m txManager, actor dkg.Actor, form types.Form,

votes := make([]types.Ballot, numberOfVotes)

start := time.Now()
for i := 0; i < numberOfVotes; i++ {

userID := "user " + strconv.Itoa(i)
Expand All @@ -251,6 +274,8 @@ func castVotesNChunks(m txManager, actor dkg.Actor, form types.Form,
if err != nil {
return nil, xerrors.Errorf("failed to addAndWait: %v", err)
}
fmt.Printf("Got vote %d at %v after %v\n", i, time.Now(), time.Now().Sub(start))

Check failure on line 277 in integration/performance_test.go

View workflow job for this annotation

GitHub Actions / Tests

should use time.Since instead of time.Now().Sub (S1012)
start = time.Now()

var ballot types.Ballot
err = ballot.Unmarshal(vote, form)
Expand Down

0 comments on commit a4c7a6c

Please sign in to comment.