wallet: upgrading a non-persistent coin lock to persistent leaves a stale lock on the spent output after restart #36304

issue elnosh opened this issue on September 20, 2026
  1. elnosh commented at 6:49 PM on September 20, 2026: none

    Is there an existing issue for this?

    • I have searched the existing issues

    Current behaviour

    I did the following against a wallet:

    1. fundrawtransaction with "lockUnspents": true
    2. lockunspent false [those inputs] persistent=true to make the same locks survive a restart.
    3. Signed and broadcast the funded transaction, then mined a block.

    After step 3 listlockunspent is empty, since the wallet released the locks when it saw the inputs get spent. But after restarting bitcoind and loading the wallet, listlockunspent lists those inputs again, even though they are spent and gettxout returns nothing for them.

    Expected behaviour

    A lock that the wallet already released when the output was spent should not come back after a restart.

    Steps to reproduce

    an LLM wrote this script but it follows the steps I did against the wallet that surfaced the issue

    bitcoin-cli -regtest createwallet w
    ADDR=$(bitcoin-cli -regtest -rpcwallet=w getnewaddress)
    bitcoin-cli -regtest -rpcwallet=w generatetoaddress 101 $ADDR
    
    # 1. fund a transaction with lockUnspents
    RAW=$(bitcoin-cli -regtest -rpcwallet=w createrawtransaction '[]' "{\"$(bitcoin-cli -regtest -rpcwallet=w getnewaddress)\":1}")
    FUNDED=$(bitcoin-cli -regtest -rpcwallet=w fundrawtransaction $RAW '{"lockUnspents":true,"minconf":1}' | jq -r .hex)
    LOCKED=$(bitcoin-cli -regtest -rpcwallet=w listlockunspent | jq -c .)
    echo $LOCKED                      # one outpoint
    
    # 2. re-lock that outpoint with persistent=true
    bitcoin-cli -regtest -rpcwallet=w lockunspent false "$LOCKED" true
    
    # 3. spend the locked output and confirm it
    SIGNED=$(bitcoin-cli -regtest -rpcwallet=w signrawtransactionwithwallet $FUNDED | jq -r .hex)
    bitcoin-cli -regtest sendrawtransaction $SIGNED
    bitcoin-cli -regtest -rpcwallet=w listlockunspent      # [] as expected
    bitcoin-cli -regtest -rpcwallet=w generatetoaddress 1 $ADDR
    
    # 4. reload the wallet (a bitcoind restart behaves the same)
    bitcoin-cli -regtest unloadwallet w
    bitcoin-cli -regtest loadwallet w
    bitcoin-cli -regtest -rpcwallet=w listlockunspent      # the spent outpoint is back
    bitcoin-cli -regtest gettxout <txid> <vout>            # empty
    
    

    Relevant log output

    No response

    How did you obtain Bitcoin Core

    Compiled from source

    What version of Bitcoin Core are you using?

    v30.2

    Operating system and version

    Ubuntu 24.04 LTS

    Machine specifications

    No response


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: 2026-09-28 10:51 UTC

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