I cannot answer all of your questions, but I can give you some help.
From the bitcoin point of view, you can always spend a transaction output (TXO) if it is not spent already by some confirmed transaction.
That said, if you opened a channel but the funding transaction is not confirmed you can spend the TXO that funded the channel, but I don't know how lightningd would react to this.
You said you have closed the channel. If you funds are still stuck it means both the funding channel and close channel transactions are unconfirmed in the mempool.
I would try to spend the TXO in the close TX in a child-pays-for-parent fashion. However, when trying to reproduce that scenario in regtest I find troubles with the clightning user interface.
I did the following to simulate your situation:
- I create a channel with peer
$ l1-cli fundchannel 0397d48baf82cf731fc8967c16e3d9575f10606bdf481738eb9cafeda29d0e3d67 1000000sat
{
"tx": "02000000000101ee026cb7c44f482eb9b1e11f6faf11956ac26f4cdb7e0c1aa9ef94025ec412c30000000000fdffffff0240420f000000000022002075e9a102dbb348646e2f1804cc3cfec9edb6f5551a074f33a615f29cbd45eeaa4c5bd70500000000160014deb1f4e1123694ca3e418cefe496d3c26b0ddde202473044022068b402d53f16204324b28607eca046a4f7121d8f83c62e17de9c9131e307b5cf022077a3aa538469f9e0983cce98c3de4c5427731b398ed395d9614cf7b54d4f5cdd012102f5093f8fd66c909fc72ee556e70cb038ae92b03fd1b56d710cf53b3cc019868e73000000",
"txid": "11b8967c62c584da9bbba5243d61bc95b4da210760bca04adb7c349319edba19",
"channel_id": "9dfe0df4c502c31e92c266bfa28af18d6f6d11a0b0197b838797f8c990625168",
"outnum": 0
}
- I closed the channel
$ l1-cli -k close id=9dfe0df4c502c31e92c266bfa28af18d6f6d11a0b0197b838797f8c990625168
# Sending closing fee offer 139sat, with range 139sat-183sat
# Received closing fee offer 139sat, with range 139sat-1000000sat
{
"tx": "020000000119baed1993347cdb4aa0bc600721dab495bc613d24a5bb9bda84c5627c96b8110000000000ffffffff01b5410f00000000001600141b420a80810dda8fd3621e6ba4ce14ce85b6877e00000000",
"txid": "e6a7d6cc0960f0f7481a3e9a18b9d9cc18ee695dd626a597883be4599c043699",
"type": "mutual"
}
At this point both the funding (11b896...
) and settlement (e6a7d6cc...
) transactions are in the mempool and unconfirmed.
The situation is shown in the diagram below
tx:c312c...(confirmed) ---> tx:11b89... (funding tx unconfirmed) ---> tx:e6a7d6cc... (settlement, unconfirmed)
Solution 1 (that doesn't work)
My idea is to spend the settlement output with a higher fee.
However, I have problems with lightning-cli
to get this working.
If I try to spend the settlement output, which is controlled by my wallet:
$ l1-cli -k txprepare outputs="[{\"bcrt1qx77wq9fyxvhsncswpl6kgqpnc49m5e5lzmls0g\":\"all\"}]" utxos="[\"e6a7d6cc0960f0f7481a3e9a18b9d9cc18ee695dd626a597883be4599c043699:0\"]" feerate=100
{
"code": -32602,
"message": "Unknown UTXO e6a7d6cc0960f0f7481a3e9a18b9d9cc18ee695dd626a597883be4599c043699:0"
}
So probably lightnind is saying: "that UTXO is not in the blockchain, I cannot spend it".
I tried a work-around, creating a PSBT with bitcoin-cli
:
$ bt-cli createpsbt "[{\"txid\":\"e6a7d6cc0960f0f7481a3e9a18b9d9cc18ee695dd626a597883be4599c043699\",\"vout\":0}]" "[{\"bcrt1qx77wq9fyxvhsncswpl6kgqpnc49m5e5lzmls0g\":0.00900000}]"
cHNidP8BAFICAAAAAZk2BJxZ5DuIl6Um1l1p7hjM2bkYmj4aSPfwYAnM1qfmAAAAAAD9////AaC7DQAAAAAAFgAUN7zgFSQzLwniDg/1ZAAzxUu6Zp8AAAAAAAAA
and then signing it with lightning-cli
:
$ l1-cli signpsbt cHNidP8BAFICAAAAAZk2BJxZ5DuIl6Um1l1p7hjM2bkYmj4aSPfwYAnM1qfmAAAAAAD9////AaC7DQAAAAAAFgAUN7zgFSQzLwniDg/1ZAAzxUu6Zp8AAAAAAAAA
{
"code": -1,
"message": "No wallet inputs to sign"
}
It seems that clightning doesn't like to sign transactions inputs that are not confirmed.
Solution 2 (the ugly)
I would spend the TXO that funded the channel since the funding transaction is unconfirmed.
$ l1-cli -k txprepare outputs="[{\"bcrt1qx77wq9fyxvhsncswpl6kgqpnc49m5e5lzmls0g\":\"all\"}]" utxos="[\"c312c45e0294efa91a0c7edb4c6fc26a9511af6f1fe1b1b92e484fc4b76c02ee:0\"]" feerate=100
{
"code": -32602,
"message": "UTXO c312c45e0294efa91a0c7edb4c6fc26a9511af6f1fe1b1b92e484fc4b76c02ee:0 already reserved"
}
So, clightning
sees that even though that TXO is not confirmed it is spent by a channel funding.
Let me try forcing again with bitcoin core PSBT:
$ bt-cli createpsbt "[{\"txid\":\"c312c45e0294efa91a0c7edb4c6fc26a9511af6f1fe1b1b92e484fc4b76c02ee\",\"vout\":0}]" "[{\"bcrt1qx77wq9fyxvhsncswpl6kgqpnc49m5e5lzmls0g\":0.98900000}]"
cHNidP8BAFICAAAAAe4CbLfET0guubHhH2+vEZVqwm9M234MGqnvlAJexBLDAAAAAAD9////ASAY5QUAAAAAFgAUN7zgFSQzLwniDg/1ZAAzxUu6Zp8AAAAAAAAA
and then get a signature from clightning wallet:
$ l1-cli signpsbt cHNidP8BAFICAAAAAe4CbLfET0guubHhH2+vEZVqwm9M234MGqnvlAJexBLDAAAAAAD9////ASAY5QUAAAAAFgAUN7zgFSQzLwniDg/1ZAAzxUu6Zp8AAAAAAAAA
{
"signed_psbt": "cHNidP8BAFICAAAAAe4CbLfET0guubHhH2+vEZVqwm9M234MGqnvlAJexBLDAAAAAAD9////ASAY5QUAAAAAFgAUN7zgFSQzLwniDg/1ZAAzxUu6Zp8AAAAAAAEBHyae5gUAAAAAFgAUrxY3yj79dai67Z9mJ4hHAjQSIzMiAgL1CT+P1myQn8cu5VbnDLA4rpKwP9G1bXEM9Ts8wBmGjkcwRAIgMdOln+3Bzrm5lWqUrBbtEleqYgclYdwSadbs7T8V+18CIFTRsrlwhdZrvrG+UiCGf44+TJrF+Oqj4w+hLFmucBcfASIGAvUJP4/WbJCfxy7lVucMsDiukrA/0bVtcQz1OzzAGYaOCK8WN8oAAAAAACICAoqr3sVLia14vPyrtYQRxA+wniCHWDV34AMh8C5p18haCDe84BUHAAAAAA=="
}
OK, so this time we have a signature, now we can construct the transaction
$ bt-cli finalizepsbt "cHNidP8BAFICAAAAAe4CbLfET0guubHhH2+vEZVqwm9M234MGqnvlAJexBLDAAAAAAD9////ASAY5QUAAAAAFgAUN7zgFSQzLwniDg/1ZAAzxUu6Zp8AAAAAAAEBHyae5gUAAAAAFgAUrxY3yj79dai67Z9mJ4hHAjQSIzMiAgL1CT+P1myQn8cu5VbnDLA4rpKwP9G1bXEM9Ts8wBmGjkcwRAIgMdOln+3Bzrm5lWqUrBbtEleqYgclYdwSadbs7T8V+18CIFTRsrlwhdZrvrG+UiCGf44+TJrF+Oqj4w+hLFmucBcfASIGAvUJP4/WbJCfxy7lVucMsDiukrA/0bVtcQz1OzzAGYaOCK8WN8oAAAAAACICAoqr3sVLia14vPyrtYQRxA+wniCHWDV34AMh8C5p18haCDe84BUHAAAAAA=="
{
"hex": "02000000000101ee026cb7c44f482eb9b1e11f6faf11956ac26f4cdb7e0c1aa9ef94025ec412c30000000000fdffffff012018e5050000000016001437bce01524332f09e20e0ff5640033c54bba669f02473044022031d3a59fedc1ceb9b9956a94ac16ed1257aa62072561dc1269d6eced3f15fb5f022054d1b2b97085d66bbeb1be5220867f8e3e4c9ac5f8eaa3e30fa12c59ae70171f012102f5093f8fd66c909fc72ee556e70cb038ae92b03fd1b56d710cf53b3cc019868e00000000",
"complete": true
}
and broadcast it
$ bt-cli sendrawtransaction 02000000000101ee026cb7c44f482eb9b1e11f6faf11956ac26f4cdb7e0c1aa9ef94025ec412c30000000000fdffffff012018e5050000000016001437bce01524332f09e20e0ff5640033c54bba669f02473044022031d3a59fedc1ceb9b9956a94ac16ed1257aa62072561dc1269d6eced3f15fb5f022054d1b2b97085d66bbeb1be5220867f8e3e4c9ac5f8eaa3e30fa12c59ae70171f012102f5093f8fd66c909fc72ee556e70cb038ae92b03fd1b56d710cf53b3cc019868e00000000
41304c4e992a0718d29cf7c46adb0f361c319d31b92eeb8d7dbc811aebc2b39f
If the miners include the last transaction 41304...
, then the funding 11b896...
and settlement e6a7...
will be invalid. But you still have your funds.
tx:c312c...(confirmed) -X-> tx:11b89... (funding tx unconfirmed) -X-> tx:e6a7d6cc... (settlement, unconfirmed)
|
+---> tx:41304... (confirmed)
Side effects
clightning sees the new funds, but it is still waiting for the previous transactions to confirm:
$ l1-cli listfunds
{
"outputs": [
{
"txid": "11b8967c62c584da9bbba5243d61bc95b4da210760bca04adb7c349319edba19",
"output": 1,
"amount_msat": 97999692000,
"scriptpubkey": "0014deb1f4e1123694ca3e418cefe496d3c26b0ddde2",
"address": "bcrt1qm6clfcgjx62v50jp3nh7f9kncf4smh0z2v5q3d",
"status": "unconfirmed",
"reserved": false
},
{
"txid": "41304c4e992a0718d29cf7c46adb0f361c319d31b92eeb8d7dbc811aebc2b39f",
"output": 0,
"amount_msat": 98900000000,
"scriptpubkey": "001437bce01524332f09e20e0ff5640033c54bba669f",
"address": "bcrt1qx77wq9fyxvhsncswpl6kgqpnc49m5e5lzmls0g",
"status": "confirmed",
"blockheight": 116,
"reserved": false
}
],
"channels": [
{
"peer_id": "0232a73b00b1e4eb6ee1787785640dca55a67bf5e6b338e42efff6a9b21da26c93",
"connected": true,
"state": "CHANNELD_NORMAL",
"channel_id": "a8664ad1bbc4debd16ea2a49b07167f35d3dd9cacac60c0ad6d60fbb76ce78e7",
"short_channel_id": "103x1x1",
"our_amount_msat": 1000000000,
"amount_msat": 1000000000,
"funding_txid": "c312c45e0294efa91a0c7edb4c6fc26a9511af6f1fe1b1b92e484fc4b76c02ee",
"funding_output": 1
}
]
}