Populating page even if block is not found
This commit is contained in:
parent
1510a4f88c
commit
8b644a9b67
8
app.py
8
app.py
|
@ -80,15 +80,11 @@ def recent_blocks():
|
||||||
def get_block(slot):
|
def get_block(slot):
|
||||||
this_config = config.get_config()
|
this_config = config.get_config()
|
||||||
start = time.time()
|
start = time.time()
|
||||||
maprows = list(block_details_database.find_block_by_slotnumber(slot))
|
block = block_details_database.find_block_by_slotnumber(slot)
|
||||||
elapsed = time.time() - start
|
elapsed = time.time() - start
|
||||||
if elapsed > .5:
|
if elapsed > .5:
|
||||||
print("block_details_database.find_block_by_slotnumber() took", elapsed, "seconds")
|
print("block_details_database.find_block_by_slotnumber() took", elapsed, "seconds")
|
||||||
if len(maprows):
|
return render_template('block_details.html', config=this_config, block=block)
|
||||||
return render_template('block_details.html', config=this_config, block=maprows[0])
|
|
||||||
else:
|
|
||||||
return "Block not found", 404
|
|
||||||
|
|
||||||
|
|
||||||
def is_slot_number(raw_string):
|
def is_slot_number(raw_string):
|
||||||
return re.fullmatch("[0-9,]+", raw_string) is not None
|
return re.fullmatch("[0-9,]+", raw_string) is not None
|
||||||
|
|
|
@ -28,19 +28,46 @@ def find_block_by_slotnumber(slot_number: int):
|
||||||
""", args=[slot_number])
|
""", args=[slot_number])
|
||||||
|
|
||||||
assert len(maprows) <= 1, "Slot is primary key - find zero or one"
|
assert len(maprows) <= 1, "Slot is primary key - find zero or one"
|
||||||
|
next_slot = (
|
||||||
|
postgres_connection.query(
|
||||||
|
"""
|
||||||
|
SELECT
|
||||||
|
min(slot) as next_slot
|
||||||
|
FROM banking_stage_results_2.blocks
|
||||||
|
WHERE slot > %s
|
||||||
|
""", args=[slot_number])
|
||||||
|
)
|
||||||
|
prev_slot = (
|
||||||
|
postgres_connection.query(
|
||||||
|
"""
|
||||||
|
SELECT
|
||||||
|
max(slot) as prev_slot
|
||||||
|
FROM banking_stage_results_2.blocks
|
||||||
|
WHERE slot < %s
|
||||||
|
""", args=[slot_number])
|
||||||
|
)
|
||||||
|
next_block = list(next_slot)[0]['next_slot']
|
||||||
|
prev_block = list(prev_slot)[0]['prev_slot']
|
||||||
|
|
||||||
for row in maprows:
|
if len(maprows) == 0:
|
||||||
slot = row["slot"]
|
block = {}
|
||||||
|
block["next_block"] = next_block
|
||||||
|
block["prev_block"] = prev_block
|
||||||
|
block["supp_infos"] = {}
|
||||||
|
return block
|
||||||
|
else:
|
||||||
|
block = list(maprows)[0]
|
||||||
|
slot = block["slot"]
|
||||||
|
|
||||||
row['supp_infos'] = json.loads(row['supp_infos'])
|
block['supp_infos'] = json.loads(block['supp_infos'])
|
||||||
|
|
||||||
# note: sort order is undefined
|
# note: sort order is undefined
|
||||||
accountinfos = (
|
accountinfos = (
|
||||||
postgres_connection.query(
|
postgres_connection.query(
|
||||||
"""
|
"""
|
||||||
SELECT
|
SELECT
|
||||||
amb.*,
|
amb.*,
|
||||||
acc.account_key
|
acc.account_key
|
||||||
FROM banking_stage_results_2.accounts_map_blocks amb
|
FROM banking_stage_results_2.accounts_map_blocks amb
|
||||||
INNER JOIN banking_stage_results_2.accounts acc ON acc.acc_id=amb.acc_id
|
INNER JOIN banking_stage_results_2.accounts acc ON acc.acc_id=amb.acc_id
|
||||||
WHERE slot = %s
|
WHERE slot = %s
|
||||||
|
@ -62,36 +89,11 @@ def find_block_by_slotnumber(slot_number: int):
|
||||||
account_info_expanded.append(info)
|
account_info_expanded.append(info)
|
||||||
account_info_expanded.sort(key=lambda acc: int(acc['cu_consumed']), reverse=True)
|
account_info_expanded.sort(key=lambda acc: int(acc['cu_consumed']), reverse=True)
|
||||||
|
|
||||||
row["heavily_writelocked_accounts_parsed"] = [acc for acc in account_info_expanded if acc['is_write_locked'] is True]
|
block["heavily_writelocked_accounts_parsed"] = [acc for acc in account_info_expanded if acc['is_write_locked'] is True]
|
||||||
row["heavily_readlocked_accounts_parsed"] = [acc for acc in account_info_expanded if acc['is_write_locked'] is False]
|
block["heavily_readlocked_accounts_parsed"] = [acc for acc in account_info_expanded if acc['is_write_locked'] is False]
|
||||||
next_slot = (
|
block["next_block"] = next_block
|
||||||
postgres_connection.query(
|
block["prev_block"] = prev_block
|
||||||
"""
|
return block
|
||||||
SELECT
|
|
||||||
slot
|
|
||||||
FROM banking_stage_results_2.blocks
|
|
||||||
WHERE slot > %s ORDER BY slot LIMIT 1
|
|
||||||
""", args=[slot])
|
|
||||||
)
|
|
||||||
prev_slot = (
|
|
||||||
postgres_connection.query(
|
|
||||||
"""
|
|
||||||
SELECT
|
|
||||||
slot
|
|
||||||
FROM banking_stage_results_2.blocks
|
|
||||||
WHERE slot < %s ORDER BY slot desc LIMIT 1
|
|
||||||
""", args=[slot])
|
|
||||||
)
|
|
||||||
next_block = None
|
|
||||||
for block in next_slot:
|
|
||||||
next_block = block['slot']
|
|
||||||
|
|
||||||
prev_block = None
|
|
||||||
for block in prev_slot:
|
|
||||||
prev_block = block['slot']
|
|
||||||
row["next_block"] = next_block
|
|
||||||
row["prev_block"] = prev_block
|
|
||||||
return maprows
|
|
||||||
|
|
||||||
|
|
||||||
def is_matching_blockhash(block_hash):
|
def is_matching_blockhash(block_hash):
|
||||||
|
|
|
@ -27,8 +27,13 @@
|
||||||
<table class="table table-sm table-nowrap card-table">
|
<table class="table table-sm table-nowrap card-table">
|
||||||
<tbody class="list">
|
<tbody class="list">
|
||||||
<tr>
|
<tr>
|
||||||
|
{% if block.slot %}
|
||||||
<td class="w-100">Slot</td>
|
<td class="w-100">Slot</td>
|
||||||
<td class="text-lg-end font-monospace"><span class="font-monospace"><a href="https://explorer.solana.com//block/{{block.slot}}?cluster={{config.cluster}}">{{ block.slot | slotnumber }}</a></span></td>
|
<td class="text-lg-end font-monospace"><span class="font-monospace"><a href="https://explorer.solana.com//block/{{block.slot}}?cluster={{config.cluster}}">{{ block.slot | slotnumber }}</a></span></td>
|
||||||
|
{% else %}
|
||||||
|
<td class="w-100">Status</td>
|
||||||
|
<td class="text-lg-end font-monospace"><span>Block Not Found</span></td>
|
||||||
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="w-100">Blockhash</td>
|
<td class="w-100">Blockhash</td>
|
||||||
|
@ -47,6 +52,7 @@
|
||||||
<td class="w-100">Previous Block</td>
|
<td class="w-100">Previous Block</td>
|
||||||
<td class="text-lg-end font-monospace"><span class="font-monospace"><a href="/block/{{block.prev_block}}">{{ block.prev_block | slotnumber }}</a></span></td>
|
<td class="text-lg-end font-monospace"><span class="font-monospace"><a href="/block/{{block.prev_block}}">{{ block.prev_block | slotnumber }}</a></span></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% if block.slot %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="w-100">Processed Transactions</td>
|
<td class="w-100">Processed Transactions</td>
|
||||||
<td class="text-lg-end font-monospace"><span>{{ block.processed_transactions | count }}</span></td>
|
<td class="text-lg-end font-monospace"><span>{{ block.processed_transactions | count }}</span></td>
|
||||||
|
@ -79,6 +85,7 @@
|
||||||
<td class="w-100">Prioritization Fees p90</td>
|
<td class="w-100">Prioritization Fees p90</td>
|
||||||
<td class="text-lg-end font-monospace"><span>{{ block.supp_infos.p_90 | lamports }} micro-lamports/CU</span></td>
|
<td class="text-lg-end font-monospace"><span>{{ block.supp_infos.p_90 | lamports }} micro-lamports/CU</span></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% endif %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue