beacon

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2020 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const BoltFileName = "drand.db"

BoltFileName is the name of the file boltdb writes to

Variables

View Source
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

func Message(prevSig []byte, prevRound, currRound uint64) []byte

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

func NextRound(now int64, period time.Duration, genesis int64) (uint64, int64)

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 RandomnessFromSignature(sig []byte) []byte

func TimeOfRound added in v0.6.1

func TimeOfRound(period time.Duration, genesis int64, round uint64) int64

TimeOfRound is returning the time the current round should happen

func Verify added in v0.6.1

func Verify(pubkey kyber.Point, prevSig []byte, prevRound, currRound uint64) error

Verify is similar to verify beacon but doesn't require to get the full beacon structure.

func VerifyBeacon added in v0.6.1

func VerifyBeacon(pubkey kyber.Point, b *Beacon) error

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) Equal added in v0.6.1

func (b *Beacon) Equal(b2 *Beacon) bool

func (*Beacon) Marshal added in v0.6.1

func (b *Beacon) Marshal() ([]byte, error)

func (*Beacon) Randomness

func (b *Beacon) Randomness() []byte

Randomness returns the hashed signature. It is an example that uses sha256, but it could use blake2b for example.

func (*Beacon) String added in v0.6.1

func (b *Beacon) String() string

func (*Beacon) Unmarshal added in v0.6.1

func (b *Beacon) Unmarshal(buff []byte) error

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
	Share    *key.Share
	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

type Cursor interface {
	First() *Beacon
	Next() *Beacon
	Seek(round uint64) *Beacon
	Last() *Beacon
}

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

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 Store, conf *Config, l log.Logger) (*Handler, error)

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

func (*Handler) AddCallback added in v0.6.1

func (h *Handler) AddCallback(fn func(*Beacon))

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

func (h *Handler) ProcessBeacon(c context.Context, p *proto.BeaconPacket) (*proto.Empty, error)

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

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 added in v0.6.1

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 added in v0.6.1

func (h *Handler) Store() Store

Store returns the store associated with this beacon handler

func (*Handler) Sync added in v0.6.1

func (h *Handler) Sync(to []*key.Identity) (*Beacon, error)

Sync will try to sync to the given identities

func (*Handler) SyncChain added in v0.6.1

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

func (h *Handler) Transition(prevNodes []*key.Identity) 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. 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

func NewBoltStore(folder string, opts *bolt.Options) (Store, error)

NewBoltStore returns a Store implementation using the boltdb storage engine.

func NewCallbackStore

func NewCallbackStore(s Store, cb func(*Beacon)) Store

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.

Jump to

Keyboard shortcuts

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