Tangle-SG
DAG-Based Distributed Ledger for Microgrid Energy Transactions

Abstract
Tangle-SG is a decentralized, DAG-based ledger system designed for microgrid energy transactions. It implements a directed acyclic graph (DAG) where transactions are organized as vertices with parent-child relationships, enabling parallel transaction processing and asynchronous consensus without requiring a global ordering mechanism like blockchain. The system features dual-signature validation, proof-of-work consensus, auto-peering via UDP broadcast with HMAC-based handshake, and real-time telemetry collection.
Problem Statement
Traditional blockchain systems face scalability limitations due to their linear block structure and global consensus requirements. For microgrid energy trading scenarios, these limitations create bottlenecks: slow transaction confirmation, high energy consumption from mining, and inability to handle parallel transactions. A new architecture was needed that could support high-throughput, low-latency energy transactions in a decentralized peer-to-peer network.
Key Challenges
- ●Blockchain linear structure limits transaction throughput
- ●Global consensus mechanisms create latency bottlenecks
- ●High energy consumption from proof-of-work mining
- ●No support for parallel transaction processing
- ●Centralized mining pools undermine decentralization
- ●Complex peer discovery in dynamic network environments
Solution
Tangle-SG addresses these challenges through a DAG-based architecture where transactions reference multiple parent transactions, enabling parallel processing and asynchronous consensus. The system implements dual-signature validation (both sender and receiver must approve), minimal proof-of-work for spam prevention, UDP-based auto-peering with HMAC authentication, and cumulative weight-based finality.
Key Design Principles
- ●Decentralized: No central authority; all nodes are peers
- ●Permissionless: Any node can join and participate
- ●Dual-Signature: Both sender and receiver must cryptographically approve transactions
- ●Proof-of-Work: Minimal PoW at each phase to prevent spam
- ●Asynchronous Consensus: Cumulative weight-based finality without explicit consensus rounds
High-Level Architecture
Module Organization
1src/2├── headers/3│ ├── transaction.h # Transaction data structures4│ ├── tangle.h # DAG storage and operations5│ ├── network.h # WebSocket communication6│ ├── peers2.h # Peer management7│ ├── peerDiscovery.h # Auto-peering via UDP8│ ├── pow.h # Proof-of-Work9│ ├── telemetry.h # Metrics collection10│ └── utils.h # Utilities11├── modules/12│ ├── transaction.cpp # Transaction signing & verification13│ ├── tangle.cpp # DAG operations14│ ├── network.cpp # WebSocket server/client15│ ├── peers2.cpp # Peer state management16│ ├── peerDiscovery.cpp # UDP-based discovery17│ ├── pow.cpp # SHA256-based PoW18│ └── telemetry.cpp # Metrics collection19└── main.cpp # Application entry
Architecture
Core Components
1. Transaction Structure
Transactions in Tangle-SG consist of immutable data and mutable metadata. The data structure contains sender, receiver, amount, and parent references. The metadata tracks approval state, signatures, and consensus progress.
1struct tx_data {2std::string transaction_id; // Unique ID3std::string sender; // Sender node UID4std::string receiver; // Receiver node UID5double amount; // Energy units6std::string unit; // Unit type (e.g., kWh)7double price_per_unit; // Tariff rate8std::string currency; // Currency code9int64_t timestamp; // Creation timestamp10std::vector<std::string> parents; // Parent transaction refs11};1213struct tx_metadata {14int64_t lastUpdated; // Last modification15std::unordered_set<std::string> weightMap;16int cumulative_weight; // Total approvals17std::string signature1; // Sender signature18std::string signature2; // Receiver signature19std::string checksum; // Integrity hash20int64_t consensusTimestamp; // When consensus reached21std::vector<std::pair<int64_t, std::string>> hops;22};
2. Tangle (DAG Storage)
The Tangle class manages the entire DAG with thread-safe operations. It provides O(1) insertion and lookup using hash maps, with recursive weight propagation for parent updates.
3. Network Module
Handles all peer communication via WebSocket with dual client/server architecture for bidirectional communication, peer monitoring with health checks, orphan pool for missing parents, and message queuing for disconnected peers.
Transaction Lifecycle
DAG Structure & Consensus
The DAG has four key properties: Directed (edges point from child to parent), Acyclic (no cycles due to timestamp ordering), Weighted (cumulative weight represents approval count), and Immutable (transaction data never changes).
Tip Selection Algorithm
The system uses weighted random selection from preferred tips. Tips with cumulative_weight > threshold AND both signatures present are preferred. This encourages building on approved transactions and prevents spam.
Consensus Mechanism
Asynchronous, weight-based finality without explicit consensus rounds. Higher cumulative weight equals higher confidence in transaction confirmation. Probabilistic finality emerges as weight accumulates across the network.
Implementation
Auto-Peering Mechanism
Tangle-SG uses UDP broadcast-based peer discovery with HMAC-based handshake for secure, decentralized peer finding. The three-phase handshake prevents replay attacks and ensures both nodes share the authentication secret.
Transaction Broadcasting
The broadcasting strategy uses WebSocket for real-time communication with JSON serialization. The system handles orphan transactions (those with missing parents) through an orphan pool, and provides message queuing for disconnected peers to prevent message loss.
1{2"type": "TRANSACTION",3"payload": {4"data": {5"transaction_id": "1234567890_nodeA_nodeB",6"sender": "nodeA",7"receiver": "nodeB",8"amount": 10.5,9"unit": "kWh",10"price_per_unit": 5.0,11"currency": "USD",12"timestamp": 1234567890,13"parents": ["parent1_id", "parent2_id"]14},15"metadata": {16"cumulative_weight": 3,17"signature1": "base64_encoded_sig1",18"signature2": "base64_encoded_sig2",19"hops": [20{"timestamp": 1234567890, "uid": "nodeA"},21{"timestamp": 1234567891, "uid": "nodeB"}22]23}24}25}
Performance Characteristics
Estimated Throughput
Time complexity for core operations: Add Transaction O(1), Get Transaction O(1), Update Weight O(d) where d = DAG depth, Broadcast O(p) where p = number of peers, Tip Selection O(t) where t = number of tips.
1Sender PoW: 10-100 ms (depends on difficulty)2Broadcast: 10-50 ms (network latency)3Receiver Processing: 1-5 ms4Receiver PoW: 10-100 ms5Broadcast Approval: 10-50 ms6Verification: 1-2 ms7Weight Propagation: 1-50 ms (depends on DAG depth)8─────────────────────────────9Total: 43-357 ms (typical: 100-150 ms)
Results
Tangle-SG successfully demonstrates a viable alternative to blockchain for microgrid energy trading. The DAG-based architecture enables parallel transaction processing, dual-signature validation ensures both parties approve transactions, and the auto-peering mechanism allows dynamic network formation without central coordination.
Research Impact
Caveats & Limitations
Known Limitations
- ●Finality threshold not fully implemented - transactions remain pending indefinitely
- ●Centralized tip selection vulnerable to tip-splitting attacks
- ●No transaction pruning mechanism - Tangle grows indefinitely
- ●Weak Sybil attack resistance due to low PoW difficulty
- ●No partition tolerance - network partitions cause divergent DAGs
- ●Peer discovery limited to local subnet via UDP broadcast
Future Scope
- ●Implement finality threshold and snapshot mechanism for pruning
- ●Add weighted random walk (MCMC) for tip selection
- ●Implement Byzantine Fault Tolerance (BFT) for partition tolerance
- ●Add reputation system and stake-based identity binding
- ●Implement DHT-based peer discovery for WAN deployment
- ●Add sharding and state channels for scalability
Key Metrics
Conclusion
Tangle-SG demonstrates that DAG-based architectures can provide viable alternatives to traditional blockchain for specific use cases like microgrid energy trading. While limitations exist around finality and partition tolerance, the system successfully implements core DAG concepts including parallel transaction processing, asynchronous consensus, and decentralized peer discovery. Future work should address the identified limitations to make the system production-ready.
