From a6381f157de3952596b209484483e2ad8903d32d Mon Sep 17 00:00:00 2001 From: GroovieGermanikus Date: Mon, 18 Dec 2023 12:51:07 +0100 Subject: [PATCH 1/3] tx details: account list accounts will be shown even if there is no amb relation (via block) --- transaction_details_database.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/transaction_details_database.py b/transaction_details_database.py index 18ec05c..8a73b82 100644 --- a/transaction_details_database.py +++ b/transaction_details_database.py @@ -63,22 +63,31 @@ def find_transaction_details_by_sig(tx_sig: str): row["tx_errors_by_slots"] = tx_errors_by_slots - # note: sort order is undefined + # note: sort order will be defined later + # note: amb vs amt: + # * relation does not exist if the transaction was not included + # * in this case the accounts are show but without the infos like prio fee + # * accounts linked via amt have no slot relation and thus appear redundantly for all slots + # * see tx ACQLVWCGhLurkcPp8a2QfaK9rpoe3opcbWa1TBtijhbQ3X6rMYpDcUaa9usY4b4fwj5pgTWj85wew7WhCEyTHBN for example accountinfos_per_slot = ( invert_by_slot( postgres_connection.query( """ SELECT - amb.*, - acc.account_key - FROM banking_stage_results_2.accounts_map_blocks amb - INNER JOIN banking_stage_results_2.accounts_map_transaction amt ON amt.acc_id=amb.acc_id - INNER JOIN banking_stage_results_2.accounts acc ON acc.acc_id=amb.acc_id - WHERE amb.slot IN (SELECT unnest(CAST(%s as bigint[]))) - AND amt.transaction_id = %s + amt.is_writable AS is_account_write_locked, + acc.account_key, + amb.* + FROM banking_stage_results_2.accounts_map_transaction amt + INNER JOIN banking_stage_results_2.accounts acc ON acc.acc_id=amt.acc_id + LEFT JOIN banking_stage_results_2.accounts_map_blocks amb ON amb.acc_id=amt.acc_id AND amb.slot IN (SELECT unnest(CAST(%s as bigint[]))) + WHERE amt.transaction_id = %s """, args=[list(relevant_slots), transaction_id])) ) + for row in accountinfos_per_slot: + if row['is_write_locked'] is not None: + assert row['is_write_locked'] == row['is_account_write_locked'] + write_lock_info = dict() read_lock_info = dict() for relevant_slot in relevant_slots: @@ -90,7 +99,7 @@ def find_transaction_details_by_sig(tx_sig: str): info = { 'slot': account_info['slot'], 'key': account_info['account_key'], - 'is_write_locked': account_info['is_write_locked'], + 'is_account_write_locked': account_info['is_account_write_locked'], 'cu_requested': account_info['total_cu_requested'], 'cu_consumed': account_info['total_cu_consumed'], 'min_pf': prio_fee_data['min'], @@ -99,8 +108,8 @@ def find_transaction_details_by_sig(tx_sig: str): } account_info_expanded.append(info) account_info_expanded.sort(key=lambda acc: int(acc['cu_consumed']), reverse=True) - write_lock_info[relevant_slot] = [acc for acc in account_info_expanded if acc['is_write_locked'] is True] - read_lock_info[relevant_slot] = [acc for acc in account_info_expanded if acc['is_write_locked'] is False] + write_lock_info[relevant_slot] = [acc for acc in account_info_expanded if acc['is_account_write_locked'] is True] + read_lock_info[relevant_slot] = [acc for acc in account_info_expanded if acc['is_account_write_locked'] is False] row["write_lock_info"] = write_lock_info row["read_lock_info"] = read_lock_info From 0856fcaf871c0bce4d3a8d184442f804c6c000c4 Mon Sep 17 00:00:00 2001 From: GroovieGermanikus Date: Mon, 18 Dec 2023 13:00:28 +0100 Subject: [PATCH 2/3] remove invariant check --- transaction_details_database.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/transaction_details_database.py b/transaction_details_database.py index 8a73b82..fab9814 100644 --- a/transaction_details_database.py +++ b/transaction_details_database.py @@ -69,6 +69,7 @@ def find_transaction_details_by_sig(tx_sig: str): # * in this case the accounts are show but without the infos like prio fee # * accounts linked via amt have no slot relation and thus appear redundantly for all slots # * see tx ACQLVWCGhLurkcPp8a2QfaK9rpoe3opcbWa1TBtijhbQ3X6rMYpDcUaa9usY4b4fwj5pgTWj85wew7WhCEyTHBN for example + # * is_write_locked and is_account_write_locked must be the same accountinfos_per_slot = ( invert_by_slot( postgres_connection.query( @@ -84,10 +85,6 @@ def find_transaction_details_by_sig(tx_sig: str): """, args=[list(relevant_slots), transaction_id])) ) - for row in accountinfos_per_slot: - if row['is_write_locked'] is not None: - assert row['is_write_locked'] == row['is_account_write_locked'] - write_lock_info = dict() read_lock_info = dict() for relevant_slot in relevant_slots: From d0a841769dcabc213f20db0784a5c7d6a3155430 Mon Sep 17 00:00:00 2001 From: GroovieGermanikus Date: Mon, 18 Dec 2023 14:29:33 +0100 Subject: [PATCH 3/3] merge account list from amb+amt --- transaction_details_database.py | 74 ++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/transaction_details_database.py b/transaction_details_database.py index fab9814..7083930 100644 --- a/transaction_details_database.py +++ b/transaction_details_database.py @@ -70,41 +70,57 @@ def find_transaction_details_by_sig(tx_sig: str): # * accounts linked via amt have no slot relation and thus appear redundantly for all slots # * see tx ACQLVWCGhLurkcPp8a2QfaK9rpoe3opcbWa1TBtijhbQ3X6rMYpDcUaa9usY4b4fwj5pgTWj85wew7WhCEyTHBN for example # * is_write_locked and is_account_write_locked must be the same - accountinfos_per_slot = ( - invert_by_slot( - postgres_connection.query( - """ - SELECT - amt.is_writable AS is_account_write_locked, - acc.account_key, - amb.* - FROM banking_stage_results_2.accounts_map_transaction amt - INNER JOIN banking_stage_results_2.accounts acc ON acc.acc_id=amt.acc_id - LEFT JOIN banking_stage_results_2.accounts_map_blocks amb ON amb.acc_id=amt.acc_id AND amb.slot IN (SELECT unnest(CAST(%s as bigint[]))) - WHERE amt.transaction_id = %s - """, args=[list(relevant_slots), transaction_id])) - ) + all_accountinfos = ( + postgres_connection.query( + """ + SELECT + amt.is_writable AS is_account_write_locked, + acc.account_key, + amb.* + FROM banking_stage_results_2.accounts_map_transaction amt + INNER JOIN banking_stage_results_2.accounts acc ON acc.acc_id=amt.acc_id + LEFT JOIN banking_stage_results_2.accounts_map_blocks amb ON amb.acc_id=amt.acc_id AND amb.slot IN (SELECT unnest(CAST(%s as bigint[]))) + WHERE amt.transaction_id = %s + ORDER BY amb.total_cu_consumed DESC NULLS LAST, amt.acc_id + """, args=[list(relevant_slots), transaction_id])) write_lock_info = dict() read_lock_info = dict() for relevant_slot in relevant_slots: - accountinfos = accountinfos_per_slot.get(relevant_slot, []) account_info_expanded = [] - for account_info in accountinfos: - prio_fee_data = json.loads(account_info['prioritization_fees_info']) - info = { - 'slot': account_info['slot'], - 'key': account_info['account_key'], - 'is_account_write_locked': account_info['is_account_write_locked'], - 'cu_requested': account_info['total_cu_requested'], - 'cu_consumed': account_info['total_cu_consumed'], - 'min_pf': prio_fee_data['min'], - 'median_pf': prio_fee_data['med'], - 'max_pf': prio_fee_data['max'] - } - account_info_expanded.append(info) - account_info_expanded.sort(key=lambda acc: int(acc['cu_consumed']), reverse=True) + + for account_info in all_accountinfos: + # slot is set if amb relation exists i.e. if the tx was included + maybe_slot = account_info['slot'] + + if maybe_slot and maybe_slot != relevant_slot: + continue + + if maybe_slot is None: + info = { + 'key': account_info['account_key'], + 'is_account_write_locked': account_info['is_account_write_locked'], + 'cu_requested': None, + 'cu_consumed': None, + 'min_pf': None, + 'median_pf': None, + 'max_pf': None, + } + account_info_expanded.append(info) + else: + prio_fee_data = json.loads(account_info['prioritization_fees_info']) + info = { + 'key': account_info['account_key'], + 'is_account_write_locked': account_info['is_account_write_locked'], + 'cu_requested': account_info['total_cu_requested'], + 'cu_consumed': account_info['total_cu_consumed'], + 'min_pf': prio_fee_data['min'], + 'median_pf': prio_fee_data['med'], + 'max_pf': prio_fee_data['max'] + } + account_info_expanded.append(info) + write_lock_info[relevant_slot] = [acc for acc in account_info_expanded if acc['is_account_write_locked'] is True] read_lock_info[relevant_slot] = [acc for acc in account_info_expanded if acc['is_account_write_locked'] is False]