random_network

package
v0.0.0-...-c7114b6 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateNetworkLogger

func CreateNetworkLogger(t *testing.T, config *FuzzConfig) *testutil.TestLogger

CreateNetworkLogger creates a logger for the network that writes to both console and main.log

func CreateNodeLogger

func CreateNodeLogger(t *testing.T, config *FuzzConfig, nodeID simplex.NodeID) *testutil.TestLogger

CreateNodeLogger creates a logger for a node that writes to both console and {nodeID}.log

func NewProtocolMetadata

func NewProtocolMetadata(round, seq uint64, prev simplex.Digest) simplex.ProtocolMetadata

Types

type Block

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

func NewBlock

func NewBlock(metadata simplex.ProtocolMetadata, blacklist simplex.Blacklist, mempool *Mempool, txs []*TX) *Block

func (*Block) Blacklist

func (b *Block) Blacklist() simplex.Blacklist

func (*Block) BlockHeader

func (b *Block) BlockHeader() simplex.BlockHeader

func (*Block) Bytes

func (b *Block) Bytes() ([]byte, error)

func (*Block) ComputeAndSetDigest

func (b *Block) ComputeAndSetDigest()

func (*Block) Verify

func (b *Block) Verify(ctx context.Context) (simplex.VerifiedBlock, error)

type BlockDeserializer

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

func (*BlockDeserializer) DeserializeBlock

func (bd *BlockDeserializer) DeserializeBlock(ctx context.Context, buff []byte) (simplex.Block, error)

type FuzzConfig

type FuzzConfig struct {
	// The minimum and maximum number of nodes in the network.
	MinNodes int // Default is 3.
	MaxNodes int // Default is 10.

	// The minimum and maximum number of transactions to be issued at a block. Default is between 5 and 20.
	MinTxsPerIssue int
	MaxTxsPerIssue int

	// Number of transactions per block. Default is 15.
	TxsPerBlock int

	// The number of blocks that must be finalized before ending the fuzz test. Default is 100.
	NumFinalizedBlocks int

	RandomSeed int64

	// Probability that a node will be randomly crashed. Default is .1 (10%).
	NodeCrashProbability float64

	// Probability that a crashed node will be restarted. Default is .5 (50%).
	NodeRecoverProbability float64

	// Amount to advance the time by. Default is simplex.DefaultMaxProposalWaitTime / 5.
	AdvanceTimeTickAmount time.Duration

	// Creates main.log for network logs and {nodeID-short}.log for each node.
	// NodeID is represented as a 16-character hex string (first 8 bytes).
	// Default directory is "tmp".
	// If empty, logging to files is disabled and logs will only be printed to console.
	LogDirectory string
}

func DefaultFuzzConfig

func DefaultFuzzConfig() *FuzzConfig

type Mempool

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

func NewMempool

func NewMempool(l simplex.Logger, config *FuzzConfig) *Mempool

func (*Mempool) AcceptBlock

func (m *Mempool) AcceptBlock(b *Block)

AcceptBlock accepts the block and updates the mempool state to clean up transactions, remove sibling/uncle blocks, and move any non-conflicting transactions from purged sibling/uncle blocks back to unaccepted

func (*Mempool) AddPendingTXs

func (m *Mempool) AddPendingTXs(txs ...*TX)

func (*Mempool) BuildBlock

func (*Mempool) Clear

func (m *Mempool) Clear()

Clear resets the mempool state to simulate a node restart. We do not remove accepted & unaccepted transactions/blocks from the mempool(since we don't have tx gossip) but we do clear verified blocks since we are expected to re-verify after a restart.

func (*Mempool) IsTxAccepted

func (m *Mempool) IsTxAccepted(txID txID) bool

IsTxAccepted returns true if the transaction has been accepted

func (*Mempool) IsTxPending

func (m *Mempool) IsTxPending(txID txID) bool

IsTxPending returns true if the transaction is still pending (unaccepted)

func (*Mempool) NotifyTxsReady

func (m *Mempool) NotifyTxsReady()

NotifyTxsReady signals that there are pending transactions in the mempool.

func (*Mempool) VerifyBlock

func (m *Mempool) VerifyBlock(ctx context.Context, b *Block) error

VerifyBlock verifies the block and its transactions. Errors if any tx is invalid or if there are duplicate txs in the block.

func (*Mempool) WaitForPendingBlock

func (m *Mempool) WaitForPendingBlock(ctx context.Context)

type Network

type Network struct {
	*testutil.BasicInMemoryNetwork
	// contains filtered or unexported fields
}

func NewNetwork

func NewNetwork(config *FuzzConfig, t *testing.T) *Network

func (*Network) PrintStatus

func (n *Network) PrintStatus()

func (*Network) Run

func (n *Network) Run()

func (*Network) SetInfoLog

func (n *Network) SetInfoLog()

func (*Network) StartInstances

func (n *Network) StartInstances()

type Node

type Node struct {
	*testutil.BasicNode
	// contains filtered or unexported fields
}

func NewNode

func NewNode(t *testing.T, nodeID simplex.NodeID, net *testutil.BasicInMemoryNetwork, config *FuzzConfig, nodeConfig randomNodeConfig) *Node

func (*Node) HandleMessage

func (n *Node) HandleMessage(msg *simplex.Message, from simplex.NodeID) error

type Storage

type Storage struct {
	*testutil.InMemStorage
	// contains filtered or unexported fields
}

func NewStorage

func NewStorage(mempool *Mempool) *Storage

func (*Storage) Clone

func (s *Storage) Clone() *Storage

func (*Storage) Index

func (s *Storage) Index(ctx context.Context, block simplex.VerifiedBlock, certificate simplex.Finalization) error

type TX

type TX struct {
	ID txID
	// contains filtered or unexported fields
}

func CreateNewTX

func CreateNewTX() *TX

func TxFromBytes

func TxFromBytes(b []byte) (*TX, error)

func (*TX) Bytes

func (t *TX) Bytes() ([]byte, error)

func (*TX) SetShouldFailVerification

func (t *TX) SetShouldFailVerification()

func (*TX) String

func (t *TX) String() string

func (*TX) Verify

func (t *TX) Verify(ctx context.Context) error

Jump to

Keyboard shortcuts

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