-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathprogress.go
49 lines (40 loc) · 1.33 KB
/
progress.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package gpbft
import "sync/atomic"
var (
_ ProgressObserver = (*atomicProgression)(nil)
_ Progress = (*atomicProgression)(nil).Get
)
type InstanceProgress struct {
Instant
// Input is the initial input chain to the instance. This field may be nil in a
// case where the instance is scheduled to start but has not started yet.
// Because, the input chain is only determined once the start alarm triggers.
//
// See: Participant.StartInstanceAt.
Input *ECChain
}
// Progress gets the latest GPBFT instance progress.
type Progress func() InstanceProgress
// ProgressObserver defines an interface for observing and being notified about
// the progress of a GPBFT instance as it advances through different instance,
// rounds or phases.
type ProgressObserver interface {
// NotifyProgress is called to notify the observer about the progress of GPBFT
// instance, round or phase.
NotifyProgress(instant InstanceProgress)
}
type atomicProgression struct {
progression atomic.Pointer[InstanceProgress]
}
func newAtomicProgression() *atomicProgression {
return &atomicProgression{}
}
func (a *atomicProgression) NotifyProgress(instant InstanceProgress) {
a.progression.Store(&instant)
}
func (a *atomicProgression) Get() (instant InstanceProgress) {
if latest := a.progression.Load(); latest != nil {
instant = *latest
}
return
}