anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: counterpartyxcp/counterparty-lib
Issue: testnet: apsw.ConstraintError: UNIQUE constraint failed: transactions.tx_hash

counterparty-lib `develop` (from July 30, I believe), with Bitcoin Core 0.11 from btcdrak's source.

```
[INFO] Block: 526440 (4.04s)
[INFO] Block: 526441 (3.78s)
[INFO] Block: 526442 (3.78s)
[INFO] Block: 526443 (3.84s)
[ERROR] Unhandled Exception
Traceback (most recent call last):
  File "/usr/local/bin/counterparty-server", line 9, in <module>
    load_entry_point('counterparty-cli==1.1.1', 'console_scripts', 'counterparty-server')()
  File "/usr/local/lib/python3.4/dist-packages/counterpartycli/__init__.py", line 16, in server_main
    server.main()
  File "/usr/local/lib/python3.4/dist-packages/counterpartycli/server.py", line 135, in main
    server.start_all(db)
  File "/usr/local/lib/python3.4/dist-packages/counterpartylib/server.py", line 372, in start_all
    blocks.follow(db)
  File "/usr/local/lib/python3.4/dist-packages/counterpartylib/lib/blocks.py", line 1074, in follow
    mempool_tx_index = list_tx(db, None, block_index, curr_time, tx_hash, mempool_tx_index)
  File "/usr/local/lib/python3.4/dist-packages/counterpartylib/lib/blocks.py", line 739, in list_tx
    data)
  File "src/cursor.c", line 231, in resetcursor
apsw.ConstraintError: ConstraintError: UNIQUE constraint failed: transactions.tx_hash

```


Changed files:
counterpartylib/lib/blocks.py

diff --git a/counterpartylib/lib/blocks.py b/counterpartylib/lib/blocks.py
index 24e356ab..2eed7e78 100644
--- a/counterpartylib/lib/blocks.py
+++ b/counterpartylib/lib/blocks.py
@@ -699,6 +699,13 @@ def reparse(db, block_index=None, quiet=False):
 
 def list_tx(db, block_hash, block_index, block_time, tx_hash, tx_index, tx_hex=None):
     assert type(tx_hash) == str
+    cursor = db.cursor()
+
+    # Edge case: confirmed tx_hash also in mempool
+    cursor.execute('''SELECT * FROM transactions WHERE tx_hash = ?''', (tx_hash,))
+    transactions = list(cursor)
+    if transactions:
+        return tx_index
 
     # Get the important details about each transaction.
     if tx_hex is None:
@@ -715,7 +722,6 @@ def list_tx(db, block_hash, block_index, block_time, tx_hash, tx_index, tx_hex=N
 
     if source and (data or destination == config.UNSPENDABLE):
         logger.debug('Saving transaction: {}'.format(tx_hash))
-        cursor = db.cursor()
         cursor.execute('''INSERT INTO transactions(
                             tx_index,
                             tx_hash,