@@ -117,37 +117,37 @@ struct VoteCounts {
117
117
118
118
/// Accumulates messages for a given round of BFT consensus.
119
119
///
120
- /// This isn't tied to the "view" of a single validator . It
120
+ /// This isn't tied to the "view" of a single authority . It
121
121
/// keeps accurate track of the state of the BFT consensus based
122
122
/// on all messages imported.
123
123
#[ derive( Debug ) ]
124
- pub struct Accumulator < Candidate , Digest , ValidatorId , Signature >
124
+ pub struct Accumulator < Candidate , Digest , AuthorityId , Signature >
125
125
where
126
126
Candidate : Eq + Clone ,
127
127
Digest : Hash + Eq + Clone ,
128
- ValidatorId : Hash + Eq ,
128
+ AuthorityId : Hash + Eq ,
129
129
Signature : Eq + Clone ,
130
130
{
131
131
round_number : usize ,
132
132
threshold : usize ,
133
- round_proposer : ValidatorId ,
133
+ round_proposer : AuthorityId ,
134
134
proposal : Option < Candidate > ,
135
- prepares : HashMap < ValidatorId , ( Digest , Signature ) > ,
136
- commits : HashMap < ValidatorId , ( Digest , Signature ) > ,
135
+ prepares : HashMap < AuthorityId , ( Digest , Signature ) > ,
136
+ commits : HashMap < AuthorityId , ( Digest , Signature ) > ,
137
137
vote_counts : HashMap < Digest , VoteCounts > ,
138
- advance_round : HashSet < ValidatorId > ,
138
+ advance_round : HashSet < AuthorityId > ,
139
139
state : State < Candidate , Digest , Signature > ,
140
140
}
141
141
142
- impl < Candidate , Digest , ValidatorId , Signature > Accumulator < Candidate , Digest , ValidatorId , Signature >
142
+ impl < Candidate , Digest , AuthorityId , Signature > Accumulator < Candidate , Digest , AuthorityId , Signature >
143
143
where
144
144
Candidate : Eq + Clone ,
145
145
Digest : Hash + Eq + Clone ,
146
- ValidatorId : Hash + Eq ,
146
+ AuthorityId : Hash + Eq ,
147
147
Signature : Eq + Clone ,
148
148
{
149
149
/// Create a new state accumulator.
150
- pub fn new ( round_number : usize , threshold : usize , round_proposer : ValidatorId ) -> Self {
150
+ pub fn new ( round_number : usize , threshold : usize , round_proposer : AuthorityId ) -> Self {
151
151
Accumulator {
152
152
round_number,
153
153
threshold,
@@ -171,11 +171,6 @@ impl<Candidate, Digest, ValidatorId, Signature> Accumulator<Candidate, Digest, V
171
171
self . round_number . clone ( )
172
172
}
173
173
174
- /// Get the round proposer.
175
- pub fn round_proposer ( & self ) -> & ValidatorId {
176
- & self . round_proposer
177
- }
178
-
179
174
pub fn proposal ( & self ) -> Option < & Candidate > {
180
175
self . proposal . as_ref ( )
181
176
}
@@ -189,7 +184,7 @@ impl<Candidate, Digest, ValidatorId, Signature> Accumulator<Candidate, Digest, V
189
184
/// and authorization should have already been checked.
190
185
pub fn import_message (
191
186
& mut self ,
192
- message : LocalizedMessage < Candidate , Digest , ValidatorId , Signature > ,
187
+ message : LocalizedMessage < Candidate , Digest , AuthorityId , Signature > ,
193
188
)
194
189
{
195
190
// message from different round.
@@ -210,7 +205,7 @@ impl<Candidate, Digest, ValidatorId, Signature> Accumulator<Candidate, Digest, V
210
205
fn import_proposal (
211
206
& mut self ,
212
207
proposal : Candidate ,
213
- sender : ValidatorId ,
208
+ sender : AuthorityId ,
214
209
) {
215
210
if sender != self . round_proposer || self . proposal . is_some ( ) { return }
216
211
@@ -221,7 +216,7 @@ impl<Candidate, Digest, ValidatorId, Signature> Accumulator<Candidate, Digest, V
221
216
fn import_prepare (
222
217
& mut self ,
223
218
digest : Digest ,
224
- sender : ValidatorId ,
219
+ sender : AuthorityId ,
225
220
signature : Signature ,
226
221
) {
227
222
// ignore any subsequent prepares by the same sender.
@@ -264,7 +259,7 @@ impl<Candidate, Digest, ValidatorId, Signature> Accumulator<Candidate, Digest, V
264
259
fn import_commit (
265
260
& mut self ,
266
261
digest : Digest ,
267
- sender : ValidatorId ,
262
+ sender : AuthorityId ,
268
263
signature : Signature ,
269
264
) {
270
265
// ignore any subsequent commits by the same sender.
@@ -304,7 +299,7 @@ impl<Candidate, Digest, ValidatorId, Signature> Accumulator<Candidate, Digest, V
304
299
305
300
fn import_advance_round (
306
301
& mut self ,
307
- sender : ValidatorId ,
302
+ sender : AuthorityId ,
308
303
) {
309
304
self . advance_round . insert ( sender) ;
310
305
@@ -332,7 +327,7 @@ mod tests {
332
327
pub struct Digest ( usize ) ;
333
328
334
329
#[ derive( Hash , PartialEq , Eq , Debug ) ]
335
- pub struct ValidatorId ( usize ) ;
330
+ pub struct AuthorityId ( usize ) ;
336
331
337
332
#[ derive( PartialEq , Eq , Clone , Debug ) ]
338
333
pub struct Signature ( usize , usize ) ;
@@ -347,7 +342,7 @@ mod tests {
347
342
348
343
let check_message = |r, d : & Digest , s : & Signature | {
349
344
if r == 2 && d. 0 == 600 && s. 0 == 600 {
350
- Some ( ValidatorId ( s. 1 ) )
345
+ Some ( AuthorityId ( s. 1 ) )
351
346
} else {
352
347
None
353
348
}
@@ -370,19 +365,19 @@ mod tests {
370
365
371
366
#[ test]
372
367
fn accepts_proposal_from_proposer_only ( ) {
373
- let mut accumulator = Accumulator :: < _ , Digest , _ , _ > :: new ( 1 , 7 , ValidatorId ( 8 ) ) ;
368
+ let mut accumulator = Accumulator :: < _ , Digest , _ , _ > :: new ( 1 , 7 , AuthorityId ( 8 ) ) ;
374
369
assert_eq ! ( accumulator. state( ) , & State :: Begin ) ;
375
370
376
371
accumulator. import_message ( LocalizedMessage {
377
- sender : ValidatorId ( 5 ) ,
372
+ sender : AuthorityId ( 5 ) ,
378
373
signature : Signature ( 999 , 5 ) ,
379
374
message : Message :: Propose ( 1 , Candidate ( 999 ) ) ,
380
375
} ) ;
381
376
382
377
assert_eq ! ( accumulator. state( ) , & State :: Begin ) ;
383
378
384
379
accumulator. import_message ( LocalizedMessage {
385
- sender : ValidatorId ( 8 ) ,
380
+ sender : AuthorityId ( 8 ) ,
386
381
signature : Signature ( 999 , 8 ) ,
387
382
message : Message :: Propose ( 1 , Candidate ( 999 ) ) ,
388
383
} ) ;
@@ -392,11 +387,11 @@ mod tests {
392
387
393
388
#[ test]
394
389
fn reaches_prepare_phase ( ) {
395
- let mut accumulator = Accumulator :: new ( 1 , 7 , ValidatorId ( 8 ) ) ;
390
+ let mut accumulator = Accumulator :: new ( 1 , 7 , AuthorityId ( 8 ) ) ;
396
391
assert_eq ! ( accumulator. state( ) , & State :: Begin ) ;
397
392
398
393
accumulator. import_message ( LocalizedMessage {
399
- sender : ValidatorId ( 8 ) ,
394
+ sender : AuthorityId ( 8 ) ,
400
395
signature : Signature ( 999 , 8 ) ,
401
396
message : Message :: Propose ( 1 , Candidate ( 999 ) ) ,
402
397
} ) ;
@@ -405,7 +400,7 @@ mod tests {
405
400
406
401
for i in 0 ..6 {
407
402
accumulator. import_message ( LocalizedMessage {
408
- sender : ValidatorId ( i) ,
403
+ sender : AuthorityId ( i) ,
409
404
signature : Signature ( 999 , i) ,
410
405
message : Message :: Prepare ( 1 , Digest ( 999 ) ) ,
411
406
} ) ;
@@ -414,7 +409,7 @@ mod tests {
414
409
}
415
410
416
411
accumulator. import_message ( LocalizedMessage {
417
- sender : ValidatorId ( 7 ) ,
412
+ sender : AuthorityId ( 7 ) ,
418
413
signature : Signature ( 999 , 7 ) ,
419
414
message : Message :: Prepare ( 1 , Digest ( 999 ) ) ,
420
415
} ) ;
@@ -427,11 +422,11 @@ mod tests {
427
422
428
423
#[ test]
429
424
fn prepare_to_commit ( ) {
430
- let mut accumulator = Accumulator :: new ( 1 , 7 , ValidatorId ( 8 ) ) ;
425
+ let mut accumulator = Accumulator :: new ( 1 , 7 , AuthorityId ( 8 ) ) ;
431
426
assert_eq ! ( accumulator. state( ) , & State :: Begin ) ;
432
427
433
428
accumulator. import_message ( LocalizedMessage {
434
- sender : ValidatorId ( 8 ) ,
429
+ sender : AuthorityId ( 8 ) ,
435
430
signature : Signature ( 999 , 8 ) ,
436
431
message : Message :: Propose ( 1 , Candidate ( 999 ) ) ,
437
432
} ) ;
@@ -440,7 +435,7 @@ mod tests {
440
435
441
436
for i in 0 ..6 {
442
437
accumulator. import_message ( LocalizedMessage {
443
- sender : ValidatorId ( i) ,
438
+ sender : AuthorityId ( i) ,
444
439
signature : Signature ( 999 , i) ,
445
440
message : Message :: Prepare ( 1 , Digest ( 999 ) ) ,
446
441
} ) ;
@@ -449,7 +444,7 @@ mod tests {
449
444
}
450
445
451
446
accumulator. import_message ( LocalizedMessage {
452
- sender : ValidatorId ( 7 ) ,
447
+ sender : AuthorityId ( 7 ) ,
453
448
signature : Signature ( 999 , 7 ) ,
454
449
message : Message :: Prepare ( 1 , Digest ( 999 ) ) ,
455
450
} ) ;
@@ -461,7 +456,7 @@ mod tests {
461
456
462
457
for i in 0 ..6 {
463
458
accumulator. import_message ( LocalizedMessage {
464
- sender : ValidatorId ( i) ,
459
+ sender : AuthorityId ( i) ,
465
460
signature : Signature ( 999 , i) ,
466
461
message : Message :: Commit ( 1 , Digest ( 999 ) ) ,
467
462
} ) ;
@@ -473,7 +468,7 @@ mod tests {
473
468
}
474
469
475
470
accumulator. import_message ( LocalizedMessage {
476
- sender : ValidatorId ( 7 ) ,
471
+ sender : AuthorityId ( 7 ) ,
477
472
signature : Signature ( 999 , 7 ) ,
478
473
message : Message :: Commit ( 1 , Digest ( 999 ) ) ,
479
474
} ) ;
@@ -486,11 +481,11 @@ mod tests {
486
481
487
482
#[ test]
488
483
fn prepare_to_advance ( ) {
489
- let mut accumulator = Accumulator :: new ( 1 , 7 , ValidatorId ( 8 ) ) ;
484
+ let mut accumulator = Accumulator :: new ( 1 , 7 , AuthorityId ( 8 ) ) ;
490
485
assert_eq ! ( accumulator. state( ) , & State :: Begin ) ;
491
486
492
487
accumulator. import_message ( LocalizedMessage {
493
- sender : ValidatorId ( 8 ) ,
488
+ sender : AuthorityId ( 8 ) ,
494
489
signature : Signature ( 999 , 8 ) ,
495
490
message : Message :: Propose ( 1 , Candidate ( 999 ) ) ,
496
491
} ) ;
@@ -499,7 +494,7 @@ mod tests {
499
494
500
495
for i in 0 ..7 {
501
496
accumulator. import_message ( LocalizedMessage {
502
- sender : ValidatorId ( i) ,
497
+ sender : AuthorityId ( i) ,
503
498
signature : Signature ( 999 , i) ,
504
499
message : Message :: Prepare ( 1 , Digest ( 999 ) ) ,
505
500
} ) ;
@@ -512,7 +507,7 @@ mod tests {
512
507
513
508
for i in 0 ..6 {
514
509
accumulator. import_message ( LocalizedMessage {
515
- sender : ValidatorId ( i) ,
510
+ sender : AuthorityId ( i) ,
516
511
signature : Signature ( 999 , i) ,
517
512
message : Message :: AdvanceRound ( 1 ) ,
518
513
} ) ;
@@ -524,7 +519,7 @@ mod tests {
524
519
}
525
520
526
521
accumulator. import_message ( LocalizedMessage {
527
- sender : ValidatorId ( 7 ) ,
522
+ sender : AuthorityId ( 7 ) ,
528
523
signature : Signature ( 999 , 7 ) ,
529
524
message : Message :: AdvanceRound ( 1 ) ,
530
525
} ) ;
@@ -537,12 +532,12 @@ mod tests {
537
532
538
533
#[ test]
539
534
fn conclude_different_than_proposed ( ) {
540
- let mut accumulator = Accumulator :: < Candidate , _ , _ , _ > :: new ( 1 , 7 , ValidatorId ( 8 ) ) ;
535
+ let mut accumulator = Accumulator :: < Candidate , _ , _ , _ > :: new ( 1 , 7 , AuthorityId ( 8 ) ) ;
541
536
assert_eq ! ( accumulator. state( ) , & State :: Begin ) ;
542
537
543
538
for i in 0 ..7 {
544
539
accumulator. import_message ( LocalizedMessage {
545
- sender : ValidatorId ( i) ,
540
+ sender : AuthorityId ( i) ,
546
541
signature : Signature ( 999 , i) ,
547
542
message : Message :: Prepare ( 1 , Digest ( 999 ) ) ,
548
543
} ) ;
@@ -555,7 +550,7 @@ mod tests {
555
550
556
551
for i in 0 ..7 {
557
552
accumulator. import_message ( LocalizedMessage {
558
- sender : ValidatorId ( i) ,
553
+ sender : AuthorityId ( i) ,
559
554
signature : Signature ( 999 , i) ,
560
555
message : Message :: Commit ( 1 , Digest ( 999 ) ) ,
561
556
} ) ;
@@ -569,12 +564,12 @@ mod tests {
569
564
570
565
#[ test]
571
566
fn begin_to_advance ( ) {
572
- let mut accumulator = Accumulator :: < Candidate , Digest , _ , _ > :: new ( 1 , 7 , ValidatorId ( 8 ) ) ;
567
+ let mut accumulator = Accumulator :: < Candidate , Digest , _ , _ > :: new ( 1 , 7 , AuthorityId ( 8 ) ) ;
573
568
assert_eq ! ( accumulator. state( ) , & State :: Begin ) ;
574
569
575
570
for i in 0 ..7 {
576
571
accumulator. import_message ( LocalizedMessage {
577
- sender : ValidatorId ( i) ,
572
+ sender : AuthorityId ( i) ,
578
573
signature : Signature ( 1 , i) ,
579
574
message : Message :: AdvanceRound ( 1 ) ,
580
575
} ) ;
@@ -588,12 +583,12 @@ mod tests {
588
583
589
584
#[ test]
590
585
fn conclude_without_prepare ( ) {
591
- let mut accumulator = Accumulator :: < Candidate , _ , _ , _ > :: new ( 1 , 7 , ValidatorId ( 8 ) ) ;
586
+ let mut accumulator = Accumulator :: < Candidate , _ , _ , _ > :: new ( 1 , 7 , AuthorityId ( 8 ) ) ;
592
587
assert_eq ! ( accumulator. state( ) , & State :: Begin ) ;
593
588
594
589
for i in 0 ..7 {
595
590
accumulator. import_message ( LocalizedMessage {
596
- sender : ValidatorId ( i) ,
591
+ sender : AuthorityId ( i) ,
597
592
signature : Signature ( 999 , i) ,
598
593
message : Message :: Commit ( 1 , Digest ( 999 ) ) ,
599
594
} ) ;
0 commit comments