1

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.

1

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 <empty> 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.

  • Thanks a lot! This is super useful :) – Darius Nov 10 '19 at 15:56
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
    <revocationpubkey>
OP_ELSE
    `to_self_delay`
    OP_CHECKSEQUENCEVERIFY
    OP_DROP
    <local_delayedpubkey>
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.