v1.5.7 Latest Latest

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

Go to latest
Published: Jul 28, 2023 License: Apache-2.0, MIT Imports: 17 Imported by: 16




View Source
const TimeOfRoundErrorValue = math.MaxInt64 - maxTimeBuffer

TimeOfRoundErrorValue is the value returned by `TimeOfRound` when an invalid round is specified.


This section is empty.


func BytesToRound added in v1.5.3

func BytesToRound(r []byte) uint64

BytesToRound unserializes a round number from bytes (8 bytes fixed length big-endian) to uint64.

func CurrentRound

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

CurrentRound calculates the active round at `now`

func MetricsStorageType added in v1.5.3

func MetricsStorageType(st StorageType) int

func NextRound

func NextRound(now int64, period time.Duration, genesis int64) (nextRound uint64, nextTime 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 PreviousRequiredFromContext added in v1.5.3

func PreviousRequiredFromContext(ctx context.Context) bool

func RoundToBytes

func RoundToBytes(r uint64) []byte

RoundToBytes serializes a round number to bytes (8 bytes fixed length big-endian).

func SetPreviousRequiredOnContext added in v1.5.3

func SetPreviousRequiredOnContext(ctx context.Context) context.Context

func TimeOfRound

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

TimeOfRound is returning the time the current round should happen


type Beacon

type Beacon struct {
	// 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 GenesisBeacon added in v1.0.2

func GenesisBeacon(seed []byte) *Beacon

GenesisBeacon returns the first beacon inserted in the chain

func (*Beacon) Equal

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

Equal indicates if two beacons are equal

func (*Beacon) GetPreviousSignature added in v1.5.3

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

GetPreviousSignature returns the previous signature if it's non-nil or nil otherwise

func (*Beacon) GetRound

func (b *Beacon) GetRound() uint64

GetRound provides the round of the beacon

func (*Beacon) GetSignature added in v1.5.3

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

GetSignature returns the signature if it's non-nil or nil otherwise

func (*Beacon) Marshal

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

Marshal provides a JSON encoding of a beacon

func (*Beacon) Randomness

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

Randomness returns the hashed signature. The choice of the hash determines the size of the output.

func (*Beacon) String

func (b *Beacon) String() string

func (*Beacon) Unmarshal

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

Unmarshal decodes a beacon from JSON

type Cursor

type Cursor interface {
	First(context.Context) (*Beacon, error)
	Next(context.Context) (*Beacon, error)
	Seek(ctx context.Context, round uint64) (*Beacon, error)
	Last(context.Context) (*Beacon, error)

Cursor iterates 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 Info

type Info struct {
	PublicKey   kyber.Point   `json:"public_key"`
	ID          string        `json:"id"`
	Period      time.Duration `json:"period"`
	Scheme      string        `json:"scheme"`
	GenesisTime int64         `json:"genesis_time"`
	GenesisSeed []byte        `json:"group_hash"`

Info represents the public information that is necessary for a client to verify any beacon present in a randomness chain.

func InfoFromJSON

func InfoFromJSON(buff io.Reader) (*Info, error)

InfoFromJSON returns a Info from JSON description in the given reader

func InfoFromProto

func InfoFromProto(p *drand.ChainInfoPacket) (*Info, error)

InfoFromProto returns a Info from the protocol description

func NewChainInfo

func NewChainInfo(g *key.Group) *Info

NewChainInfo makes a chain Info from a group

func (*Info) Equal

func (c *Info) Equal(c2 *Info) bool

Equal indicates if two Chain Info objects are equivalent

func (*Info) GetSchemeName added in v1.5.3

func (c *Info) GetSchemeName() string

GetSchemeName returns the scheme name used

func (*Info) Hash

func (c *Info) Hash() []byte

Hash returns the canonical hash representing the chain information. A hash is consistent throughout the entirety of a chain, regardless of the network composition, the actual nodes, generating the randomness.

func (*Info) HashString added in v1.4.6

func (c *Info) HashString() string

HashString returns the value of Hash in string format

func (*Info) ToJSON

func (c *Info) ToJSON(w io.Writer, metadata *common.Metadata) error

ToJSON provides a json serialization of an info packet

func (*Info) ToProto

func (c *Info) ToProto(metadata *common.Metadata) *drand.ChainInfoPacket

ToProto returns the protobuf description of the chain info

type StorageType added in v1.5.3

type StorageType string

StorageType defines the supported storage engines

const (
	// BoltDB uses the BoltDB engine for storing data
	BoltDB StorageType = "bolt"

	// PostgreSQL uses the PostgreSQL database for storing data
	PostgreSQL StorageType = "postgres"

	// MemDB uses the in-memory database to store data
	MemDB StorageType = "memdb"

Storage engine types

type Store

type Store interface {
	Len(context.Context) (int, error)
	Put(context.Context, *Beacon) error
	Last(context.Context) (*Beacon, error)
	Get(ctx context.Context, round uint64) (*Beacon, error)
	Cursor(context.Context, func(context.Context, Cursor) error) error
	Close(context.Context) error
	Del(ctx context.Context, round uint64) error
	SaveTo(ctx context.Context, w io.Writer) error

Store is an interface to store Beacons packets where they can also be retrieved to be delivered to end clients.


Path Synopsis
Package database provides support for access the database.
Package database provides support for access the database.
Package schema helps to keep the database up to date with schema.
Package schema helps to keep the database up to date with schema.

Jump to

Keyboard shortcuts

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