Skip to content

KevinKien/asynchronous-execution-simulation

Repository files navigation

Blockchain PoA with Asynchronous & Parallel Execution

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.

Key Improvements

This implementation includes several optimizations and improvements over the initial version:

  1. Fixed Block Validation Logic: Corrected validation issues to ensure validators properly accept valid blocks regardless of proposer.

  2. 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
  3. 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
  4. Improved Speculative Execution:

    • Better validation of speculative results
    • Transaction dependency analysis for more accurate speculation
    • Mempool snapshots to validate speculative results
  5. Benchmarking and Analysis Tools:

    • Detailed performance metrics collection
    • Transaction timing analysis
    • Conflict rate monitoring

Architecture

├── 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

Configuration Options

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

Command-line Flags

  • --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)

Transaction Types

The simulation generates different transaction patterns to test execution strategies:

  1. Independent Transactions:

    • Different senders and recipients
    • Highly parallelizable
    • Best case for parallel execution
  2. Sequential Transactions:

    • Same sender with increasing nonces
    • Strong sequential dependencies
    • Worst case for parallel execution
  3. 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

Execution Process

Block Consensus

  1. Leader proposes a new block containing transactions
  2. Validators verify the block structure without executing transactions
  3. If valid, validators sign the block
  4. When enough signatures are collected (quorum), the block is voted
  5. When the next block is voted, the previous block is finalized

Asynchronous Execution

  1. Finalized blocks enter the execution queue
  2. Transactions are executed in parallel or sequentially based on adaptive strategy
  3. State root is calculated and stored
  4. D blocks later, the state root is verified against the delayed root in a future block

Parallel Execution

  1. Transactions are analyzed for dependencies
  2. Independent transactions are grouped into batches
  3. Batches are executed in parallel by worker pool
  4. Results are merged and conflicts are resolved
  5. Final state is updated with all changes

Performance Analysis

The simulation includes comprehensive performance analysis:

  1. Sequential vs. Parallel Comparison:

    • Execution time comparison
    • Success rate analysis
    • Conflict detection and resolution
  2. Transaction Metrics:

    • Min/max/median execution times
    • Conflict rates and patterns
    • Re-execution statistics
  3. Adaptive Strategy Effectiveness:

    • Analysis of when parallel execution is beneficial
    • Overhead measurement
    • Batch size impact

How to Run the Simulation

# 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

Expected Results

The simulation will output:

  1. Transaction generation logs
  2. Block proposal and voting results
  3. Execution performance statistics
  4. Comparative benchmarks between sequential and parallel execution
  5. 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.

Implementation Notes

  • 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

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages