Cannot unlock already spent output #12738

issue pedrobranco opened this issue on March 20, 2018
  1. pedrobranco commented at 6:51 PM on March 20, 2018: contributor

    When using the lockunspent RPC method to prevent concurrency when creating raw transactions, after spending a locked output it is impossible to remove that output from locked unspent list due to an issue introduced in this PR #11087.

    Example:

    ❯ bitcoin-cli listunspent
    [ { "txid": "889379c3ea542024c2cba1d2f938ed3ea9d77d1c3b25bc36c6cc7b866aed9624", "vout": 0, "address": "mhNZnkDU9DtNqXDCo8jNUpPAYX4bfsdYdy", "scriptPubKey": "21030e468d40a69954e5ed1d9536a8bec61317c423b423a4eac49869609a0034d859ac", "amount": 50.00000000, "confirmations": 101, "spendable": true, "solvable": true, "safe": true } ]
    
    ❯ bitcoin-cli lockunspent false '[{ "txid": "889379c3ea542024c2cba1d2f938ed3ea9d77d1c3b25bc36c6cc7b866aed9624", "vout": 0 }]'
    true
    
    ❯ bitcoin-cli listlockunspent
    [ { "txid": "889379c3ea542024c2cba1d2f938ed3ea9d77d1c3b25bc36c6cc7b866aed9624", "vout": 0 } ]
    
    ❯ bitcoin-cli createrawtransaction '[{"txid":"889379c3ea542024c2cba1d2f938ed3ea9d77d1c3b25bc36c6cc7b866aed9624", "vout":0}]' '{ "mhNZnkDU9DtNqXDCo8jNUpPAYX4bfsdYdy": 49.99999 }'
    02000000012496ed6a867bccc636bc253b1c7dd7a93eed38f9d2a1cbc2242054eac37993880000000000ffffffff0118ee052a010000001976a914145a232ba20c2f679585145d487546cc294cf54e88ac00000000
    
    ❯ bitcoin-cli signrawtransaction 02000000012496ed6a867bccc636bc253b1c7dd7a93eed38f9d2a1cbc2242054eac37993880000000000ffffffff0118ee052a010000001976a914145a232ba20c2f6795851
    45d487546cc294cf54e88ac00000000
    { "hex": "02000000012496ed6a867bccc636bc253b1c7dd7a93eed38f9d2a1cbc2242054eac37993880000000049483045022100e71376bc4336db9021a3ec0d4ec99d160d062d941127771c05ce9120c93be90f02202670572802b27ae363f420cea7a7abd7cf29ac0f7277057a6e4ff1bced6c88eb01ffffffff0118ee052a010000001976a914145a232ba20c2f679585145d487546cc294cf54e88ac00000000", "complete": true }
    
    
    ❯ bitcoin-cli sendrawtransaction 02000000012496ed6a867bccc636bc253b1c7dd7a93eed38f9d2a1cbc2242054eac37993880000000049483045022100e71376bc4336db9021a3ec0d4ec99d160d062d941127771c05ce9120c93be90f02202670572802b27ae363f420cea7a7abd7cf29ac0f7277057a6e4ff1bced6c88eb01ffffffff0118ee052a010000001976a914145a232ba20c2f679585145d487546cc294cf54e88ac00000000
    1b66295a16eda977788516c71d1e87c7a24b88651141678320b50b85c6602026
    
    
    ❯ bitcoin-cli listlockunspent
    [ { "txid": "889379c3ea542024c2cba1d2f938ed3ea9d77d1c3b25bc36c6cc7b866aed9624", "vout": 0 } ]
    
    # Unlock the already spent output
    ❯ bitcoin-cli lockunspent true '[{ "txid": "889379c3ea542024c2cba1d2f938ed3ea9d77d1c3b25bc36c6cc7b866aed9624", "vout": 0 }]'
    error code: -8
    error message:
    Invalid parameter, expected unspent output
    
    ❯ bitcoin-cli listlockunspent
    [ { "txid": "889379c3ea542024c2cba1d2f938ed3ea9d77d1c3b25bc36c6cc7b866aed9624", "vout": 0 } ]
    

    The expected output was:

    # Unlock the already spent output
    ❯ bitcoin-cli lockunspent true '[{ "txid": "889379c3ea542024c2cba1d2f938ed3ea9d77d1c3b25bc36c6cc7b866aed9624", "vout": 0 }]'
    true 
    
    ❯ bitcoin-cli listlockunspent
    [ ]
    
  2. pedrobranco cross-referenced this on Mar 20, 2018 from issue Fix unlocking of an already spent output by pedrobranco
  3. fanquake added the label Wallet on Mar 21, 2018
  4. fanquake added the label RPC/REST/ZMQ on Mar 21, 2018
  5. promag commented at 3:09 PM on March 21, 2018: member

    IMO after sendrawtransaction this should be the case:

    ❯ bitcoin-cli listlockunspent
    []
    

    Because at this point it is not an unspent and it's not listed in listunspent.

    Therefore Invalid parameter, expected unspent output seams to be a sensible error.

  6. pedrobranco commented at 5:02 PM on March 21, 2018: contributor

    IMO after sendrawtransaction this should be the case

    They are different situations:

    • having sendrawtransaction to remove the used unspents from the locked unspent list, which is nice
    • As of now, we cannot unlock spent outputs (in older versions worked fine).
  7. promag commented at 5:09 PM on March 21, 2018: member

    I don't think the fix is to reintroduce the old behavior. As you said:

    cannot unlock spent outputs

    And the call is lockunspent.

  8. promag cross-referenced this on May 3, 2018 from issue wallet: Unlock spent outputs by promag
  9. laanwj closed this on Jun 24, 2018

  10. laanwj referenced this in commit 868cf431be on Jun 24, 2018
  11. PastaPastaPasta referenced this in commit 416473131d on Jul 7, 2020
  12. PastaPastaPasta referenced this in commit a9a0dc664c on Jul 7, 2020
  13. PastaPastaPasta referenced this in commit 719d9a542c on Jul 8, 2020
  14. PastaPastaPasta referenced this in commit a276a69ea9 on Jun 27, 2021
  15. PastaPastaPasta referenced this in commit 6a98d72c54 on Jun 28, 2021
  16. PastaPastaPasta referenced this in commit 21fe14aa24 on Jun 29, 2021
  17. bitcoin locked this on Sep 8, 2021
  18. gades referenced this in commit 50159b671b on Feb 15, 2022

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-05-20 06:55 UTC