twins

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

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

Generator generates twins scenarios.

func NewGenerator

func NewGenerator(logger logging.Logger, numNodes, numTwins, partitions, rounds uint8) *Generator

NewGenerator creates a new generator.

func (*Generator) NextScenario

func (g *Generator) NextScenario() (s Scenario, err error)

NextScenario generates the next scenario.

func (*Generator) Remaining

func (g *Generator) Remaining() int64

Remaining returns the number of scenarios remaining to be generated.

func (*Generator) Settings

func (g *Generator) Settings() Settings

Settings returns the settings of the generator.

func (*Generator) Shuffle

func (g *Generator) Shuffle(seed int64)

Shuffle shuffles the list of leaders and partitions.

type JSONWriter

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

JSONWriter writes scenarios to JSON.

func ToJSON

func ToJSON(settings Settings, wr io.Writer) (*JSONWriter, error)

ToJSON returns a JSONWriter that can be used to write scenarios as JSON.

func (*JSONWriter) Close

func (jwr *JSONWriter) Close() error

Close closes the JSON stream.

func (*JSONWriter) WriteScenario

func (jwr *JSONWriter) WriteScenario(s Scenario) error

WriteScenario writes a single scenario to the JSON stream.

type NodeID

type NodeID struct {
	ReplicaID hotstuff.ID
	NetworkID uint32
}

NodeID is an ID that is unique to a node in the network. The ReplicaID is the ID that the node uses when taking part in the consensus protocol, while the NetworkID is used to distinguish nodes on the network.

func (NodeID) String

func (id NodeID) String() string

type NodeSet

type NodeSet map[uint32]struct{}

NodeSet is a set of network ids.

func (NodeSet) Add

func (s NodeSet) Add(v uint32)

Add adds a NodeID to the set.

func (NodeSet) Contains

func (s NodeSet) Contains(v uint32) bool

Contains returns true if the set contains the NodeID, false otherwise.

func (NodeSet) MarshalJSON

func (s NodeSet) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of the node set.

func (*NodeSet) UnmarshalJSON

func (s *NodeSet) UnmarshalJSON(data []byte) error

UnmarshalJSON restores the node set from JSON.

type Scenario

type Scenario []View

Scenario specifies the nodes, partitions and leaders for a twins scenario.

func (Scenario) String

func (s Scenario) String() string

type ScenarioResult

type ScenarioResult struct {
	Safe       bool
	Commits    int
	NetworkLog string
	NodeLogs   map[NodeID]string
}

ScenarioResult contains the result and logs from executing a scenario.

func ExecuteScenario

func ExecuteScenario(scenario Scenario, numNodes, numTwins uint8, consensusName string) (result ScenarioResult, err error)

ExecuteScenario executes a twins scenario.

type ScenarioSource

type ScenarioSource interface {
	Settings() Settings
	NextScenario() (Scenario, error)
	Remaining() int64
}

ScenarioSource is a source of twins scenarios to execute.

func FromJSON

func FromJSON(rd io.Reader) (ScenarioSource, error)

FromJSON returns a scenario source that reads from the given reader.

type Settings

type Settings struct {
	NumNodes   uint8
	NumTwins   uint8
	Partitions uint8
	Rounds     uint8
	Shuffle    bool
	Seed       int64
}

Settings contains the settings used with the scenario generator.

type View

type View struct {
	Leader     hotstuff.ID `json:"leader"`
	Partitions []NodeSet   `json:"partitions"`
}

View specifies the leader id an the partition scenario for a single round of consensus.

Jump to

Keyboard shortcuts

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