From 8e61090a2530b7bf5f81ed9947628c28623c82a6 Mon Sep 17 00:00:00 2001 From: Ouziel Slama Date: Sat, 4 Jan 2025 16:21:22 +0000 Subject: [PATCH 1/2] Fix transaction_type field --- .../counterpartycore/lib/blocks.py | 23 +++++++++++++------ .../counterpartycore/lib/gettxinfo.py | 4 +++- .../counterpartycore/lib/message_type.py | 10 +++++--- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/counterparty-core/counterpartycore/lib/blocks.py b/counterparty-core/counterpartycore/lib/blocks.py index 07fca77aa0..b976967a2e 100644 --- a/counterparty-core/counterpartycore/lib/blocks.py +++ b/counterparty-core/counterpartycore/lib/blocks.py @@ -429,22 +429,24 @@ def parse_block( return None, None, None -def update_transaction_type(db): +def update_transaction_type(db, fix_utxo_move=False): start = time.time() logger.info("Updating `transaction_type` column in `transactions` table...") with db: cursor = db.cursor() - cursor.execute("ALTER TABLE transactions ADD COLUMN transaction_type TEXT") - cursor.execute( - "SELECT tx_index, destination, block_index, data, supported FROM transactions" - ) + if not fix_utxo_move: + cursor.execute("ALTER TABLE transactions ADD COLUMN transaction_type TEXT") + sql = "SELECT tx_index, destination, block_index, data, utxos_info, supported FROM transactions" + if fix_utxo_move: + sql += " WHERE transaction_type = 'utxomove'" + cursor.execute(sql) counter = 0 for tx in cursor.fetchall(): transaction_type = "unknown" if tx["supported"]: transaction_type = message_type.get_transaction_type( - tx["data"], tx["destination"], tx["block_index"] + tx["data"], tx["destination"], tx["utxos_info"].split(" "), tx["block_index"] ) cursor.execute( @@ -585,6 +587,11 @@ def initialise(db): if "transaction_type" not in transactions_columns: update_transaction_type(db) + if database.get_config_value(db, "FIX_TRANSACTION_TYPE_1") is None: + with db: + update_transaction_type(db, fix_utxo_move=True) + database.set_config_value(db, "FIX_TRANSACTION_TYPE_1", True) + database.create_indexes( cursor, "transactions", @@ -1055,7 +1062,9 @@ def list_tx(db, block_hash, block_index, block_time, tx_hash, tx_index, decoded_ "fee": fee, "data": data, "utxos_info": " ".join(utxos_info), - "transaction_type": message_type.get_transaction_type(data, destination, block_index), + "transaction_type": message_type.get_transaction_type( + data, destination, utxos_info, block_index + ), } ledger.insert_record(db, "transactions", transaction_bindings, "NEW_TRANSACTION") diff --git a/counterparty-core/counterpartycore/lib/gettxinfo.py b/counterparty-core/counterpartycore/lib/gettxinfo.py index 67a3f80e62..8d1efc8596 100644 --- a/counterparty-core/counterpartycore/lib/gettxinfo.py +++ b/counterparty-core/counterpartycore/lib/gettxinfo.py @@ -761,7 +761,9 @@ def get_utxos_info(db, decoded_tx): def update_utxo_balances_cache(db, utxos_info, data, destination, block_index): if util.enabled("utxo_support", block_index=block_index) and not util.PARSING_MEMPOOL: - transaction_type = message_type.get_transaction_type(data, destination, block_index) + transaction_type = message_type.get_transaction_type( + data, destination, utxos_info, block_index + ) if utxos_info[0] != "": # always remove from cache inputs with balance ledger.UTXOBalancesCache(db).remove_balance(utxos_info[0]) diff --git a/counterparty-core/counterpartycore/lib/message_type.py b/counterparty-core/counterpartycore/lib/message_type.py index 26d7f713dc..bfb81ab6ad 100644 --- a/counterparty-core/counterpartycore/lib/message_type.py +++ b/counterparty-core/counterpartycore/lib/message_type.py @@ -44,7 +44,7 @@ def unpack(packed_data, block_index=None): return (message_type_id, message_remainder) -def get_transaction_type(data: bytes, destination: str, block_index: int): +def get_transaction_type(data: bytes, destination: str, utxos_info: list, block_index: int): TRANSACTION_TYPE_BY_ID = { messages.bet.ID: "bet", messages.broadcast.ID: "broadcast", @@ -75,9 +75,13 @@ def get_transaction_type(data: bytes, destination: str, block_index: int): if not data: if destination == config.UNSPENDABLE and block_index <= config.BURN_END: return "burn" - if block_index >= util.get_change_block_index("utxo_support"): + if block_index >= util.get_change_block_index("utxo_support") and utxos_info[0] != "": return "utxomove" - if block_index >= util.get_change_block_index("dispensers"): + if ( + destination != config.UNSPENDABLE + and block_index >= util.get_change_block_index("dispensers") + and block_index < util.get_change_block_index("disable_vanilla_btc_dispense") + ): return "dispense" return "unknown" From ec1fddf38a5723c7e98a53a1d645a38a598da2a4 Mon Sep 17 00:00:00 2001 From: Ouziel Slama Date: Sat, 4 Jan 2025 21:34:36 +0000 Subject: [PATCH 2/2] fix and add tests --- .../counterpartycore/lib/message_type.py | 6 +++- .../fixtures/scenarios/multisig_1_of_2.log | 2 ++ .../fixtures/scenarios/multisig_1_of_2.sql | 1 + .../fixtures/scenarios/multisig_1_of_3.log | 2 ++ .../fixtures/scenarios/multisig_1_of_3.sql | 1 + .../fixtures/scenarios/multisig_2_of_2.log | 2 ++ .../fixtures/scenarios/multisig_2_of_2.sql | 1 + .../fixtures/scenarios/multisig_2_of_3.log | 2 ++ .../fixtures/scenarios/multisig_2_of_3.sql | 1 + .../fixtures/scenarios/multisig_3_of_3.log | 2 ++ .../fixtures/scenarios/multisig_3_of_3.sql | 1 + .../scenarios/parseblock_unittest_fixture.log | 2 ++ .../scenarios/parseblock_unittest_fixture.sql | 1 + .../test/fixtures/scenarios/simplesig.log | 2 ++ .../test/fixtures/scenarios/simplesig.sql | 1 + .../fixtures/scenarios/unittest_fixture.log | 2 ++ .../fixtures/scenarios/unittest_fixture.sql | 1 + .../counterpartycore/test/fixtures/vectors.py | 28 +++++++++++++++---- 18 files changed, 51 insertions(+), 7 deletions(-) diff --git a/counterparty-core/counterpartycore/lib/message_type.py b/counterparty-core/counterpartycore/lib/message_type.py index bfb81ab6ad..f73b37425c 100644 --- a/counterparty-core/counterpartycore/lib/message_type.py +++ b/counterparty-core/counterpartycore/lib/message_type.py @@ -75,7 +75,11 @@ def get_transaction_type(data: bytes, destination: str, utxos_info: list, block_ if not data: if destination == config.UNSPENDABLE and block_index <= config.BURN_END: return "burn" - if block_index >= util.get_change_block_index("utxo_support") and utxos_info[0] != "": + if ( + block_index >= util.get_change_block_index("utxo_support") + and len(utxos_info) > 0 + and utxos_info[0] != "" + ): return "utxomove" if ( destination != config.UNSPENDABLE diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_2.log b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_2.log index 963cbf056c..d4108a506e 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_2.log +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_2.log @@ -1,4 +1,6 @@ Initializing database... +Updating `transaction_type` column in `transactions` table... +Updated 0 transactions in 0.00 seconds Adding `send_type` column to `sends` table Added `send_type` column to `sends` table in 0.00 seconds Adding `source_address` and `destination_address` column to `sends` table diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_2.sql b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_2.sql index 6b8a691a5c..b41e26816c 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_2.sql +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_2.sql @@ -301,6 +301,7 @@ CREATE TABLE config ( name TEXT PRIMARY KEY, value TEXT ); +INSERT INTO config VALUES('FIX_TRANSACTION_TYPE_1','1'); INSERT INTO config VALUES('FIX_ASSET_EVENTS_FIELD_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_2','1'); diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_3.log b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_3.log index a48807ca98..a0b9289d64 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_3.log +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_3.log @@ -1,4 +1,6 @@ Initializing database... +Updating `transaction_type` column in `transactions` table... +Updated 0 transactions in 0.00 seconds Adding `send_type` column to `sends` table Added `send_type` column to `sends` table in 0.00 seconds Adding `source_address` and `destination_address` column to `sends` table diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_3.sql b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_3.sql index fc78446e46..8411ebaec7 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_3.sql +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_3.sql @@ -301,6 +301,7 @@ CREATE TABLE config ( name TEXT PRIMARY KEY, value TEXT ); +INSERT INTO config VALUES('FIX_TRANSACTION_TYPE_1','1'); INSERT INTO config VALUES('FIX_ASSET_EVENTS_FIELD_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_2','1'); diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_2.log b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_2.log index 6eca07a368..8bbd645068 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_2.log +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_2.log @@ -1,4 +1,6 @@ Initializing database... +Updating `transaction_type` column in `transactions` table... +Updated 0 transactions in 0.00 seconds Adding `send_type` column to `sends` table Added `send_type` column to `sends` table in 0.00 seconds Adding `source_address` and `destination_address` column to `sends` table diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_2.sql b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_2.sql index 2a13b3b91a..600d337caa 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_2.sql +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_2.sql @@ -301,6 +301,7 @@ CREATE TABLE config ( name TEXT PRIMARY KEY, value TEXT ); +INSERT INTO config VALUES('FIX_TRANSACTION_TYPE_1','1'); INSERT INTO config VALUES('FIX_ASSET_EVENTS_FIELD_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_2','1'); diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_3.log b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_3.log index 8fbcf852f1..6b212eda44 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_3.log +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_3.log @@ -1,4 +1,6 @@ Initializing database... +Updating `transaction_type` column in `transactions` table... +Updated 0 transactions in 0.00 seconds Adding `send_type` column to `sends` table Added `send_type` column to `sends` table in 0.00 seconds Adding `source_address` and `destination_address` column to `sends` table diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_3.sql b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_3.sql index 06b17404e4..1f9d3a886e 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_3.sql +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_3.sql @@ -301,6 +301,7 @@ CREATE TABLE config ( name TEXT PRIMARY KEY, value TEXT ); +INSERT INTO config VALUES('FIX_TRANSACTION_TYPE_1','1'); INSERT INTO config VALUES('FIX_ASSET_EVENTS_FIELD_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_2','1'); diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_3_of_3.log b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_3_of_3.log index ea7729a0af..14f7296fb3 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_3_of_3.log +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_3_of_3.log @@ -1,4 +1,6 @@ Initializing database... +Updating `transaction_type` column in `transactions` table... +Updated 0 transactions in 0.00 seconds Adding `send_type` column to `sends` table Added `send_type` column to `sends` table in 0.00 seconds Adding `source_address` and `destination_address` column to `sends` table diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_3_of_3.sql b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_3_of_3.sql index 979f0cfd04..7314645831 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_3_of_3.sql +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_3_of_3.sql @@ -301,6 +301,7 @@ CREATE TABLE config ( name TEXT PRIMARY KEY, value TEXT ); +INSERT INTO config VALUES('FIX_TRANSACTION_TYPE_1','1'); INSERT INTO config VALUES('FIX_ASSET_EVENTS_FIELD_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_2','1'); diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/parseblock_unittest_fixture.log b/counterparty-core/counterpartycore/test/fixtures/scenarios/parseblock_unittest_fixture.log index 02e2f4dcdd..1f47807372 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/parseblock_unittest_fixture.log +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/parseblock_unittest_fixture.log @@ -1,4 +1,6 @@ Initializing database... +Updating `transaction_type` column in `transactions` table... +Updated 0 transactions in 0.00 seconds Adding `send_type` column to `sends` table Added `send_type` column to `sends` table in 0.00 seconds Adding `source_address` and `destination_address` column to `sends` table diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/parseblock_unittest_fixture.sql b/counterparty-core/counterpartycore/test/fixtures/scenarios/parseblock_unittest_fixture.sql index 0ef95d79ec..1a6564f408 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/parseblock_unittest_fixture.sql +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/parseblock_unittest_fixture.sql @@ -999,6 +999,7 @@ CREATE TABLE config ( name TEXT PRIMARY KEY, value TEXT ); +INSERT INTO config VALUES('FIX_TRANSACTION_TYPE_1','1'); INSERT INTO config VALUES('FIX_ASSET_EVENTS_FIELD_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_2','1'); diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/simplesig.log b/counterparty-core/counterpartycore/test/fixtures/scenarios/simplesig.log index 1a57751940..94858a3887 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/simplesig.log +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/simplesig.log @@ -1,4 +1,6 @@ Initializing database... +Updating `transaction_type` column in `transactions` table... +Updated 0 transactions in 0.00 seconds Adding `send_type` column to `sends` table Added `send_type` column to `sends` table in 0.00 seconds Adding `source_address` and `destination_address` column to `sends` table diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/simplesig.sql b/counterparty-core/counterpartycore/test/fixtures/scenarios/simplesig.sql index 5d39967acf..f27fb5d3a8 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/simplesig.sql +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/simplesig.sql @@ -301,6 +301,7 @@ CREATE TABLE config ( name TEXT PRIMARY KEY, value TEXT ); +INSERT INTO config VALUES('FIX_TRANSACTION_TYPE_1','1'); INSERT INTO config VALUES('FIX_ASSET_EVENTS_FIELD_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_2','1'); diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/unittest_fixture.log b/counterparty-core/counterpartycore/test/fixtures/scenarios/unittest_fixture.log index 9aa4119f42..4cce4424d4 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/unittest_fixture.log +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/unittest_fixture.log @@ -1,4 +1,6 @@ Initializing database... +Updating `transaction_type` column in `transactions` table... +Updated 0 transactions in 0.00 seconds Adding `send_type` column to `sends` table Added `send_type` column to `sends` table in 0.00 seconds Adding `source_address` and `destination_address` column to `sends` table diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/unittest_fixture.sql b/counterparty-core/counterpartycore/test/fixtures/scenarios/unittest_fixture.sql index e049d6d534..8a9eb5e078 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/unittest_fixture.sql +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/unittest_fixture.sql @@ -998,6 +998,7 @@ CREATE TABLE config ( name TEXT PRIMARY KEY, value TEXT ); +INSERT INTO config VALUES('FIX_TRANSACTION_TYPE_1','1'); INSERT INTO config VALUES('FIX_ASSET_EVENTS_FIELD_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_2','1'); diff --git a/counterparty-core/counterpartycore/test/fixtures/vectors.py b/counterparty-core/counterpartycore/test/fixtures/vectors.py index 1cdac4b6a5..9b296a69f7 100644 --- a/counterparty-core/counterpartycore/test/fixtures/vectors.py +++ b/counterparty-core/counterpartycore/test/fixtures/vectors.py @@ -7560,27 +7560,37 @@ ], "get_transaction_type": [ { - "in": (b"CNTRPRTY00", "", 3000000), + "in": (b"CNTRPRTY00", "", [], 3000000), "out": "unknown", "mock_protocol_changes": {"short_tx_type_id": True}, }, { - "in": (b"[A95428957753448833|1", "", 3000000), + "in": (b"[A95428957753448833|1", "", [], 3000000), "out": "fairmint", "mock_protocol_changes": {"short_tx_type_id": True}, }, { - "in": (None, "", 3000000), + "in": (None, "", ["txid:0"], 3000000), "out": "utxomove", "mock_protocol_changes": {"short_tx_type_id": True, "utxo_support": True}, }, { - "in": (b"eXCPMEME|25000000000|", "", 3000000), + "in": (None, "", [""], 3000000), + "out": "unknown", + "mock_protocol_changes": {"short_tx_type_id": True}, + }, + { + "in": (None, "", [""], 2900000), + "out": "dispense", + "mock_protocol_changes": {"short_tx_type_id": True}, + }, + { + "in": (b"eXCPMEME|25000000000|", "", [], 3000000), "out": "attach", "mock_protocol_changes": {"short_tx_type_id": True}, }, { - "in": (b"fbc1qcxlwq8x9fnhyhgywlnja35l7znt58tud9duqay", "", 3000000), + "in": (b"fbc1qcxlwq8x9fnhyhgywlnja35l7znt58tud9duqay", "", [], 3000000), "out": "detach", "mock_protocol_changes": {"short_tx_type_id": True}, }, @@ -7588,16 +7598,22 @@ "in": ( b"\x02\x00>\xc7\xd9>|n\x19\x00\x00\x00\x00\x00\x00\x00P\x00%?\x9e\x96I\xb3\xf9u\x15$\xb2\x90\xf93Pra\x0c\xcc\x01", "", + [], 3000000, ), "out": "enhanced_send", "mock_protocol_changes": {"short_tx_type_id": True}, }, { - "in": (None, config.UNSPENDABLE_TESTNET, 3000000), + "in": (None, config.UNSPENDABLE_TESTNET, [""], 3000000), "out": "burn", "mock_protocol_changes": {"short_tx_type_id": True, "utxo_support": True}, }, + { + "in": (None, config.UNSPENDABLE_TESTNET, [""], 5000000), + "out": "unknown", + "mock_protocol_changes": {"short_tx_type_id": True, "utxo_support": True}, + }, ], }, "address": {