sim

package
v0.0.0-...-475921b Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0, MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TraceNone = iota
	TraceSent
	TraceRecvd
	TraceLogic
	TraceAll //nolint:unused
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChainCount

type ChainCount struct {
	Count int
	Chain gpbft.ECChain
}

type DecisionLog

type DecisionLog struct {

	// Base tipset for each instance.
	Bases []gpbft.TipSet
	// Powertable for each instance.
	PowerTables []*gpbft.PowerTable
	// Decisions received for each instance and participant.
	Decisions []map[gpbft.ActorID]*gpbft.Justification
	// contains filtered or unexported fields
}

Receives and validates finality decisions

func (*DecisionLog) BeginInstance

func (dl *DecisionLog) BeginInstance(instance uint64, base gpbft.TipSet, power *gpbft.PowerTable)

Establishes the base tipset and power table for a new instance.

func (*DecisionLog) HasCompletedInstance

func (dl *DecisionLog) HasCompletedInstance(instance uint64, adversary gpbft.ActorID) bool

Checks whether all participants (except any adversary) have decided on a value for an instance.

func (*DecisionLog) PrintInstance

func (dl *DecisionLog) PrintInstance(instance uint64)

func (*DecisionLog) ReceiveDecision

func (dl *DecisionLog) ReceiveDecision(participant gpbft.ActorID, decision *gpbft.Justification) (first bool)

Verifies and records a decision from a participant. Returns whether this was the first decision for the instance.

func (*DecisionLog) VerifyInstance

func (dl *DecisionLog) VerifyInstance(instance uint64, adversary gpbft.ActorID) error

Checks that all participants (except any adversary) for an instance decided on the same value.

type EC

type EC struct {
	Instances []*ECInstance
}

Simulated EC state for each protocol instance.

func (*EC) AddInstance

func (ec *EC) AddInstance(chain gpbft.ECChain, power *gpbft.PowerTable, beacon []byte)

Adds a new instance to the EC state, with a new chain shared by all participants. The power table and beacon correspond to the base of the new chain.

func (*EC) AddParticipant

func (ec *EC) AddParticipant(id gpbft.ActorID, power *gpbft.StoragePower, pubkey []byte)

Adds a participant to the first instance.

type ECInstance

type ECInstance struct {
	// The base of all chains, which participants must agree on.
	Base gpbft.ECChain
	// EC chains visible to participants.
	Chains map[gpbft.ActorID]gpbft.ECChain
	// The power table at the base chain head.
	PowerTable *gpbft.PowerTable
	// The beacon value of the base chain head.
	Beacon []byte
}

type Network

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

func (*Network) AddParticipant

func (n *Network) AddParticipant(p gpbft.Receiver)

func (*Network) Broadcast

func (n *Network) Broadcast(msg *gpbft.GMessage)

func (*Network) BroadcastSynchronous

func (n *Network) BroadcastSynchronous(sender gpbft.ActorID, msg gpbft.GMessage)

func (*Network) Log

func (n *Network) Log(format string, args ...interface{})

func (*Network) NetworkName

func (n *Network) NetworkName() gpbft.NetworkName

func (*Network) SetAlarm

func (n *Network) SetAlarm(sender gpbft.ActorID, at time.Time)

func (*Network) Tick

func (n *Network) Tick(adv *adversary.Adversary) (bool, error)

Returns whether there are any more messages to process.

func (*Network) Time

func (n *Network) Time() time.Time

type Option

type Option func(*options) error

func WitECStabilisationDelay

func WitECStabilisationDelay(d time.Duration) Option

func WithAdversary

func WithAdversary(generator adversary.Generator) Option

func WithBaseChain

func WithBaseChain(base *gpbft.ECChain) Option

func WithECEpochDuration

func WithECEpochDuration(d time.Duration) Option

func WithECStabilisationDelay

func WithECStabilisationDelay(d time.Duration) Option

func WithGpbftOptions

func WithGpbftOptions(gOpts ...gpbft.Option) Option

func WithHonestParticipantCount

func WithHonestParticipantCount(i int) Option

func WithLatencyModel

func WithLatencyModel(lm latency.Model) Option

func WithSigningBackend

func WithSigningBackend(sb signing.Backend) Option

WithSigningBackend sets the signing backend to be used by all participants in the simulation. Defaults to signing.FakeBackend if unset.

See signing.FakeBackend, signing.BLSBackend.

func WithTipSetGenerator

func WithTipSetGenerator(tsg *TipSetGenerator) Option

func WithTraceLevel

func WithTraceLevel(i int) Option

type Simulation

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

func NewSimulation

func NewSimulation(o ...Option) (*Simulation, error)

func (*Simulation) Describe

func (s *Simulation) Describe() string

func (*Simulation) GetDecision

func (s *Simulation) GetDecision(instance uint64, participant gpbft.ActorID) (gpbft.ECChain, bool)

Returns the decision for a participant in an instance.

func (*Simulation) GetInstance

func (s *Simulation) GetInstance(i int) *ECInstance

func (*Simulation) HonestParticipantsCount

func (s *Simulation) HonestParticipantsCount() int

func (*Simulation) ListParticipantIDs

func (s *Simulation) ListParticipantIDs() []gpbft.ActorID

func (*Simulation) PowerTable

func (s *Simulation) PowerTable(instance uint64) *gpbft.PowerTable

func (*Simulation) PrintResults

func (s *Simulation) PrintResults()

func (*Simulation) Run

func (s *Simulation) Run(instanceCount uint64, maxRounds uint64) error

Runs simulation, and returns whether all participants decided on the same value.

func (*Simulation) SetChains

func (s *Simulation) SetChains(chains ...ChainCount)

Sets canonical chains to be delivered to honest participants in the first instance.

type TipSetGenerator

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

A tipset generator. This uses a fast xorshift PRNG to generate random tipset IDs. The statistical properties of these are not important to correctness.

func NewTipSetGenerator

func NewTipSetGenerator(seed uint64) *TipSetGenerator

func (*TipSetGenerator) Sample

func (c *TipSetGenerator) Sample() gpbft.TipSet

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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