github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/consensus/hotstuff/timeout_collector.go (about) 1 package hotstuff 2 3 import ( 4 "github.com/onflow/flow-go/consensus/hotstuff/model" 5 ) 6 7 // TimeoutCollector collects all timeout objects for a specified view. On the happy path, it 8 // generates a TimeoutCertificate when enough timeouts have been collected. The TimeoutCollector 9 // is a higher-level structure that orchestrates deduplication, caching and processing of 10 // timeouts, delegating those tasks to underlying modules (such as TimeoutProcessor). 11 // Implementations of TimeoutCollector must be concurrency safe. 12 type TimeoutCollector interface { 13 // AddTimeout adds a Timeout Object [TO] to the collector. 14 // When TOs from strictly more than 1/3 of consensus participants (measured by weight) 15 // were collected, the callback for partial TC will be triggered. 16 // After collecting TOs from a supermajority, a TC will be created and passed to the EventLoop. 17 // Expected error returns during normal operations: 18 // * timeoutcollector.ErrTimeoutForIncompatibleView - submitted timeout for incompatible view 19 // All other exceptions are symptoms of potential state corruption. 20 AddTimeout(timeoutObject *model.TimeoutObject) error 21 22 // View returns the view that this instance is collecting timeouts for. 23 // This method is useful when adding the newly created timeout collector to timeout collectors map. 24 View() uint64 25 } 26 27 // TimeoutProcessor ingests Timeout Objects [TO] for a particular view. It implements the algorithms 28 // for validating TOs, orchestrates their low-level aggregation and emits `OnPartialTcCreated` and 29 // `OnTcConstructedFromTimeouts` notifications. TimeoutProcessor cannot deduplicate TOs (this should 30 // be handled by the higher-level TimeoutCollector) and errors instead. 31 // Depending on their implementation, a TimeoutProcessor might drop timeouts or attempt to construct a TC. 32 type TimeoutProcessor interface { 33 // Process performs processing of single timeout object. This function is safe to call from multiple goroutines. 34 // Expected error returns during normal operations: 35 // * timeoutcollector.ErrTimeoutForIncompatibleView - submitted timeout for incompatible view 36 // * model.InvalidTimeoutError - submitted invalid timeout(invalid structure or invalid signature) 37 // * model.DuplicatedSignerError if a timeout from the same signer was previously already added 38 // It does _not necessarily_ imply that the timeout is invalid or the sender is equivocating. 39 // All other errors should be treated as exceptions. 40 Process(timeout *model.TimeoutObject) error 41 } 42 43 // TimeoutCollectorFactory performs creation of TimeoutCollector for a given view 44 type TimeoutCollectorFactory interface { 45 // Create is a factory method to generate a TimeoutCollector for a given view 46 // Expected error returns during normal operations: 47 // * model.ErrViewForUnknownEpoch no epoch containing the given view is known 48 // All other errors should be treated as exceptions. 49 Create(view uint64) (TimeoutCollector, error) 50 } 51 52 // TimeoutProcessorFactory performs creation of TimeoutProcessor for a given view 53 type TimeoutProcessorFactory interface { 54 // Create is a factory method to generate a TimeoutProcessor for a given view 55 // Expected error returns during normal operations: 56 // * model.ErrViewForUnknownEpoch no epoch containing the given view is known 57 // All other errors should be treated as exceptions. 58 Create(view uint64) (TimeoutProcessor, error) 59 }