lightning-routing
Lightning pathfinding and routing: cost models, MPP / AMP / trampoline, blinded paths (BOLT 4 update), apriori probability, pickhardt-payments. USE WHEN: implementing/tuning a routing algorithm, debugging "no route" errors, evaluating pathfinding strategies.
What this skill does
# Lightning Routing
Lightning is a **source-routed** network: the sender computes the full
path through intermediaries and constructs the onion accordingly. Each
hop sees only its forwarding instructions, not the full route.
## Channel graph
Built from `channel_announcement` + `channel_update` gossip:
```
Edge {
short_channel_id,
node_a, node_b,
capacity (from on-chain funding tx),
per-direction:
fee_base_msat,
fee_proportional_millionths (PPM),
cltv_expiry_delta,
htlc_minimum_msat, htlc_maximum_msat,
enabled flag,
}
```
Each edge has TWO directions, each with potentially different fees
and CLTV deltas.
## Cost function
Standard scoring (LND, CLN, LDK):
```
cost(edge, amount) =
base_fee_msat
+ (proportional_millionths × amount) / 10^6
+ cltv_delta × cltv_factor
+ amount × probability_factor / 10^6 × ln(1 / p_success)
```
`p_success` (apriori probability of success) often defaults to 95% for
unknown edges, decreasing with recent failures.
Pathfinder: Dijkstra or Yen's k-shortest-paths over the cost function.
## Multi-Path Payments (MPP)
Split a payment across multiple paths; each part has the same payment
hash. Receiver claims when **all** parts arrive.
`payment_secret` (BOLT 11 's' tag) marks parts as belonging to one
payment.
`max_parts` typically 16 in LND, configurable. Smaller parts =
higher likelihood of finding routes; more onion overhead.
## Atomic Multi-Path (AMP)
Each "part" has a *different* payment hash, computed deterministically
from a shared secret + per-part nonce. Receiver computes secret from
any t-of-n parts (Shamir-like). Variant of MPP, less common in
production.
## Trampoline routing
Solves: pathfinding requires complete network gossip → mobile clients
can't keep up.
Mechanism:
- Sender constructs onion targeting **trampoline nodes**.
- Each trampoline does its own pathfinding to the next trampoline /
destination.
- Sender doesn't need full graph; just knows about trampoline nodes.
CLN, LDK support; LND partial.
## Blinded paths (BOLT 4 update, BOLT12)
Receiver constructs a "blinded path" — a partial route that hides the
final destination. Sender's pathfinder routes to the blinded path's
**introduction node**, then onion delivers via blinded routing data.
Privacy benefit: sender doesn't learn receiver's node id.
## Pickhardt payments (probabilistic)
Research direction (Pickhardt-Nowostawski 2021):
- Treat routing as min-cost-flow problem.
- Cost incorporates probability of channel having sufficient
liquidity at the moment.
- Optimization: maximize success probability under some fee budget.
CLN and LDK have implementations; experimental in production.
## CLTV calculation
For a 3-hop route Alice → Bob → Carol → Dave:
```
final_cltv = current_height + min_final_cltv_expiry_delta + payment_secret_buffer
carol_cltv = final_cltv + carol.cltv_expiry_delta
bob_cltv = carol_cltv + bob.cltv_expiry_delta
alice_cltv = bob_cltv + alice's_safety_margin
```
`alice_cltv` is what's set in Alice's first HTLC.
## Failure handling
When a hop fails:
- Returns `update_fail_htlc` with encrypted error message.
- Sender decrypts, learns:
- Which hop failed.
- Failure type (channel disabled, fee insufficient, expiry
mismatch, no liquidity, etc.).
- Sender's pathfinder updates its scoring (decrease p_success on
failed edge) and retries with different path.
## Common failure types (BOLT 4)
- `temporary_channel_failure` — try again later.
- `permanent_channel_failure` — drop this edge.
- `fee_insufficient` — your fee assumption was off; retry with more
fee.
- `channel_disabled` — peer marked channel disabled, drop edge.
- `expiry_too_soon` / `incorrect_cltv_expiry` — CLTV mismatch.
- `incorrect_or_unknown_payment_details` — destination doesn't
recognize this payment hash (BOLT 11 invoice expired or wrong).
- `final_incorrect_htlc_amount` — receiver doesn't recognize amount
(MPP not assembled correctly).
## Implementations
| Algorithm | LND | CLN | LDK |
|-----------|-----|-----|-----|
| Dijkstra | yes | yes | yes |
| Multi-path (MPP) | yes | yes | yes |
| AMP keysend | yes | partial | yes |
| Trampoline | partial | yes | yes |
| Blinded paths | yes | yes | yes |
| Pickhardt-style | partial | yes | yes |
## Common bugs
- Hardcoding `cltv_factor` → routes prefer few-hop high-fee paths
vs many-hop low-fee.
- Treating `htlc_maximum_msat = 0` as "infinite" → all routes
rejected (it means "no max" only when set to channel capacity).
- Stale `channel_update` cached → routing through a channel that's
been disabled an hour ago.
- Privacy: pathfinder leaking through timing attacks (test all hops
but route only first part).
## See also
- [bolts/SKILL.md](../bolts/SKILL.md)
- [onion/SKILL.md](../onion/SKILL.md)
- [gossip/SKILL.md](../gossip/SKILL.md)
- [trampoline/SKILL.md](../trampoline/SKILL.md)
- [amp-mpp/SKILL.md](../amp-mpp/SKILL.md)
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.