CounterpartyXCP / counterparty-core

Counterparty Protocol Reference Implementation
http://counterparty.io
MIT License
287 stars 206 forks source link

`/compose` is constructing transactions with spent txouts #1953

Closed dime-squanderer closed 4 months ago

dime-squanderer commented 4 months ago

Using v10.2.0, on testnet I tried when composing a send on testate against my local node Counterparty tried to spend a spent transaction output.

2024-06-21T14:13:08.630335000-04:00 - [   TRACE] - API Request - 127.0.0.1 GET http://localhost:14000/v2/addresses/tb1qmlykf0ej29ane2874y38c46kezr7jywrw6jqr9/compose/send?destination=tb1q26dvutas09nshf78h4k0wr2ddz63zz3ckay8vs&asset=XCP&quantity=10&allow_unconfirmed_inputs=true&fee=167
2024-06-21T14:13:08.632502000-04:00 - [   DEBUG] - API Request - Compose Send (destination=tb1q26dvutas09nshf78h4k0wr2ddz63zz3ckay8vs asset=XCP quantity=10 allow_unconfirmed_inputs=true fee=167 address=tb1qmlykf0ej29ane2874y38c46kezr7jywrw6jqr9)
2024-06-21T14:13:08.635517000-04:00 - [   TRACE] - API Request - Arguments: {'address': 'tb1qmlykf0ej29ane2874y38c46kezr7jywrw6jqr9', 'destination': 'tb1q26dvutas09nshf78h4k0wr2ddz63zz3ckay8vs', 'asset': 'XCP', 'quantity': 10, 'memo': None, 'memo_is_hex': False, 'use_enhanced_send': True, 'encoding': 'auto', 'fee_per_kb': None, 'regular_dust_size': 546, 'multisig_dust_size': 1000, 'pubkey': None, 'allow_unconfirmed_inputs': True, 'fee': 167, 'fee_provided': 0, 'unspent_tx_hash': None, 'dust_return_pubkey': None, 'disable_utxo_locks': False, 'extended_tx_info': False, 'p2sh_pretx_txid': None, 'segwit': False, 'confirmation_target': 3}
2024-06-21T14:13:08.648634000-04:00 - [   DEBUG] - TX Construct - Constructing `OPRETURN` transaction from tb1qmlykf0ej29ane2874y38c46kezr7jywrw6jqr9.
2024-06-21T14:13:08.649339000-04:00 - [   TRACE] - TX Construct - data_btc_out=0 (data_value=0 len(data_array)=1)
2024-06-21T14:13:08.658013000-04:00 - [   DEBUG] - AddrindexRS Client - Server: `localhost:18432` - Message sent: b'{"method": "blockchain.scripthash.get_utxos", "params": ["2324fbf0a28029871d85f1f7e600ad1e45f0d096fa43a4400ea72ba3c0017508"], "id": 7}\n'
2024-06-21T14:13:08.694638000-04:00 - [   TRACE] - TX Construct - Unspent UTXOs: ['amount: 0.00005296; txid: 19e5b6b130901872f8ea77afe7f3ea2099defa9b936f3e03632da1bd9c7f87ec; vout: 0; confirmations: 1186', 'amount: 0.00364579; txid: 9a3abb655439decdb9514efd2e5c7ce2ffb2fab6c9d9d139bca98146573fb8ee; vout: 1; confirmations: 818']
2024-06-21T14:13:08.700108000-04:00 - [   TRACE] - TX Construct - Fee/KB 0.01014242
2024-06-21T14:13:08.700478000-04:00 - [   TRACE] - TX Construct - New input: amount: 0.00364579; txid: 9a3abb655439decdb9514efd2e5c7ce2ffb2fab6c9d9d139bca98146573fb8ee; vout: 1; confirmations: 818
2024-06-21T14:13:08.700645000-04:00 - [   TRACE] - TX Construct - Size: 247 Fee: 0.00000167 Change quantity: 0.00364412 BTC
2024-06-21T14:13:08.701468000-04:00 - [   DEBUG] - TX Construct - Transaction constructed.
2024-06-21T14:13:08.701953000-04:00 - [   DEBUG] - API Request - Compose Send (destination=tb1q26dvutas09nshf78h4k0wr2ddz63zz3ckay8vs asset=XCP quantity=10 allow_unconfirmed_inputs=true fee=167 address=tb1qmlykf0ej29ane2874y38c46kezr7jywrw6jqr9) - Response 200 - 72ms
2024-06-21T14:13:08.732724000-04:00 - [   TRACE] - API Request - 127.0.0.1 GET http://localhost:14000/v2/bitcoin/addresses/tb1qmlykf0ej29ane2874y38c46kezr7jywrw6jqr9/utxos
2024-06-21T14:13:08.734026000-04:00 - [   DEBUG] - API Request - Get Unspent Txouts (address=tb1qmlykf0ej29ane2874y38c46kezr7jywrw6jqr9)
2024-06-21T14:13:08.735233000-04:00 - [   TRACE] - API Request - Arguments: {'address': 'tb1qmlykf0ej29ane2874y38c46kezr7jywrw6jqr9', 'unconfirmed': False, 'unspent_tx_hash': None}
2024-06-21T14:13:08.742331000-04:00 - [   DEBUG] - AddrindexRS Client - Server: `localhost:18432` - Message sent: b'{"method": "blockchain.scripthash.get_utxos", "params": ["2324fbf0a28029871d85f1f7e600ad1e45f0d096fa43a4400ea72ba3c0017508"], "id": 8}\n'
2024-06-21T14:13:08.761068000-04:00 - [   DEBUG] - API Request - Get Unspent Txouts (address=tb1qmlykf0ej29ane2874y38c46kezr7jywrw6jqr9) - Response 200 - 28ms
2024-06-21T14:13:08.963777000-04:00 - [   TRACE] - No message available in topic `sequence`
2024-06-21T14:13:08.979156000-04:00 - [   TRACE] - API Request - 127.0.0.1 POST http://localhost:14000/v2/bitcoin/transactions?signedhex=02000000000101eeb83f574681a9bc39d1d9c9b6fab2ffe27c5c2efd4e51b9cdde395465bb3a9a0100000000ffffffff020000000000000000306a2e41743866490745f41ffdfe4c2309d5c9918c78423b1746baafdf12a38a8f0438e033534bc71447f54416ad3b98d27c8f050000000000160014dfc964bf32517b3ca8fea9227c5756c887e911c302483045022100eaea2332d9658db1e86da14655752807e20ba6e749f5efc1562a613946e0161d02203ecc51be02642dbc9d0b80a53c4f629d1920bdcee66c1474e757b892c528b53a012102b5e4f10078c695afc8291f77d7ec0c7339c86c50072281bc92962aff7973504b00000000
2024-06-21T14:13:08.983193000-04:00 - [   DEBUG] - API Request - Sendrawtransaction (signedhex=02000000000101eeb83f574681a9bc39d1d9c9b6fab2ffe27c5c2efd4e51b9cdde395465bb3a9a0100000000ffffffff020000000000000000306a2e41743866490745f41ffdfe4c2309d5c9918c78423b1746baafdf12a38a8f0438e033534bc71447f54416ad3b98d27c8f050000000000160014dfc964bf32517b3ca8fea9227c5756c887e911c302483045022100eaea2332d9658db1e86da14655752807e20ba6e749f5efc1562a613946e0161d02203ecc51be02642dbc9d0b80a53c4f629d1920bdcee66c1474e757b892c528b53a012102b5e4f10078c695afc8291f77d7ec0c7339c86c50072281bc92962aff7973504b00000000)
2024-06-21T14:13:08.996920000-04:00 - [   TRACE] - API Request - Arguments: {'signedhex': '02000000000101eeb83f574681a9bc39d1d9c9b6fab2ffe27c5c2efd4e51b9cdde395465bb3a9a0100000000ffffffff020000000000000000306a2e41743866490745f41ffdfe4c2309d5c9918c78423b1746baafdf12a38a8f0438e033534bc71447f54416ad3b98d27c8f050000000000160014dfc964bf32517b3ca8fea9227c5756c887e911c302483045022100eaea2332d9658db1e86da14655752807e20ba6e749f5efc1562a613946e0161d02203ecc51be02642dbc9d0b80a53c4f629d1920bdcee66c1474e757b892c528b53a012102b5e4f10078c695afc8291f77d7ec0c7339c86c50072281bc92962aff7973504b00000000'}
2024-06-21T14:13:09.014684000-04:00 - [   ERROR] - Error in API: Error connecting to http://XXXXXXXX@localhost:18332/: {'code': -25, 'message': 'bad-txns-inputs-missingorspent'}
2024-06-21T14:13:09.015752000-04:00 - [   DEBUG] - API Request - Sendrawtransaction (signedhex=02000000000101eeb83f574681a9bc39d1d9c9b6fab2ffe27c5c2efd4e51b9cdde395465bb3a9a0100000000ffffffff020000000000000000306a2e41743866490745f41ffdfe4c2309d5c9918c78423b1746baafdf12a38a8f0438e033534bc71447f54416ad3b98d27c8f050000000000160014dfc964bf32517b3ca8fea9227c5756c887e911c302483045022100eaea2332d9658db1e86da14655752807e20ba6e749f5efc1562a613946e0161d02203ecc51be02642dbc9d0b80a53c4f629d1920bdcee66c1474e757b892c528b53a012102b5e4f10078c695afc8291f77d7ec0c7339c86c50072281bc92962aff7973504b00000000) - Response 503 (Unknown error) - 36ms
dime-squanderer commented 4 months ago

Related to: https://github.com/CounterpartyXCP/counterparty-core/issues/1954#issuecomment-2185875068

The real issue was that /addresses/tb1qmlykf0ej29ane2874y38c46kezr7jywrw6jqr9/utxos was returning a spent UTXO. I fixed this by restarting addrindexrs, which forced it to sync to the current block height. After that I restarted counterparty-server which made /addresses/tb1qmlykf0ej29ane2874y38c46kezr7jywrw6jqr9/utxos return the correct UTXOs (and, per #1954 the correct X-BITCOIN-HEIGHT in the response header).