Skip to content

Commit

Permalink
feat(db): use new column names
Browse files Browse the repository at this point in the history
  • Loading branch information
blombern committed Aug 13, 2024
1 parent 2247565 commit 18f41d2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
15 changes: 6 additions & 9 deletions src/phoenix/demotion_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use sqlx::{PgPool, Row};
use tracing::{debug, info};

use crate::{
env::{ToBeaconExplorerUrl, ToNetwork},
env::ToBeaconExplorerUrl,
phoenix::{
alerts::{telegram::TelegramSafeAlert, SendAlert},
promotion_monitor::is_promotable_error,
Expand All @@ -32,24 +32,21 @@ pub async fn get_builder_demotions(
start: &DateTime<Utc>,
end: &DateTime<Utc>,
) -> Result<Vec<BuilderDemotion>> {
let query = format!(
"
let query = "
SELECT
bd.builder_pubkey,
bb.builder_id,
bd.slot,
bd.sim_error
FROM {network}_builder_demotions bd
INNER JOIN {network}_blockbuilder bb
FROM builder_demotions bd
INNER JOIN builder bb
ON bd.builder_pubkey = bb.builder_pubkey
WHERE bd.inserted_at > $1
AND bd.inserted_at <= $2
ORDER BY bd.inserted_at ASC
",
network = &APP_CONFIG.env.to_network().to_string()
);
";

sqlx::query(&query)
sqlx::query(query)
.bind(start)
.bind(end)
.fetch_all(relay_pool)
Expand Down
15 changes: 6 additions & 9 deletions src/phoenix/inclusion_monitor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use loki_client::PublishedPayloadStats;

use crate::{
beacon_api::{BeaconApi, ExecutionPayload},
env::{ToBeaconExplorerUrl, ToNetwork},
env::ToBeaconExplorerUrl,
phoenix::{
alerts,
inclusion_monitor::proposer_meta::{
Expand Down Expand Up @@ -47,23 +47,20 @@ async fn get_delivered_payloads(
start: &DateTime<Utc>,
end: &DateTime<Utc>,
) -> anyhow::Result<Vec<DeliveredPayload>> {
let query = format!(
"
let query = "
SELECT
inserted_at,
slot,
block_hash,
block_number,
proposer_pubkey
FROM {}_payload_delivered
FROM payload_delivered
WHERE inserted_at > $1
AND inserted_at <= $2
ORDER BY inserted_at ASC
",
&APP_CONFIG.env.to_network().to_string(),
);
";

sqlx::query(&query)
sqlx::query(query)
.bind(start)
.bind(end)
.fetch_all(relay_pool)
Expand Down Expand Up @@ -124,7 +121,7 @@ async fn check_is_adjustment_hash(pg_pool: &PgPool, block_hash: &str) -> anyhow:
"
SELECT EXISTS (
SELECT 1
FROM turbo_adjustment_trace
FROM adjustment_trace
WHERE adjusted_block_hash = $1
)
",
Expand Down
14 changes: 4 additions & 10 deletions src/phoenix/promotion_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ use itertools::Itertools;
use sqlx::{PgPool, Row};
use tracing::{debug, info, warn};

use crate::env::ToNetwork;

use super::{
checkpoint::{self, CheckpointId},
demotion_monitor::{get_builder_demotions, BuilderDemotion},
env::APP_CONFIG,
};

async fn get_missed_slots(mev_pool: &PgPool, start: &DateTime<Utc>) -> Result<Vec<i64>> {
Expand All @@ -30,20 +27,17 @@ async fn promote_builder_ids(
relay_pool: &PgPool,
builder_ids: &Vec<String>,
) -> Result<Vec<(String, String)>> {
let query = format!(
"
UPDATE {}_blockbuilder
let query = "
UPDATE builder
SET is_optimistic = true
WHERE
builder_id = ANY($1)
AND collateral > 0
AND is_optimistic = false
RETURNING builder_id, builder_pubkey
",
APP_CONFIG.env.to_network()
);
";

sqlx::query(&query)
sqlx::query(query)
.bind(builder_ids)
.fetch_all(relay_pool)
.await
Expand Down

0 comments on commit 18f41d2

Please sign in to comment.