Skip to content

Commit d2ca87c

Browse files
authored
Merge pull request #191 from c4dt/fix-create-forms
Revert "@pierluca's and @jbsv's comments"
2 parents 5ca296c + 04b007a commit d2ca87c

File tree

8 files changed

+53
-58
lines changed

8 files changed

+53
-58
lines changed

.github/workflows/go_test.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ jobs:
1919
- name: Check out code into the Go module directory
2020
uses: actions/checkout@v3
2121

22-
# TODO: https://github.com/dedis/d-voting/issues/392
23-
# - name: Run lint
24-
# run: make lint
25-
#
22+
- name: Run lint
23+
run: make lint
24+
2625
- name: Run vet
2726
run: make vet
2827

contracts/evoting/json/forms.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func (formFormat) Encode(ctx serde.Context, message serde.Message) ([]byte, erro
3636
}
3737
}
3838

39-
suffragias := make([]string, len(m.SuffragiaStoreKeys))
40-
for i, suf := range m.SuffragiaStoreKeys {
39+
suffragias := make([]string, len(m.SuffragiaIDs))
40+
for i, suf := range m.SuffragiaIDs {
4141
suffragias[i] = hex.EncodeToString(suf)
4242
}
4343

@@ -146,19 +146,19 @@ func (formFormat) Decode(ctx serde.Context, data []byte) (serde.Message, error)
146146
}
147147

148148
return types.Form{
149-
Configuration: formJSON.Configuration,
150-
FormID: formJSON.FormID,
151-
Status: types.Status(formJSON.Status),
152-
Pubkey: pubKey,
153-
BallotSize: formJSON.BallotSize,
154-
SuffragiaStoreKeys: suffragias,
155-
SuffragiaHashes: suffragiaHashes,
156-
BallotCount: formJSON.BallotCount,
157-
ShuffleInstances: shuffleInstances,
158-
ShuffleThreshold: formJSON.ShuffleThreshold,
159-
PubsharesUnits: pubSharesSubmissions,
160-
DecryptedBallots: formJSON.DecryptedBallots,
161-
Roster: roster,
149+
Configuration: formJSON.Configuration,
150+
FormID: formJSON.FormID,
151+
Status: types.Status(formJSON.Status),
152+
Pubkey: pubKey,
153+
BallotSize: formJSON.BallotSize,
154+
SuffragiaIDs: suffragias,
155+
SuffragiaHashes: suffragiaHashes,
156+
BallotCount: formJSON.BallotCount,
157+
ShuffleInstances: shuffleInstances,
158+
ShuffleThreshold: formJSON.ShuffleThreshold,
159+
PubsharesUnits: pubSharesSubmissions,
160+
DecryptedBallots: formJSON.DecryptedBallots,
161+
Roster: roster,
162162
}, nil
163163
}
164164

contracts/evoting/mod.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"go.dedis.ch/dela/core/execution/native"
1111
"go.dedis.ch/dela/core/ordering/cosipbft/authority"
1212
"go.dedis.ch/dela/core/store"
13-
"go.dedis.ch/dela/core/store/prefixed"
1413
"go.dedis.ch/dela/serde"
1514
"go.dedis.ch/dela/serde/json"
1615

@@ -199,8 +198,6 @@ func (c Contract) Execute(snap store.Snapshot, step execution.Step) error {
199198
return xerrors.Errorf("%q not found in tx arg", CmdArg)
200199
}
201200

202-
snap = prefixed.NewSnapshot(ContractUID, snap)
203-
204201
switch Command(cmd) {
205202
case CmdCreateForm:
206203
err = c.cmd.createForm(snap, step)

contracts/evoting/types/election.go

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ const (
4242
Canceled Status = 6
4343
)
4444

45-
// BallotsPerBatch to improve performance, so that (de)serializing only touches
45+
// BallotsPerBlock to improve performance, so that (de)serializing only touches
4646
// 100 ballots at a time.
47-
var BallotsPerBatch = uint32(100)
47+
var BallotsPerBlock = uint32(100)
4848

49-
// TestCastBallots if true, automatically fills every batch with ballots.
49+
// TestCastBallots if true, automatically fills every block with ballots.
5050
var TestCastBallots = false
5151

5252
// formFormat contains the supported formats for the form. Right now
@@ -78,17 +78,18 @@ type Form struct {
7878
// to pad smaller ballots such that all ballots cast have the same size
7979
BallotSize int
8080

81-
// SuffragiaStoreKeys holds a slice of storage-keys to 0 or more Suffragia.
81+
// SuffragiaIDs holds a slice of IDs to slices of SuffragiaIDs.
8282
// This is to optimize the time it takes to (De)serialize a Form.
83-
SuffragiaStoreKeys [][]byte
83+
SuffragiaIDs [][]byte
8484

8585
// BallotCount is the total number of ballots cast, including double
8686
// ballots.
8787
BallotCount uint32
8888

89-
// SuffragiaHashes holds a slice of hashes to all SuffragiaStoreKeys.
90-
// In case a Form has also to be proven to be correct outside the nodes,
91-
// the hashes are needed to prove the Suffragia are correct.
89+
// SuffragiaHashes holds a slice of hashes to all SuffragiaIDs.
90+
// LG: not really sure if this is needed. In case a Form has also to be
91+
// proven to be correct outside the nodes, the hashes are definitely
92+
// needed.
9293
SuffragiaHashes [][]byte
9394

9495
// ShuffleInstances is all the shuffles, along with their proof and identity
@@ -203,9 +204,8 @@ func (e *Form) ChunksPerBallot() int {
203204
// CastVote stores the new vote in the memory.
204205
func (s *Form) CastVote(ctx serde.Context, st store.Snapshot, userID string, ciphervote Ciphervote) error {
205206
var suff Suffragia
206-
var batchID []byte
207-
208-
if s.BallotCount%BallotsPerBatch == 0 {
207+
var blockID []byte
208+
if s.BallotCount%BallotsPerBlock == 0 {
209209
// Need to create a random ID for storing the ballots.
210210
// H( formID | ballotcount )
211211
// should be random enough, even if it's previsible.
@@ -216,43 +216,42 @@ func (s *Form) CastVote(ctx serde.Context, st store.Snapshot, userID string, cip
216216
h := sha256.New()
217217
h.Write(id)
218218
binary.LittleEndian.PutUint32(id, s.BallotCount)
219-
batchID = h.Sum(id[0:4])[:32]
220-
221-
err = st.Set(batchID, []byte{})
219+
blockID = h.Sum(id[0:4])[:32]
220+
err = st.Set(blockID, []byte{})
222221
if err != nil {
223-
return xerrors.Errorf("couldn't store new ballot batch: %v", err)
222+
return xerrors.Errorf("couldn't store new ballot block: %v", err)
224223
}
225-
s.SuffragiaStoreKeys = append(s.SuffragiaStoreKeys, batchID)
224+
s.SuffragiaIDs = append(s.SuffragiaIDs, blockID)
226225
s.SuffragiaHashes = append(s.SuffragiaHashes, []byte{})
227226
} else {
228-
batchID = s.SuffragiaStoreKeys[len(s.SuffragiaStoreKeys)-1]
229-
buf, err := st.Get(batchID)
227+
blockID = s.SuffragiaIDs[len(s.SuffragiaIDs)-1]
228+
buf, err := st.Get(blockID)
230229
if err != nil {
231-
return xerrors.Errorf("couldn't get ballots batch: %v", err)
230+
return xerrors.Errorf("couldn't get ballots block: %v", err)
232231
}
233232
format := suffragiaFormat.Get(ctx.GetFormat())
234233
ctx = serde.WithFactory(ctx, CiphervoteKey{}, CiphervoteFactory{})
235234
msg, err := format.Decode(ctx, buf)
236235
if err != nil {
237-
return xerrors.Errorf("couldn't unmarshal ballots batch in cast: %v", err)
236+
return xerrors.Errorf("couldn't unmarshal ballots block in cast: %v", err)
238237
}
239238
suff = msg.(Suffragia)
240239
}
241240

242241
suff.CastVote(userID, ciphervote)
243242
if TestCastBallots {
244-
for i := uint32(1); i < BallotsPerBatch; i++ {
243+
for i := uint32(1); i < BallotsPerBlock; i++ {
245244
suff.CastVote(fmt.Sprintf("%s-%d", userID, i), ciphervote)
246245
}
247-
s.BallotCount += BallotsPerBatch - 1
246+
s.BallotCount += BallotsPerBlock - 1
248247
}
249248
buf, err := suff.Serialize(ctx)
250249
if err != nil {
251-
return xerrors.Errorf("couldn't marshal ballots batch: %v", err)
250+
return xerrors.Errorf("couldn't marshal ballots block: %v", err)
252251
}
253-
err = st.Set(batchID, buf)
252+
err = st.Set(blockID, buf)
254253
if err != nil {
255-
xerrors.Errorf("couldn't set new ballots batch: %v", err)
254+
xerrors.Errorf("couldn't set new ballots block: %v", err)
256255
}
257256
s.BallotCount += 1
258257
return nil
@@ -264,16 +263,16 @@ func (s *Form) CastVote(ctx serde.Context, st store.Snapshot, userID string, cip
264263
// the latest ballot.
265264
func (s *Form) Suffragia(ctx serde.Context, rd store.Readable) (Suffragia, error) {
266265
var suff Suffragia
267-
for _, id := range s.SuffragiaStoreKeys {
266+
for _, id := range s.SuffragiaIDs {
268267
buf, err := rd.Get(id)
269268
if err != nil {
270-
return suff, xerrors.Errorf("couldn't get ballot batch: %v", err)
269+
return suff, xerrors.Errorf("couldn't get ballot block: %v", err)
271270
}
272271
format := suffragiaFormat.Get(ctx.GetFormat())
273272
ctx = serde.WithFactory(ctx, CiphervoteKey{}, CiphervoteFactory{})
274273
msg, err := format.Decode(ctx, buf)
275274
if err != nil {
276-
return suff, xerrors.Errorf("couldn't unmarshal ballots batch in cast: %v", err)
275+
return suff, xerrors.Errorf("couldn't unmarshal ballots block in cast: %v", err)
277276
}
278277
suffTmp := msg.(Suffragia)
279278
for i, uid := range suffTmp.UserIDs {

integration/performance_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func customVotesScenario(b *testing.B, stuffing bool) {
4545
types.TestCastBallots = false
4646
}()
4747
numVotes = 10000
48-
transactions = numVotes / int(types.BallotsPerBatch)
48+
transactions = numVotes / int(types.BallotsPerBlock)
4949
}
5050

5151
adminID := "I am an admin"
@@ -169,7 +169,7 @@ func customVotesScenario(b *testing.B, stuffing bool) {
169169
b.Logf("Submitting shares took: %v", durationPubShares)
170170
b.Logf("Decryption took: %v", durationDecrypt)
171171

172-
require.Len(b, form.DecryptedBallots, len(castedVotes)*int(types.BallotsPerBatch))
172+
require.Len(b, form.DecryptedBallots, len(castedVotes)*int(types.BallotsPerBlock))
173173

174174
// There will be a lot of supplementary ballots, but at least the ones that were
175175
// cast by the test should be present.

services/dkg/pedersen/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ func (s *state) UnmarshalJSON(data []byte) error {
790790
}
791791

792792
if aux.Participants != nil {
793-
// TODO: https://github.com/dedis/d-voting/issues/391
793+
// TODO: use addressFactory here
794794
f := session.AddressFactory{}
795795
var participants = make([]mino.Address, len(aux.Participants))
796796
for i, partStr := range aux.Participants {

services/dkg/pedersen/handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func TestState_MarshalJSON(t *testing.T) {
267267

268268
// Try with some data
269269
distKey := suite.Point().Pick(suite.RandomStream())
270-
// TODO: https://github.com/dedis/d-voting/issues/391
270+
// TODO: use AddressFactory here
271271
participants := []mino.Address{session.NewAddress("grpcs://localhost:12345"), session.NewAddress("grpcs://localhost:1234")}
272272

273273
s1.SetDistKey(distKey)

services/shuffle/neff/handler_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func TestHandler_Stream(t *testing.T) {
5454
err = handler.Stream(fake.Sender{}, receiver)
5555

5656
require.NoError(t, err)
57+
5758
}
5859

5960
func TestHandler_StartShuffle(t *testing.T) {
@@ -109,14 +110,14 @@ func TestHandler_StartShuffle(t *testing.T) {
109110
err = handler.handleStartShuffle(dummyID)
110111
require.EqualError(t, err, "the form must be closed: (0)")
111112

112-
// TODO: think how to re-enable this test
113-
t.Skip("Issue 390 - Doesn't work with new form because of snap needed by Form")
113+
t.Skip("Doesn't work with new form because of snap needed by Form")
114114

115115
Ks, Cs, pubKey := fakeKCPoints(k)
116116

117117
// Wrong formatted ballots:
118118
form.Status = etypes.Closed
119119

120+
// TODO: think how to re-enable this test
120121
//deleteUserFromSuffragia := func(suff *etypes.Suffragia, userID string) bool {
121122
// for i, u := range suff.UserIDs {
122123
// if u == userID {
@@ -139,8 +140,7 @@ func TestHandler_StartShuffle(t *testing.T) {
139140
C: Cs[i],
140141
},
141142
}
142-
err := form.CastVote(service.Context, snap, "dummyUser"+strconv.Itoa(i), ballot)
143-
require.NoError(t, err)
143+
form.CastVote(service.Context, snap, "dummyUser"+strconv.Itoa(i), ballot)
144144
}
145145

146146
service = updateService(form, dummyID)

0 commit comments

Comments
 (0)