beacon

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2020 License: Apache-2.0, MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const CallbackWorkerQueue = 100

CallbackWorkerQueue is the length of the channel that the callback worker uses to dispatch beacons to its workers.

View Source
const MaxCatchupBuffer = 1000

MaxCatchupBuffer is the maximum size of the channel that receives beacon from a sync mechanism.

View Source
const MaxPartialsPerNode = 100

MaxPartialsPerNode is the maximum number of partials the cache stores about any node at any given time. This constant could be much lower, 3 for example but when the network is catching up, it may happen that some nodes goes much faster than other. In that case, multiple partials can be received from a fast nodes and these are valid.

Variables

View Source
var MaxSyncWaitTime = 2 * time.Second

MaxSyncWaitTime sets how long we'll wait after a new connection to receive new beacons from one peer

Functions

This section is empty.

Types

type CallbackStore added in v1.0.2

type CallbackStore interface {
	chain.Store
	AddCallback(id string, fn func(*chain.Beacon))
	RemoveCallback(id string)
}

CallbackStore is an interface that allows to register callbacks that gets called each time a new beacon is inserted

func NewCallbackStore added in v1.0.2

func NewCallbackStore(s chain.Store) CallbackStore

NewCallbackStore returns a Store that uses a pool of worker to dispatch the beacon to the registered callbacks. The callbacks are not called if the "Put" operations failed.

type Config

type Config struct {
	// Public key of this node
	Public *key.Node
	// Share of this node in the network
	Share *key.Share
	// Group listing all nodes and public key of the network
	Group *key.Group
	// Clock to use - useful to testing
	Clock clock.Clock
}

Config holds the different cryptographc informations necessary to run the randomness beacon.

type CryptoSafe added in v1.0.2

type CryptoSafe interface {
	// SignPartial returns the partial signature
	SignPartial(msg []byte) ([]byte, error)
}

CryptoSafe holds the cryptographic information to generate a partial beacon

type Handler

type Handler struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Handler holds the logic to initiate, and react to the TBLS protocol. Each time a full signature can be recosntructed, it saves it to the given Store.

func NewHandler

func NewHandler(c net.ProtocolClient, s chain.Store, conf *Config, l log.Logger) (*Handler, error)

NewHandler returns a fresh handler ready to serve and create randomness beacon

func (*Handler) AddCallback

func (h *Handler) AddCallback(id string, fn func(*chain.Beacon))

AddCallback is a proxy method to register a callback on the backend store

func (*Handler) Catchup

func (h *Handler) Catchup()

Catchup waits the next round's time to participate. This method is called when a node stops its daemon (maintenance or else) and get backs in the already running network . If the node does not have the previous randomness, it sync its local chain with other nodes to be able to participate in the next upcoming round.

func (*Handler) ProcessPartialBeacon

func (h *Handler) ProcessPartialBeacon(c context.Context, p *proto.PartialBeaconPacket) (*proto.Empty, error)

ProcessPartialBeacon receives a request for a beacon partial signature. It forwards it to the round manager if it is a valid beacon.

func (*Handler) RemoveCallback added in v1.0.2

func (h *Handler) RemoveCallback(id string)

RemoveCallback is a proxy method to remove a callback on the backend store

func (*Handler) Start

func (h *Handler) Start() error

Start runs the beacon protocol (threshold BLS signature). The first round will sign the message returned by the config.FirstRound() function. If the genesis time specified in the group is already passed, Start returns an error. In that case, if the group is already running, you should call SyncAndRun(). Round 0 = genesis seed - fixed Round 1 starts at genesis time, and is signing over the genesis seed

func (*Handler) Stop

func (h *Handler) Stop()

Stop the beacon loop from aggregating further randomness, but it finishes the one it is aggregating currently.

func (*Handler) StopAt

func (h *Handler) StopAt(stopTime int64) error

StopAt will stop the handler at the given time. It is useful when transitionining for a resharing.

func (*Handler) Store

func (h *Handler) Store() chain.Store

Store returns the store associated with this beacon handler

func (*Handler) SyncChain

func (h *Handler) SyncChain(req *proto.SyncRequest, stream proto.Protocol_SyncChainServer) error

SyncChain is a proxy method to sync a chain

func (*Handler) Transition

func (h *Handler) Transition(prevGroup *key.Group) error

Transition makes this beacon continuously sync until the time written in the "TransitionTime" in the handler's group file, where he will start generating randomness. To sync, he contact the nodes listed in the previous group file given.

func (*Handler) TransitionNewGroup

func (h *Handler) TransitionNewGroup(newShare *key.Share, newGroup *key.Group)

TransitionNewGroup prepares the node to transition to the new group

type Syncer added in v1.0.2

type Syncer interface {
	// Follow is a blocking call that continuously fetches the beacon from the
	// given nodes, verify the validity (chain etc) and then  stores it, until
	// the context is canceled or the round reaches upTo.  To follow
	// indefinitely, simply pass upTo = 0.
	Follow(c context.Context, upTo uint64, to []net.Peer) error
	// Syncing returns true if the syncer is currently being syncing
	Syncing() bool
	// SyncChain imeplements the server side of the syncing process
	SyncChain(req *proto.SyncRequest, p proto.Protocol_SyncChainServer) error
}

Syncer allows to follow a chain from other nodes and replies to syncing requests.

func NewSyncer added in v1.0.2

func NewSyncer(l log.Logger, s CallbackStore, info *chain.Info, client net.ProtocolClient) Syncer

NewSyncer returns a syncer implementation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL