Documentation ¶
Index ¶
- Constants
- Variables
- func Message(prevSig []byte, prevRound, currRound uint64) []byte
- func NextRound(now int64, period time.Duration, genesis int64) (uint64, int64)
- func RandomnessFromSignature(sig []byte) []byte
- func TimeOfRound(period time.Duration, genesis int64, round uint64) int64
- func Verify(pubkey kyber.Point, prevSig []byte, prevRound, currRound uint64) error
- func VerifyBeacon(pubkey kyber.Point, b *Beacon) error
- type Beacon
- type Config
- type Cursor
- type Handler
- func (h *Handler) AddCallback(fn func(*Beacon))
- func (h *Handler) Catchup()
- func (h *Handler) ProcessBeacon(c context.Context, p *proto.BeaconPacket) (*proto.Empty, error)
- func (h *Handler) Start() error
- func (h *Handler) Stop()
- func (h *Handler) StopAt(stopTime int64) error
- func (h *Handler) Store() Store
- func (h *Handler) Sync(to []*key.Identity) (*Beacon, error)
- func (h *Handler) SyncChain(req *proto.SyncRequest, p proto.Protocol_SyncChainServer) error
- func (h *Handler) Transition(prevNodes []*key.Identity) error
- type Store
Constants ¶
const BoltFileName = "drand.db"
BoltFileName is the name of the file boltdb writes to
Variables ¶
var ErrNoBeaconSaved = errors.New("beacon not found in database")
ErrNoBeaconSaved is the error returned when no beacon have been saved in the database yet.
Functions ¶
func Message ¶
Message returns a slice of bytes as the message to sign or to verify alongside a beacon signature. H ( prevRound || prevSig || currRound)
func NextRound ¶ added in v0.6.1
NextRound returns the next upcoming round and its UNIX time given the genesis time and the period. round at time genesis = round 1. Round 0 is fixed.
func RandomnessFromSignature ¶ added in v0.6.1
func TimeOfRound ¶ added in v0.6.1
TimeOfRound is returning the time the current round should happen
func Verify ¶ added in v0.6.1
Verify is similar to verify beacon but doesn't require to get the full beacon structure.
func VerifyBeacon ¶ added in v0.6.1
VerifyBeacon returns an error if the given beacon does not verify given the public key. The public key "point" can be obtained from the `key.DistPublic.Key()` method. The distributed public is the one written in the configuration file of the network.
Types ¶
type Beacon ¶
type Beacon struct { // PreviousRound is the round that is pointed to by this beacon. The beacon // chain can have gaps if the network has been down for a while. The rule // here is that one round corresponds to one exact time given a genesis // time. PreviousRound uint64 // PreviousSig is the previous signature generated PreviousSig []byte // Round is the round number this beacon is tied to Round uint64 // Signature is the BLS deterministic signature over Round || PreviousRand Signature []byte }
Beacon holds the randomness as well as the info to verify it.
func (*Beacon) Randomness ¶
Randomness returns the hashed signature. It is an example that uses sha256, but it could use blake2b for example.
type Config ¶ added in v0.5.2
type Config struct { // XXX Think of removing uncessary access to keypair - only given for index Private *key.Pair Group *key.Group Scheme sign.ThresholdScheme Clock clock.Clock WaitTime time.Duration }
Config holds the different cryptographc informations necessary to run the randomness beacon.
type Cursor ¶
Iterate over items in sorted key order. This starts from the first key/value pair and updates the k/v variables to the next key/value on each iteration.
The loop finishes at the end of the cursor when a nil key is returned.
for k, v := c.First(); k != nil; k, v = c.Next() { fmt.Printf("A %s is %s.\n", k, v) }
type Handler ¶
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 ¶
NewHandler returns a fresh handler ready to serve and create randomness beacon
func (*Handler) AddCallback ¶ added in v0.6.1
AddCallback adds function that is called each time a new beacon is created
func (*Handler) Catchup ¶ added in v0.6.1
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) ProcessBeacon ¶
ProcessBeacon receives a request for a beacon partial signature. It replies successfully with a valid partial signature over the given beacon packet information if the following is true: 1- the round for the request is not different than the current round by a certain threshold 2- the partial signature in the embedded response is valid. This proves that the requests comes from a qualified node from the DKG phase.
func (*Handler) Start ¶ added in v0.6.1
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 ¶ added in v0.6.1
StopAt will stop the handler at the given time. It is useful when transitionining for a resharing.
func (*Handler) SyncChain ¶ added in v0.6.1
func (h *Handler) SyncChain(req *proto.SyncRequest, p proto.Protocol_SyncChainServer) error
SyncChain is the server side call that reply with the beacon in order to the client requesting the syncing.
func (*Handler) Transition ¶ added in v0.6.1
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. TODO: it should be better to use the public streaming API but since it is likely to change, right now we use the sync API. Later on when API is well defined, best to use streaming.
type Store ¶
type Store interface { Len() int Put(*Beacon) error Last() (*Beacon, error) Get(round uint64) (*Beacon, error) Cursor(func(Cursor)) // XXX Misses a delete function Close() }
Store is an interface to store Beacons packets where they can also be retrieved to be delivered to end clients.
func NewBoltStore ¶
NewBoltStore returns a Store implementation using the boltdb storage engine.
func NewCallbackStore ¶
NewCallbackStore returns a Store that calls the given callback in a goroutine each time a new Beacon is saved into the given store. It does not call the callback if there has been any errors while saving the beacon.