Skip to content

Commit

Permalink
fix(stats): add backup case for gas_price=null
Browse files Browse the repository at this point in the history
  • Loading branch information
bragov4ik committed Jul 10, 2024
1 parent 48201e2 commit d1f39cf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
22 changes: 20 additions & 2 deletions stats/stats/src/charts/lines/average_txn_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ impl ChartPartialUpdater for AverageTxnFee {
r#"
SELECT
DATE(b.timestamp) as date,
(AVG(t.gas_used * t.gas_price) / $1)::FLOAT as value
(AVG(
t.gas_used *
COALESCE(
t.gas_price,
b.base_fee_per_gas + LEAST(
t.max_priority_fee_per_gas,
t.max_fee_per_gas - b.base_fee_per_gas
)
)
) / $1)::FLOAT as value
FROM transactions t
JOIN blocks b ON t.block_hash = b.hash
WHERE
Expand All @@ -43,7 +52,16 @@ impl ChartPartialUpdater for AverageTxnFee {
r#"
SELECT
DATE(b.timestamp) as date,
(AVG(t.gas_used * t.gas_price) / $1)::FLOAT as value
(AVG(
t.gas_used *
COALESCE(
t.gas_price,
b.base_fee_per_gas + LEAST(
t.max_priority_fee_per_gas,
t.max_fee_per_gas - b.base_fee_per_gas
)
)
) / $1)::FLOAT as value
FROM transactions t
JOIN blocks b ON t.block_hash = b.hash
WHERE
Expand Down
22 changes: 20 additions & 2 deletions stats/stats/src/charts/lines/txns_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ impl ChartPartialUpdater for TxnsFee {
r#"
SELECT
DATE(b.timestamp) as date,
(SUM(t.gas_used * t.gas_price) / $1)::FLOAT as value
(SUM(
t.gas_used *
COALESCE(
t.gas_price,
b.base_fee_per_gas + LEAST(
t.max_priority_fee_per_gas,
t.max_fee_per_gas - b.base_fee_per_gas
)
)
) / $1)::FLOAT as value
FROM transactions t
JOIN blocks b ON t.block_hash = b.hash
WHERE
Expand All @@ -43,7 +52,16 @@ impl ChartPartialUpdater for TxnsFee {
r#"
SELECT
DATE(b.timestamp) as date,
(SUM(t.gas_used * t.gas_price) / $1)::FLOAT as value
(SUM(
t.gas_used *
COALESCE(
t.gas_price,
b.base_fee_per_gas + LEAST(
t.max_priority_fee_per_gas,
t.max_fee_per_gas - b.base_fee_per_gas
)
)
) / $1)::FLOAT as value
FROM transactions t
JOIN blocks b ON t.block_hash = b.hash
WHERE
Expand Down

0 comments on commit d1f39cf

Please sign in to comment.