Instability in listunspent after #24699 #26406

issue bitcoinhodler openend this issue on October 28, 2022
  1. bitcoinhodler commented at 0:28 am on October 28, 2022: contributor

    I maintain a wallet that uses bitcoin-cli for signing transactions, and its test system uses regtest to create a bunch of UTXOs for the signing tests to sign. These tests use a git-committed wallet.dat that is copied into the newly-created datadir before launching bitcoind.

    For years, up until bc886fcb31e1afa7bbf7b86bfd93e51da7076ccf (part of #24699), this was stable and worked well. Occasionally I would need to recreate all the transactions when this project changed mining (#24732) or coin selection (#24584) but I could handle that.

    What I can’t handle is having the generated transactions be different each time I run the exact same sequence of bitcoin-cli commands starting from the same wallet.dat. Starting with bc886fcb31e1afa7bbf7b86bfd93e51da7076ccf, that’s what happens.

    Is this a supported use model, or is it unreasonable to expect this to be stable?

    Summarizing:

    • v0.20.0 – stable
    • v0.21.0 – stable
    • v22.0 – stable
    • v23.0 – stable
    • 272356024db978c92112167f8d8e4cc62adad63d (which is bc886fcb31e1afa7bbf7b86bfd93e51da7076ccf^) – stable
    • bc886fcb31e1afa7bbf7b86bfd93e51da7076ccf – unstable
    • v24.0rc2 – unstable
    • Current master (f37bd15d472fdc7dd3d40cafaba9e8dfddd6b530) – unstable

    Expected behavior

    The generated transactions should be identical given an identical series of bitcoin-cli calls.

    Actual behavior

    The generated transactions choose different input coins from the regtest blockchain every time I run.

    To reproduce

    In my Glacier wallet fork, run t/online_regtest_wallet.py recreate-all-tests; git commit the result. Run the same command again – git status should show no changes.

    When it’s unstable, dozens of files change.

    System information

    Running on Whonix 16. Building inside the git repo as such:

    0(cd depends && make -j4 NO_QT=1) && ./autogen.sh && ./configure --prefix=`pwd`/depends/x86_64-pc-linux-gnu && make -j4
    
  2. bitcoinhodler added the label Bug on Oct 28, 2022
  3. achow101 commented at 0:40 am on October 28, 2022: member
    I don’t think it is reasonable to expect that coin selection will be deterministic, especially because we intentionally introduced a random coin selection algorithm. Determinism also has an issue with being potentially fingerprinting as well as potentially revealing other information about your wallet.
  4. willcl-ark commented at 1:48 pm on October 28, 2022: contributor
    For what benefit would you want to have Bitcoin Core’s coin control select the same coins deterministically? If you want bitcoin core to deteministically create transactions for tests, it seems that you’d be better off using createrawtransaction and supplying the inputs and outputs manually…
  5. bitcoinhodler renamed this:
    Instability in coin selection after #24699
    Instability in `listunspent` after #24699
    on Oct 28, 2022
  6. bitcoinhodler commented at 5:21 pm on October 28, 2022: contributor

    @willcl-ark because I am testing a command-line wallet that signs transactions. I want to submit the signed transactions to a regtest blockchain for validation. I don’t want the unsigned transactions that I give to the wallet changing every time I run because that could hide bugs in the wallet code. @achow101 based on your comment, I went to implement explicit coin selection, only to realize I was already doing so.

    I’d misdiagnosed the issue: it wasn’t coin selection that was unstable, but the order of UTXOs output by listunspent.

    I fixed that by sorting the unspents before choosing amongst them. Problem solved.

  7. bitcoinhodler closed this on Oct 28, 2022

  8. bitcoin locked this on Oct 28, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-18 21:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me