Research/Bitcoin Dev Archive / lightning-dev list
Spending `to_local` output of commitment
4 messages, Apr 27 to May 19, 2023. Started by Benjamin Weintraub.
Benjamin Weintraub (2), Ken Sedgwick, Keagan McClelland
Hi all,
I have a question about commitments. If a peer force closes a channel by sending a commitment to the blockchain, what kind of witness script is needed to redeem the `to_local` funds? (assuming the `to_self_delay` has elapsed.) It seems that the transaction described here is for cooperative closures: https://github.com/lightning/bolts/blob/c74a3bbcf890799d343c62cb05fcbcdc952a1cf3/03-transactions.md#closing-transaction. But for force closures, I would think that the txin would need to be the `to_local` txout of the commitment.
Concretely, I have commited the following transaction on a local simnet bitcoin blockchain and mined 500 blocks on top of it. I want to spend vout[2], how can I generate such a transaction?
{
"hash": "47d15337bb3c29c7c2881dd7cd912604b401ed221c66ea6f781b456d4983d451",
"size": 444,
"vsize": 279,
"weight": 1113,
"version": 2,
"locktime": 551351761,
"vin": [
{
"txid": "0248025b9447df8267d02d14c34ab9b269f52cd827132c70159a55cbf27ab3c1",
"vout": 0,
"scriptSig": {
"asm": "",
"hex": ""
},
"txinwitness": [
"",
"3045022100d3f52ca04d6a71587c29592931e542b16a47f3e9e577f1869b416547d00c62dd0220485da35ad31ff71b4263b1a25f0ba9f35990e1c8d5ac848365bbd588c3ce83d701",
"3044022057fc3878e17a865c12d57b7885ed48f0d6122bd9e00511c8eac150180d1508d502205fd1d0674a41b3c0118d0b6c19b1c77d35fc95bb89f929da6478f22e94dbf5ce01",
"5221038acdafe305edd06e91706ee687a091be306f0f29bcbda52dadde084bbaa36c902103d8fd53b9b43638c2255e1abd6f134a0232d2fba65527252c4eb81f926ddf50ad52ae"
],
"sequence": 2161061453
}
],
"vout": [
{
"value": 0.0000033,
"n": 0,
"scriptPubKey": {
"asm": "0 45ec86244376d47000ca6592783ba26f6b2ae619a24c8f5fad249b8c716955d6",
"hex": "002045ec86244376d47000ca6592783ba26f6b2ae619a24c8f5fad249b8c716955d6",
"reqSigs": 1,
"type": "witness_v0_scripthash",
"addresses": [
"sb1qghkgvfzrwm28qqx2vkf8swazda4j4ese5fxg7hadyjdccutf2htqysq3qz"
]
}
},
{
"value": 0.0000033,
"n": 1,
"scriptPubKey": {
"asm": "0 502a17644b334482d0a3f589d9861af6e2105a9b7afd3f5c258efc98bb6aeeed",
"hex": "0020502a17644b334482d0a3f589d9861af6e2105a9b7afd3f5c258efc98bb6aeeed",
"reqSigs": 1,
"type": "witness_v0_scripthash",
"addresses": [
"sb1q2q4pweztxdzg959r7kyanps67m3pqk5m0t7n7hp93m7f3wm2amksa0fysc"
]
}
},
{
"value": 0.0002,
"n": 2,
"scriptPubKey": {
"asm": "0 045553fc789494f16eff4cfa221d0294e140fb79772efeb7d8397d0ac1c4cf85",
"hex": "0020045553fc789494f16eff4cfa221d0294e140fb79772efeb7d8397d0ac1c4cf85",
"reqSigs": 1,
"type": "witness_v0_scripthash",
"addresses": [
"sb1qq3248lrcjj20zmhlfnazy8gzjns5p7mewuh0ad7c897s4swye7zsyrm5pc"
]
}
},
{
"value": 0.009761,
"n": 3,
"scriptPubKey": {
"asm": "0 2d51ca420d0b6ab56c97ca2631d7304c9ad9025252ea71f3af8f97361679042e",
"hex": "00202d51ca420d0b6ab56c97ca2631d7304c9ad9025252ea71f3af8f97361679042e",
"reqSigs": 1,
"type": "witness_v0_scripthash",
"addresses": [
"sb1q94gu5ssdpd4t2myhegnrr4esfjddjqjj2t48rua037tnv9neqshqm4z7yr"
]
}
}
],
"blockhash": "0fa78bc7e9f6e0a60be71bb5fb2eaaf42a97895bb057f09d7cbb2c49120fa61d",
"confirmations": 500,
"time": 1682451410,
"blocktime": 1682451410
}
Thanks in advance,
Ben
Ben,
The necessary witness is described here: https://github.com/lightning/bolts/blob/master/03-transactions.md#to_local-output
Regards,
Ken
On Sat, Apr 29, 2023 at 7:57 PM Benjamin Weintraub via Lightning-dev < lightning-dev at lists.linuxfoundation.org> wrote:
Quoted text (124 lines)
> Hi all, > > I have a question about commitments. If a peer force closes a channel by > sending a commitment to the blockchain, what kind of witness script is > needed to redeem the `to_local` funds? (assuming the `to_self_delay` has > elapsed.) It seems that the transaction described here is for cooperative > closures: > https://github.com/lightning/bolts/blob/c74a3bbcf890799d343c62cb05fcbcdc952a1cf3/03-transactions.md#closing-transaction > . But for force closures, I would think that the txin would need to be > the `to_local` txout of the commitment. > > Concretely, I have commited the following transaction on a local simnet > bitcoin blockchain and mined 500 blocks on top of it. I want to spend > vout[2], how can I generate such a transaction? > > > { > "hash": > "47d15337bb3c29c7c2881dd7cd912604b401ed221c66ea6f781b456d4983d451", > "size": 444, > "vsize": 279, > "weight": 1113, > "version": 2, > "locktime": 551351761, > "vin": [ > { > "txid": > "0248025b9447df8267d02d14c34ab9b269f52cd827132c70159a55cbf27ab3c1", > "vout": 0, > "scriptSig": { > "asm": "", > "hex": "" > }, > "txinwitness": [ > "", > > "3045022100d3f52ca04d6a71587c29592931e542b16a47f3e9e577f1869b416547d00c62dd0220485da35ad31ff71b4263b1a25f0ba9f35990e1c8d5ac848365bbd588c3ce83d701", > > "3044022057fc3878e17a865c12d57b7885ed48f0d6122bd9e00511c8eac150180d1508d502205fd1d0674a41b3c0118d0b6c19b1c77d35fc95bb89f929da6478f22e94dbf5ce01", > > "5221038acdafe305edd06e91706ee687a091be306f0f29bcbda52dadde084bbaa36c902103d8fd53b9b43638c2255e1abd6f134a0232d2fba65527252c4eb81f926ddf50ad52ae" > ], > "sequence": 2161061453 > } > ], > "vout": [ > { > "value": 0.0000033, > "n": 0, > "scriptPubKey": { > "asm": "0 > 45ec86244376d47000ca6592783ba26f6b2ae619a24c8f5fad249b8c716955d6", > "hex": > "002045ec86244376d47000ca6592783ba26f6b2ae619a24c8f5fad249b8c716955d6", > "reqSigs": 1, > "type": "witness_v0_scripthash", > "addresses": [ > "sb1qghkgvfzrwm28qqx2vkf8swazda4j4ese5fxg7hadyjdccutf2htqysq3qz" > ] > } > }, > { > "value": 0.0000033, > "n": 1, > "scriptPubKey": { > "asm": "0 > 502a17644b334482d0a3f589d9861af6e2105a9b7afd3f5c258efc98bb6aeeed", > "hex": > "0020502a17644b334482d0a3f589d9861af6e2105a9b7afd3f5c258efc98bb6aeeed", > "reqSigs": 1, > "type": "witness_v0_scripthash", > "addresses": [ > "sb1q2q4pweztxdzg959r7kyanps67m3pqk5m0t7n7hp93m7f3wm2amksa0fysc" > ] > } > }, > { > "value": 0.0002, > "n": 2, > "scriptPubKey": { > "asm": "0 > 045553fc789494f16eff4cfa221d0294e140fb79772efeb7d8397d0ac1c4cf85", > "hex": > "0020045553fc789494f16eff4cfa221d0294e140fb79772efeb7d8397d0ac1c4cf85", > "reqSigs": 1, > "type": "witness_v0_scripthash", > "addresses": [ > "sb1qq3248lrcjj20zmhlfnazy8gzjns5p7mewuh0ad7c897s4swye7zsyrm5pc" > ] > } > }, > { > "value": 0.009761, > "n": 3, > "scriptPubKey": { > "asm": "0 > 2d51ca420d0b6ab56c97ca2631d7304c9ad9025252ea71f3af8f97361679042e", > "hex": > "00202d51ca420d0b6ab56c97ca2631d7304c9ad9025252ea71f3af8f97361679042e", > "reqSigs": 1, > "type": "witness_v0_scripthash", > "addresses": [ > "sb1q94gu5ssdpd4t2myhegnrr4esfjddjqjj2t48rua037tnv9neqshqm4z7yr" > ] > } > } > ], > "blockhash": > "0fa78bc7e9f6e0a60be71bb5fb2eaaf42a97895bb057f09d7cbb2c49120fa61d", > "confirmations": 500, > "time": 1682451410, > "blocktime": 1682451410 > } > > > > Thanks in advance, > > Ben > _______________________________________________ > Lightning-dev mailing list > Lightning-dev at lists.linuxfoundation.org > https://www.learnbitcoin.com/archive/lists/lightning-dev >
Thank you, Ken. I have a follow up question as well.
Context: I’m playing around with some failure scenarios in LND. Say Alice is paying Bob, before Bob is able to send the fulfillment (which includes the HTLC preimage), Alice’s node dies and becomes unreachable.
Bob has already received the commitment for the updated balance and already has the preimage, so he force closes the channel.
My understanding is that he will submit the updated commitment to the blockchain as well as the channel closing transaction (after the CSV timeout) which spends his to_local and the HTLC output.
Here is my problem. After using `lncli closechannel --force ...` , I only see the commitment transaction in the mempool, not the subsequent HTLC/to_local spend. How can I generate the transaction that spends the to_local and HTLC output? If there's a way to generate it with lnd, that would be ideal.
Thanks in advance!
Ben ________________________________ From: Ken Sedgwick <ksedgwic at bonsai.com> Sent: Sunday, April 30, 2023 14:30 To: Benjamin Weintraub <weintraub.b at northeastern.edu> Cc: Lightning-dev at lists.linuxfoundation.org <lightning-dev at lists.linuxfoundation.org> Subject: Re: [Lightning-dev] Spending `to_local` output of commitment
Ben,
The necessary witness is described here: https://github.com/lightning/bolts/blob/master/03-transactions.md#to_local-output
Regards,
Ken
On Sat, Apr 29, 2023 at 7:57 PM Benjamin Weintraub via Lightning-dev <lightning-dev at lists.linuxfoundation.org<mailto:lightning-dev at lists.linuxfoundation.org>> wrote: Hi all,
I have a question about commitments. If a peer force closes a channel by sending a commitment to the blockchain, what kind of witness script is needed to redeem the `to_local` funds? (assuming the `to_self_delay` has elapsed.) It seems that the transaction described here is for cooperative closures: https://github.com/lightning/bolts/blob/c74a3bbcf890799d343c62cb05fcbcdc952a1cf3/03-transactions.md#closing-transaction. But for force closures, I would think that the txin would need to be the `to_local` txout of the commitment.
Concretely, I have commited the following transaction on a local simnet bitcoin blockchain and mined 500 blocks on top of it. I want to spend vout[2], how can I generate such a transaction?
{
"hash": "47d15337bb3c29c7c2881dd7cd912604b401ed221c66ea6f781b456d4983d451",
"size": 444,
"vsize": 279,
"weight": 1113,
"version": 2,
"locktime": 551351761,
"vin": [
{
"txid": "0248025b9447df8267d02d14c34ab9b269f52cd827132c70159a55cbf27ab3c1",
"vout": 0,
"scriptSig": {
"asm": "",
"hex": ""
},
"txinwitness": [
"",
"3045022100d3f52ca04d6a71587c29592931e542b16a47f3e9e577f1869b416547d00c62dd0220485da35ad31ff71b4263b1a25f0ba9f35990e1c8d5ac848365bbd588c3ce83d701",
"3044022057fc3878e17a865c12d57b7885ed48f0d6122bd9e00511c8eac150180d1508d502205fd1d0674a41b3c0118d0b6c19b1c77d35fc95bb89f929da6478f22e94dbf5ce01",
"5221038acdafe305edd06e91706ee687a091be306f0f29bcbda52dadde084bbaa36c902103d8fd53b9b43638c2255e1abd6f134a0232d2fba65527252c4eb81f926ddf50ad52ae"
],
"sequence": 2161061453
}
],
"vout": [
{
"value": 0.0000033,
"n": 0,
"scriptPubKey": {
"asm": "0 45ec86244376d47000ca6592783ba26f6b2ae619a24c8f5fad249b8c716955d6",
"hex": "002045ec86244376d47000ca6592783ba26f6b2ae619a24c8f5fad249b8c716955d6",
"reqSigs": 1,
"type": "witness_v0_scripthash",
"addresses": [
"sb1qghkgvfzrwm28qqx2vkf8swazda4j4ese5fxg7hadyjdccutf2htqysq3qz"
]
}
},
{
"value": 0.0000033,
"n": 1,
"scriptPubKey": {
"asm": "0 502a17644b334482d0a3f589d9861af6e2105a9b7afd3f5c258efc98bb6aeeed",
"hex": "0020502a17644b334482d0a3f589d9861af6e2105a9b7afd3f5c258efc98bb6aeeed",
"reqSigs": 1,
"type": "witness_v0_scripthash",
"addresses": [
"sb1q2q4pweztxdzg959r7kyanps67m3pqk5m0t7n7hp93m7f3wm2amksa0fysc"
]
}
},
{
"value": 0.0002,
"n": 2,
"scriptPubKey": {
"asm": "0 045553fc789494f16eff4cfa221d0294e140fb79772efeb7d8397d0ac1c4cf85",
"hex": "0020045553fc789494f16eff4cfa221d0294e140fb79772efeb7d8397d0ac1c4cf85",
"reqSigs": 1,
"type": "witness_v0_scripthash",
"addresses": [
"sb1qq3248lrcjj20zmhlfnazy8gzjns5p7mewuh0ad7c897s4swye7zsyrm5pc"
]
}
},
{
"value": 0.009761,
"n": 3,
"scriptPubKey": {
"asm": "0 2d51ca420d0b6ab56c97ca2631d7304c9ad9025252ea71f3af8f97361679042e",
"hex": "00202d51ca420d0b6ab56c97ca2631d7304c9ad9025252ea71f3af8f97361679042e",
"reqSigs": 1,
"type": "witness_v0_scripthash",
"addresses": [
"sb1q94gu5ssdpd4t2myhegnrr4esfjddjqjj2t48rua037tnv9neqshqm4z7yr"
]
}
}
],
"blockhash": "0fa78bc7e9f6e0a60be71bb5fb2eaaf42a97895bb057f09d7cbb2c49120fa61d",
"confirmations": 500,
"time": 1682451410,
"blocktime": 1682451410
}
Thanks in advance,
Ben
Hi Benjamin,
Keep in mind that the to_local output is only spendable after the delay period which means it is not a valid transaction (and won't show up in the mempool) until the output becomes spendable. This is also true for HTLC outputs if the channel type has anchors. The delay period for HTLCs is only one block if you are trying to redeem an HTLC (instead of timing it out). LND normally automatically handles the submission of these transactions when they become viable. Submitting them prior will do nothing.
I will let others comment on how to actually generate this with lncli or chantools or the like, since I'm unsure of how to do so off the top of my head.
Stay Inspired, Keags
On Fri, May 5, 2023 at 9:19 PM Benjamin Weintraub via Lightning-dev < lightning-dev at lists.linuxfoundation.org> wrote:
Quoted text (183 lines)
> Thank you, Ken. I have a follow up question as well. > > Context: I’m playing around with some failure scenarios in LND. Say Alice > is paying Bob, before Bob is able to send the fulfillment (which includes > the HTLC preimage), Alice’s node dies and becomes unreachable. > > Bob has already received the commitment for the updated balance and > already has the preimage, so he force closes the channel. > > My understanding is that he will submit the updated commitment to the > blockchain as well as the channel closing transaction (after the CSV > timeout) which spends his to_local and the HTLC output. > > Here is my problem. After using `lncli closechannel --force ...` , I only > see the commitment transaction in the mempool, not the subsequent > HTLC/to_local spend. How can I generate the transaction that spends the > to_local and HTLC output? If there's a way to generate it with lnd, that > would be ideal. > > Thanks in advance! > > Ben > ------------------------------ > *From:* Ken Sedgwick <ksedgwic at bonsai.com> > *Sent:* Sunday, April 30, 2023 14:30 > *To:* Benjamin Weintraub <weintraub.b at northeastern.edu> > *Cc:* Lightning-dev at lists.linuxfoundation.org < > lightning-dev at lists.linuxfoundation.org> > *Subject:* Re: [Lightning-dev] Spending `to_local` output of commitment > > Ben, > > The necessary witness is described here: > > https://github.com/lightning/bolts/blob/master/03-transactions.md#to_local-output > > Regards, > > Ken > > On Sat, Apr 29, 2023 at 7:57 PM Benjamin Weintraub via Lightning-dev < > lightning-dev at lists.linuxfoundation.org> wrote: > > Hi all, > > I have a question about commitments. If a peer force closes a channel by > sending a commitment to the blockchain, what kind of witness script is > needed to redeem the `to_local` funds? (assuming the `to_self_delay` has > elapsed.) It seems that the transaction described here is for cooperative > closures: > https://github.com/lightning/bolts/blob/c74a3bbcf890799d343c62cb05fcbcdc952a1cf3/03-transactions.md#closing-transaction > . But for force closures, I would think that the txin would need to be > the `to_local` txout of the commitment. > > Concretely, I have commited the following transaction on a local simnet > bitcoin blockchain and mined 500 blocks on top of it. I want to spend > vout[2], how can I generate such a transaction? > > > { > "hash": > "47d15337bb3c29c7c2881dd7cd912604b401ed221c66ea6f781b456d4983d451", > "size": 444, > "vsize": 279, > "weight": 1113, > "version": 2, > "locktime": 551351761, > "vin": [ > { > "txid": > "0248025b9447df8267d02d14c34ab9b269f52cd827132c70159a55cbf27ab3c1", > "vout": 0, > "scriptSig": { > "asm": "", > "hex": "" > }, > "txinwitness": [ > "", > > "3045022100d3f52ca04d6a71587c29592931e542b16a47f3e9e577f1869b416547d00c62dd0220485da35ad31ff71b4263b1a25f0ba9f35990e1c8d5ac848365bbd588c3ce83d701", > > "3044022057fc3878e17a865c12d57b7885ed48f0d6122bd9e00511c8eac150180d1508d502205fd1d0674a41b3c0118d0b6c19b1c77d35fc95bb89f929da6478f22e94dbf5ce01", > > "5221038acdafe305edd06e91706ee687a091be306f0f29bcbda52dadde084bbaa36c902103d8fd53b9b43638c2255e1abd6f134a0232d2fba65527252c4eb81f926ddf50ad52ae" > ], > "sequence": 2161061453 > } > ], > "vout": [ > { > "value": 0.0000033, > "n": 0, > "scriptPubKey": { > "asm": "0 > 45ec86244376d47000ca6592783ba26f6b2ae619a24c8f5fad249b8c716955d6", > "hex": > "002045ec86244376d47000ca6592783ba26f6b2ae619a24c8f5fad249b8c716955d6", > "reqSigs": 1, > "type": "witness_v0_scripthash", > "addresses": [ > "sb1qghkgvfzrwm28qqx2vkf8swazda4j4ese5fxg7hadyjdccutf2htqysq3qz" > ] > } > }, > { > "value": 0.0000033, > "n": 1, > "scriptPubKey": { > "asm": "0 > 502a17644b334482d0a3f589d9861af6e2105a9b7afd3f5c258efc98bb6aeeed", > "hex": > "0020502a17644b334482d0a3f589d9861af6e2105a9b7afd3f5c258efc98bb6aeeed", > "reqSigs": 1, > "type": "witness_v0_scripthash", > "addresses": [ > "sb1q2q4pweztxdzg959r7kyanps67m3pqk5m0t7n7hp93m7f3wm2amksa0fysc" > ] > } > }, > { > "value": 0.0002, > "n": 2, > "scriptPubKey": { > "asm": "0 > 045553fc789494f16eff4cfa221d0294e140fb79772efeb7d8397d0ac1c4cf85", > "hex": > "0020045553fc789494f16eff4cfa221d0294e140fb79772efeb7d8397d0ac1c4cf85", > "reqSigs": 1, > "type": "witness_v0_scripthash", > "addresses": [ > "sb1qq3248lrcjj20zmhlfnazy8gzjns5p7mewuh0ad7c897s4swye7zsyrm5pc" > ] > } > }, > { > "value": 0.009761, > "n": 3, > "scriptPubKey": { > "asm": "0 > 2d51ca420d0b6ab56c97ca2631d7304c9ad9025252ea71f3af8f97361679042e", > "hex": > "00202d51ca420d0b6ab56c97ca2631d7304c9ad9025252ea71f3af8f97361679042e", > "reqSigs": 1, > "type": "witness_v0_scripthash", > "addresses": [ > "sb1q94gu5ssdpd4t2myhegnrr4esfjddjqjj2t48rua037tnv9neqshqm4z7yr" > ] > } > } > ], > "blockhash": > "0fa78bc7e9f6e0a60be71bb5fb2eaaf42a97895bb057f09d7cbb2c49120fa61d", > "confirmations": 500, > "time": 1682451410, > "blocktime": 1682451410 > } > > > > Thanks in advance, > > Ben > _______________________________________________ > Lightning-dev mailing list > Lightning-dev at lists.linuxfoundation.org > https://www.learnbitcoin.com/archive/lists/lightning-dev > > > > -- > Ken Sedgwick > Bonsai Software, Inc. > http://www.bonsai.com/ken/ > (•••) •••-•••• > ken at bonsai.com > Public Key: http://www.bonsai.com/ken/ken.asc > GPG Fingerprint: 4695 E5B8 F781 BF85 4326 9639 BBFC E515 8602 5550 > > _______________________________________________ > Lightning-dev mailing list > Lightning-dev at lists.linuxfoundation.org > https://www.learnbitcoin.com/archive/lists/lightning-dev >