<p>If you look at <a href="https://blockstream.info/address/bc1qdv0fk4c73fem89s708pzdny8q25d7k5nrckckp87c8alwaw803fq3mqrpz" rel="nofollow noreferrer">https://blockstream.info/address/bc1qdv0fk4c73fem89s708pzdny8q25d7k5nrckckp87c8alwaw803fq3mqrpz</a> you will see that there are two transactions. </p>

<p>The first one  <a href="https://blockstream.info/tx/943f18e17aa2ba716f2d13785268a1bd6b25c39d2718f3b4785559a5eeaba883" rel="nofollow noreferrer">https://blockstream.info/tx/943f18e17aa2ba716f2d13785268a1bd6b25c39d2718f3b4785559a5eeaba883</a> is the funding TX to open the payment channel included in block <code>587093</code> (at least according to what was send over gossip) </p>

<p>The second one <a href="https://blockstream.info/tx/a175425ee2f3c01acc97ef32ab1082db14eaa94e5af4c54f02f3b01dec72558e" rel="nofollow noreferrer">https://blockstream.info/tx/a175425ee2f3c01acc97ef32ab1082db14eaa94e5af4c54f02f3b01dec72558e</a> is the force closed timelocked commitment tx included to block <code>587314</code></p>

<p>The output 0 of the commitment tx has a relative timelock and was self spend / sweeped with this transaction <a href="https://blockstream.info/tx/0be2b9a3a6a9dc99443d6ce7bd3beaf33c713a4938af3bf0fec1e918257bbd32" rel="nofollow noreferrer">https://blockstream.info/tx/0be2b9a3a6a9dc99443d6ce7bd3beaf33c713a4938af3bf0fec1e918257bbd32</a> which was included in block <code>588801</code></p>

<p>If you decode the transaction you see nothing special</p>

<pre><code>304402204a54d94068512c22847cc07fa85f2b93feaf758411920a9b20ce9b85831e8aa5022005924cb82c331c5173e21477a4d8298eb25c0d967ace065b883455f2537c3d0a01 &lt;empty&gt; 632103f96d73ffe138690f032e97408af933a71782ad27a28df66a750b48c56b2d7fa96702cf05b275210304f332f50363cd01b679d9fb50fb8691fb0fb638737867bd02f06850c6191a2268ac

p2wsh witness script
OP_IF OP_PUSHBYTES_33 03f96d73ffe138690f032e97408af933a71782ad27a28df66a750b48c56b2d7fa9 OP_ELSE OP_PUSHBYTES_2 cf05 OP_CSV OP_DROP OP_PUSHBYTES_33 0304f332f50363cd01b679d9fb50fb8691fb0fb638737867bd02f06850c6191a22 OP_ENDIF OP_CHECKSIG

nsequence
0x05cf

previous output script
OP_0 OP_PUSHBYTES_32 c9452fef6bd1c72c8648d6ac78ce552543a1e5bf80a470fb259ff670aa5ced26 (v0_p2wsh)
</code></pre>

<p>However you can observe the <code>nSequance = 0x05cf</code> which encoded in decimal is <code>5*256 + c*16 + f = 5*256 + 12*16 + 15 = 1487</code></p>

<p>As the commitment tx was included in block <code>587314</code> the timelocked spend from it would have been rejected any block earlier than <code>587314 + 1487 = 588801</code> which was exactly the block height of the third tx.</p>

CC BY-SA 4.0
2019-11-09T06:55:44.283Z
2019-11-09T06:55:44.283Z
Rene Pickhardt
<p>It's a case when a local node closes the channel unilaterally with broadcasting its local commitment transaction that contains <code>to_local</code> output below. This output is spent by a transaction with nSequence field set to <code>to_self_delay</code> (which can only be valid after that duration has passed.)</p>

<pre><code>OP_IF
    # Penalty transaction
    &lt;revocationpubkey&gt;
OP_ELSE
    `to_self_delay`
    OP_CHECKSEQUENCEVERIFY
    OP_DROP
    &lt;local_delayedpubkey&gt;
OP_ENDIF
OP_CHECKSIG
</code></pre>

<p>It's a commitment transaction on Testnet as following.</p>

<p>txid: <a href="https://api.blockcypher.com/v1/btc/test3/txs/4f8d776c85b1fc15c1125e7043a9aee70e33f0793b472823e3946a8de075bec4" rel="nofollow noreferrer">4f8d776c85b1fc15c1125e7043a9aee70e33f0793b472823e3946a8de075bec4</a></p>

<p><code>to_local</code> output:</p>

<pre><code>6321026644cb387614f66421d14da3596c21cffa239011416c9adf3f351ee8551a9fc767029000b27521029654f80732769d7c435a184a3559f12178315526c53bbf003349390811c7590a68ac
</code></pre>

<p>decoded output:</p>

<pre><code>{
  "asm": "OP_IF 026644cb387614f66421d14da3596c21cffa239011416c9adf3f351ee8551a9fc7 OP_ELSE 144 OP_CHECKSEQUENCEVERIFY OP_DROP 029654f80732769d7c435a184a3559f12178315526c53bbf003349390811c7590a OP_ENDIF OP_CHECKSIG",
  "type": "nonstandard",
  "p2sh": "35M7MGVGd3ajyiTMvriUiyUM3H2cT5sgb4"
}
</code></pre>

<p>The commitment transaction got mined in <code>1356328</code> block height, and <code>to_self_delay</code> is <code>144</code>, so the output can be spent after it reaches <code>1356183</code> block height. </p>

CC BY-SA 4.0
2019-11-09T07:20:06.363Z
2019-11-09T07:27:41.053Z
2019-11-09T07:27:41.053Z
ogw_yuya
<p>I want to see an example of a raw transaction which spends from an input which has a relative LockTime applied to it. An example would be a transaction from a Lightning payment channel in which a user force closes a channel and claims their 'local' balance, after having waited for the 'to self' delay in their commitment transaction. </p>

<p>It would be very helpful for understanding how to spend from an input encumbered with a relative LockTime.</p>

<lightning-network><sequence><checksequenceverify><ln-commitment-transaction>
Could someone provide an example of a tx spending from an input with a relative LockTime?
Darius
# Could someone provide an example of a tx spending from an input with a relative LockTime?

(Asked by: username_0 on 2019-11-09)

I want to see an example of a raw transaction which spends from an input which has a relative LockTime applied to it. An example would be a transaction from a Lightning payment channel in which a user force closes a channel and claims their 'local' balance, after having waited for the 'to self' delay in their commitment transaction.

It would be very helpful for understanding how to spend from an input encumbered with a relative LockTime.

**Tags:** lightning-network, sequence, checksequenceverify, ln-commitment-transaction


---

## 2 answers

### Answer by username_1 on 2019-11-09. Score: 1 | Accepted answer

If you look at https://blockstream.info/address/bc1qdv0fk4c73fem89s708pzdny8q25d7k5nrckckp87c8alwaw803fq3mqrpz you will see that there are two transactions. 
The first one  https://blockstream.info/tx/943f18e17aa2ba716f2d13785268a1bd6b25c39d2718f3b4785559a5eeaba883 is the funding TX to open the payment channel included in block 587093 (at least according to what was send over gossip) 
The second one https://blockstream.info/tx/a175425ee2f3c01acc97ef32ab1082db14eaa94e5af4c54f02f3b01dec72558e is the force closed timelocked commitment tx included to block 587314
The output 0 of the commitment tx has a relative timelock and was self spend / sweeped with this transaction https://blockstream.info/tx/0be2b9a3a6a9dc99443d6ce7bd3beaf33c713a4938af3bf0fec1e918257bbd32 which was included in block 588801
If you decode the transaction you see nothing special
304402204a54d94068512c22847cc07fa85f2b93feaf758411920a9b20ce9b85831e8aa5022005924cb82c331c5173e21477a4d8298eb25c0d967ace065b883455f2537c3d0a01  632103f96d73ffe138690f032e97408af933a71782ad27a28df66a750b48c56b2d7fa96702cf05b275210304f332f50363cd01b679d9fb50fb8691fb0fb638737867bd02f06850c6191a2268ac

p2wsh witness script
OP_IF OP_PUSHBYTES_33 03f96d73ffe138690f032e97408af933a71782ad27a28df66a750b48c56b2d7fa9 OP_ELSE OP_PUSHBYTES_2 cf05 OP_CSV OP_DROP OP_PUSHBYTES_33 0304f332f50363cd01b679d9fb50fb8691fb0fb638737867bd02f06850c6191a22 OP_ENDIF OP_CHECKSIG

nsequence
0x05cf

previous output script
OP_0 OP_PUSHBYTES_32 c9452fef6bd1c72c8648d6ac78ce552543a1e5bf80a470fb259ff670aa5ced26 (v0_p2wsh)

However you can observe the nSequance = 0x05cf which encoded in decimal is 5*256 + c*16 + f = 5*256 + 12*16 + 15 = 1487
As the commitment tx was included in block 587314 the timelocked spend from it would have been rejected any block earlier than 587314 + 1487 = 588801 which was exactly the block height of the third tx.


---

### Answer by username_2 on 2019-11-09. Score: 0

It's a case when a local node closes the channel unilaterally with broadcasting its local commitment transaction that contains to_local output below. This output is spent by a transaction with nSequence field set to to_self_delay (which can only be valid after that duration has passed.)
OP_IF
    # Penalty transaction
    
OP_ELSE
    `to_self_delay`
    OP_CHECKSEQUENCEVERIFY
    OP_DROP
    
OP_ENDIF
OP_CHECKSIG

It's a commitment transaction on Testnet as following.
txid: 4f8d776c85b1fc15c1125e7043a9aee70e33f0793b472823e3946a8de075bec4
to_local output:
6321026644cb387614f66421d14da3596c21cffa239011416c9adf3f351ee8551a9fc767029000b27521029654f80732769d7c435a184a3559f12178315526c53bbf003349390811c7590a68ac

decoded output:
{
  "asm": "OP_IF 026644cb387614f66421d14da3596c21cffa239011416c9adf3f351ee8551a9fc7 OP_ELSE 144 OP_CHECKSEQUENCEVERIFY OP_DROP 029654f80732769d7c435a184a3559f12178315526c53bbf003349390811c7590a OP_ENDIF OP_CHECKSIG",
  "type": "nonstandard",
  "p2sh": "35M7MGVGd3ajyiTMvriUiyUM3H2cT5sgb4"
}

The commitment transaction got mined in 1356328 block height, and to_self_delay is 144, so the output can be spent after it reaches 1356183 block height.


---

