-
Notifications
You must be signed in to change notification settings - Fork 180
/
vote_collectors.go
51 lines (44 loc) · 2.31 KB
/
vote_collectors.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
50
51
package hotstuff
import "github.com/onflow/flow-go/module"
// VoteCollectors is an interface which allows VoteAggregator to interact with collectors structured by
// view.
// Implementations of this interface are responsible for state transitions of `VoteCollector`s and pruning of
// stale and outdated collectors by view.
type VoteCollectors interface {
module.ReadyDoneAware
module.Startable
// GetOrCreateCollector retrieves the hotstuff.VoteCollector for the specified
// view or creates one if none exists.
// When creating a vote collector, the view will be used to get epoch by view, then create the random beacon
// signer object by epoch, because epoch determines DKG, which determines random beacon committee.
// It returns:
// - (collector, true, nil) if no collector can be found by the view, and a new collector was created.
// - (collector, false, nil) if the collector can be found by the view
// - (nil, false, error) if running into any exception creating the vote collector state machine
// Expected error returns during normal operations:
// * mempool.BelowPrunedThresholdError - in case view is lower than last pruned view
GetOrCreateCollector(view uint64) (collector VoteCollector, created bool, err error)
// PruneUpToView prunes the vote collectors with views _below_ the given value, i.e.
// we only retain and process whose view is equal or larger than `lowestRetainedView`.
// If `lowestRetainedView` is smaller than the previous value, the previous value is
// kept and the method call is a NoOp.
PruneUpToView(lowestRetainedView uint64)
}
// Workers queues and processes submitted tasks. We explicitly do not
// expose any functionality to terminate the worker pool.
type Workers interface {
// Submit enqueues a function for a worker to execute. Submit will not block
// regardless of the number of tasks submitted. Each task is immediately
// given to an available worker or queued otherwise. Tasks are processed in
// FiFO order.
Submit(task func())
}
// Workerpool adds the functionality to terminate the workers to the
// Workers interface.
type Workerpool interface {
Workers
// StopWait stops the worker pool and waits for all queued tasks to
// complete. No additional tasks may be submitted, but all pending tasks are
// executed by workers before this function returns.
StopWait()
}