-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(hapi-evm): get the partial ATH when the old blocks are synchroni…
…zing and when it ends increase the timeout
- Loading branch information
1 parent
2ebfbc7
commit 7c02161
Showing
3 changed files
with
97 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Stats } from '../models/stats/interfaces' | ||
import { sequelizeUtil } from '../utils' | ||
|
||
export const getATHInRange = async ( | ||
lowerBlockNumber: number, | ||
upperBlockNumber: number | ||
) => { | ||
const [rows] = await sequelizeUtil.sequelize.query(` | ||
SELECT | ||
ath_in_range.blocks AS ath_blocks, | ||
COALESCE( | ||
(ath_in_range.max_transaction_sum) :: numeric, | ||
(0) :: numeric | ||
) AS ath_transactions_count, | ||
COALESCE(ath_in_range.gas_used_sum, (0) :: numeric) AS ath_gas_used | ||
FROM | ||
( | ||
WITH subquery AS ( | ||
SELECT | ||
array_to_string(array_agg(block.number), ',' :: text) AS blocks, | ||
sum(jsonb_array_length(block.transactions)) AS total_transaction_count, | ||
sum(block.gas_used) AS gas_used_sum | ||
FROM | ||
evm.block | ||
WHERE (block.number >= ${lowerBlockNumber} and block.number <= ${upperBlockNumber}) | ||
GROUP BY | ||
block."timestamp" | ||
) | ||
SELECT | ||
q2.blocks, | ||
q1.max_transaction_sum, | ||
q2.gas_used_sum | ||
FROM | ||
( | ||
( | ||
SELECT | ||
max(subquery.total_transaction_count) AS max_transaction_sum | ||
FROM | ||
subquery | ||
) q1 | ||
JOIN subquery q2 ON ( | ||
( | ||
q1.max_transaction_sum = q2.total_transaction_count | ||
) | ||
) | ||
) | ||
LIMIT | ||
1 | ||
) ath_in_range | ||
`) | ||
|
||
const row = rows[0] as Stats | ||
|
||
return { | ||
ath_blocks: row.ath_blocks, | ||
ath_transactions_count: Number(row.ath_transactions_count) || 0, | ||
ath_gas_used: Number(row.ath_gas_used) | ||
} as Stats | ||
} |