JoinMarket-Org / joinmarket-clientserver

Bitcoin CoinJoin implementation with incentive structure to convince people to take part
GNU General Public License v3.0
699 stars 173 forks source link

Missing old UTXO in emptied used address #1705

Closed domohawk closed 1 month ago

domohawk commented 1 month ago

So I have JM going through btc-core on watch-only rpc, and noticed the balances were slightly different. I tracked it down to a UTXO that JM (neither qt nor wallet-tool) will show but bitcoin-core still counts. Address didn't show up in gui and wallet-tool displayall showed a 0 balance.

This TX was a couple years ago- I suspect the state is because I emptied the external address (sending it into "used" state) then sent some sats back into the address. I imagine it still showed up in JM at that time, but at some point it disappeared.

Curiously I sent a few more sats to it now, and the GUI now shows the address again but only with the new UTXO sats.

Is there some way to reset the "UTXO history" for the wallet, other than a full phrase recovery? The amount in the missing UTXO is small so have not risked a full wallet recovery.

roshii commented 1 month ago

You may want to increase gap limit: see https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/master/docs/USAGE.md#gaplimit

domohawk commented 1 month ago

I tried increasing gap limit and didn't work, but that's not the issue. Both gui and wallet-tool now show the address, but only with the balance of the recent UTXO. If i check bitcoin-core or use online block explorer, I see the address has more balance from the old UTXO.

I suspect there is some code that once an external address is emptied, it's marked "used" and not meant to be reused. After some time or confluence of events the old UTXOs stop showing up and now JM's "UTXO cache" index is past where that UTXO happened.

domohawk commented 1 month ago

Ok so I have more info, definitely a bug. After reloading the GUI the address with the new UTXO balance is now gone.

  1. wallet-tool displayall shows the address with a balance of 0 ("used" state, not "deposit")
  2. wallet-tool showutxos does NOT show the utxos
  3. wallet-tool history DOES show the previous 2 deposit utxos that still exist at the address.

More tellingly, history shows BUG ERRORs at the end of output

BUG ERROR: wallet balance (X) does not match balance from history (X+Y)
BUG ERROR: wallet utxo count (N) does not match utxo count from history (N+3)

Seems like an issue where once an address goes into "used" state, it cannot go back to "deposit", and "used" state address UTXOs are ignored/discarded..?

domohawk commented 1 month ago

Ok, I suspect it was because I was missing deprecatedrpc=create_bdb bitcoin-core config (which I just saw added to the notes in the latest 9.11 version). I did some sweep tx's and suddenly all my addresses that were frozen were all 0.

I did a wallet-tool --recoversync and all the address balances show up now.