Documentation
¶
Overview ¶
Package hare implements the Hare Protocol.
Index ¶
- Constants
- Variables
- type Broker
- func (b *Broker) Close()
- func (b *Broker) CloseChannel() chan struct{}
- func (b *Broker) HandleMessage(ctx context.Context, pid peer.ID, msg []byte) pubsub.ValidationResult
- func (b *Broker) Register(ctx context.Context, id types.LayerID) (chan *Msg, error)
- func (b *Broker) Start(ctx context.Context) error
- func (b *Broker) Synced(ctx context.Context, id types.LayerID) bool
- func (b *Broker) Unregister(ctx context.Context, id types.LayerID)
- type CertificationOutput
- type Consensus
- type Hare
- type LayerClock
- type Message
- type Msg
- type RefCountTracker
- type Rolacle
- type RoundClock
- type Set
- func (s *Set) Add(id types.ProposalID)
- func (s *Set) Clone() *Set
- func (s *Set) Complement(u *Set) *Set
- func (s *Set) Contains(id types.ProposalID) bool
- func (s *Set) Equals(g *Set) bool
- func (s *Set) ID() uint32
- func (s *Set) Intersection(g *Set) *Set
- func (s *Set) IsSubSetOf(g *Set) bool
- func (s *Set) Remove(id types.ProposalID)
- func (s *Set) Size() int
- func (s *Set) String() string
- func (s *Set) Subtract(g *Set)
- func (s *Set) ToSlice() []types.ProposalID
- func (s *Set) Union(g *Set) *Set
- type Signer
- type SimpleRoundClock
- type State
- type TerminationOutput
Constants ¶
const LayerBuffer = 20
LayerBuffer is the number of layer results we keep at a given time.
const (
// RoundsPerIteration is the number of rounds per iteration in the hare protocol.
RoundsPerIteration = 4
)
const Wakeup = math.MaxUint32 - 1 // -2
Wakeup has a value of -2 because it occurs exactly two round durations before the end of round 0. This accounts for the duration of round zero and the preround.
Variables ¶
var ErrTooLate = errors.New("consensus process finished too late")
ErrTooLate means that the consensus was terminated too late.
Functions ¶
This section is empty.
Types ¶
type Broker ¶
Broker is the dispatcher of incoming Hare messages. The broker validates that the sender is eligible and active and forwards the message to the corresponding outbox.
func (*Broker) CloseChannel ¶
func (b *Broker) CloseChannel() chan struct{}
CloseChannel returns the channel to wait on for close signal.
func (*Broker) HandleMessage ¶ added in v1.0.0
func (b *Broker) HandleMessage(ctx context.Context, pid peer.ID, msg []byte) pubsub.ValidationResult
HandleMessage separate listener routine that receives gossip messages and adds them to the priority queue.
func (*Broker) Register ¶
Register a layer to receive messages Note: the registering instance is assumed to be started and accepting messages.
type CertificationOutput ¶
CertificationOutput represents an certification output of a consensus process.
type Consensus ¶
type Consensus interface { ID() types.LayerID Close() CloseChannel() chan struct{} Start(ctx context.Context) error SetInbox(chan *Msg) }
Consensus represents an item that acts like a consensus process.
type Hare ¶
Hare is the orchestrator that starts new consensus processes and collects their output.
func New ¶
func New( conf config.Config, pid peer.ID, publisher pubsub.PublishSubsciber, sign Signer, nid types.NodeID, blockGen blockGenerator, syncState system.SyncStateProvider, mesh meshProvider, ppp proposalProvider, beacons system.BeaconGetter, fetch system.ProposalFetcher, rolacle Rolacle, patrol layerPatrol, layersPerEpoch uint16, idProvider identityProvider, stateQ stateQuerier, layerClock LayerClock, logger log.Log, ) *Hare
New returns a new Hare struct.
type LayerClock ¶ added in v1.0.0
type LayerClock interface { LayerToTime(id types.LayerID) time.Time AwaitLayer(layerID types.LayerID) chan struct{} GetCurrentLayer() types.LayerID }
LayerClock provides a timer for the start of a given layer, as well as the current layer and allows converting a layer number to a clock time.
type Message ¶
type Message struct { Sig []byte InnerMsg *innerMessage }
Message is the tuple of a message and its corresponding signature.
func MessageFromBuffer ¶
MessageFromBuffer builds an Hare message from the provided bytes buffer. It returns an error if unmarshal of the provided byte slice failed.
type Msg ¶
Msg is the wrapper of the protocol's message. Messages are sent as type Message. Upon receiving, the public key is added to this wrapper (public key extraction).
type RefCountTracker ¶
type RefCountTracker struct {
// contains filtered or unexported fields
}
RefCountTracker tracks the number of references of any object id.
func NewRefCountTracker ¶
func NewRefCountTracker() *RefCountTracker
NewRefCountTracker creates a new reference count tracker.
func (*RefCountTracker) CountStatus ¶
func (tracker *RefCountTracker) CountStatus(id interface{}) uint32
CountStatus returns the number of references to the given id.
func (*RefCountTracker) String ¶
func (tracker *RefCountTracker) String() string
func (*RefCountTracker) Track ¶
func (tracker *RefCountTracker) Track(id interface{}, count uint32)
Track increases the count for the given object id.
type Rolacle ¶
type Rolacle interface { Validate(context.Context, types.LayerID, uint32, int, types.NodeID, []byte, uint16) (bool, error) CalcEligibility(context.Context, types.LayerID, uint32, int, types.NodeID, []byte) (uint16, error) Proof(context.Context, types.LayerID, uint32) ([]byte, error) IsIdentityActiveOnConsensusView(context.Context, string, types.LayerID) (bool, error) }
Rolacle is the roles oracle provider.
type RoundClock ¶ added in v1.0.0
type RoundClock interface { AwaitWakeup() <-chan struct{} AwaitEndOfRound(round uint32) <-chan struct{} }
RoundClock is a timer interface.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set represents a unique set of values.
func NewDefaultEmptySet ¶
func NewDefaultEmptySet() *Set
NewDefaultEmptySet creates an empty set with the default size.
func NewEmptySet ¶
NewEmptySet creates an empty set with the provided size.
func NewSet ¶
func NewSet(data []types.ProposalID) *Set
NewSet creates a set from the provided array of values. Note: duplicated values are ignored.
func NewSetFromValues ¶
func NewSetFromValues(values ...types.ProposalID) *Set
NewSetFromValues creates a set of the provided values. Note: duplicated values are ignored.
func (*Set) Add ¶
func (s *Set) Add(id types.ProposalID)
Add a value to the set. It has no effect if the value already exists in the set.
func (*Set) Complement ¶
Complement returns a new set that represents the complement of s relatively to the world u.
func (*Set) Contains ¶
func (s *Set) Contains(id types.ProposalID) bool
Contains returns true if the provided value is contained in the set, false otherwise.
func (*Set) Intersection ¶
Intersection returns the intersection a new set which represents the intersection of s and g.
func (*Set) IsSubSetOf ¶
IsSubSetOf returns true if s is a subset of g, false otherwise.
func (*Set) Remove ¶
func (s *Set) Remove(id types.ProposalID)
Remove a value from the set. It has no effect if the value doesn't exist in the set.
func (*Set) ToSlice ¶
func (s *Set) ToSlice() []types.ProposalID
ToSlice returns the array representation of the set.
type SimpleRoundClock ¶ added in v1.0.0
type SimpleRoundClock struct { LayerTime time.Time WakeupDelta time.Duration RoundDuration time.Duration }
SimpleRoundClock is a simple Hare-round clock. Repeated calls to AwaitEndOfRound() will each return a new channel and will be backed by a new timer which will not be garbage collected until it expires. To avoid leaking resources, callers should avoid calling AwaitEndOfRound() more than once for a given round (e.g. by storing the resulting channel and reusing it).
func NewSimpleRoundClock ¶ added in v1.0.0
func NewSimpleRoundClock(layerTime time.Time, wakeupDelta, roundDuration time.Duration) *SimpleRoundClock
NewSimpleRoundClock returns a new SimpleRoundClock, given the provided configuration.
func (*SimpleRoundClock) AwaitEndOfRound ¶ added in v1.0.0
func (c *SimpleRoundClock) AwaitEndOfRound(round uint32) <-chan struct{}
AwaitEndOfRound returns a channel that gets closed when the given round ends. Repeated calls to this method will return new instances of the channel and use new underlying timers which will not be garbage collected until they expire. To avoid leaking resources, callers should avoid calling AwaitEndOfRound() more than once for a given round (e.g. by storing the resulting channel and reusing it).
func (*SimpleRoundClock) AwaitWakeup ¶ added in v1.0.0
func (c *SimpleRoundClock) AwaitWakeup() <-chan struct{}
AwaitWakeup returns a channel that gets closed when the Hare wakeup delay has passed.