Documentation ¶
Overview ¶
Package hare implements the Hare Protocol.
Index ¶
- Constants
- Variables
- func NewMessageBuilder() *messageBuilder
- func NewMsgsTracker() *msgsTracker
- type Broker
- type Closer
- type Consensus
- type ConsensusProcess
- type Hare
- type Message
- type Msg
- type NetworkService
- type RefCountTracker
- type Rolacle
- type Set
- func (s *Set) Add(id types.BlockID)
- func (s *Set) Clone() *Set
- func (s *Set) Complement(u *Set) *Set
- func (s *Set) Contains(id types.BlockID) bool
- func (s *Set) Equals(g *Set) bool
- func (s *Set) Id() objectId
- func (s *Set) Intersection(g *Set) *Set
- func (s *Set) IsSubSetOf(g *Set) bool
- func (s *Set) Remove(id types.BlockID)
- func (s *Set) Size() int
- func (s *Set) String() string
- func (s *Set) Subtract(g *Set)
- func (s *Set) ToSlice() []types.BlockID
- func (s *Set) Union(g *Set) *Set
- type Signer
- type State
- type StateQuerier
- type TerminationOutput
Constants ¶
const LayerBuffer = 20
LayerBuffer is the number of layer results we keep at a given time.
Variables ¶
var ErrTooLate = errors.New("consensus process %v finished too late")
ErrTooLate means that the consensus was terminated too late
var ( // ErrTooOld means the requested result has already been evacuated from the buffer because the layer is too old ErrTooOld = errors.New("layer has already been evacuated from buffer") )
Functions ¶
func NewMessageBuilder ¶
func NewMessageBuilder() *messageBuilder
NewMessageBuilder returns a new, empty message builder. One should not assume any values are pre-set.
func NewMsgsTracker ¶
func NewMsgsTracker() *msgsTracker
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) Register ¶
Register a layer to receive messages Note: the registering instance is assumed to be started and accepting messages
func (*Broker) Synced ¶ added in v0.1.2
Synced returns true if the given layer is synced, false otherwise
func (*Broker) Unregister ¶
func (b *Broker) Unregister(id instanceId)
Unregister a layer from receiving messages
type Closer ¶
type Closer struct {
// contains filtered or unexported fields
}
Closer adds the ability to close objects.
func (*Closer) Close ¶
func (closer *Closer) Close()
Close signals all listening instances to close. Note: should be called only once.
func (*Closer) CloseChannel ¶
func (closer *Closer) CloseChannel() chan struct{}
CloseChannel returns the channel to wait on for close signal.
type Consensus ¶
type Consensus interface { Id() instanceId Close() CloseChannel() chan struct{} Start() error SetInbox(chan *Msg) }
Consensus represents an item that acts like a consensus process.
type ConsensusProcess ¶
ConsensusProcess is an entity (a single participant) in the Hare protocol. Once started, the CP iterates through the rounds until consensus is reached or the instance is cancelled. The output is then written to the provided TerminationReport channel. If the consensus process is canceled one should not expect the output to be written to the output channel.
func NewConsensusProcess ¶
func NewConsensusProcess(cfg config.Config, instanceId instanceId, s *Set, oracle Rolacle, stateQuerier StateQuerier, layersPerEpoch uint16, signing Signer, nid types.NodeId, p2p NetworkService, terminationReport chan TerminationOutput, ev roleValidator, logger log.Log) *ConsensusProcess
NewConsensusProcess creates a new consensus process instance.
func (*ConsensusProcess) Id ¶
func (proc *ConsensusProcess) Id() instanceId
Id returns the instance id.
func (*ConsensusProcess) SetInbox ¶
func (proc *ConsensusProcess) SetInbox(inbox chan *Msg)
SetInbox sets the inbox channel for incoming messages.
func (*ConsensusProcess) Start ¶
func (proc *ConsensusProcess) Start() error
Start the consensus process. It starts the PreRound round and then iterates through the rounds until consensus is reached or the instance is cancelled. It is assumed that the inbox is set before the call to Start. It returns an error if Start has been called more than once, the set size is zero (no values) or the inbox is nil.
type Hare ¶
Hare is the orchestrator that starts new consensus processes and collects their output.
func New ¶
func New(conf config.Config, p2p NetworkService, sign Signer, nid types.NodeId, validate outputValidationFunc, syncState syncStateFunc, obp orphanBlockProvider, rolacle Rolacle, layersPerEpoch uint16, idProvider identityProvider, stateQ StateQuerier, beginLayer chan types.LayerID, logger log.Log) *Hare
New returns a new Hare struct.
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 NetworkService ¶
type NetworkService interface { RegisterGossipProtocol(protocol string, prio priorityq.Priority) chan service.GossipMessage Broadcast(protocol string, payload []byte) error }
NetworkService provides the registration and broadcast abilities in the network.
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) Track ¶
func (tracker *RefCountTracker) Track(id interface{})
Track increases the count for the given object id.
type Rolacle ¶
type Rolacle interface { Eligible(layer types.LayerID, round int32, committeeSize int, id types.NodeId, sig []byte) (bool, error) Proof(layer types.LayerID, round int32) ([]byte, error) IsIdentityActiveOnConsensusView(edId string, layer types.LayerID) (bool, error) }
Rolacle is the roles oracle provider.
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 ¶
NewSet creates a set from the provided array of values. Note: duplicated values are ignored.
func NewSetFromValues ¶
NewSetFromValues creates a set of the provided values. Note: duplicated values are ignored.
func (*Set) Complement ¶
Complement returns a new set that represents the complement of s relatively to the world u.
func (*Set) Contains ¶
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 ¶
Remove a value from the set. It has no effect if the value doesn't exist in the set.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State holds the current state of the consensus process (aka the participant).
type StateQuerier ¶
type StateQuerier interface {
IsIdentityActiveOnConsensusView(edId string, layer types.LayerID) (bool, error)
}
StateQuerier provides a query to check if an Ed public key is active on the current consensus view. It returns true if the identity is active and false otherwise. An error is set iff the identity could not be checked for activeness.
type TerminationOutput ¶
TerminationOutput represents an output of a consensus process.