@@ -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.
5050var 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.
204205func (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.
265264func (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 {
0 commit comments