github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/consensus/hotstuff/vote_collectors.go (about) 1 package hotstuff 2 3 import "github.com/onflow/flow-go/module" 4 5 // VoteCollectors is an interface which allows VoteAggregator to interact with collectors structured by 6 // view. 7 // Implementations of this interface are responsible for state transitions of `VoteCollector`s and pruning of 8 // stale and outdated collectors by view. 9 type VoteCollectors interface { 10 module.ReadyDoneAware 11 module.Startable 12 13 // GetOrCreateCollector retrieves the hotstuff.VoteCollector for the specified 14 // view or creates one if none exists. 15 // When creating a vote collector, the view will be used to get epoch by view, then create the random beacon 16 // signer object by epoch, because epoch determines DKG, which determines random beacon committee. 17 // It returns: 18 // - (collector, true, nil) if no collector can be found by the view, and a new collector was created. 19 // - (collector, false, nil) if the collector can be found by the view 20 // - (nil, false, error) if running into any exception creating the vote collector state machine 21 // Expected error returns during normal operations: 22 // * mempool.BelowPrunedThresholdError - in case view is lower than last pruned view 23 GetOrCreateCollector(view uint64) (collector VoteCollector, created bool, err error) 24 25 // PruneUpToView prunes the vote collectors with views _below_ the given value, i.e. 26 // we only retain and process whose view is equal or larger than `lowestRetainedView`. 27 // If `lowestRetainedView` is smaller than the previous value, the previous value is 28 // kept and the method call is a NoOp. 29 PruneUpToView(lowestRetainedView uint64) 30 } 31 32 // Workers queues and processes submitted tasks. We explicitly do not 33 // expose any functionality to terminate the worker pool. 34 type Workers interface { 35 // Submit enqueues a function for a worker to execute. Submit will not block 36 // regardless of the number of tasks submitted. Each task is immediately 37 // given to an available worker or queued otherwise. Tasks are processed in 38 // FiFO order. 39 Submit(task func()) 40 } 41 42 // Workerpool adds the functionality to terminate the workers to the 43 // Workers interface. 44 type Workerpool interface { 45 Workers 46 47 // StopWait stops the worker pool and waits for all queued tasks to 48 // complete. No additional tasks may be submitted, but all pending tasks are 49 // executed by workers before this function returns. 50 StopWait() 51 }