@@ -209,7 +209,8 @@ type instance struct {
209
209
// independently of protocol phases/rounds.
210
210
decision * quorumState
211
211
// tracer traces logic logs for debugging and simulation purposes.
212
- tracer Tracer
212
+ tracer Tracer
213
+ progress ProgressObserver
213
214
}
214
215
215
216
func newInstance (
@@ -218,7 +219,8 @@ func newInstance(
218
219
input ECChain ,
219
220
data * SupplementalData ,
220
221
powerTable PowerTable ,
221
- beacon []byte ) (* instance , error ) {
222
+ beacon []byte ,
223
+ progress ProgressObserver ) (* instance , error ) {
222
224
if input .IsZero () {
223
225
return nil , fmt .Errorf ("input is empty" )
224
226
}
@@ -247,6 +249,7 @@ func newInstance(
247
249
},
248
250
decision : newQuorumState (powerTable ),
249
251
tracer : participant .tracer ,
252
+ progress : progress ,
250
253
}, nil
251
254
}
252
255
@@ -482,6 +485,7 @@ func (i *instance) beginQuality() error {
482
485
i .phaseTimeout = i .alarmAfterSynchrony ()
483
486
i .resetRebroadcastParams ()
484
487
i .broadcast (i .round , QUALITY_PHASE , i .proposal , false , nil )
488
+ i .progress .NotifyProgress (i .instanceID , i .round , i .phase )
485
489
metrics .phaseCounter .Add (context .TODO (), 1 , metric .WithAttributes (attrQualityPhase ))
486
490
metrics .currentPhase .Record (context .TODO (), int64 (QUALITY_PHASE ))
487
491
return nil
@@ -542,6 +546,7 @@ func (i *instance) beginConverge(justification *Justification) {
542
546
i .getRound (i .round ).converged .SetSelfValue (i .proposal , justification )
543
547
544
548
i .broadcast (i .round , CONVERGE_PHASE , i .proposal , true , justification )
549
+ i .progress .NotifyProgress (i .instanceID , i .round , i .phase )
545
550
metrics .phaseCounter .Add (context .TODO (), 1 , metric .WithAttributes (attrConvergePhase ))
546
551
metrics .currentPhase .Record (context .TODO (), int64 (CONVERGE_PHASE ))
547
552
}
@@ -599,6 +604,7 @@ func (i *instance) beginPrepare(justification *Justification) {
599
604
i .resetRebroadcastParams ()
600
605
601
606
i .broadcast (i .round , PREPARE_PHASE , i .value , false , justification )
607
+ i .progress .NotifyProgress (i .instanceID , i .round , i .phase )
602
608
metrics .phaseCounter .Add (context .TODO (), 1 , metric .WithAttributes (attrPreparePhase ))
603
609
metrics .currentPhase .Record (context .TODO (), int64 (PREPARE_PHASE ))
604
610
}
@@ -652,6 +658,7 @@ func (i *instance) beginCommit() {
652
658
}
653
659
654
660
i .broadcast (i .round , COMMIT_PHASE , i .value , false , justification )
661
+ i .progress .NotifyProgress (i .instanceID , i .round , i .phase )
655
662
metrics .phaseCounter .Add (context .TODO (), 1 , metric .WithAttributes (attrCommitPhase ))
656
663
metrics .currentPhase .Record (context .TODO (), int64 (COMMIT_PHASE ))
657
664
}
@@ -712,6 +719,7 @@ func (i *instance) tryCommit(round uint64) error {
712
719
func (i * instance ) beginDecide (round uint64 ) {
713
720
i .phase = DECIDE_PHASE
714
721
i .resetRebroadcastParams ()
722
+
715
723
var justification * Justification
716
724
// Value cannot be empty here.
717
725
if quorum , ok := i .getRound (round ).committed .FindStrongQuorumFor (i .value .Key ()); ok {
@@ -727,6 +735,7 @@ func (i *instance) beginDecide(round uint64) {
727
735
// Since each node sends only one DECIDE message, they must share the same vote
728
736
// in order to be aggregated.
729
737
i .broadcast (0 , DECIDE_PHASE , i .value , false , justification )
738
+ i .progress .NotifyProgress (i .instanceID , i .round , i .phase )
730
739
metrics .phaseCounter .Add (context .TODO (), 1 , metric .WithAttributes (attrDecidePhase ))
731
740
metrics .currentPhase .Record (context .TODO (), int64 (DECIDE_PHASE ))
732
741
}
@@ -740,6 +749,7 @@ func (i *instance) skipToDecide(value ECChain, justification *Justification) {
740
749
i .value = i .proposal
741
750
i .resetRebroadcastParams ()
742
751
i .broadcast (0 , DECIDE_PHASE , i .value , false , justification )
752
+ i .progress .NotifyProgress (i .instanceID , i .round , i .phase )
743
753
metrics .phaseCounter .Add (context .TODO (), 1 , metric .WithAttributes (attrDecidePhase ))
744
754
metrics .currentPhase .Record (context .TODO (), int64 (DECIDE_PHASE ))
745
755
metrics .skipCounter .Add (context .TODO (), 1 , metric .WithAttributes (attrSkipToDecide ))
@@ -775,6 +785,7 @@ func (i *instance) getRound(r uint64) *roundState {
775
785
func (i * instance ) beginNextRound () {
776
786
i .log ("moving to round %d with %s" , i .round + 1 , i .proposal .String ())
777
787
i .round += 1
788
+ i .progress .NotifyProgress (i .instanceID , i .round , i .phase )
778
789
metrics .currentRound .Record (context .TODO (), int64 (i .round ))
779
790
780
791
prevRound := i .getRound (i .round - 1 )
@@ -802,6 +813,7 @@ func (i *instance) beginNextRound() {
802
813
func (i * instance ) skipToRound (round uint64 , chain ECChain , justification * Justification ) {
803
814
i .log ("skipping from round %d to round %d with %s" , i .round , round , i .proposal .String ())
804
815
i .round = round
816
+ i .progress .NotifyProgress (i .instanceID , i .round , i .phase )
805
817
metrics .currentRound .Record (context .TODO (), int64 (i .round ))
806
818
metrics .skipCounter .Add (context .TODO (), 1 , metric .WithAttributes (attrSkipToRound ))
807
819
@@ -843,6 +855,7 @@ func (i *instance) terminate(decision *Justification) {
843
855
i .value = decision .Vote .Value
844
856
i .terminationValue = decision
845
857
i .resetRebroadcastParams ()
858
+ i .progress .NotifyProgress (i .instanceID , i .round , i .phase )
846
859
metrics .phaseCounter .Add (context .TODO (), 1 , metric .WithAttributes (attrTerminatedPhase ))
847
860
metrics .roundHistogram .Record (context .TODO (), int64 (i .round ))
848
861
metrics .currentPhase .Record (context .TODO (), int64 (TERMINATED_PHASE ))
@@ -940,7 +953,7 @@ func (i *instance) rebroadcastTimeoutElapsed() bool {
940
953
941
954
func (i * instance ) rebroadcast () error {
942
955
// Rebroadcast quality and all messages from the current and previous rounds, unless the
943
- // instance has progressed to DECIDE phase. In which case, only DECIDE message is
956
+ // instance has progress to DECIDE phase. In which case, only DECIDE message is
944
957
// rebroadcasted.
945
958
//
946
959
// Note that the implementation here rebroadcasts more messages than FIP-0086
0 commit comments