Skip to content

Commit

Permalink
Fix queries where CL Client table is used
Browse files Browse the repository at this point in the history
  • Loading branch information
IuriPons committed Dec 23, 2023
1 parent 6afb7c0 commit 30a2075
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 19 deletions.
18 changes: 10 additions & 8 deletions packages/client/components/layouts/ChainOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,16 @@ const ChainOverview = () => {
</div>

<div className='flex flex-col gap-y-4'>
<div className='flex justify-center md:justify-start pl-2'>
<Toggle
value={showClient}
labelLeft='CL Clients'
labelRight='Entities'
onToggle={() => setShowClient(!showClient)}
/>
</div>
{network === 'mainnet' && (
<div className='flex justify-center md:justify-start pl-2'>
<Toggle
value={showClient}
labelLeft='CL Clients'
labelRight='Entities'
onToggle={() => setShowClient(!showClient)}
/>
</div>
)}

<div className='flex justify-center space-x-4 md:space-x-5'>
{blocks &&
Expand Down
2 changes: 1 addition & 1 deletion packages/client/components/layouts/Epochs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ const Epochs = ({ epochs, blocksPerEpoch, showCalculatingEpochs }: Props) => {
color: themeMode?.darkMode ? 'var(--white)' : 'var(--black)',
}}
>
<div className='flex flex-col w-[10%]'>
<div className='flex flex-col text-center w-[10%]'>
<p>{new Date(blockGenesis + epoch.f_epoch * 32 * 12000).toLocaleDateString('ja-JP')}</p>
<p>{new Date(blockGenesis + epoch.f_epoch * 32 * 12000).toLocaleTimeString('ja-JP')}</p>
</div>
Expand Down
4 changes: 3 additions & 1 deletion packages/client/pages/slot/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ const Slot = () => {
/>
)}

{existsBlock && <Card title='Client' text={block?.f_cl_client?.toLocaleString() ?? 'others'} />}
{existsBlock && network === 'mainnet' && (
<Card title='Client' text={block?.f_cl_client?.toLocaleString() ?? 'others'} />
)}

{existsBlock && (
<Card
Expand Down
37 changes: 28 additions & 9 deletions packages/server/controllers/slots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,22 @@ export const getBlocks = async (req: Request, res: Response) => {

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)}
Expand All @@ -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
Expand Down Expand Up @@ -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(`
Expand All @@ -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(`
Expand Down

0 comments on commit 30a2075

Please sign in to comment.