Feedback
Sign in./start

Site navigation

Theme

Learn

  • Roadmaps

Build

  • Projects
  • Developer Tools

Contribute

  • Open Source Projects
  • Issues
  • Reviews
  • First Contribution
  • BountiesSoon
  • Feedback

Prove

  • Builders

Ecosystem

  • Partners
  • Get Funded↗
  • HackathonsSoon
Sign in./start-building

Become an Open Source Builder. Learn. Build. Contribute. Prove.

Feedback welcome — open a GitHub issue.

Learn

RoadmapsStart Building

Build

ProjectsDeveloper Tools

Contribute

Open Source ProjectsIssuesReviewsFirst ContributionSupportFeedback

Prove

Builders Directory

Account

Sign in

Legal

PrivacyTermsCredits

© 2026 Pull // code MIT · curriculum CC BY-SA 4.0

PrivacyTermsCredits

lesson // lightning

HTLC Mechanics

Trace payment hashes and timelocks across multi-hop routes.

advanced6 days

Public lesson — sign in to track progress on this roadmap.

./sign-in

On this page

Learning objectives

  • Trace a multi-hop HTLC forward and backward
  • Explain payment hash vs preimage
  • Reason about decreasing timelocks along a route

study // plan

Lessons are primers. Start with Step 1 (required reading) when present, then follow the numbered steps in the article. Depth comes from primary sources, labs, reflection, and evidence.

Research on Bitcoin Search

Step 1 // Required reading

Complete these before the numbered steps in the lesson body. Links are listed here once — not repeated below.

  • boltBOLT2 HTLC handling

Reflection prompts

  1. Explain HTLC Mechanics to a teammate without jargon - what problem does it solve?
  2. What would break in production if you misunderstood HTLC Mechanics?
  3. Which BOLT (or implementation doc) is the source of truth for this topic, and what did you verify there?

Lab // Multi-hop settle or fail

Complete Steps 2–3. On Polar/regtest, pay across a 2–3 node path. Optionally force a mid-route failure and note how unlocks unwind vs a successful preimage settle.

evidence required

  • ·Successful multi-hop pay proof (or Polar UI)
  • ·One sentence tracing hash forward and preimage back
  • ·Note on CLTV decreasing toward the payee (or why deltas matter)
  • ·Link to BOLT2 or Ch. 8 section you used
  1. 01

    Worked mental model

    Re-read the diagrams in this lesson once out loud in plain language. If you cannot explain the flow to a friend without jargon, pause and revisit the Mastering Bitcoin / Mastering Lightning chapters linked in Resources. Chapter references are intentional, not decorative.

  2. 02

    Hands-on habit

    Every protocol idea should be paired with one local experiment. That habit turns reading into builder instinct.

    1. Reproduce the happy path on regtest (or Polar for Lightning)
    2. Break it on purpose (wrong fee, expired invoice, offline peer)
    3. Write down what error you saw and which layer produced it (wallet, node, mempool, peer)
  3. 03

    Glossary check

    Pick three terms from this lesson and define them in one sentence each without opening notes. Weak definitions mean the lesson is not finished yet.

  4. 04

    Resource order

    Use Resources in order: narrative book chapter first, then BIP/BOLT for precision, then implementation docs for commands. Jumping straight to RPC flags without the mental model creates brittle knowledge.

HTLCs (Hash Time Locked Contracts) are conditional payments: claim with a preimage before timeout, otherwise refund. Chained HTLCs create atomic multi-hop Lightning payments.

Complete Step 1 // Required reading in the study plan above, then continue here.

Step 2 — Core idea: same hash, decreasing timelocks

Every routed payment is an HTLC dance. Debugging failures means reading hashes, CLTV deltas, and onion errors — not guessing.

Analogy: A locked briefcase opens with a secret word (preimage). Each courier holds a briefcase with the same word requirement but earlier deadlines. When the final person learns the word, it propagates back so everyone can settle.

Loading diagram…

Same payment hash along the path; timelocks decrease toward the payee.

Each hop needs enough timelock margin. Implementations enforce minimums — do not invent tighter custom deltas without reading BOLTs. Modern invoices include a payment secret so intermediaries cannot settle incorrectly. While an HTLC is outstanding, that slice of outbound is reserved — ties back to channel liquidity.

Atomicity

Either the preimage settles the chain, or timeouts refund. Intermediaries should not lose funds if they follow protocol and stay online as required.

Done when: You can contrast payment hash vs preimage and why CLTV shrinks toward the payee.

Step 3 — Try it: path pay (lab)

Pay across a 2–3 node Polar path. Optionally fail mid-route and compare unwind vs successful settle.

Common mistakes

  • Confusing payment hash with payment secret
  • Setting timelock deltas too tight for hops
  • Ignoring that held HTLCs lock liquidity

Done when: Lab evidence (pay proof + hash/preimage sentence + CLTV note + source) is complete.

Next lesson

Channel Lifecycle — cooperative close, force close, and backups.

further reading

  • bookMastering the Lightning Network

    Ch. 8: Routing on the Lightning Network

  • articleLightning Network Paper

review // club

Review club

Practice on real Lightning OSS changes tied to this chapter. Read the diff, use the checklist, and optionally paste your review comment URL in your lab notes.

  • LND HTLC failure handling PRs

    Find an HTLC-related PR and trace how failures unwind along the path.

    pr review
    timelockserror propagation
    45 min·advancedopen on GitHub
review checklist
  1. Does the change solve the stated problem?
  2. Are edge cases and rollout behavior covered?
  3. Are tests or test vectors included?
  4. Is the diff minimal and clearly explained?

More repos and GFIs on /discover and /issues.

progress // sign in

Reading is public. Sign in to mark lessons complete, sync across devices, and unlock your roadmap.

./sign-in-to-track

discussion

Discussion

prevCommitment TransactionsnextChannel Lifecycle

On this page

Press Shift + ? for keyboard shortcuts.

Press R to research on Bitcoin Search.

No questions yet — be the first to ask.