This project is a Go implementation of a blockchain using Proof of Authority (PoA) consensus with asynchronous and parallel transaction execution. It demonstrates the entire workflow from transaction submission to state verification, with particular focus on optimizing execution performance.
This implementation includes several optimizations and improvements over the initial version:
-
Fixed Block Validation Logic: Corrected validation issues to ensure validators properly accept valid blocks regardless of proposer.
-
Optimized Parallel Execution:
- Worker pool implementation to reduce goroutine creation overhead
- Batch processing based on transaction dependencies
- Improved conflict detection to avoid false positives
- Transaction grouping for better parallelism
-
Adaptive Execution Strategy:
- Dynamic switching between sequential and parallel execution based on batch size
- Configurable threshold for minimum batch size to use parallel execution
- Special handling for compute-intensive transactions
-
Improved Speculative Execution:
- Better validation of speculative results
- Transaction dependency analysis for more accurate speculation
- Mempool snapshots to validate speculative results
-
Benchmarking and Analysis Tools:
- Detailed performance metrics collection
- Transaction timing analysis
- Conflict rate monitoring
├── block/ # Block structure and operations
├── blockchain/ # Core blockchain engine
├── config/ # Configuration parameters
├── execution/ # Parallel execution engine
├── performance/ # Benchmarking tools
├── state/ # State management
├── transaction/ # Transaction operations
├── validator/ # Validator operations
├── visualization/ # Visualization utilities
└── main.go # Simulation entry point
The simulation can be configured with various options to test different scenarios:
# Run with default settings
go run main.go
# Run with simple transactions (sequential execution preferred)
go run main.go --test-mode=small
# Run with compute-intensive transactions (parallel execution beneficial)
go run main.go --test-mode=complex --compute=true --complexity=10
# Run with custom parameters
go run main.go --txs=1000 --block-size=100 --workers=8 --min-batch=30
--txs
: Number of transactions to generate (default: 500)--block-size
: Size of each block in transactions (default: 50)--workers
: Number of parallel worker threads (default: CPU cores)--min-batch
: Minimum batch size for parallel execution (default: 20)--compute
: Simulate compute-intensive transactions (default: false)--complexity
: Computation complexity level (1-20, default: 1)--sequential-only
: Disable parallel execution (default: false)--test-mode
: Test mode (small/medium/complex/mixed, default: mixed)
The simulation generates different transaction patterns to test execution strategies:
-
Independent Transactions:
- Different senders and recipients
- Highly parallelizable
- Best case for parallel execution
-
Sequential Transactions:
- Same sender with increasing nonces
- Strong sequential dependencies
- Worst case for parallel execution
-
Complex Patterns:
- Circular transfers (A→B→C→A)
- Many-to-one transfers (many senders, one recipient)
- One-to-many transfers (one sender, many recipients)
- Tests dependency analysis and execution ordering
- Leader proposes a new block containing transactions
- Validators verify the block structure without executing transactions
- If valid, validators sign the block
- When enough signatures are collected (quorum), the block is voted
- When the next block is voted, the previous block is finalized
- Finalized blocks enter the execution queue
- Transactions are executed in parallel or sequentially based on adaptive strategy
- State root is calculated and stored
- D blocks later, the state root is verified against the delayed root in a future block
- Transactions are analyzed for dependencies
- Independent transactions are grouped into batches
- Batches are executed in parallel by worker pool
- Results are merged and conflicts are resolved
- Final state is updated with all changes
The simulation includes comprehensive performance analysis:
-
Sequential vs. Parallel Comparison:
- Execution time comparison
- Success rate analysis
- Conflict detection and resolution
-
Transaction Metrics:
- Min/max/median execution times
- Conflict rates and patterns
- Re-execution statistics
-
Adaptive Strategy Effectiveness:
- Analysis of when parallel execution is beneficial
- Overhead measurement
- Batch size impact
# Clone the repository
git clone https://github.com/yourusername/asynchronous-execution-simulation.git
cd asynchronous-execution-simulation
# Build the project
go build
# Run the simulation
./asynchronous-execution-simulation
# Or with specific configuration
./asynchronous-execution-simulation --test-mode=complex --compute=true --complexity=15 --workers=8
The simulation will output:
- Transaction generation logs
- Block proposal and voting results
- Execution performance statistics
- Comparative benchmarks between sequential and parallel execution
- Final blockchain state analysis
For compute-intensive transactions, parallel execution typically shows significant speedup (1.5-10x). For simple transactions, sequential execution is often faster due to lower overhead.
- This is a simulation - in a production environment, additional security and robustness measures would be required
- Network communication between nodes is simulated within a single process
- The PoA consensus mechanism is simplified for demonstration purposes
- Transaction execution is simulated and can be configured for different complexity levels
MIT