Every transaction type we have studied—P2PKH, P2WSH, multisig, timelocks, RBF, CPFP—converges in the Lightning Network. Lightning is not a separate blockchain or token; it is a protocol for constructing Bitcoin transactions that parties hold but do not broadcast, updating them off-chain until a final settlement is written to the blockchain.
This chapter examines the on-chain transaction anatomy of Lightning: the funding transaction that opens a channel, the commitment transactions that track balances, the HTLC outputs that route payments, and the closing transactions that settle on-chain. All formats follow BOLT 3†, the Lightning specification for on-chain transactions.
Every numerical example in this chapter refers back to a single channel between Alice and Bob. Establishing it once means each later example reconciles to concrete sat amounts.
| Field | Value |
|---|---|
| Channel capacity | 1 BTC = 100,000,000 sats |
| Funding type | Dual-funded — Alice contributes 60M sats, Bob contributes 40M sats |
| Funding output | 2-of-2 P2WSH at the lex-ordered (pubkeyA, pubkeyB) |
| Initial balance | Alice 60,000,000 sats · Bob 40,000,000 sats |
to_self_delay | 144 blocks (≈ 1 day) |
| Anchor outputs | option_anchors enabled — 330 sats each, one per party |
Throughout this chapter, "state #N" refers to the N-th commitment transaction. Both parties hold their own version of state #N as described in §18.2.1. We track Alice's view of the balance unless stated otherwise.
A Lightning channel begins with a funding transaction: an on-chain transaction that locks bitcoin into a 2-of-2 P2WSH multisig output.
The funding output is a P2WSH whose witness script is:
OP_2 <pubkey1> <pubkey2> OP_2 OP_CHECKMULTISIG
where pubkey1 is the lexicographically lesser of the two funding public keys (compressed, 33 bytes each) and pubkey2 is the greater. The canonical ordering ensures both parties derive the same script and the same P2WSH address.
Once the funding transaction confirms on-chain, the channel passes through three phases — only the first and last touch the blockchain:
The funding output is never spent during normal operation. It sits on-chain, holding the channel's capacity, while the commitment transactions (held off-chain) track the current balance. Hundreds or thousands of payments can flow through a channel before either party touches the blockchain again.
A 2-of-2 multisig ensures that neither party can spend the funds unilaterally during normal operation. Both signatures are required to create any valid transaction spending the funding output. This mutual control is what makes the off-chain update mechanism safe: neither party can steal by broadcasting a transaction the other hasn't co-signed.
The core innovation of Lightning is the commitment transaction: a pre-signed Bitcoin transaction that both parties hold but do not broadcast. Each commitment transaction spends the funding output and distributes the channel's balance according to the current state.
The next several sections lean heavily on CSV — short for OP_CHECKSEQUENCEVERIFY (opcode 0xb2, BIP 112, activated July 2016). It is the script-level relative timelock opcode: a script that contains <N> OP_CHECKSEQUENCEVERIFY OP_DROP can only be unlocked once the spending input's nSequence field encodes a delay of at least N blocks (or N × 512 seconds, in time-mode) since the input was confirmed. Where OP_CHECKLOCKTIMEVERIFY (CLTV, BIP 65) enforces an absolute deadline ("after block 900,000"), CSV enforces a relative one ("at least 144 blocks after this output entered the chain"). The full treatment is in §16.4; for Lightning purposes it is enough to know that a "CSV delay of 144 blocks" on an output means the output cannot be spent for ~24 hours after the transaction containing it confirms — exactly the window Lightning needs to detect and punish a revoked commitment.
The commitment-transaction tables below also reference anchor outputs. The full definition lives in §18.6; for now, the short version: an anchor is a tiny 330-satoshi output (one per party) added to every commitment transaction under the option_anchors channel feature, which has been the default in mainline Lightning implementations since 2021. Each anchor is locked to its owner's funding key with a script that lets the owner spend it immediately, but lets anyone spend it after a 16-block CSV delay.
Why it exists: a commitment transaction is signed long before it might be broadcast, so its fee is estimated against fee-market conditions that may have changed by the time the channel actually closes. Anchors give either party a tiny attachable UTXO they can use to pay CPFP (Child-Pays-for-Parent — covered in Chapter 17) and bump the fee at broadcast time, regardless of whether they hold the channel's main balance. The 16-block timeout means abandoned anchors don't pollute the UTXO set forever — anyone can sweep them up after that window. So when the next sections say "anchor (Alice) — 330 sats — Alice now, anyone after 16 blocks," that's the structure being described: a fee-bump escape hatch hard-coded into the commitment.
The problem. A Lightning channel must support unilateral exit — either party should be able to settle on chain at any time, even if the other has gone offline or become hostile. The funding output is a 2-of-2 multisig, so no party can spend it alone with a fresh signature; the only way out is to broadcast a transaction that has already been signed by both parties. Lightning therefore has both parties pre-sign settlement transactions in advance — one per channel state — and hold them privately until they're needed.
This raises an immediate problem: every new payment creates a new state, but the OLD signed settlements never disappear. Alice could simply broadcast a stale commitment from a moment when she held a more favorable balance. What stops her?
The answer: an asymmetric design with a built-in kill-switch. Three ingredients work together to make stale-state broadcasts an objectively losing bet:
commitment_A(N); Bob holds commitment_B(N). Same balances, different shape.to_remote AND the broadcaster's CSV-locked to_local in a single penalty transaction. Total balance, not just the cheating delta.The trick that makes this work in practice: Alice signs Bob's version of the commitment and sends the signature to Bob; Bob signs Alice's version and sends the signature back. Now Alice holds a commitment that Bob has already signed — structured to put Alice's funds in CSV jail; Bob holds the mirror. Either party can broadcast unilaterally because the counterparty's signature is already in hand, but the only thing each can broadcast is a transaction the other party deliberately shaped to penalize broadcasting a stale version.
Neither party ever sees the other's revocation private key in advance — only the secret used to derive it, and only for already-revoked states. This means Alice can sweep Bob's to_local ONLY if Bob has actually broadcast a state for which she received the secret, never preemptively.
The diagram below shows both versions of state #1 for the specimen channel — same 60M/40M split, but with the CSV encumbrance on opposite outputs.
| Output | Amount | Spending condition |
|---|---|---|
to_local (Alice) | 59,999,340 sats | CSV 144 blocks OR revocation |
to_remote (Bob) | 40M sats | immediate (1-block CSV with anchors) |
| anchor (Alice) | 330 sats | Alice now, anyone after 16 blocks |
| anchor (Bob) | 330 sats | Bob now, anyone after 16 blocks |
If Alice broadcasts this, Alice waits 144 blocks before her funds clear. Bob can sweep his 40M immediately.
| Output | Amount | Spending condition |
|---|---|---|
to_local (Bob) | 40M sats | CSV 144 blocks OR revocation |
to_remote (Alice) | 59,999,340 sats | immediate (1-block CSV with anchors) |
| anchor (Alice) | 330 sats | Alice now, anyone after 16 blocks |
| anchor (Bob) | 330 sats | Bob now, anyone after 16 blocks |
If Bob broadcasts this, Bob waits 144 blocks before his funds clear. Alice can sweep her 60M immediately.
Both transactions distribute the same 60M / 40M balance (less the two 330-sat anchors, paid from the initiator Alice's side; the commitment fee is ignored here for clarity), but the CSV delay always lands on the broadcaster's own funds. Three consequences fall out of this single architectural choice:
to_remote and your CSV-locked to_local. You don't merely forfeit the cheating profit; you forfeit everything you legitimately held, plus everything they legitimately held, in one unified swing of the hammer.The interactive widget below lets you move through six states of the specimen channel and see — visually — what happens when either party broadcasts each one, current or revoked.
The static table above shows state #1. But Lightning channels evolve: every payment creates a new state, with both parties holding new commitment transactions. Click a state below to see what each party's commitment looks like at that moment, then click If Alice broadcasts / If Bob broadcasts to trace what happens on chain. The non-current states are revoked — broadcasting them is an attempt to cheat, and the widget shows what the other party can do about it.
to_local · CSV 144 + revocation
to_remote · immediate (1-block CSV)
anchors · 330 sats × 2
Per BOLT 3, a commitment transaction has:
| Field | Value |
|---|---|
| Version | 2 |
| Input | Funding outpoint (2-of-2 P2WSH) |
| nSequence | Upper 8 bits = 0x80, lower 24 bits = upper 24 bits of obscured commitment # |
| nLockTime | Upper 8 bits = 0x20, lower 24 bits = lower 24 bits of obscured commitment # |
| Outputs | to_local, to_remote, HTLCs, anchors |
The 48-bit commitment number is obscured by XOR with the lower 48 bits of: \[ \text{SHA256}(\textit{payment\_basepoint}_A \| \textit{payment\_basepoint}_B) \] This hides how many state updates have occurred, so a passive on-chain observer cannot infer channel activity, payment frequency, or the number of failed payment attempts from a broadcast commitment. The nLockTime carries the lower 24 bits and nSequence carries the upper 24 bits, so together they reconstruct the full obscured value. The 0x20 prefix places nLockTime above 500,000,000 (interpreted as a past Unix timestamp), and the 0x80 prefix sets bit 31 of nSequence (disabling BIP 68)—neither field imposes an actual lock.
to_local OutputThe to_local output returns funds to the commitment's owner, but with two spending paths:
OP_IF
<revocationpubkey>
OP_ELSE
<to_self_delay> OP_CHECKSEQUENCEVERIFY OP_DROP
<local_delayedpubkey>
OP_ENDIF
OP_CHECKSIG
to_self_delay blocks (typically 144–2,016). Witness: <local_sig> <><revocation_sig> 1The trailing witness element selects the branch: OP_IF executes its then block when the top of stack is non-zero (here, 1 selects the revocation path) and falls through to OP_ELSE when the top of stack is empty or zero (here, <>—OP_FALSE—selects the normal path).
to_remote OutputThe counterparty's funds. In the simplest case, this is a standard P2WPKH output, immediately spendable with no delay.
With option_anchors (the modern default), the to_remote output adds a 1-block CSV lock:
<remotepubkey> OP_CHECKSIGVERIFY
1 OP_CHECKSEQUENCEVERIFY
This 1-block delay ensures the output cannot be spent in the same block as the commitment, preventing certain fee-manipulation attacks.
Walk through the very first payment after the channel opens. Starting state is #1 (60M / 40M from the specimen above); Alice pays Bob 10,000,000 sats; the result is state #2 (50M / 50M).
| Step | Who | Action | Channel state |
|---|---|---|---|
| 0 | — | Starting balance from specimen | State #1: Alice 60M / Bob 40M |
| 1 | Alice → Bob | Sends commitment_signed for state #2 — Alice's signature on Bob's commitment for the new (50M, 50M) split. | State #1 still active |
| 2 | Bob → Alice | Sends revoke_and_ack: reveals per_commitment_secret_1 (the secret that produces Bob's old revocation key) AND commitment_signed for state #2. | State #1 partially revoked (Bob's side) |
| 3 | Alice → Bob | Sends revoke_and_ack: reveals her per_commitment_secret_1. | State #1 fully revoked; state #2 active |
| 4 | — | Resulting balance | State #2: Alice 50M / Bob 50M |
What "revoked" means concretely: after step 3, both parties know the other's per_commitment_secret_1. If Alice now broadcasts her old commitment for state #1 (which gives her 60M), Bob can derive the corresponding revocation key and sweep both her to_local (60M) and his own to_remote (40M) — the entire 100M sats — within Alice's 144-block CSV window. Same in reverse: if Bob broadcasts his state-#1 commitment, Alice sweeps everything. The penalty mechanic enforced by §18.3 is the cryptographic flip side of the secret exchange in step 3.
What touches the chain: nothing. Alice and Bob exchanged 4 messages over their encrypted Lightning peer connection. The funding output remains untouched on-chain. The same 4-message dance can repeat thousands of times before either party broadcasts a settlement transaction.
Every time the channel state updates (a payment is made), both parties:
Once Alice reveals her old revocation secret, she has effectively "destroyed" her old commitment: if she broadcasts it, Bob can use the revocation key to claim all channel funds (not just his share—all of it). This is the penalty mechanism that keeps Lightning honest.
If a party broadcasts a revoked commitment, the counterparty can claim the entire channel balance—not just their share. This harsh penalty ensures that broadcasting old states is economically irrational: you lose everything, even the funds that were legitimately yours. A proportional penalty (only losing the cheating party's share) would still permit rational cheating whenever detection probability is low enough; a total penalty removes that calculation regardless of detection probability, provided watchtowers or online partners are watching. This is why watchtowers exist: automated services that monitor the blockchain for revoked commitments and broadcast penalty transactions on the user's behalf.
The specimen channel has been busy. Many payments have flowed both ways since state #1 (Alice 60M / Bob 40M from the specimen). At state #5, Bob had been ahead: Alice 30M / Bob 70M. By state #20, the pendulum has swung back: Alice 80M / Bob 20M. Bob is currently holding his commitment for state #20 — but he never deleted his old commitment for state #5, and he's tempted. If he can broadcast state #5 and have it confirm before Alice notices, he claims 70M sats instead of the 20M he is honestly owed.
| t | Event | Effect |
|---|---|---|
| 0 | Bob broadcasts his state-#5 commitment to mainnet. | Funding output spent; on-chain outputs: Bob's to_local = 70M (CSV 144 blocks), Alice's to_remote = 30M (immediate), 2 anchor outputs. |
| 0 | Alice's watchtower (or her own node) sees the transaction in the mempool. | It computes the SHA-256 of the commitment txid plus a hint and matches it against the watchtower's pre-shared revocation database — finds per_commitment_secret_5. |
| ~1 block | Alice's penalty transaction is broadcast. | Single transaction with two inputs: (a) Bob's to_local spent via the OP_IF revocation branch using per_commitment_secret_5 → revocation_key; (b) Alice's to_remote spent normally with her key. Single output: 99,999,xxx sats to Alice (minus on-chain fees). |
| ≤ 2 blocks total | Penalty transaction confirms before Bob's CSV expires. | Alice claims the full 100M sats. Bob: 0 sats. |
Bob's payoff calculation:
| Strategy | Best case | Worst case (caught) | Expected value |
|---|---|---|---|
| Honest close at state #20 | 20M sats | 20M sats | 20M sats |
| Cheat with state #5 (70M on his side) | 70M sats (no watchtower) | 0 sats (caught) | 70M × P(success) − ∞ reputation |
For the cheat to be profitable, the probability that Alice has no watchtower AND is offline for the full 144-block CSV window must be high enough that 70M × P(success) > 20M. With watchtowers running for free as a service and 144 blocks ≈ 24 hours, P(success) is effectively zero against any moderately resourced counterparty. The penalty mechanism makes cheating an objective net-loss bet; this is what allows hundreds of state updates to occur safely off-chain.
Bob has just broadcast his revoked state-#5 commitment at block 0. His to_local output is locked with OP_CSV 144 — he cannot spend it until block 144. Alice has that window to broadcast a penalty transaction using the revocation secret she learned when state #6 was negotiated. Whoever's transaction confirms first wins the 70M sats. Tune the parameters and run the simulation.
| Alice (sats) | Bob (sats) | |
|---|---|---|
| Honest close at state #20 | 80,000,000 | 20,000,000 |
| Cheat — penalty wins (Alice confirms first) | ~99,999,xxx | 0 |
| Cheat — Bob escapes (CSV expires first) | 30,000,000 | 70,000,000 |
So far our specimen has just two parties — but the real power of Lightning is routed payments: paying a third party (Carol) by hopping through intermediaries (Bob). To make a multi-hop payment atomic, the same payment_hash appears as an HTLC output on every channel along the route. Carol controls the preimage; revealing it on her last hop cascades back through every intermediate channel.
Red arrows: HTLCs locked forward (sender → receiver) · Green arrows: preimage revealed backward, HTLCs settle
Each in-flight payment adds an HTLC output with two spending paths:
Both paths additionally include a revocation clause (if the commitment is revoked, the counterparty claims everything).
BOLT 3 defines two HTLC types:
The offered HTLC witness script (without option_anchors) illustrates all three spending paths:
OP_DUP OP_HASH160 <RIPEMD160(SHA256(revocationpubkey))> OP_EQUAL
OP_IF
OP_CHECKSIG revocation path
OP_ELSE
<remote_htlcpubkey> OP_SWAP OP_SIZE 32 OP_EQUAL
OP_NOTIF
OP_DROP 2 OP_SWAP <local_htlcpubkey> 2 OP_CHECKMULTISIG
timeout path
OP_ELSE
OP_HASH160 <RIPEMD160(payment_hash)> OP_EQUALVERIFY
OP_CHECKSIG preimage path
OP_ENDIF
OP_ENDIF
<revocation_sig> <revocationpubkey>. The script hashes the key, matches it against the revocation hash, and verifies the signature.<remote_sig> <payment_preimage>. The OP_SIZE 32 OP_EQUAL check distinguishes a 32-byte preimage from a public key; the script verifies the hash and signature.nLockTime set to the CLTV expiry). The 2-of-2 OP_CHECKMULTISIG requires both local and remote HTLC signatures, ensuring the timeout cannot be claimed unilaterally before expiry.HTLC outputs are resolved via separate HTLC-success and HTLC-timeout transactions (second-stage transactions), each of which includes its own CSV delay. This two-stage design separates the HTLC resolution from the to_self_delay, preventing the delay from extending HTLC timeouts across the network.
Pick a spending path, then step through it. The same script routes execution into one of three branches based purely on what the spender pushes onto the stack as witness data. Specimens are real — the hash equality checks below verify (e.g. RIPEMD160(SHA256(R)) == HASH160(R) = ff762f2a…).
Assume two channels: our specimen Alice↔Bob (state #2 from §18.2.5: 50M / 50M), plus a Bob↔Carol channel that opened separately (50M / 50M). Carol has been waiting for a payment of 5,000,000 sats. Bob is willing to forward for a 1,000-sat fee.
Phase 1 — Setup (off-chain, no transactions broadcast):
| Step | Who | Action |
|---|---|---|
| 0 | Carol | Generates random 32-byte preimage R. Computes H = SHA256(R). Sends Alice a Lightning invoice containing H + amount 5,000,000 + her node ID + min CLTV expiry. |
| 1 | Alice | Routes the payment: discovers Alice→Bob→Carol path via gossip. Constructs an onion-encrypted message: outer layer for Bob (forward 5M to Carol, take 1k fee), inner layer for Carol (final payment, amount 5M). |
Phase 2 — HTLCs locked forward:
| Step | Channel | State change |
|---|---|---|
| 2 | Alice↔Bob | Update from state #2 (50M / 50M) to state #3: Alice 44,999,000 / Bob 50M / HTLC out 5,001,000 sats locked to H, CLTV = current + 80 blocks. |
| 3 | Bob↔Carol | Bob forwards: update Bob↔Carol channel to a new state with HTLC out 5,000,000 sats locked to the same H, CLTV = current + 40 blocks (stricter — must resolve before Bob's upstream HTLC times out). |
Phase 3 — Preimage revealed backward, HTLCs settle:
| Step | Channel | State change |
|---|---|---|
| 4 | Bob↔Carol | Carol sends update_fulfill_htlc revealing R. Bob verifies SHA256(R) = H, accepts. Channel updates: HTLC removed, Carol +5M sats. New state: Bob 45M / Carol 55M. |
| 5 | Alice↔Bob | Bob forwards update_fulfill_htlc with R to Alice. Alice verifies, channel updates: HTLC removed, Bob +5,001,000 sats. New state: Alice 44,999,000 / Bob 55,001,000. |
Net effect across all parties:
| Party | Δ Balance | Notes |
|---|---|---|
| Alice | −5,001,000 sats | Paid 5M to Carol + 1k routing fee to Bob |
| Bob | +1,000 sats | Earned routing fee. Net liquidity moved: 5,001,000 in from Alice, 5,000,000 out to Carol |
| Carol | +5,000,000 sats | Received the full payment |
| Sum | 0 sats | Lightning is conservation-of-sats, just like base Bitcoin |
Atomicity: if Carol disappears before step 4, the HTLCs simply time out — Alice gets her 5,001,000 back via the timeout path, Bob gets his 5,000,000 back. There is no scenario where Bob loses money but Carol gains; both HTLCs share the same H, so either both succeed (preimage revealed, both settle forward) or both fail (preimage never appears, both refund). The CLTV cushion (80 vs 40 blocks) gives Bob a 40-block window to claim his upstream HTLC after his downstream one expires — he is never left holding a paid-out forward with no recourse.
Pick a scenario and walk forward step-by-step. Watch how Bob's net Δ from start goes negative the moment he forwards (he has fronted his own liquidity) and only returns to positive after he claims upstream — that's the temporary loss the routing fee compensates for. The timeout scenario shows what happens if Carol never reveals R: every HTLC eventually expires and refunds, restoring the starting balances.
A Lightning channel can close in three ways. Which path the channel takes depends on the answers to two questions: are both parties online and cooperating? and has either party already broadcast a revoked commitment?
to_local waits 144 blocks (CSV); counterparty's to_remote immediate. HTLCs resolved via 2nd-stage txs.Both parties agree on the final balance and co-sign a closing transaction that spends the funding output directly to each party's address. No timelocks, no HTLCs, no delays—the simplest and most efficient close.
One party broadcasts their latest commitment transaction. The broadcaster's funds are subject to the CSV delay (to_local); the counterparty receives their funds immediately (to_remote). Any in-flight HTLCs are resolved on-chain via HTLC-success or HTLC-timeout transactions.
Force closes are expensive: multiple on-chain transactions, each paying fees, and funds locked for the delay period.
If a party broadcasts a revoked commitment, the counterparty detects it (directly or via a watchtower) and broadcasts a penalty transaction that sweeps all outputs using the revocation key. The cheating party loses their entire channel balance.
Commitment transactions are pre-signed, so their fee is fixed at signing time. If the fee market changes between signing and broadcast, the commitment may be too expensive (wasting funds) or too cheap (failing to confirm).
Anchor outputs solve this by attaching small, spendable outputs (330 sats each, per BOLT 3) to the commitment. Each party gets its own anchor, locked to their funding key:
<local_funding_pubkey> OP_CHECKSIG OP_IFDUP
OP_NOTIF
OP_16 OP_CHECKSEQUENCEVERIFY
OP_ENDIF
The keyholder spends immediately with <sig>. If the anchor remains unspent for 16 blocks, anyone can sweep it with an empty witness (<>), preventing UTXO set pollution. This "self-cleaning" design ensures abandoned anchors do not bloat the UTXO set indefinitely.
Either party can use CPFP (Chapter 17) to attach a high-fee child to their anchor, adjusting the effective feerate at broadcast time.
With TRUC transactions and package relay (also Chapter 17), this mechanism is further improved: the commitment can pay minimal or even zero fees, with the child transaction covering the full cost.
The Lightning channel lifecycle ties together nearly every concept in this book: P2WSH (funding output), multisig (2-of-2), CSV (to_local delay), CLTV (HTLC timeouts), hash preimages (HTLC success), SegWit (witness-based scripts), RBF/CPFP (fee management), and TRUC/package relay (anchor outputs). Lightning is not built beside Bitcoin—it is built from Bitcoin's transaction primitives.
to_local output has two paths: normal (CSV delay) and revocation (immediate, for penalty).Lightning uses Bitcoin's transaction primitives for payments. Chapter 19 explores a very different use of transaction anatomy: Ordinals and Inscriptions, which embed arbitrary data—images, text, even programs—into the witness field, turning Bitcoin into a data layer.
to_local output have a CSV delay?to_local witness script for a channel with to_self_delay = 144 blocks. What nSequence value must the spending input use?L1. A 2-of-2 P2WSH multisig output. The witness script is OP_2 <pubkey1> <pubkey2> OP_2 OP_CHECKMULTISIG, with keys in lexicographic order.
L2. The CSV delay creates a time window during which the counterparty can detect and punish a revoked commitment. Without the delay, the broadcaster could spend their output immediately, leaving no opportunity for the penalty transaction.
L3. The counterparty can claim the entire channel balance using the revocation key. The broadcaster loses all funds—not just the counterparty's share, but their own share too. This is the penalty mechanism.
L4. (1) Cooperative close (both parties agree, no delays). (2) Force close (one party broadcasts their latest commitment, CSV delays apply). (3) Breach remedy / penalty (revoked commitment detected, all funds swept).
L5. Anchor outputs (330 sats each) allow either party to fee-bump the commitment transaction via CPFP after broadcast. This decouples the fee decision from the signing time.
H1. The to_local witness script:
OP_IF
<revocationpubkey>
OP_ELSE
02 90 00 OP_CHECKSEQUENCEVERIFY OP_DROP
<local_delayedpubkey>
OP_ENDIF
OP_CHECKSIG
The spending input must set \(\texttt{nSequence} = 144 = \texttt{0x00000090}\) (BIP 68 block-based relative timelock). In the witness: <local_sig> <> (the empty vector selects the OP_ELSE branch).
H2. Target: 20 sat/vB for the package. Package = commitment (900 vB, 500 sats) + child. Assume, for round numbers, a 141-vB child spending the 330-sat anchor (in practice the anchor spend is a P2WSH witness-script input, and the extra funding input adds roughly 70 vB, raising the required fee accordingly).
Required package feerate: \((500 + f) / (900 + 141) = 20\), so \(f = 20 \times 1,041 - 500 = 20,320\) sats.
The child must pay 20,320 sats in fees (144 sat/vB for the child alone). The child spends the 330-sat anchor, so it needs an additional input providing at least \(20,320 - 330 = 19,990\) sats.
H3. If C claims the preimage from B (settling the BC HTLC), B must relay the preimage upstream to settle the AB HTLC before A's timeout. If A's timeout were \(\leq\) B's, then A could reclaim funds via timeout before B can settle—B would lose the payment. The decreasing timeouts (\(n+40 > n+20\)) give each hop a safety margin to propagate the preimage upstream.
P1. If both parties held identical commitments, the revocation mechanism would fail. When Alice reveals her revocation secret, she would also be revealing the key to her own commitment—Bob could use it against her even if she broadcast the current (non-revoked) state. Asymmetric commitments solve this: Alice's revocation secret only compromises Alice's version of the commitment. Bob's version has a different revocation key derived from Bob's secret. Each party can safely reveal old secrets without compromising their current commitment.
P2. If HTLC outputs were resolved directly from the commitment (without second-stage transactions), the CSV to_self_delay would apply to HTLC resolution. This would extend the effective HTLC timeout by the delay period. For multi-hop payments, each hop adds delay, so a 144-block delay per hop on a 5-hop route would add 720 blocks (5 days) to the HTLC timeout. Second-stage transactions decouple the CSV delay from HTLC resolution: the HTLC can be resolved (success or timeout) immediately, and only the resulting output is delayed. This keeps HTLC timeouts reasonable across the network.
P3. Broadcasting a revoked commitment is economically rational only if the counterparty cannot detect it before the CSV delay expires—i.e., the counterparty is offline and has no watchtower. If detected, the broadcaster loses their entire balance (penalty). The expected value of cheating is: \(P(undetected) \times gain - P(detected) \times entire_{balance}\). As long as the counterparty (or their watchtower) monitors the chain, \(P(detected) \approx 1\), making cheating deeply irrational. The penalty must be total (not proportional) to ensure the expected value is negative even for small probability of detection.
C1. Timelocks in a Lightning force close:
0x20 prefix makes it a past Unix timestamp—not a functional lock.0x80 prefix disables BIP 68.to_local: prevents the broadcaster from spending their own funds for the delay period—the revocation window.to_remote (anchors): 1-block delay prevents same-block spending.C2. Pre-SegWit, transaction malleability allowed third parties (or miners) to modify the txid of the funding transaction without invalidating it. If the funding txid changes, every commitment transaction (which references the funding outpoint) becomes invalid—the entire channel breaks. SegWit fixes this by moving the witness (the malleable part) outside the txid calculation. The funding transaction's txid is stable, so all commitment transactions remain valid. This is why Lightning was not practical before SegWit's activation in August 2017.
B1. In theory, witness data in a commitment transaction could contain an inscription envelope. In practice, this is impractical: commitment transactions are pre-signed by both parties, and the witness data is tightly specified by BOLT 3 (signatures, keys, hash preimages). Adding arbitrary inscription data would require both parties to agree to include it and would increase the transaction's weight, raising fees. Lightning commitment transactions are designed for minimal on-chain footprint, which is the opposite of inscriptions' goal.
B2. Lightning excels for frequent, small payments between parties with established channels: near-zero marginal cost, instant finality, and no on-chain footprint. On-chain batching excels for one-time payments to many recipients: a single transaction with many outputs. Lightning requires channel setup (on-chain funding transaction) and liquidity management; batching requires only one on-chain transaction but no persistent relationship. For recurring payments to the same parties, Lightning is far more efficient. For one-time distributions (e.g., exchange withdrawals), batching is simpler.