utils

package
v0.0.0-...-c85edb6 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2019 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package utils defines utility functions for the beacon-chain.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DemoConfigFlag determines whether to launch a beacon chain using demo parameters
	// such as shorter cycle length, fewer shards, and more.
	DemoConfigFlag = cli.BoolFlag{
		Name:  "demo-config",
		Usage: " Run the beacon node using demo paramteres (i.e. shorter cycles, fewer shards and committees)",
	}
	// Web3ProviderFlag defines a flag for a mainchain RPC endpoint.
	Web3ProviderFlag = cli.StringFlag{
		Name:  "web3provider",
		Usage: "A mainchain web3 provider string endpoint. Can either be an IPC file string or a WebSocket endpoint. Uses WebSockets by default at ws://127.0.0.1:8546. Cannot be an HTTP endpoint.",
		Value: "ws://127.0.0.1:8546",
	}
	// VrcContractFlag defines a flag for VRC contract address.
	VrcContractFlag = cli.StringFlag{
		Name:  "vrcaddr",
		Usage: "Validator registration contract address. Beacon chain node will listen logs coming from VRC to determine when validator is eligible to participate.",
	}
	// PubKeyFlag defines a flag for validator's public key on the mainchain
	PubKeyFlag = cli.StringFlag{
		Name:  "pubkey",
		Usage: "Validator's public key. Beacon chain node will listen to VRC log to determine when registration has completed based on this public key address.",
	}
	// RPCPort defines a beacon node RPC port to open.
	RPCPort = cli.StringFlag{
		Name:  "rpc-port",
		Usage: "RPC port exposed by a beacon node",
		Value: "4000",
	}
	// CertFlag defines a flag for the node's TLS certificate.
	CertFlag = cli.StringFlag{
		Name:  "tls-cert",
		Usage: "Certificate for secure gRPC. Pass this and the tls-key flag in order to use gRPC securely.",
	}
	// KeyFlag defines a flag for the node's TLS key.
	KeyFlag = cli.StringFlag{
		Name:  "tls-key",
		Usage: "Key for secure gRPC. Pass this and the tls-cert flag in order to use gRPC securely.",
	}
	// GenesisJSON defines a flag for bootstrapping validators from genesis JSON.
	// If this flag is not specified, beacon node will bootstrap validators from code from crystallized_state.go.
	GenesisJSON = cli.StringFlag{
		Name:  "genesis-json",
		Usage: "Beacon node will bootstrap genesis state defined in genesis.json",
	}
	// EnablePOWChain tells the beacon node to use a real web3 endpoint. Disabled by default.
	EnablePOWChain = cli.BoolFlag{
		Name:  "enable-powchain",
		Usage: "Enable a real, web3 proof-of-work chain endpoint in the beacon node",
	}
	// EnableDBCleanup tells the beacon node to automatically clean DB content such as block vote cache.
	EnableDBCleanup = cli.BoolFlag{
		Name:  "enable-db-cleanup",
		Usage: "Enable automatic DB cleanup routine",
	}
)

Functions

func ShuffleIndices

func ShuffleIndices(seed common.Hash, indicesList []uint64) ([]uint64, error)

ShuffleIndices returns a list of pseudorandomly sampled indices. This is used to shuffle validators on ETH2.0 beacon chain.

func SplitIndices

func SplitIndices(l []uint64, n uint64) [][]uint64

SplitIndices splits a list into n pieces.

Types

type BlockVote

type BlockVote struct {
	VoterIndices     []uint32
	VoteTotalDeposit uint32
}

BlockVote is for tracking which validators voted for a certain block hash and total deposit supported for such block hash.

func NewBlockVote

func NewBlockVote() *BlockVote

NewBlockVote generates a fresh new BlockVote.

func (*BlockVote) Marshal

func (v *BlockVote) Marshal() ([]byte, error)

Marshal serializes a BlockVote.

func (*BlockVote) Unmarshal

func (v *BlockVote) Unmarshal(blob []byte) error

Unmarshal deserializes a BlockVote.

type BlockVoteCache

type BlockVoteCache map[[32]byte]*BlockVote

BlockVoteCache is a map from hash to BlockVote object.

func NewBlockVoteCache

func NewBlockVoteCache() BlockVoteCache

NewBlockVoteCache creates a new BlockVoteCache.

func (BlockVoteCache) IsVoteCacheExist

func (blockVoteCache BlockVoteCache) IsVoteCacheExist(blockHash [32]byte) bool

IsVoteCacheExist looks up a BlockVote with a hash.

type Clock

type Clock interface {
	Now() time.Time
}

Clock represents a time providing interface that can be mocked for testing.

type RealClock

type RealClock struct{}

RealClock represents an unmodified clock.

func (RealClock) Now

func (RealClock) Now() time.Time

Now represents the standard functionality of time.

Jump to

Keyboard shortcuts

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