beacon

package
v1.4.5-testnet Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2022 License: Apache-2.0, MIT Imports: 23 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 ErrFailedAll = errors.New("sync failed: tried all nodes")

ErrFailedAll means all nodes failed to provide the requested beacons

View Source
var ErrNoBeaconStored = errors.New("no beacon stored above requested round")

ErrNoBeaconStored is the error we get when a sync is called too early and there are no beacon above the requested round

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

func NewSchemeStore added in v1.4.6

func NewSchemeStore(s chain.Store, sch scheme.Scheme) chain.Store

func SyncChain added in v1.4.6

func SyncChain(l log.Logger, store CallbackStore, req SyncRequest, stream SyncStream) error

SyncChain holds the receiver logic to reply to a sync request

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 reconstructed, it saves it to the given Store.

func NewHandler

func NewHandler(c net.ProtocolClient, s chain.Store, conf *Config, l log.Logger, version commonutils.Version) (*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) CorrectChain added in v1.4.6

func (h *Handler) CorrectChain(ctx context.Context, faultyBeacons []uint64, peers []net.Peer, cb func(r, u uint64)) error

CorrectChain tells the sync manager to fetch the invalid beacon from its peers.

func (*Handler) GetConfg added in v1.4.6

func (h *Handler) GetConfg() *Config

GetConfg returns the conf used by the handler

func (*Handler) IsRunning added in v1.4.6

func (h *Handler) IsRunning() bool

func (*Handler) IsServing added in v1.4.6

func (h *Handler) IsServing() bool

func (*Handler) IsStarted added in v1.4.6

func (h *Handler) IsStarted() bool

func (*Handler) IsStopped added in v1.4.6

func (h *Handler) IsStopped() bool

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) Reset added in v1.4.6

func (h *Handler) Reset()

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 transitioning for a resharing.

func (*Handler) Store

func (h *Handler) Store() CallbackStore

Store returns the store associated with this beacon handler

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 contacts 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

func (*Handler) ValidateChain added in v1.4.6

func (h *Handler) ValidateChain(ctx context.Context, upTo uint64, cb func(r, u uint64)) ([]uint64, error)

ValidateChain asks the chain store to ask the sync manager to check the chain store up to the given beacon, in order to find invalid beacons and it returns the list of round numbers for which the beacons were corrupted / invalid / not found in the store. Note: it does not attempt to correct or fetch these faulty beacons.

type SyncConfig added in v1.4.6

type SyncConfig struct {
	Log         log.Logger
	Client      net.ProtocolClient
	Clock       cl.Clock
	Store       chain.Store
	BoltdbStore chain.Store
	Info        *chain.Info
	NodeAddr    string
}

type SyncManager added in v1.4.6

type SyncManager struct {
	// contains filtered or unexported fields
}

SyncManager manages all the sync requests to other peers. It performs a cancellation of sync requests if not progressing, performs rate limiting of sync requests.

func NewSyncManager added in v1.4.6

func NewSyncManager(c *SyncConfig) *SyncManager

NewSyncManager returns a sync manager that will use the given store to store newly synced beacon.

func (*SyncManager) CheckPastBeacons added in v1.4.6

func (s *SyncManager) CheckPastBeacons(ctx context.Context, upTo uint64, cb func(r, u uint64)) ([]uint64, error)

func (*SyncManager) CorrectPastBeacons added in v1.4.6

func (s *SyncManager) CorrectPastBeacons(ctx context.Context, faultyBeacons []uint64, peers []net.Peer, cb func(r, u uint64)) error

func (*SyncManager) ReSync added in v1.4.6

func (s *SyncManager) ReSync(ctx context.Context, from, to uint64, nodes []net.Peer) error

ReSync handles resyncs that where necessarily launched by a CLI.

func (*SyncManager) RequestSync added in v1.4.6

func (s *SyncManager) RequestSync(upTo uint64, nodes []net.Peer)

RequestSync asks the sync manager to sync up with those peers up to the given round. Depending on the current state of the syncing process, there might not be a new process starting (for example if we already have the round requested). upTo == 0 means the syncing process goes on forever.

func (*SyncManager) Run added in v1.4.6

func (s *SyncManager) Run()

Run handles non-blocking sync requests coming from the regular operation of the daemon

func (*SyncManager) Stop added in v1.4.6

func (s *SyncManager) Stop()

func (*SyncManager) Sync added in v1.4.6

func (s *SyncManager) Sync(ctx context.Context, request requestInfo) error

Sync will launch the requested sync with the requested peers and returns once done, even if it failed

type SyncRequest added in v1.4.6

type SyncRequest interface {
	GetFromRound() uint64
	GetMetadata() *common.Metadata
}

SyncRequest is an interface representing any kind of request to sync. Those exist in both the protocol API and the public API.

type SyncStream added in v1.4.6

type SyncStream interface {
	Context() context.Context
	Send(*proto.BeaconPacket) error
}

SyncStream is an interface representing any kind of stream to send beacons to. Those exist in both the protocol API and the public API.

Jump to

Keyboard shortcuts

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