sim

package
v0.3.9-beta.1 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultNumBlocks = 5

DefaultNumBlocks is a number of blocks in a layer by default.

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) Layer

func (g *Generator) Layer(i int) *types.Layer

Layer returns generated layer.

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 the 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 WithBlockTickHeights

func WithBlockTickHeights(heights ...uint64) NextOpt

WithBlockTickHeights updates height of the blocks.

func WithCoin

func WithCoin(coin bool) NextOpt

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

func WithEmptyHareOutput

func WithEmptyHareOutput() NextOpt

WithEmptyHareOutput will save an empty vector for hare output.

func WithHareOutputIndex

func WithHareOutputIndex(i int) NextOpt

WithHareOutputIndex sets the index of the block that will be stored as a hare output.

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 WithNumBlocks

func WithNumBlocks(num int) NextOpt

WithNumBlocks sets number of the generated blocks.

func WithVoteGenerator

func WithVoteGenerator(gen VotesGenerator) NextOpt

WithVoteGenerator declares vote generator for a layer.

func WithoutHareOutput

func WithoutHareOutput() NextOpt

WithoutHareOutput will prevent from saving hare output.

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 WithSetupTicks

func WithSetupTicks(ticks ...uint64) SetupOpt

WithSetupTicks configures ticks for every atx.

func WithSetupTicksRange

func WithSetupTicksRange(low, high int) SetupOpt

WithSetupTicksRange configures range of atxs, that will be randomly chosen by atxs.

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 {
	DB      *datastore.CachedDB
	Beacons *beaconStore
	// contains filtered or unexported fields
}

State of the node.

func (*State) OnActivationTx

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

OnActivationTx callback to store activation transaction.

func (*State) OnBallot

func (s *State) OnBallot(ballot *types.Ballot)

OnBallot callback to store ballot.

func (*State) OnBeacon

func (s *State) OnBeacon(eid types.EpochID, beacon types.Beacon)

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) OnHareOutput

func (s *State) OnHareOutput(lid types.LayerID, bid types.BlockID)

OnHareOutput callback to store hare output.

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?

func VaryingVoting

func VaryingVoting(mid int, first, second VotesGenerator) VotesGenerator

VaryingVoting votes using first generator for ballots before mid, and with second generator after mid.

type Voting

type Voting = types.Votes

Voting contains blocks voting.

func ConsistentVoting

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

ConsistentVoting selects same base ballot for ballot at a specific index.

func PerfectVoting

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

PerfectVoting selects base ballot 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