chaos

package
v1.20.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 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 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 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