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 25, 2024
1 parent d59f5e3 commit 38ea046
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
1 change: 1 addition & 0 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ func getIntegrationTestCrash(numNodes, numVotes, failingNodes int) func(*testing
form, err = getForm(formFac, formID, nodes[0].GetOrdering())
t.Logf("PubsharesUnit: %v", form.PubsharesUnits)
require.NoError(t, err)
// LG@240124: had some fuzzy failures when decrypting the ballots here.
err = decryptBallots(m, actor, form)
require.NoError(t, err)

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.Since(start))
start = time.Now()

var ballot types.Ballot
err = ballot.Unmarshal(vote, form)
Expand Down
6 changes: 5 additions & 1 deletion integration/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/base64"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"net/http"
"testing"
Expand Down Expand Up @@ -114,9 +115,12 @@ func (m txManager) addAndWait(args ...txn.Arg) ([]byte, error) {

err = m.n.GetPool().Add(sentTxn)
if err != nil {
return nil, xerrors.Errorf("failed to Add: %v", err)
fmt.Printf("Failed to add transaction: %v", err)
continue
}

time.Sleep(time.Second)

sentTxnID := sentTxn.GetID()

accepted := isAccepted(events, sentTxnID)
Expand Down

0 comments on commit 38ea046

Please sign in to comment.