ElementsProject / lightning

Core Lightning — Lightning Network implementation focusing on spec compliance and performance
Other
2.87k stars 906 forks source link

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

Open whitslack opened 6 months ago

whitslack commented 6 months ago

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:

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.

whitslack commented 2 weeks ago

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

Its existence was interfering with my using fundchannel minconf=0, so I had to get rid of it. I manually deleted it from the outputs table in the database, and it promptly stopped appearing in the output of listfunds, so I hope that was a safe thing to do. :crossed_fingers: