Skip to content

Commit

Permalink
fix(update-validator-rewards): text casting
Browse files Browse the repository at this point in the history
  • Loading branch information
alextes committed Dec 3, 2024
1 parent e9cf1f3 commit f2970b0
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/bin/update-validator-rewards/mev_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use eth_analysis::{
units::{EthNewtype, GweiNewtype, WeiNewtype},
};
use sqlx::PgExecutor;
use sqlx::Row;
use tracing::{debug, info};

use crate::{ValidatorReward, SLOTS_PER_YEAR};
Expand Down Expand Up @@ -45,18 +46,18 @@ pub async fn calc_mev_reward(
executor: impl PgExecutor<'_>,
effective_balance_sum: GweiNewtype,
) -> Result<ValidatorReward> {
let mev_per_slot: EthNewtype = sqlx::query!(
let mev_per_slot: EthNewtype = sqlx::query(
"
SELECT PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY bid_wei)::TEXT AS median_bid_wei
-- median bid in the last 6 months
SELECT
(PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY bid_wei))::NUMERIC::TEXT AS median_bid_wei
FROM mev_blocks
WHERE timestamp > NOW() - INTERVAL '6 months'
"
",
)
.fetch_one(executor)
.await
.unwrap()
.median_bid_wei
.context("expect at least one block in mev_blocks table before computing MEV reward")?
.await?
.get::<String, _>("median_bid_wei")
.parse::<WeiNewtype>()
.context("failed to parse MEV per slot as Wei")?
.into();
Expand Down

0 comments on commit f2970b0

Please sign in to comment.