"The result is a distributed timestamped server which provides proof for financial records without exposing information beyond what is necessary."
Lightning Routing & Forwarding
Routing is the process of finding a path across the Lightning Network to send a payment between two nodes that don't have a direct channel. Nodes that participate in relaying these payments are called routing nodes, and they earn small fees for providing this service.
Routing Fundamentals
Understanding how routing works is essential for both sending payments efficiently and operating a successful routing node.
Key Concepts
- Network Graph: Nodes maintain a map of public channels and their policies (fees, capacity, etc.).
- Source Routing: The *sender's* node calculates the entire path before sending the payment.
- Onion Routing: Payment instructions are encrypted layer-by-layer, so each hop only knows the previous and next node, enhancing privacy.
- HTLCs: Payments along the route are secured by Hashed Time-Locked Contracts, ensuring atomicity (either the whole payment succeeds or fails).
- Liquidity: A route is only viable if every channel along the path has sufficient balance in the correct direction.
Routing Fees
- Base Fee: A flat fee charged per forwarded payment (HTLC), regardless of amount.
- Fee Rate: A proportional fee based on the payment amount (usually measured in ppm - parts per million).
- Node Policy: Each node sets its own fee policy for its channels.
- Market Dynamics: Fees are influenced by supply (available liquidity) and demand (payment volume).
- Sender Pays: The total fee for the route is included in the amount the sender initially sends.
Pathfinding Challenge
Finding the optimal route involves balancing low fees, sufficient capacity, node reliability (uptime), and path length. This is a complex calculation performed by the sender's node using its view of the network graph.
The Routing Process Step-by-Step
1. Pathfinding
Sender's node queries its network graph data to find potential paths to the recipient, considering fees, capacity, and hop count.
2. Onion Construction
Sender creates the layered 'onion' packet containing encrypted instructions for each hop (next peer, amount to forward, CLTV delta).
3. HTLC Forwarding
Sender adds an HTLC to the first channel. Each intermediate node receives the onion, decrypts its layer, learns the next hop, updates the HTLC (lowers amount by its fee, reduces CLTV), and forwards to the next peer.
4. Preimage Release
Recipient receives the final HTLC. To claim the funds, they reveal the payment preimage (secret) to the last intermediate node.
5. Settlement Cascade
The preimage travels back along the route. Each node uses it to claim the incoming HTLC from the previous node, effectively settling the payment hop-by-hop back to the sender.
If any hop fails (e.g., insufficient capacity, node offline), an error message propagates back, the HTLCs time out or are cancelled, and the sender can attempt a different route. The funds are never lost due to the HTLC mechanism.
Operating a Routing Node
Running a successful routing node involves more than just being online. It requires active management and optimization.
Uptime & Reliability
Consistent uptime is paramount. Offline nodes can't route payments and hurt the reliability of paths involving them.
Capital & Liquidity
Sufficient capital allocated to well-placed, balanced channels is crucial for handling routing volume.
Fee Strategy
Set competitive but sustainable fees. Monitor flows and adjust fees to manage liquidity and maximize earnings.
Balanced Channels
Actively manage channel liquidity (rebalancing) so channels can forward payments in both directions.
Connectivity
Connect to diverse, well-connected peers to position your node strategically within the network graph.
Monitoring & Automation
Use tools (RTL, Thunderhub, scripts) to monitor performance, automate fee adjustments, and manage channels.
Running a routing node can be complex and requires ongoing effort. Start small, learn the dynamics, and gradually scale your operations.