Lux Docs

Consensus Testing

Verify consensus correctness under adversarial conditions

Netrunner provides tools for verifying consensus liveness and safety properties under various failure modes.

Liveness Testing

Verify that the network continues to produce blocks and finalize transactions:

# Run liveness test for 2 minutes
netrunner test --liveness --duration 120s

# With a specific block production target
netrunner test --liveness --min-blocks 100 --duration 120s

The liveness test verifies:

  • All chains produce blocks within expected intervals
  • Transactions are confirmed within timeout
  • No chain falls behind

Safety Testing

Verify that the network does not produce conflicting finalized blocks:

# Safety test with 1 faulty node
netrunner test --safety --faults 1

# Safety with network partitions
netrunner test --safety --partition-duration 30s

The safety test verifies:

  • No two nodes finalize conflicting blocks
  • Chain state is consistent across all honest nodes
  • Block hashes match at the same height

Consensus Parameters

ParameterValueDescription
consensus-sample-size5Validators sampled per consensus round
consensus-quorum-size4Required agreement for finality
Maximum Byzantine faults1floor((n-1)/3) for n=5

Test Scenarios

ScenarioCommandVerifies
Happy pathtest --livenessNormal block production
Node crashtest --safety --faults 1Consensus with minority failure
Partitiontest --safety --partition-duration 30sRecovery after partition
Slow nodetest --liveness --latency 500msTolerance for slow peers
Full restarttest --liveness --restart-allBootstrap from saved state

Chain-Specific Tests

# Test P-Chain consensus
netrunner test --chain P --liveness

# Test C-Chain consensus
netrunner test --chain C --liveness --min-blocks 50

# Test all chains
netrunner test --all-chains --liveness

CI/CD Integration

# GitHub Actions example
- name: Run consensus tests
  run: |
    netrunner server &
    netrunner control start --number-of-nodes=5 --node-path=./luxd
    netrunner test --liveness --duration 60s
    netrunner test --safety --faults 1
    netrunner control stop

On this page