A comprehensive multi-algorithm fee market simulator supporting various fee adjustment mechanisms including EIP-1559, AIMD (Additive Increase Multiplicative Decrease), and PID Controllers. This simulator provides advanced features including burst capacity, randomness injection, real blockchain data integration, and visualization capabilities for comparing different fee adjustment strategies.
โโโ cmd/simulator/ # Application entry point
โโโ pkg/
โ โโโ config/ # Configuration management
โ โโโ simulator/ # Core fee adjustment algorithm implementations
โ โโโ scenarios/ # Simulation scenario generation
โ โโโ analysis/ # Statistical analysis and reporting
โ โโโ blockchain/ # Real blockchain data integration
โ โโโ randomizer/ # Data randomization
| โโโ visualization/ # Chart generation
|
โโโ go.mod
The standard Ethereum fee adjustment mechanism as specified in EIP-1559.
gasUsedDelta = gasUsed - targetGas
baseFeeChange = baseFee * gasUsedDelta / targetGas / 8
newBaseFee = baseFee + baseFeeChange
| Parameter | Description | Default Value |
|---|---|---|
MaxFeeChange |
Maximum fee change per block | 0.125 (12.5%) |
An enhanced variant of EIP-1559 with adaptive learning rates and historical window analysis.
-
Dynamic Block Capacity:
maxBlockSize = targetBlockSize * burstMultiplier -
Target Utilization Calculation:
targetUtilization = sumBlockSizesInWindow(window) / (window * targetBlockSize) -
Learning Rate Adjustment:
utilizationDeviation = |targetUtilization - 1.0| if utilizationDeviation > gamma: newLearningRate = min(MaxLearningRate, ฮฑ + currentLearningRate) else: newLearningRate = max(MinLearningRate, ฮฒ * currentLearningRate) -
Base Fee Update:
newBaseFee = currentBaseFee * (1 + learningRate * (currentBlockSize - targetBlockSize) / targetBlockSize) + ฮด * netGasDelta(window)
| Parameter | Description | Default Value |
|---|---|---|
WindowSize |
Blocks in analysis window | 10 blocks |
Gamma (ฮณ) |
Target utilization deviation threshold | 0.25 (25%) |
MaxLearningRate |
Maximum learning rate | 0.5 (50%) |
MinLearningRate |
Minimum learning rate | 0.001 (0.1%) |
Alpha (ฮฑ) |
Additive increase factor | 0.01 (1%) |
Beta (ฮฒ) |
Multiplicative decrease factor | 0.9 (90%) |
Delta (ฮด) |
Net gas delta coefficient | 0.000001 |
InitialLearningRate |
Initial learning rate | 0.1 (10%) |
A Proportional-Integral-Derivative control system approach to fee adjustment.
error = (gasUsed / targetBlockSize) - 1.0
proportional = Kp * error
integral += error (with windup protection)
derivative = slope of recent errors
controlOutput = proportional + Ki * integral + Kd * derivative
newBaseFee = baseFee * (1 + controlOutput)
| Parameter | Description | Default Value |
|---|---|---|
Kp |
Proportional gain | 0.02 |
Ki |
Integral gain | 0.00001 |
Kd |
Derivative gain | 0.01 |
MaxIntegral |
Maximum integral value | 100.0 |
MinIntegral |
Minimum integral value | -100.0 |
MaxFeeChange |
Maximum fee change per block | 0.25 (25%) |
WindowSize |
Window for derivative calculation | 10 blocks |
| Parameter | Description | Default Value |
|---|---|---|
TargetBlockSize |
Target gas usage per block | 15M gas |
BurstMultiplier |
Max capacity as multiple of target | 2.0 (30M gas max) |
InitialBaseFee |
Initial base fee | 1 Gwei |
MinBaseFee |
Minimum base fee | 0 |
RandomnessFactor |
Gaussian noise level | 0.1 (10%) |
# Clone the repository
git clone https://github.com/brianbland/feemarketsim
cd feemarketsim
# Build the simulator
go build -o feemarketsim cmd/simulator/main.go
# Or run directly
go run cmd/simulator/main.go# Compare all algorithms with default settings
./feemarketsim -adjuster-type=aimd -scenario=mixed -graph
./feemarketsim -adjuster-type=eip1559 -scenario=mixed -graph
./feemarketsim -adjuster-type=pid -scenario=mixed -graph
# Quick start with different algorithms
./feemarketsim -adjuster-type=aimd # AIMD with adaptive learning
./feemarketsim -adjuster-type=eip1559 # Standard Ethereum mechanism
./feemarketsim -adjuster-type=pid # PID controller approach# Conservative AIMD (stable fees, slow adaptation)
./feemarketsim -adjuster-type=aimd -aimd-gamma=0.5 -aimd-alpha=0.005 -window-size=20
# Aggressive AIMD (responsive fees, fast adaptation)
./feemarketsim -adjuster-type=aimd -aimd-gamma=0.1 -aimd-alpha=0.02 -window-size=5
# Custom learning rate range
./feemarketsim -adjuster-type=aimd -aimd-min-learning-rate=0.0001 -aimd-max-learning-rate=0.8# More aggressive proportional response
./feemarketsim -adjuster-type=pid -pid-kp=0.2
# Higher integral gain for steady-state accuracy
./feemarketsim -adjuster-type=pid -pid-ki=0.05
# More derivative action for faster response
./feemarketsim -adjuster-type=pid -pid-kd=0.1
# Complete PID tuning
./feemarketsim -adjuster-type=pid -pid-kp=0.15 -pid-ki=0.02 -pid-kd=0.08 -pid-max-fee-change=0.3# More aggressive fee changes
./feemarketsim -adjuster-type=eip1559 -eip1559-max-fee-change=0.2
# Conservative fee changes
./feemarketsim -adjuster-type=eip1559 -eip1559-max-fee-change=0.1# Fetch small range for testing
./feemarketsim fetch-base 12000000 12000010 test_data.json
# Fetch larger dataset (with confirmation prompt)
./feemarketsim fetch-base 12000000 12001000 base_data.json
# Fetch recent data
./feemarketsim fetch-base 18000000 18000500 recent_base.jsonFeatures:
- Concurrent fetching with configurable worker pools
- Exponential backoff retry with jitter protection
- Gap detection ensuring complete datasets
- Progress reporting with real-time statistics
- Large range warnings with user confirmation
# Test all algorithms against the same dataset
./feemarketsim simulate-base base_data.json -adjuster-type=aimd -graph
./feemarketsim simulate-base base_data.json -adjuster-type=eip1559 -graph
./feemarketsim simulate-base base_data.json -adjuster-type=pid -graph
# With custom parameters and logarithmic scale
./feemarketsim simulate-base base_data.json -adjuster-type=aimd -aimd-gamma=0.1 -graph -log-scale
./feemarketsim simulate-base base_data.json -adjuster-type=pid -pid-kp=0.15 -graph -log-scale-adjuster-type=aimd # AIMD - Adaptive learning rate algorithm
-adjuster-type=eip1559 # EIP-1559 - Standard Ethereum mechanism
-adjuster-type=pid # PID Controller - Industrial control system-target-block-size=15000000 # Target block size in gas units
-burst-multiplier=2.0 # Max burst capacity multiplier
-initial-base-fee=1000000000 # Initial base fee in wei
-min-base-fee=0 # Minimum base fee in wei-window-size=10 # Analysis window size in blocks
-aimd-gamma=0.25 # Learning rate adjustment threshold
-aimd-max-learning-rate=0.5 # Maximum learning rate
-aimd-min-learning-rate=0.001 # Minimum learning rate
-aimd-alpha=0.01 # Additive increase factor
-aimd-beta=0.9 # Multiplicative decrease factor
-aimd-delta=0.000001 # Net gas delta coefficient
-aimd-initial-learning-rate=0.1 # Initial learning rate-eip1559-max-fee-change=0.125 # Maximum fee change per block-window-size=10 # Window for derivative calculation
-pid-kp=0.02 # Proportional gain
-pid-ki=0.00001 # Integral gain
-pid-kd=0.01 # Derivative gain
-pid-max-integral=100.0 # Maximum integral value
-pid-min-integral=-100.0 # Minimum integral value
-pid-max-fee-change=0.25 # Maximum fee change per block-scenario=all # Scenario selection (full, empty, stable, mixed, all)
-graph # Generate visualization charts
-log-scale # Use logarithmic scale for Y-axis in charts
-help # Show detailed help- Sustained high congestion testing
- 180-200% of target capacity
- Tests aggressive fee increases across all algorithms
- Sustained low demand testing
- 2-13% of target capacity
- Tests fee reduction mechanisms and algorithm stability
- Long-term stability testing
- 85-115% of target capacity
- Tests different algorithms' ability to maintain steady fees
- Realistic traffic patterns
- Gradual transitions between states
- Tests adaptability and responsiveness of each algorithm
Each scenario can be run with different algorithms to compare:
- AIMD: Adaptive learning rate behavior and window-based analysis
- EIP-1559: Standard Ethereum baseline performance
- PID: Control system stability and response characteristics
Generated files include:
chart_[algorithm]_[scenario]_[params].html- Individual algorithm analysiscomparison_[scenario]_[algorithms].html- Multi-algorithm comparisonbase_comparison_[start]_[end].html- Real data comparisonbase_comparison_[start]_[end]_gas.html- Gas usage analysis
# Compare all algorithms on the same scenario
./feemarketsim -adjuster-type=aimd -scenario=mixed -graph
./feemarketsim -adjuster-type=eip1559 -scenario=mixed -graph
./feemarketsim -adjuster-type=pid -scenario=mixed -graph# AIMD parameter testing
./feemarketsim -adjuster-type=aimd -aimd-gamma=0.1 -aimd-alpha=0.02 # Aggressive
./feemarketsim -adjuster-type=aimd -aimd-gamma=0.5 -aimd-alpha=0.005 # Conservative
# PID controller tuning
./feemarketsim -adjuster-type=pid -pid-kp=0.2 # More aggressive P
./feemarketsim -adjuster-type=pid -pid-ki=0.05 # Higher integral gain
# EIP-1559 variants
./feemarketsim -adjuster-type=eip1559 -eip1559-max-fee-change=0.2 # More aggressive
./feemarketsim -adjuster-type=eip1559 -eip1559-max-fee-change=0.08 # More conservative# 1. Fetch blockchain data
./feemarketsim fetch-base 12000000 12001000 analysis.json
# 2. Test different algorithms on the same data
./feemarketsim simulate-base analysis.json -adjuster-type=aimd -graph
./feemarketsim simulate-base analysis.json -adjuster-type=eip1559 -graph
./feemarketsim simulate-base analysis.json -adjuster-type=pid -graph
# 3. Compare with parameter variations
./feemarketsim simulate-base analysis.json -adjuster-type=aimd -aimd-gamma=0.1 -graph
./feemarketsim simulate-base analysis.json -adjuster-type=pid -pid-kp=0.15 -graph# Test algorithm stability under different conditions
./feemarketsim -adjuster-type=aimd -scenario=stable -window-size=20
./feemarketsim -adjuster-type=eip1559 -scenario=stable
./feemarketsim -adjuster-type=pid -scenario=stable -pid-ki=0.001 # Low integral gain# Test response to sudden changes
./feemarketsim -adjuster-type=aimd -scenario=mixed -aimd-alpha=0.03
./feemarketsim -adjuster-type=pid -scenario=mixed -pid-kp=0.25
./feemarketsim -adjuster-type=eip1559 -scenario=mixed -eip1559-max-fee-change=0.25# Test different burst configurations across algorithms
./feemarketsim -adjuster-type=aimd -burst-multiplier=3.0 -aimd-gamma=0.1
./feemarketsim -adjuster-type=eip1559 -burst-multiplier=3.0
./feemarketsim -adjuster-type=pid -burst-multiplier=3.0 -pid-max-fee-change=0.3# Run all tests
go test ./...
# Run with coverage
go test -cover ./...
# Run specific package tests
go test ./pkg/simulator/
go test ./pkg/blockchain/
go test ./pkg/visualization/
# Test specific algorithms
go test ./pkg/simulator/ -run TestAdjusterTypes
go test ./pkg/simulator/ -run TestFactoryWithConfigs- Strengths: Adaptive learning, window-based analysis, handles sustained congestion well
- Use Cases: Networks with variable traffic patterns, when fine-tuned responsiveness is needed
- Tuning: Adjust gamma for responsiveness, alpha/beta for learning rate behavior
- Strengths: Simple, predictable, battle-tested on Ethereum mainnet
- Use Cases: Baseline comparison, production environments requiring proven stability
- Tuning: Limited to max fee change parameter
- Strengths: Control system theory foundations, good steady-state accuracy, configurable response
- Use Cases: When precise fee targeting is needed, systems requiring minimal overshoot
- Tuning: Classic PID tuning methods apply (Ziegler-Nichols, etc.)
To add a new fee adjustment algorithm:
- Implement the
FeeAdjusterinterface inpkg/simulator/ - Add configuration struct following existing patterns
- Update the factory in
pkg/simulator/factory.go - Add CLI flags in
pkg/config/config.go - Add tests in
pkg/simulator/
# Test against all scenarios
./feemarketsim -adjuster-type=your-algorithm -scenario=all -graph
# Compare against existing algorithms
./feemarketsim -adjuster-type=your-algorithm -scenario=mixed -graph
./feemarketsim -adjuster-type=aimd -scenario=mixed -graph
./feemarketsim -adjuster-type=eip1559 -scenario=mixed -graph
# Test with real data
./feemarketsim simulate-base your_data.json -adjuster-type=your-algorithm -graph