From 30a20754166a05ceaa0a1be7f829657e3ca2a246 Mon Sep 17 00:00:00 2001 From: Iuri Date: Sat, 23 Dec 2023 09:46:44 +0100 Subject: [PATCH] Fix queries where CL Client table is used --- .../components/layouts/ChainOverview.tsx | 18 +++++---- packages/client/components/layouts/Epochs.tsx | 2 +- packages/client/pages/slot/[id].tsx | 4 +- packages/server/controllers/slots.ts | 37 ++++++++++++++----- 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/packages/client/components/layouts/ChainOverview.tsx b/packages/client/components/layouts/ChainOverview.tsx index 62d6a4a1..d13a6c1c 100644 --- a/packages/client/components/layouts/ChainOverview.tsx +++ b/packages/client/components/layouts/ChainOverview.tsx @@ -84,14 +84,16 @@ const ChainOverview = () => {
-
- setShowClient(!showClient)} - /> -
+ {network === 'mainnet' && ( +
+ setShowClient(!showClient)} + /> +
+ )}
{blocks && diff --git a/packages/client/components/layouts/Epochs.tsx b/packages/client/components/layouts/Epochs.tsx index a9052e35..3fdce161 100644 --- a/packages/client/components/layouts/Epochs.tsx +++ b/packages/client/components/layouts/Epochs.tsx @@ -485,7 +485,7 @@ const Epochs = ({ epochs, blocksPerEpoch, showCalculatingEpochs }: Props) => { color: themeMode?.darkMode ? 'var(--white)' : 'var(--black)', }} > -
+

{new Date(blockGenesis + epoch.f_epoch * 32 * 12000).toLocaleDateString('ja-JP')}

{new Date(blockGenesis + epoch.f_epoch * 32 * 12000).toLocaleTimeString('ja-JP')}

diff --git a/packages/client/pages/slot/[id].tsx b/packages/client/pages/slot/[id].tsx index c9f009b5..c0f8fdf5 100644 --- a/packages/client/pages/slot/[id].tsx +++ b/packages/client/pages/slot/[id].tsx @@ -329,7 +329,9 @@ const Slot = () => { /> )} - {existsBlock && } + {existsBlock && network === 'mainnet' && ( + + )} {existsBlock && ( { const skip = Number(page) * Number(limit); + const select = network === 'mainnet' + ? ', t_slot_client_guesses.f_best_guess_single AS f_cl_client' + : ''; + + const joinDuties = network === 'mainnet' + ? 'LEFT OUTER JOIN t_slot_client_guesses ON t_proposer_duties.f_proposer_slot = t_slot_client_guesses.f_slot' + : ''; + if (Number(page) > 0) { const blocks = await pgPool.query(` SELECT (f_proposer_slot/32) AS f_epoch, f_proposer_slot AS f_slot, f_proposed, t_eth2_pubkeys.f_pool_name, - t_proposer_duties.f_val_idx AS f_proposer_index, t_slot_client_guesses.f_best_guess_single AS f_cl_client + t_proposer_duties.f_val_idx AS f_proposer_index ${select} FROM t_proposer_duties LEFT OUTER JOIN t_eth2_pubkeys ON t_proposer_duties.f_val_idx = t_eth2_pubkeys.f_val_idx - LEFT OUTER JOIN t_slot_client_guesses ON t_proposer_duties.f_proposer_slot = t_slot_client_guesses.f_slot + ${joinDuties} ORDER BY f_proposer_slot DESC OFFSET ${skip} LIMIT ${Number(limit)} @@ -83,23 +91,26 @@ export const getBlocks = async (req: Request, res: Response) => { } else { + const joinMetrics = network === 'mainnet' + ? 'LEFT OUTER JOIN t_slot_client_guesses ON t_block_metrics.f_slot = t_slot_client_guesses.f_slot' + : ''; + const [actualBlocks, finalBlocks] = await Promise.all([ pgPool.query(` SELECT (f_proposer_slot/32) AS f_epoch, f_proposer_slot AS f_slot, f_proposed, t_eth2_pubkeys.f_pool_name, - t_proposer_duties.f_val_idx AS f_proposer_index, t_slot_client_guesses.f_best_guess_single AS f_cl_client + t_proposer_duties.f_val_idx AS f_proposer_index ${select} FROM t_proposer_duties LEFT OUTER JOIN t_eth2_pubkeys ON t_proposer_duties.f_val_idx = t_eth2_pubkeys.f_val_idx - LEFT OUTER JOIN t_slot_client_guesses ON t_proposer_duties.f_proposer_slot = t_slot_client_guesses.f_slot + ${joinDuties} ORDER BY f_proposer_slot DESC OFFSET ${skip} LIMIT ${Number(limit)} `), pgPool.query(` - SELECT t_block_metrics.f_epoch, t_block_metrics.f_slot, t_eth2_pubkeys.f_pool_name, t_block_metrics.f_proposed, t_block_metrics.f_proposer_index, - t_block_metrics.f_graffiti, t_block_metrics.f_el_block_number, t_slot_client_guesses.f_best_guess_single AS f_cl_client + SELECT t_block_metrics.f_epoch, t_block_metrics.f_slot, t_eth2_pubkeys.f_pool_name, t_block_metrics.f_proposed, t_block_metrics.f_proposer_index, t_block_metrics.f_graffiti, t_block_metrics.f_el_block_number ${select} FROM t_block_metrics LEFT OUTER JOIN t_eth2_pubkeys ON t_block_metrics.f_proposer_index = t_eth2_pubkeys.f_val_idx - LEFT OUTER JOIN t_slot_client_guesses ON t_block_metrics.f_slot = t_slot_client_guesses.f_slot + ${joinMetrics} WHERE t_block_metrics.f_epoch IN ( SELECT DISTINCT(f_epoch) FROM t_block_metrics @@ -135,6 +146,14 @@ export const getSlotById = async (req: Request, res: Response) => { const pgPool = pgPools[network as string]; + const select = network === 'mainnet' + ? ', t_slot_client_guesses.f_best_guess_single AS f_cl_client' + : ''; + + const join = network === 'mainnet' + ? 'LEFT OUTER JOIN t_slot_client_guesses ON t_block_metrics.f_slot = t_slot_client_guesses.f_slot' + : ''; + const [ block, proposerDuties ] = await Promise.all([ pgPool.query(` @@ -144,10 +163,10 @@ export const getSlotById = async (req: Request, res: Response) => { t_block_metrics.f_att_slashings, t_block_metrics.f_voluntary_exits, t_block_metrics.f_sync_bits, t_block_metrics.f_el_fee_recp, t_block_metrics.f_el_gas_limit, t_block_metrics.f_el_gas_used, t_block_metrics.f_el_transactions, t_block_metrics.f_el_block_hash, t_eth2_pubkeys.f_pool_name, - t_block_metrics.f_el_block_number, t_slot_client_guesses.f_best_guess_single AS f_cl_client + t_block_metrics.f_el_block_number ${select} FROM t_block_metrics LEFT OUTER JOIN t_eth2_pubkeys ON t_block_metrics.f_proposer_index = t_eth2_pubkeys.f_val_idx - LEFT OUTER JOIN t_slot_client_guesses ON t_block_metrics.f_slot = t_slot_client_guesses.f_slot + ${join} WHERE t_block_metrics.f_slot = '${id}' `), pgPool.query(`