Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

lightning-routing

/lightning-routing

Opisuje wyszukiwanie tras w Lightning: modele kosztów, MPP, AMP, trampoline, ukryte ścieżki, prawdopodobieństwo apriori i pickhardt-payments, przy strojeniu algorytmu i błędach braku trasy.

Licencja
MIT
Ostatnia zmiana repozytorium
21.10.2026

Ocena i bezpieczeństwo

95/ 100Klasa: dobry
Format20 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 21.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Opisuje wyszukiwanie tras w Lightning: modele kosztów, MPP, AMP, trampoline, ukryte ścieżki, prawdopodobieństwo apriori i pickhardt-payments, przy strojeniu algorytmu i błędach braku trasy.

Wyzwalacze z opisu

no route
Oryginalny opis (EN)

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.

Jak działa

  1. Channel graph
  2. Cost function
  3. Multi-Path Payments (MPP)
  4. Atomic Multi-Path (AMP)
  5. Trampoline routing
  6. Blinded paths (BOLT 4 update, BOLT12)
  7. Pickhardt payments (probabilistic)
  8. CLTV calculation
  9. Failure handling
  10. Common failure types (BOLT 4)
Sekcje z nagłówków SKILL.md, w oryginale · 158 linii, 678 słów
Podgląd SKILL.md
---
name: lightning-routing
description: |
  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.
allowed-tools: Read, Grep, Glob
---

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

Wersje

W bazie nie ma innych skilli o nazwie lightning-routing.

Migawka bazy z 28.10.2026 · wersja paczki 0fac046b5229 (skrót SHA-256 całej paczki)

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 95lightning-trampoline
    Opisuje routing trampoline, który zleca wyszukiwanie tras węzłom pośrednim dla klientów bez pełnego grafu, z Eclair jako wdrożeniem referencyjnym i stanem PR #836 do BOLT.
  • 95lightning-amp-mpp
    Opisuje płatności wielościeżkowe MPP i AMP w sieci Lightning: dzielenie płatności na równoległe trasy, wspólny hash lub osobne hashe części oraz diagnozę problemów z routingiem pełnej kwoty.
  • 100mpp
    Pomaga budować rozwiązania z MPP (Machine Payments Protocol), czyli płatnościami maszyna do maszyny przez HTTP 402, dla płatnych API, agentów i rozliczeń naliczanych z SDK mppx, pympp i Rust.
  • 100mpp-setup
    Tworzy szkielet projektu MPP: instaluje SDK mppx, konfiguruje metody płatności i middleware serwera oraz przygotowuje podstawowy płatny endpoint API.
  • 100mpp-stripe-method
    Konfiguruje Stripe jako metodę płatności MPP: płatności kartą i portfelem przez Shared Payment Tokens, z integracją przepływu HTTP 402 z infrastrukturą płatniczą Stripe.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.