core

package
v2.0.5-testnet Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: Apache-2.0, MIT Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultConfigFolderName = ".drand"

DefaultConfigFolderName is the name of the folder containing all key materials (and the beacons db file by default). It is relative to the user's home directory.

View Source
const DefaultControlPort = "8888"

DefaultControlPort is the default port the daemon and CLI use to communicate together.

View Source
const DefaultDBFolder = "db"

DefaultDBFolder is the name of the folder in which the db file is saved. It is relative to the DefaultConfigFolder path.

View Source
const DefaultDKGKickoffGracePeriod = 5 * time.Second

DefaultDKGKickoffGracePeriod is the amount of time that each node waits after receiving the execution notification from the leader.

View Source
const DefaultDKGPhaseTimeout = 10 * time.Second

DefaultDKGPhaseTimeout is the default time of each DKG period by default. Note that by default, DKG uses the "fast sync" mode that shorten the first phase and the second phase, "as fast as possible" when the protocol runs smoothly (there is no malicious party).

View Source
const DefaultDKGTimeout = 24 * time.Hour

DefaultDKGTimeout is the max amount of time from start of a DKG until it gets aborted automatically

View Source
const InProgressDesc = "In progress"
View Source
const NotStartedDesc = "Not started"
View Source
const UnknownDesc = "Unknown"

Variables

View Source
var ErrDKGNotStarted = errors.New("DKG not started")
View Source
var ErrNoGroupSetup = errors.New("drand: no dkg group setup yet")

Functions

func DefaultConfigFolder

func DefaultConfigFolder() string

DefaultConfigFolder returns the default path of the configuration folder.

func GetBeaconDescription

func GetBeaconDescription(value BeaconStatus) string

func GetDkgStatusDescription

func GetDkgStatusDescription(value DkgStatus) string

func Proxy

Proxy wraps a server interface into a client interface so it can be queried

func StatusResponseToString

func StatusResponseToString(status *drand.StatusResponse) string

Types

type BeaconProcess

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

BeaconProcess is the main logic of the program. It reads the keys / group file, it can start the DKG, read/write shares to files and can initiate/respond to tBLS signature requests.

func NewBeaconProcess

func NewBeaconProcess(ctx context.Context,
	log dlog.Logger,
	store key.Store,
	completedDKGs *util.FanOutChan[dkg.SharingOutput],
	beaconID string,
	opts *Config,
	privGateway *net.PrivateGateway) (*BeaconProcess, error)

func (*BeaconProcess) BackupDatabase

func (bp *BeaconProcess) BackupDatabase(ctx context.Context, req *drand.BackupDBRequest) (*drand.BackupDBResponse, error)

BackupDatabase triggers a backup of the primary database.

func (*BeaconProcess) ChainInfo

ChainInfo replies with the chain information this node participates to

func (*BeaconProcess) GetIdentity

GetIdentity returns the identity of this drand node

func (*BeaconProcess) GroupFile

GroupFile replies with the distributed key in the response

func (*BeaconProcess) Home

Home provides the address the local node is listening

func (*BeaconProcess) ListBeaconIDs

func (*BeaconProcess) ListSchemes

func (*BeaconProcess) Load

func (bp *BeaconProcess) Load(ctx context.Context) error

Load restores a drand instance that is ready to serve randomness, with a pre-existing distributed share.

func (*BeaconProcess) PartialBeacon

func (bp *BeaconProcess) PartialBeacon(ctx context.Context, in *drand.PartialBeaconPacket) (*drand.Empty, error)

PartialBeacon receives a beacon generation request and answers with the partial signature from this drand node.

func (*BeaconProcess) PingPong

func (bp *BeaconProcess) PingPong(ctx context.Context, _ *drand.Ping) (*drand.Pong, error)

PingPong simply responds with an empty packet, proving that this drand node is up and alive.

func (*BeaconProcess) PublicKey

PublicKey is a functionality of Control Service defined in protobuf/control that requests the long term public key of the drand node running locally

func (*BeaconProcess) PublicRand

PublicRand returns a public random beacon according to the request. If the Round field is 0, then it returns the last one generated.

func (*BeaconProcess) PublicRandStream

PublicRandStream exports a stream of new beacons as they are generated over gRPC

func (*BeaconProcess) RemoteStatus

func (*BeaconProcess) StartBeacon

func (bp *BeaconProcess) StartBeacon(ctx context.Context, catchup bool) error

StartBeacon initializes the beacon if needed and launch a go routine that runs the generation loop.

func (*BeaconProcess) StartCheckChain

StartCheckChain checks a chain for validity and pulls invalid beacons from other nodes

func (*BeaconProcess) StartFollowChain

StartFollowChain syncs up with a chain from other nodes

func (*BeaconProcess) StartListeningForDKGUpdates

func (bp *BeaconProcess) StartListeningForDKGUpdates(ctx context.Context)

func (*BeaconProcess) Status

Status responds with the actual status of drand process

func (*BeaconProcess) Stop

func (bp *BeaconProcess) Stop(ctx context.Context)

Stop simply stops all drand operations.

func (*BeaconProcess) StopBeacon

func (bp *BeaconProcess) StopBeacon(ctx context.Context)

StopBeacon stops the beacon generation process and resets it.

func (*BeaconProcess) SyncChain

func (bp *BeaconProcess) SyncChain(req *drand.SyncRequest, stream drand.Protocol_SyncChainServer) error

SyncChain is an inter-node protocol that replies to a syncing request from a given round

func (*BeaconProcess) WaitExit

func (bp *BeaconProcess) WaitExit() chan bool

WaitExit returns a channel that signals when drand stops its operations

type BeaconStatus

type BeaconStatus uint32
const (
	BeaconNotInited BeaconStatus = iota
	BeaconInited
)

type Client

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

Client is the endpoint logic, communicating with drand servers TODO: This API should go away. Do not extend any further.

func NewGrpcClient

func NewGrpcClient(lg log.Logger, chainHash []byte, opts ...grpc.DialOption) *Client

NewGrpcClient returns a Client able to talk to drand instances using gRPC communication method.

func (*Client) ChainInfo

func (c *Client) ChainInfo(ctx context.Context, p net.Peer) (*chain.Info, error)

ChainInfo returns the chain info as reported by the given peer.

type Config

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

Config holds all relevant information for a drand node to run.

func NewConfig

func NewConfig(l log.Logger, opts ...ConfigOption) *Config

NewConfig returns the config to pass to drand with the default options set and the updated values given by the options.

func (*Config) BoltOptions

func (d *Config) BoltOptions() *bolt.Options

BoltOptions returns the options given to the bolt db

func (*Config) ConfigFolder

func (d *Config) ConfigFolder() string

ConfigFolder returns the folder under which drand stores all its configuration.

func (*Config) ConfigFolderMB

func (d *Config) ConfigFolderMB() string

ConfigFolderMB returns the folder under which multi-beacon drand stores all its configuration.

func (*Config) ControlPort

func (d *Config) ControlPort() string

ControlPort returns the port used for control port communications which can be the default one or the port setup thanks to WithControlPort

func (*Config) DBFolder

func (d *Config) DBFolder(beaconID string) string

DBFolder returns the folder under which drand stores db file specifically. If beacon id is empty, it will use the default value

func (*Config) Logger

func (d *Config) Logger() log.Logger

Logger returns the logger associated with this config.

func (*Config) PgDSN

func (d *Config) PgDSN() string

PgDSN returns the PostgreSQL specific DSN configuration.

func (*Config) PrivateListenAddress

func (d *Config) PrivateListenAddress(defaultAddr string) string

PrivateListenAddress returns the given default address or the listen address stored in the config thanks to WithPrivateListenAddress

func (*Config) PublicListenAddress

func (d *Config) PublicListenAddress(defaultAddr string) string

PublicListenAddress returns the given default address or the listen address stored in the config thanks to WithPublicListenAddress

func (*Config) TracesEndpoint

func (d *Config) TracesEndpoint() string

TracesEndpoint retrieves the configured tracing data endpoint

func (*Config) TracesProbability

func (d *Config) TracesProbability() float64

TracesProbability retrieves the probability of for traces to be collected and sent to the server

func (*Config) Version

func (d *Config) Version() string

Version returns the configured version of the binary

type ConfigOption

type ConfigOption func(*Config)

ConfigOption is a function that applies a specific setting to a Config.

func WithBoltOptions

func WithBoltOptions(opts *bolt.Options) ConfigOption

WithBoltOptions applies boltdb specific options when storing random beacons.

func WithCallOption

func WithCallOption(opts ...grpc.CallOption) ConfigOption

WithCallOption applies grpc options when drand calls a gRPC method.

func WithConfigFolder

func WithConfigFolder(folder string) ConfigOption

WithConfigFolder sets the base configuration folder to the given string.

func WithControlPort

func WithControlPort(port string) ConfigOption

WithControlPort specifies which port on localhost the ListenerControl should bind to.

func WithDBStorageEngine

func WithDBStorageEngine(engine chain.StorageType) ConfigOption

WithDBStorageEngine allows setting the specific storage type

func WithDkgKickoffGracePeriod

func WithDkgKickoffGracePeriod(t time.Duration) ConfigOption

func WithDkgPhaseTimeout

func WithDkgPhaseTimeout(t time.Duration) ConfigOption

func WithDkgTimeout

func WithDkgTimeout(t time.Duration) ConfigOption

WithDkgTimeout sets the timeout under which the DKG must finish.

func WithMemDBSize

func WithMemDBSize(bufferSize int) ConfigOption

func WithNamedLogger

func WithNamedLogger(name string) ConfigOption

func WithPgDSN

func WithPgDSN(dsn string) ConfigOption

WithPgDSN applies PosgresSQL specific options to the PG store. It will also create a new database connection.

func WithPrivateListenAddress

func WithPrivateListenAddress(addr string) ConfigOption

WithPrivateListenAddress specifies the address the drand instance should bind to. It is useful if you want to advertise a public proxy address and the drand instance runs behind your network.

func WithPublicListenAddress

func WithPublicListenAddress(addr string) ConfigOption

WithPublicListenAddress specifies the address the drand instance should bind to. It is useful if you want to advertise a public proxy address and the drand instance runs behind your network.

func WithTracesEndpoint

func WithTracesEndpoint(tracesEndpoint string) ConfigOption

WithTracesEndpoint sets the receiver for the tracing data

func WithTracesProbability

func WithTracesProbability(tracesProbability float64) ConfigOption

WithTracesProbability sets the probability of for traces to be collected and sent to the server

func WithVersion

func WithVersion(version string) ConfigOption

WithVersion sets a version for drand, a visible string to other peers.

type DKGProcess

type DKGProcess interface {
	DKGStatus(context context.Context, request *pdkg.DKGStatusRequest) (*pdkg.DKGStatusResponse, error)
	Command(context context.Context, command *pdkg.DKGCommand) (*pdkg.EmptyDKGResponse, error)
	Packet(context context.Context, packet *pdkg.GossipPacket) (*pdkg.EmptyDKGResponse, error)
	Migrate(beaconID string, group *key.Group, share *key.Share) error
	BroadcastDKG(context context.Context, packet *pdkg.DKGPacket) (*pdkg.EmptyDKGResponse, error)
	Close()
}

type DkgStatus

type DkgStatus uint32
const (
	DkgReady DkgStatus = iota
	DkgInProgress
	DkgNotStarted
)

type DrandDaemon

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

func NewDrandDaemon

func NewDrandDaemon(ctx context.Context, c *Config) (*DrandDaemon, error)

NewDrandDaemon creates a new instance of DrandDaemon

func (*DrandDaemon) AddBeaconHandler

func (dd *DrandDaemon) AddBeaconHandler(ctx context.Context, beaconID string, bp *BeaconProcess)

AddBeaconHandler adds a handler linked to beacon with chain hash from http server used to expose public services

func (*DrandDaemon) BackupDatabase

func (dd *DrandDaemon) BackupDatabase(ctx context.Context, in *drand.BackupDBRequest) (*drand.BackupDBResponse, error)

BackupDatabase triggers a backup of the primary database.

func (*DrandDaemon) BroadcastDKG

func (dd *DrandDaemon) BroadcastDKG(ctx context.Context, packet *drand.DKGPacket) (*drand.EmptyDKGResponse, error)

func (*DrandDaemon) ChainInfo

ChainInfo replies with the chain information this node participates to

func (*DrandDaemon) Command

func (dd *DrandDaemon) Command(ctx context.Context, command *drand.DKGCommand) (*drand.EmptyDKGResponse, error)

func (*DrandDaemon) DKGStatus

func (dd *DrandDaemon) DKGStatus(ctx context.Context, request *drand.DKGStatusRequest) (*drand.DKGStatusResponse, error)

func (*DrandDaemon) GetIdentity

GetIdentity returns the identity of this drand node

func (*DrandDaemon) GroupFile

func (dd *DrandDaemon) GroupFile(ctx context.Context, in *drand.GroupRequest) (*drand.GroupPacket, error)

GroupFile replies with the distributed key in the response

func (*DrandDaemon) Home

Home provides the address the local node is listening

func (*DrandDaemon) InstantiateBeaconProcess

func (dd *DrandDaemon) InstantiateBeaconProcess(ctx context.Context, beaconID string, store key.Store) (*BeaconProcess, error)

InstantiateBeaconProcess creates a new BeaconProcess linked to beacon with id 'beaconID'

func (*DrandDaemon) KeypairFor

func (dd *DrandDaemon) KeypairFor(beaconID string) (*key.Pair, error)

func (*DrandDaemon) ListBeaconIDs

func (*DrandDaemon) ListSchemes

func (*DrandDaemon) LoadBeacon

LoadBeacon tells the DrandDaemon to load a new beacon into the memory

func (*DrandDaemon) LoadBeaconFromDisk

func (dd *DrandDaemon) LoadBeaconFromDisk(ctx context.Context, beaconID string) (*BeaconProcess, error)

func (*DrandDaemon) LoadBeaconFromStore

func (dd *DrandDaemon) LoadBeaconFromStore(ctx context.Context, beaconID string, store key.Store) (*BeaconProcess, error)

func (*DrandDaemon) LoadBeaconsFromDisk

func (dd *DrandDaemon) LoadBeaconsFromDisk(ctx context.Context, metricsFlag string, singleBeacon bool, singleBeaconName string) error

LoadBeaconsFromDisk checks for existing stores and creates the corresponding BeaconProcess accordingly to each stored BeaconID. When singleBeacon is set, and the singleBeaconName matches one of the stored beacons, then only that beacon will be loaded. If the singleBeaconName is an empty string, no beacon will be loaded.

func (*DrandDaemon) Metrics

func (*DrandDaemon) NodeVersionStreamValidator

func (dd *DrandDaemon) NodeVersionStreamValidator(srv interface{}, ss grpc.ServerStream,
	_ *grpc.StreamServerInfo, handler grpc.StreamHandler) error

func (*DrandDaemon) NodeVersionValidator

func (dd *DrandDaemon) NodeVersionValidator(ctx context.Context, req interface{},
	_ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (response interface{}, err error)

func (*DrandDaemon) Packet

func (*DrandDaemon) PartialBeacon

func (dd *DrandDaemon) PartialBeacon(ctx context.Context, in *drand.PartialBeaconPacket) (*drand.Empty, error)

PartialBeacon receives a beacon generation request and answers with the partial signature from this drand node.

func (*DrandDaemon) PingPong

func (dd *DrandDaemon) PingPong(ctx context.Context, _ *drand.Ping) (*drand.Pong, error)

PingPong simply responds with an empty packet, proving that this drand node is up and alive.

func (*DrandDaemon) PublicKey

PublicKey is a functionality of Control Service defined in protobuf/control that requests the long term public key of the drand node running locally

func (*DrandDaemon) PublicRand

PublicRand returns a public random beacon according to the request. If the Round field is 0, then it returns the last one generated.

func (*DrandDaemon) PublicRandStream

func (dd *DrandDaemon) PublicRandStream(in *drand.PublicRandRequest, stream drand.Public_PublicRandStreamServer) error

PublicRandStream exports a stream of new beacons as they are generated over gRPC

func (*DrandDaemon) RemoteStatus

func (*DrandDaemon) RemoveBeaconHandler

func (dd *DrandDaemon) RemoveBeaconHandler(ctx context.Context, beaconID string, bp *BeaconProcess)

RemoveBeaconHandler removes a handler linked to beacon with chain hash from http server used to expose public services

func (*DrandDaemon) RemoveBeaconProcess

func (dd *DrandDaemon) RemoveBeaconProcess(ctx context.Context, beaconID string, bp *BeaconProcess)

RemoveBeaconProcess remove a BeaconProcess linked to beacon with id 'beaconID'

func (*DrandDaemon) Shutdown

Shutdown stops the node

func (*DrandDaemon) StartCheckChain

func (*DrandDaemon) StartFollowChain

func (dd *DrandDaemon) StartFollowChain(in *drand.StartSyncRequest, stream drand.Control_StartFollowChainServer) error

func (*DrandDaemon) Status

Status responds with the actual status of drand process

func (*DrandDaemon) Stop

func (dd *DrandDaemon) Stop(ctx context.Context)

Stop simply stops all drand operations.

func (*DrandDaemon) SyncChain

func (dd *DrandDaemon) SyncChain(in *drand.SyncRequest, stream drand.Protocol_SyncChainServer) error

SyncChain is an inter-node protocol that replies to a syncing request from a given round

func (*DrandDaemon) WaitExit

func (dd *DrandDaemon) WaitExit() chan bool

WaitExit returns a channel that signals when drand stops its operations

type MetadataGetter

type MetadataGetter interface {
	GetMetadata() *drand.Metadata
}

type MockNode

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

func (*MockNode) GetAddr

func (n *MockNode) GetAddr() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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