ElementsProject / ElementsProject/lightning

`listfunds` lists unconfirmed transaction that can never confirm because it conflicts with a confirmed transaction also in the wallet

Open
#7,348 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
3.1k
Forks
1k
Avg merge
4d 10h
Merged PRs (30d)
13

Description

### Issue and Steps to Reproduce

**Two same-valued outputs in the CLN wallet: one confirmed, one unconfirmed:**
```
$ lightning-cli listfunds | jq '.outputs[] | select(.amount_msat == 3043012000)'
{
"txid": "8dd15ef35ae9f93dffbd91363559c134ee7677ec90ba7ec9b87e98e9dcac37f0",
"output": 0,
"amount_msat": 3043012000,
"scriptpubkey": "001483d06d6cd33172510019240fcc995dc9488c2a6c",
"address": "bc1qs0gx6mxnx9e9zqqeys8uex2ae9ygc2nvc547pn",
"status": "unconfirmed",
"reserved": false
}
{
"txid": "4855e70bb0fddc772c167c74803a816fc323f4d4f235524fe6166a6378b670a2",
"output": 0,
"amount_msat": 3043012000,
"scriptpubkey": "0014a15d0ddfba227d9f0383f09e86b2335d17ca1495",
"address": "bc1q59wsmha6yf7e7qur7z0gdv3nt5tu59y4hhr8ua",
"status": "confirmed",
"blockheight": 829100,
"reserved": false
}
```

**Decoding the _unconfirmed_ transaction:**
```
$ alias rev2='sed -Ee '\''s/^.*$/\n\0\n/;:x;s/(\n..)(.*)(..\n)/\3\2\1/;tx;s/\n//g'\'
$ bitcoin-cli decoderawtransaction $(echo "SELECT encode(rawtx, 'hex') FROM transactions WHERE id = '\x$(rev2 <<<8dd15ef35ae9f93dffbd91363559c134ee7677ec90ba7ec9b87e98e9dcac37f0)';" | psql -Xt lightning lightning)
{
"txid": "8dd15ef35ae9f93dffbd91363559c134ee7677ec90ba7ec9b87e98e9dcac37f0",
"hash": "4ea3972dccefa1001a0a2016186f0d63774c885056c9a5ac4eaa9f32e739aa5c",
"version": 2,
"size": 345,
"vsize": 180,
"weight": 720,
"locktime": 0,
"vin": [
{
"txid": "91ae893f62a190cf60acc826e36605a69a468b731c5a0bdfe5f08d17ef305f91",
"vout": 1,
"scriptSig": {
"asm": "",
"hex": ""
},
"txinwitness": [
"",
"3044022073e9cfa7a9147eb57aabd8f4269301a8d54b6daf8711875741ebac1e63d30f1d02201d114b84e243b5bf535f17f56aeba386125ba66f3d7ba99307bd05d055956bdd01",
"30440220207b93d4d59c6e4c310860134c9c9b3a2f6b90912877d56ed2d4901aec47869b02201b9874608aafef21b85ca445c9d0bff0c8083f50d5bd2cebb713c73df797863201",
"52210273ab3a4ceea412968818c5d546a78e4854eb2d46b4bfb02eba86d2f498803fec21031f84193405d120ea2db786d368a61059a3a7cdbec73141a256ae469d23a4b4d252ae"
],
"sequence": 4294967295
}
],
"vout": [
{
"value": 0.03043012,
"n": 0,
"scriptPubKey": {
"asm": "0 83d06d6cd33172510019240fcc995dc9488c2a6c",
"desc": "addr(bc1qs0gx6mxnx9e9zqqeys8uex2ae9ygc2nvc547pn)#em2vyf49",
"hex": "001483d06d6cd33172510019240fcc995dc9488c2a6c",
"address": "bc1qs0gx6mxnx9e9zqqeys8uex2ae9ygc2nvc547pn",
"type": "witness_v0_keyhash"
}
},
{
"value": 0.13617316,
"n": 1,
"scriptPubKey": {
"asm": "1 8a6a98c88db0c054628dbce7ab97687c4cb6092df7b3b02ca42943e801684f05",
"desc": "rawtr(8a6a98c88db0c054628dbce7ab97687c4cb6092df7b3b02ca42943e801684f05)#s7xj63wn",
"hex": "51208a6a98c88db0c054628dbce7ab97687c4cb6092df7b3b02ca42943e801684f05",
"address": "bc1p3f4f3jydkrq9gc5dhnn6h9mg03xtvzfd77emqt9y99p7sqtgfuzsv2sckj",
"type": "witness_v1_taproot"
}
}
]
}
```

**Decoding the _confirmed_ transaction:**
```
$ bitcoin-cli decoderawtransaction $(echo "SELECT encode(rawtx, 'hex') FROM transactions WHERE id = '\x$(rev2 <<<4855e70bb0fddc772c167c74803a816fc323f4d4f235524fe6166a6378b670a2)';" | psql -Xt lightning lightning)
{
"txid": "4855e70bb0fddc772c167c74803a816fc323f4d4f235524fe6166a6378b670a2",
"hash": "b6c01734ad8ef69dca24e7bef8ab3c346c3fb6a4e4a622a99b4dff2d71e28484",
"version": 2,
"size": 345,
"vsize": 180,
"weight": 720,
"locktime": 543435189,
"vin": [
{
"txid": "91ae893f62a190cf60acc826e36605a69a468b731c5a0bdfe5f08d17ef305f91",
"vout": 1,
"scriptSig": {
"asm": "",
"hex": ""
},
"txinwitness": [
"",
"304402201471bd6943231b6043f850aedd132b13d030a1e1c8e03431dbcd0fd55b454098022034b02258f6f88b794e300901a80e44c7413d2d94f5af61064ad03e271c1bec7e01",
"304402204851790e5ee17323902ed72e922e0cbd803acebfca763cafa94fbb4756bd9b0202207c8873fdb10a8c7587388337ab62b494ee446e50d8df5fa7df07a6753c68f3f901",
"52210273ab3a4ceea412968818c5d546a78e4854eb2d46b4bfb02eba86d2f498803fec21031f84193405d120ea2db786d368a61059a3a7cdbec73141a256ae469d23a4b4d252ae"
],
"sequence": 2158399764
}
],
"vout": [
{
"value": 0.03043012,
"n": 0,
"scriptPubKey": {
"asm": "0 a15d0ddfba227d9f0383f09e86b2335d17ca1495",
"desc": "addr(bc1q59wsmha6yf7e7qur7z0gdv3nt5tu59y4hhr8ua)#5wllwuaz",
"hex": "0014a15d0ddfba227d9f0383f09e86b2335d17ca1495",
"address": "bc1q59wsmha6yf7e7qur7z0gdv3nt5tu59y4hhr8ua",
"type": "witness_v0_keyhash"
}
},
{
"value": 0.13617046,
"n": 1,
"scriptPubKey": {
"asm": "0 2801c81bacbaf2e2a5897a68cbd5a5d7edd82d1c7e9ceeec05330a7b3f060a8a",
"desc": "addr(bc1q9qqusxavhtew9fvf0f5vh4d96lkastgu06wwamq9xv98k0cxp29qknqnlr)#hwa8nzd9",
"hex": "00202801c81bacbaf2e2a5897a68cbd5a5d7edd82d1c7e9ceeec05330a7b3f060a8a",
"address": "bc1q9qqusxavhtew9fvf0f5vh4d96lkastgu06wwamq9xv98k0cxp29qknqnlr",
"type": "witness_v0_scripthash"
}
}
]
}
```

**Points of note:**
* Both transactions spend the same prevout, which is why they conflict and why the unconfirmed transaction can never be confirmed.
* The unconfirmed transaction is a _mutual_ close, while the confirmed transaction is the _peer's unilateral_ close.
* The transactions have exactly the same weight despite having different output script types, as a P2WSH output has the same size as a P2TR output.
* The mutual close offered 270 sats more as a mining fee, yet the unilateral close was the one that got mined.

My best guess as to how this happened is that a mutual close was successfully negotiated, but then the peer broadcast their own unilateral close anyway, and the unilateral close is the one that got mined into a block. My node did not drop the mutual close transaction from its wallet when the peer's unilateral close confirmed.

Now I have no way of pruning the unconfirmable transaction from my wallet.

### `getinfo` output
I am running CLN v24.02.2.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.