sim

package
v0.2.10-beta.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenLayers

func GenLayers(g *Generator, seqs ...Sequence) []types.LayerID

GenLayers produces sequence of layers using all configurators.

Types

type Fraction

type Fraction struct {
	Nominator, Denominator int
}

Fraction of something.

func Frac

func Frac(nominator, denominator int) Fraction

Frac is a shortcut for creating Fraction object.

func (Fraction) String

func (f Fraction) String() string

type GenOpt

type GenOpt func(*Generator)

GenOpt for configuring Generator.

func WithLayerSize

func WithLayerSize(size uint32) GenOpt

WithLayerSize configures average layer size.

func WithLogger

func WithLogger(logger log.Log) GenOpt

WithLogger configures logger.

func WithPath

func WithPath(path string) GenOpt

WithPath configures path for persistent databases.

func WithSeed

func WithSeed(seed int64) GenOpt

WithSeed configures seed for Generator. By default 0 is used.

func WithStates

func WithStates(n int) GenOpt

WithStates creates n states.

type Generator

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

Generator for layers of blocks.

func New

func New(opts ...GenOpt) *Generator

New creates Generator instance.

func (*Generator) GetState

func (g *Generator) GetState(i int) State

GetState at index.

func (*Generator) Merge

func (g *Generator) Merge(other *Generator)

Merge other Generator state into this Generator state.

func (*Generator) Next

func (g *Generator) Next(opts ...NextOpt) types.LayerID

Next generates next layer.

func (*Generator) Setup

func (g *Generator) Setup(opts ...SetupOpt)

Setup should be called before running Next.

func (*Generator) Split

func (g *Generator) Split(opts ...SplitOpt) []*Generator

Split generator into multiple partitions. First generator will use original tortoise state (mesh, activations).

type NextOpt

type NextOpt func(*nextConf)

NextOpt is for configuring layer generator.

func WithCoin

func WithCoin(coin bool) NextOpt

WithCoin is to setup weak coin for voting. By default coin will support blocks.

func WithEmptyInputVector

func WithEmptyInputVector() NextOpt

WithEmptyInputVector will save empty input vector.

func WithLayerSizeOverwrite

func WithLayerSizeOverwrite(size int) NextOpt

WithLayerSizeOverwrite overwrite expected layer size.

func WithNextReorder

func WithNextReorder(delay uint32) NextOpt

WithNextReorder configures when reordered layer should be returned. Examples: Next() Next(WithNextReorder(1)) Next() 1 3 2 Next() Next(WithNextReorder(2)) Next() Next() 1 3 4 2

So the Next layer with WithNextReorder will be delayed exactly by `delay` value.

func WithPartialHare

func WithPartialHare(nominator, denominator int) NextOpt

WithPartialHare will set input vector only to a fraction of all known blocks. Input vector will be limited to nominator*size/denominator.

func WithVoteGenerator

func WithVoteGenerator(gen VotesGenerator) NextOpt

WithVoteGenerator declares vote generator for a layer.

func WithoutInputVector

func WithoutInputVector() NextOpt

WithoutInputVector will prevent from saving input vector.

type Sequence

type Sequence struct {
	Length int
	Opts   []NextOpt
}

Sequence of layers with same configuration.

func WithSequence

func WithSequence(lth int, opts ...NextOpt) Sequence

WithSequence creates Sequence object.

type SetupOpt

type SetupOpt func(g *setupConf)

SetupOpt configures setup.

func WithSetupMinerRange

func WithSetupMinerRange(low, high int) SetupOpt

WithSetupMinerRange number of miners will be selected between low and high values.

func WithSetupUnitsRange

func WithSetupUnitsRange(low, high int) SetupOpt

WithSetupUnitsRange adjusts units of the ATXs, which will directly affect block weight.

type SplitOpt

type SplitOpt func(*splitConf)

SplitOpt is for configuring partition.

func WithPartitions

func WithPartitions(parts ...Fraction) SplitOpt

WithPartitions configures number of miners in each partition relative to original Generator.

type State

type State struct {
	MeshDB  *mesh.DB
	AtxDB   *activation.DB
	Beacons *beaconStore
	// contains filtered or unexported fields
}

State of the node.

func (*State) OnActivationTx

func (s *State) OnActivationTx(atx *types.ActivationTx)

OnActivationTx callback to store activation transaction.

func (*State) OnBeacon

func (s *State) OnBeacon(eid types.EpochID, beacon []byte)

OnBeacon callback to store generated beacon.

func (*State) OnBlock

func (s *State) OnBlock(block *types.Block)

OnBlock callback to store block.

func (*State) OnCoinflip

func (s *State) OnCoinflip(lid types.LayerID, coinflip bool)

OnCoinflip callback to store coinflip.

func (*State) OnInputVector

func (s *State) OnInputVector(lid types.LayerID, vector []types.BlockID)

OnInputVector callback to store input vector.

type VotesGenerator

type VotesGenerator func(rng *rand.Rand, layers []*types.Layer, i int) Voting

VotesGenerator allows to replace default votes generator. TODO(dshulyak) what is the best way to encapsulate all configuration that is required to generate votes?

type Voting

type Voting struct {
	Base                      types.BlockID
	Support, Against, Abstain []types.BlockID
}

Voting contains blocks voting.

func PerfectVoting

func PerfectVoting(rng *rand.Rand, layers []*types.Layer, _ int) Voting

PerfectVoting selects base block from previous layer and supports all blocks from previous layer. used by default.

Jump to

Keyboard shortcuts

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