chaos

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultHealthCheckTimeout is default timeout for health checks
	DefaultHealthCheckTimeout = 2 * time.Minute

	// DefaultHealthCheckInterval is default interval between health checks
	DefaultHealthCheckInterval = 2 * time.Second

	// DefaultConsensusTimeout is default timeout for consensus verification
	DefaultConsensusTimeout = 5 * time.Minute

	// DefaultConsensusInterval is default interval between consensus checks
	DefaultConsensusInterval = 5 * time.Second
)

Variables

View Source
var (
	ErrNetworkNotHealthy       = errors.New("network not healthy after recovery")
	ErrConsensusNotProgressing = errors.New("consensus not progressing after recovery")
	ErrNodeNotConnected        = errors.New("node not connected to peers")
)

Functions

func CompareSnapshots

func CompareSnapshots(before, after *NetworkHealthSnapshot) bool

CompareSnapshots compares two health snapshots and returns whether recovery occurred

Types

type ByzantineBehavior added in v1.20.5

type ByzantineBehavior string

ByzantineBehavior defines types of Byzantine behavior

const (
	// ByzantineEquivocation sends different messages to different peers
	ByzantineEquivocation ByzantineBehavior = "equivocation"

	// ByzantineOmission withholds messages from certain peers
	ByzantineOmission ByzantineBehavior = "omission"

	// ByzantineLying sends false/invalid messages
	ByzantineLying ByzantineBehavior = "lying"

	// ByzantineDelaying delays message propagation
	ByzantineDelaying ByzantineBehavior = "delaying"

	// ByzantineFlooding floods the network with invalid messages
	ByzantineFlooding ByzantineBehavior = "flooding"

	// ByzantineCorruption corrupts messages before forwarding
	ByzantineCorruption ByzantineBehavior = "corruption"

	// ByzantineDoubleVoting votes for multiple conflicting blocks
	ByzantineDoubleVoting ByzantineBehavior = "double_voting"
)

type ByzantineConfig added in v1.20.5

type ByzantineConfig struct {
	Behavior    ByzantineBehavior
	TargetNodes []ids.NodeID
	VictimNodes []ids.NodeID // Specific victims of Byzantine behavior
	Duration    time.Duration
	Intensity   float64 // 0.0-1.0, how aggressive the behavior is
	Parameters  map[string]interface{}
}

ByzantineConfig defines configuration for Byzantine behavior injection

type ByzantineFault added in v1.20.5

type ByzantineFault struct {
	Config    ByzantineConfig
	StartTime time.Time
	EndTime   time.Time
	Active    bool
	Stats     *ByzantineStats
}

ByzantineFault represents an active Byzantine fault

type ByzantineInjector added in v1.20.5

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

ByzantineInjector injects Byzantine behavior into nodes

func NewByzantineInjector added in v1.20.5

func NewByzantineInjector(network *tmpnet.Network, logger log.Logger, injector *ChaosInjector) *ByzantineInjector

NewByzantineInjector creates a new Byzantine behavior injector

func (*ByzantineInjector) GetActiveByzantineFaults added in v1.20.5

func (bi *ByzantineInjector) GetActiveByzantineFaults() map[string]*ByzantineFault

GetActiveByzantineFaults returns all active Byzantine faults

func (*ByzantineInjector) GetByzantineStats added in v1.20.5

func (bi *ByzantineInjector) GetByzantineStats(faultID string) (*ByzantineStats, error)

GetByzantineStats returns statistics for a Byzantine fault

func (*ByzantineInjector) InjectByzantineBehavior added in v1.20.5

func (bi *ByzantineInjector) InjectByzantineBehavior(ctx context.Context, config ByzantineConfig) error

InjectByzantineBehavior injects Byzantine behavior into specified nodes

func (*ByzantineInjector) StopByzantineBehavior added in v1.20.5

func (bi *ByzantineInjector) StopByzantineBehavior(faultID string) error

StopByzantineBehavior stops a specific Byzantine fault

type ByzantineStats added in v1.20.5

type ByzantineStats struct {
	MessagesCorrupted   uint64
	MessagesWithheld    uint64
	MessagesDelayed     uint64
	EquivocationsSent   uint64
	InvalidMessagesSent uint64
	DoubleVotes         uint64
}

ByzantineStats tracks statistics of Byzantine behavior

type ChaosInjector

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

ChaosInjector manages chaos injection into a network

func NewChaosInjector

func NewChaosInjector(network *tmpnet.Network, logger log.Logger) *ChaosInjector

NewChaosInjector creates a new chaos injector for the given network

func (*ChaosInjector) GetActiveFaults

func (ci *ChaosInjector) GetActiveFaults() map[string]FaultConfig

GetActiveFaults returns the currently active faults

func (*ChaosInjector) InjectFault

func (ci *ChaosInjector) InjectFault(ctx context.Context, config FaultConfig) error

InjectFault injects a specific fault into the network

func (*ChaosInjector) InjectRandomFault

func (ci *ChaosInjector) InjectRandomFault(ctx context.Context, faultTypes []FaultType, probability float64, duration time.Duration) error

InjectRandomFault injects a random fault based on probability

func (*ChaosInjector) PartitionNodesByID

func (ci *ChaosInjector) PartitionNodesByID(ctx context.Context, nodeIDs []ids.NodeID, duration time.Duration) error

PartitionNodesByID partitions network by isolating specific node IDs

func (*ChaosInjector) Stop

func (ci *ChaosInjector) Stop()

Stop stops all active fault injections

type FaultConfig

type FaultConfig struct {
	Type        FaultType
	TargetNodes []*tmpnet.Node
	Duration    time.Duration
	Probability float64 // 0.0 to 1.0
	Parameters  map[string]interface{}
}

FaultConfig defines configuration for a specific fault injection

type FaultType

type FaultType string

FaultType defines the type of chaos injection

const (
	// Network faults
	FaultTypePartition  FaultType = "partition"
	FaultTypeLatency    FaultType = "latency"
	FaultTypePacketLoss FaultType = "packet_loss"
	FaultTypeBandwidth  FaultType = "bandwidth"

	// Node faults
	FaultTypeCrash    FaultType = "crash"
	FaultTypeShutdown FaultType = "shutdown"
	FaultTypeFreeze   FaultType = "freeze"

	// Byzantine faults
	FaultTypeInvalidMessage FaultType = "invalid_message"
	FaultTypeEquivocation   FaultType = "equivocation"
	FaultTypeWithhold       FaultType = "withhold"

	// Resource faults
	FaultTypeCPUThrottle FaultType = "cpu_throttle"
	FaultTypeMemory      FaultType = "memory_pressure"
	FaultTypeDiskIO      FaultType = "disk_io"
)

type NetworkHealthSnapshot

type NetworkHealthSnapshot struct {
	Timestamp    time.Time
	HealthyNodes int
	TotalNodes   int
	Connectivity map[ids.NodeID]int // NodeID -> peer count
}

NetworkHealthSnapshot captures current network health state

type NetworkPartitioner added in v1.20.5

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

NetworkPartitioner manages network partition scenarios

func NewNetworkPartitioner added in v1.20.5

func NewNetworkPartitioner(network *tmpnet.Network, logger log.Logger, injector *ChaosInjector) *NetworkPartitioner

NewNetworkPartitioner creates a new network partitioner

func (*NetworkPartitioner) CreateAsymmetricPartition added in v1.20.5

func (np *NetworkPartitioner) CreateAsymmetricPartition(ctx context.Context, nodeA, nodeB ids.NodeID, duration time.Duration) error

CreateAsymmetricPartition creates asymmetric partition where A can reach B but not vice versa

func (*NetworkPartitioner) CreateRandomPartitions added in v1.20.5

func (np *NetworkPartitioner) CreateRandomPartitions(ctx context.Context, groupCount int, duration time.Duration) error

CreateRandomPartitions creates random network partitions

func (*NetworkPartitioner) CreateSplitBrainPartition added in v1.20.5

func (np *NetworkPartitioner) CreateSplitBrainPartition(ctx context.Context, duration time.Duration) error

CreateSplitBrainPartition creates a split-brain scenario dividing network in half

func (*NetworkPartitioner) GetActivePartitions added in v1.20.5

func (np *NetworkPartitioner) GetActivePartitions() map[string]*PartitionInfo

GetActivePartitions returns currently active partitions

func (*NetworkPartitioner) HealAllPartitions added in v1.20.5

func (np *NetworkPartitioner) HealAllPartitions(ctx context.Context) error

HealAllPartitions heals all active network partitions

func (*NetworkPartitioner) IsolateNode added in v1.20.5

func (np *NetworkPartitioner) IsolateNode(ctx context.Context, nodeID ids.NodeID, duration time.Duration) error

IsolateNode isolates a single node from the rest of the network

func (*NetworkPartitioner) PartitionMajority added in v1.20.5

func (np *NetworkPartitioner) PartitionMajority(ctx context.Context, duration time.Duration) error

PartitionMajority partitions a majority of validators from the network

func (*NetworkPartitioner) PartitionMinority added in v1.20.5

func (np *NetworkPartitioner) PartitionMinority(ctx context.Context, duration time.Duration) error

PartitionMinority partitions a minority of validators from the network

type PartitionInfo added in v1.20.5

type PartitionInfo struct {
	Type       PartitionType
	Groups     [][]ids.NodeID // Node groups in the partition
	StartTime  time.Time
	Duration   time.Duration
	Asymmetric bool // If true, partition is asymmetric
}

PartitionInfo tracks partition details

type PartitionType added in v1.20.5

type PartitionType string

PartitionType defines different types of network partitions

const (
	// PartitionTypeSplitBrain creates a classic split-brain scenario
	PartitionTypeSplitBrain PartitionType = "split_brain"

	// PartitionTypeIsolate isolates a single node from the rest
	PartitionTypeIsolate PartitionType = "isolate"

	// PartitionTypeMinority partitions minority of validators
	PartitionTypeMinority PartitionType = "minority"

	// PartitionTypeMajority partitions majority of validators
	PartitionTypeMajority PartitionType = "majority"

	// PartitionTypeRandom creates random partitions
	PartitionTypeRandom PartitionType = "random"

	// PartitionTypeAsymmetric creates asymmetric partition (A can reach B but not vice versa)
	PartitionTypeAsymmetric PartitionType = "asymmetric"
)

type RecoveryVerifier

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

RecoveryVerifier verifies that a network has recovered from chaos injection

func NewRecoveryVerifier

func NewRecoveryVerifier(network *tmpnet.Network, logger log.Logger) *RecoveryVerifier

NewRecoveryVerifier creates a new recovery verifier

func (*RecoveryVerifier) CaptureHealthSnapshot

func (rv *RecoveryVerifier) CaptureHealthSnapshot(ctx context.Context) (*NetworkHealthSnapshot, error)

CaptureHealthSnapshot captures current network health state

func (*RecoveryVerifier) VerifyConsensusProgressing

func (rv *RecoveryVerifier) VerifyConsensusProgressing(ctx context.Context, minBlocks uint64) error

VerifyConsensusProgressing checks that consensus is making progress by verifying that P-Chain height is increasing

func (*RecoveryVerifier) VerifyFullRecovery

func (rv *RecoveryVerifier) VerifyFullRecovery(ctx context.Context, tc tests.TestContext) error

VerifyFullRecovery performs comprehensive recovery verification

func (*RecoveryVerifier) VerifyNetworkHealth

func (rv *RecoveryVerifier) VerifyNetworkHealth(ctx context.Context) error

VerifyNetworkHealth checks that all nodes in the network are healthy

func (*RecoveryVerifier) VerifyNodeConnectivity

func (rv *RecoveryVerifier) VerifyNodeConnectivity(ctx context.Context) error

VerifyNodeConnectivity checks that all nodes are connected to their peers

func (*RecoveryVerifier) WaitForNetworkHealth

func (rv *RecoveryVerifier) WaitForNetworkHealth(ctx context.Context, timeout time.Duration) error

WaitForNetworkHealth waits for all nodes to become healthy with timeout

func (*RecoveryVerifier) WaitForNodeConnectivity

func (rv *RecoveryVerifier) WaitForNodeConnectivity(ctx context.Context, timeout time.Duration) error

WaitForNodeConnectivity waits for all nodes to be connected with timeout

Jump to

Keyboard shortcuts

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