Documentation ¶
Index ¶
- Constants
- Variables
- func NewSchemeStore(s chain.Store, sch scheme.Scheme) chain.Store
- func SyncChain(l log.Logger, store CallbackStore, req SyncRequest, stream SyncStream) error
- type CallbackStore
- type Config
- type CryptoSafe
- type Handler
- func (h *Handler) AddCallback(id string, fn func(*chain.Beacon))
- func (h *Handler) Catchup()
- func (h *Handler) CorrectChain(ctx context.Context, faultyBeacons []uint64, peers []net.Peer, ...) error
- func (h *Handler) GetConfg() *Config
- func (h *Handler) IsRunning() bool
- func (h *Handler) IsServing() bool
- func (h *Handler) IsStarted() bool
- func (h *Handler) IsStopped() bool
- func (h *Handler) ProcessPartialBeacon(c context.Context, p *proto.PartialBeaconPacket) (*proto.Empty, error)
- func (h *Handler) RemoveCallback(id string)
- func (h *Handler) Reset()
- func (h *Handler) Start() error
- func (h *Handler) Stop()
- func (h *Handler) StopAt(stopTime int64) error
- func (h *Handler) Store() CallbackStore
- func (h *Handler) Transition(prevGroup *key.Group) error
- func (h *Handler) TransitionNewGroup(newShare *key.Share, newGroup *key.Group)
- func (h *Handler) ValidateChain(ctx context.Context, upTo uint64, cb func(r, u uint64)) ([]uint64, error)
- type SyncConfig
- type SyncManager
- func (s *SyncManager) CheckPastBeacons(ctx context.Context, upTo uint64, cb func(r, u uint64)) ([]uint64, error)
- func (s *SyncManager) CorrectPastBeacons(ctx context.Context, faultyBeacons []uint64, peers []net.Peer, ...) error
- func (s *SyncManager) ReSync(ctx context.Context, from, to uint64, nodes []net.Peer) error
- func (s *SyncManager) RequestSync(upTo uint64, nodes []net.Peer)
- func (s *SyncManager) Run()
- func (s *SyncManager) Stop()
- func (s *SyncManager) Sync(ctx context.Context, request requestInfo) error
- type SyncRequest
- type SyncStream
Constants ¶
const CallbackWorkerQueue = 100
CallbackWorkerQueue is the length of the channel that the callback worker uses to dispatch beacons to its workers.
const MaxCatchupBuffer = 1000
MaxCatchupBuffer is the maximum size of the channel that receives beacon from a sync mechanism.
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 ¶
var ErrFailedAll = errors.New("sync failed: tried all nodes")
ErrFailedAll means all nodes failed to provide the requested beacons
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
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 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 *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 ¶
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 ¶
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) 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
RemoveCallback is a proxy method to remove a callback on the backend store
func (*Handler) Start ¶
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 ¶
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 ¶
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 ¶
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 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 (*SyncManager) CorrectPastBeacons ¶ added in v1.4.6
func (*SyncManager) ReSync ¶ added in v1.4.6
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()
type SyncRequest ¶ added in v1.4.6
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.