Skip to content

Repository files navigation

TXGraph - DAG-Based Concurrent Executor for Blockchain Systems

License: MITBuild StatusGo

Contributions Welcome

Built to answer:How do you execute millions of smart contract transactions — concurrently — without breaking determinism?


🔍 Overview

TXGraph is a high‑performance, DAG‑based concurrent transaction executor designed for Layer 1 blockchains, rollups, and smart contract runtimes.
It analyzes read/write conflicts, builds a Directed Acyclic Graph (DAG) of dependencies, and schedules transactions for safe parallel executionpreserving determinism while unlocking massive scalability.


🚀 Features

  • DAG‑driven Scheduling – Detects conflicts and orders execution deterministically.
  • Safe Parallel Execution – Executes non‑conflicting transactions across multiple cores.
  • Deterministic Results – Identical output as a valid sequential run.
  • State Isolation – Versioned, concurrency‑safe state transitions.
  • Multi‑Backend Support – In‑memory, RocksDB, and Merkle‑tree backends.
  • Metrics & Observability – Prometheus/Grafana ready. --

🔹 Executive Summary

TXGraph is a concurrency-aware, dependency-tracking transaction executor built to address the core scalability challenge in blockchain and smart contract platforms: safe parallelism without sacrificing determinism.

Traditional systems execute transactions sequentially, leaving modern multi-core systems underutilized. TXGraph unlocks parallel execution by intelligently analyzing read/write conflicts and dynamically orchestrating non-conflicting transactions across worker threads.

It ensures correctness, observability, and scalability, making it an ideal backbone for:

  • Layer 1/2 blockchain nodes (EVM, WASM, UTXO)
  • Rollup sequencers
  • Parallelized smart contract runtimes
  • Blockchain simulation/testnet environments

🎯 Project Goals & Design Principles

ObjectiveDescription
Concurrency-FirstMaximize parallelism while preventing unsafe race conditions
Determinism-PreservingGuarantee identical results as a canonical sequential execution
Robust Fault ToleranceIsolate and report individual transaction errors
Horizontal ScalabilityScale execution across CPU cores
Memory EfficiencyUse lazy evaluation and snapshots to scale to millions of state entries
ExtensibilityModular support for different virtual machines or state backends

🔗 System Overview

+--------------+ +----------------+ +------------------+ +-------------+ +-----------------+
| Input Queue | --> | RW Set Analyzer| --> | DAG Scheduler | --> | Worker Pool | --> | Result Aggregator|
+--------------+ +----------------+ +------------------+ +-------------+ +-----------------+

🔗 Achitecture Design (System level)

%%{
init: {
'theme': 'base',
'themeVariables': {
'primaryColor': '#BB2528',
'primaryTextColor': '#fff',
'primaryBorderColor': '#7C0000',
'lineColor': '#F8B229',
'secondaryColor': '#006100',
'tertiaryColor': '#fff',
'lineWidth': 8,
'fontSize':30
}
}
}%%
flowchart TD
A[Input Queue<br/>Tx1, Tx2, ..., TxN] --> B[Dependency Analyzer<br/>Extract RW Sets<br/>Build Conflict Graph]
B --> C[Scheduler<br/>Topological Sorting<br/>Wavefront Batching]
subgraph Worker Pool [Parallel Worker Pool]
D1[Worker 1<br/>Isolated State View]
D2[Worker 2<br/>Isolated State View]
D3[Worker N<br/>Isolated State View]
end
C --> D1
C --> D2
C --> D3
D1 --> E[Global State Manager<br/>Thread-Safe Write Buffer<br/>Versioned State]
D2 --> E
D3 --> E
E --> F[Result Collector<br/>Reorder Results<br/>Aggregate Errors<br/>Commit Final State]
F --> G[Final Output<br/>State Root, Logs, Metrics]
style Worker_Pool fill:#f9f,stroke:#333,stroke-width:1px
Loading

🧩 Component Highlights

  • Input Queue
    Receives and stores the incoming batch of transactions for execution.

  • Dependency Analyzer
    Extracts read/write sets for each transaction and constructs a Directed Acyclic Graph (DAG) to represent execution dependencies based on conflicts.

  • Scheduler
    Performs topological sorting of the DAG and groups non-conflicting transactions into parallelizable wavefronts.

  • Worker Pool
    A fixed-size or dynamically scalable pool of workers that execute independent transactions concurrently using isolated or versioned state views.

  • Global State Manager
    Maintains a thread-safe, versioned view of application state. Applies transaction state deltas while enforcing serialization of conflicting writes.

  • Result Collector
    Aggregates execution results, reorders them to match input sequence, logs successes/failures, and commits the final state root.


🧱 Core Components

Transaction Model

structTransaction{id:u64,from:Address,to:Option<Address>,reads:Vec<Address>,writes:Vec<Address>,payload:Vec<u8>,}

Dependency Graph Builder

  • Builds DAG from RW conflicts
  • Uses bloom filters or hashmaps for quick overlap detection
  • Conflict if: Tj.writes ∩ Ti.reads ∪ Ti.writes ≠ ∅ → Tj → Ti

Scheduler

  • Topologically sorts DAG
  • Identifies wavefront of independent transactions
  • Dispatches batches to worker threads
  • Balances load with queues or work-stealing

Worker Engine

  • Each worker has isolated state view
  • Executes transaction and returns:
    • Status
    • Logs
    • Modified state
    • Errors (if any)

Global State Manager

  • Versioned state
  • Copy-on-write, shadow states
  • Final commit based on dependency ordering
  • Supports backends: in-memory, RocksDB, MerkleDB

📁 Directory Layout

TXGraph/
├── cmd/
│ └── app/
│ └── main.go # Entry point: wiring everything together
│
├── internal/
| |── api/
│ | └── grpc/
│ | └── executor.proto # Optional: gRPC service definition
│ │ ├── core/
│ │ ├── dependency_graph.go # DAG builder from RW conflict sets
│ │ ├── scheduler.go # Topological scheduler
│ │ └── state_manager.go # Versioned state manager
│
│ ├── executor/
│ │ ├── worker.go # Worker logic and state isolation
│ │ ├── pool.go # Worker pool manager
│ │ └── isolation.go # View-based state access
│
│ ├── model/
│ │ ├── transaction.go # Transaction struct, payload, read/write sets
│ │ └── result.go # Execution result, gas, logs, errors
│
│ ├── utils/
│ │ ├── analyzer.go # ABI or bytecode analyzer for RW sets
│ │ ├── metrics.go # Prometheus/Grafana instrumentation
│ │ └── logging.go # Structured logger (zap/logrus)
│
│ ├── storage/
│ │ ├── memstore.go # In-memory backend for state storage
│ │ ├── rocksdb_store.go # RocksDB-based state backend
│ │ └── merkle_backend.go # Optional: Merkle tree or SMT storage
│
├── examples/
│ └── simple_chain/
│ └── main.go # Simulates running the executor with mock txs
│
├── benchmarks/
│ └── throughput_test.go # Benchmarking different tx loads
│
├── go.mod # Go module definition
├── go.sum
└── README.md # Project documentation

🔍 Execution Flow Example

Tx1: R[A], W[B]
Tx2: R[B], W[C]
Tx3: R[D], W[E]
Tx4: R[C], W[F]
DAG:
Tx1 → Tx2 → Tx4
Tx3 (independent)
Execution Waves:
Wave 1: Tx1, Tx3
Wave 2: Tx2
Wave 3: Tx4

📊 Performance & Scalability

MetricTarget
Throughput100,000 tx/sec on 8-core machine
DAG Build Time<1ms per 1000 transactions
Conflict DetectionOptimized with bloom filters or maps
Memory OverheadMinimal with copy-on-write + caching
Latency Spread90% transactions complete in under 5ms

🔒 Correctness Guarantees

PropertyDescription
SerializabilityExecution matches some valid serial schedule
LinearizabilitySlot-level version control ensures atomic transitions
DeterminismSame input → same DAG → same state
AtomicityPer-transaction isolation with rollback on failure
ProgressNo starvation or deadlocks

🚀 Future Enhancements

FeatureDescription
Speculative ExecutionRollback support for optimistic concurrency
Dynamic TracingRuntime RW detection via VM hooks
Distributed ExecutionMulti-node DAG partitioning and execution
GPU AccelerationCUDA/OpenCL batch execution pipeline
DAG VisualizationTooling for graph rendering and inspection

🧪 Testing and Benchmarks

  • Unit & property tests with quickcheck
  • Integration tests with synthetic transaction batches
  • Profiling with criterion.rs
  • Metrics via Prometheus

🛠️ Recommended Tech Stack

  • Language: Rust (Tokio, Petgraph, Rayon)
  • Storage: RocksDB, Redis, MerkleDB
  • Graph: Petgraph DAG
  • State Isolation: COW maps, version clocks
  • Concurrency: RwLocks, work-stealing, crossbeam

🔌 Integration Targets

  • Layer 1 clients (EVM, MoveVM)
  • Layer 2 rollups (OP, ZK)
  • Smart contract platforms
  • Off-chain simulation frameworks
  • Parallel local development tools

📘 License

MIT License. Open source roadmap planned under TXGraph.dev.


💡 Why TXGraph?

TXGraph enables truly parallel blockchain computation — with safety, determinism, and performance guarantees — serving as the foundation of next-generation execution engines.

It’s not just faster — it’s correctly faster.

Memory efficiency for large state sizes

Releases

Packages

Contributors

Languages