diff --git a/account_details_database.py b/account_details_database.py index b569b18..9447c20 100644 --- a/account_details_database.py +++ b/account_details_database.py @@ -2,24 +2,23 @@ import transaction_database import postgres_connection import json -def build_account_details(pubkey: str): + +def build_account_details(pubkey: str, recent_blocks_row_limit=10): (transactions, is_limit_exceeded) = list(transaction_database.query_transactions_by_address(pubkey)) - account = {} - account['pubkey'] = pubkey + account = {'pubkey': pubkey} blocks = postgres_connection.query( """ - SELECT * FROM ( SELECT slot, total_cu_consumed, prioritization_fees_info - FROM banking_stage_results_2.accounts_map_blocks - WHERE acc_id = (select acc_id from banking_stage_results_2.accounts where account_key = %s) and is_write_locked = true - order by slot desc - limit 10 - ) AS data - """, args=[pubkey]) + FROM banking_stage_results_2.accounts_map_blocks b + INNER JOIN banking_stage_results_2.accounts acc ON acc.acc_id=b.acc_id + WHERE b.is_write_locked AND account_key = %s + ORDER BY slot DESC + limit %s + """, args=[pubkey, recent_blocks_row_limit]) for row in blocks: pf = json.loads(row['prioritization_fees_info']) row['min'] = pf['min'] @@ -28,8 +27,7 @@ def build_account_details(pubkey: str): row['p75'] = pf['p75'] row['p90'] = pf['p90'] row['p95'] = pf['p95'] - account['blocks'] = blocks - return (account, transactions, is_limit_exceeded) + return account, blocks, transactions, is_limit_exceeded def main(): build_account_details('AfASDKLEWG7Di9HtZDmHKftR1fsMXBtTSxP7qMo9qv7L') diff --git a/app.py b/app.py index baf7505..1aa4775 100644 --- a/app.py +++ b/app.py @@ -94,11 +94,11 @@ def get_account(pubkey): if not is_b58_44(pubkey): return "Invalid account", 404 start = time.time() - (account, transactions, is_limit_exceeded) = account_details_database.build_account_details(pubkey) + (account, blocks, transactions, is_limit_exceeded) = account_details_database.build_account_details(pubkey, recent_blocks_row_limit=10) elapsed = time.time() - start if elapsed > .5: print("account_details_database.build_account_details() took", elapsed, "seconds") - return render_template('account_details.html', config=this_config, account=account, transactions=transactions, limit_exceeded=is_limit_exceeded) + return render_template('account_details.html', config=this_config, account=account, recent_blocks=blocks, transactions=transactions, limit_exceeded=is_limit_exceeded) def is_slot_number(raw_string): diff --git a/templates/account_details.html b/templates/account_details.html index ec5c6a7..375a394 100644 --- a/templates/account_details.html +++ b/templates/account_details.html @@ -64,7 +64,7 @@ - {% for block in account.blocks %} + {% for block in recent_blocks %} diff --git a/transaction_database.py b/transaction_database.py index 76a95df..92718b9 100644 --- a/transaction_database.py +++ b/transaction_database.py @@ -16,7 +16,8 @@ def run_query(transaction_row_limit=None, filter_txsig=None, filter_account_addr ( txi is not null ) AS was_included_in_block, txi.cu_requested, txi.prioritization_fees, - utc_timestamp + utc_timestamp, + tx_slot.transaction_id FROM banking_stage_results_2.transaction_slot tx_slot INNER JOIN banking_stage_results_2.transactions txs ON txs.transaction_id=tx_slot.transaction_id LEFT JOIN banking_stage_results_2.transaction_infos txi ON txi.transaction_id=tx_slot.transaction_id @@ -29,7 +30,8 @@ def run_query(transaction_row_limit=None, filter_txsig=None, filter_account_addr WHERE account_key = %s )) ) AS data - ORDER BY utc_timestamp DESC + -- transaction_id is required as tie breaker + ORDER BY utc_timestamp, transaction_id DESC LIMIT %s """, [ filter_txsig is None, filter_txsig,