Skip to content

Commit

Permalink
fix(hubble): improve max height performance (#2062)
Browse files Browse the repository at this point in the history
  • Loading branch information
qlp authored Jun 7, 2024
2 parents 2ac5c5b + 0e7e3d8 commit c04af33
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 34 deletions.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 3 additions & 8 deletions hubble/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,13 @@ impl Config {
.get_inner_logged();

let current = sqlx::query!(
r#"SELECT height
FROM "v0"."logs"
WHERE chain_id = $1
ORDER BY height DESC
NULLS LAST
LIMIT 1"#,
r#"SELECT MAX(height) height FROM "v0"."logs" WHERE chain_id = $1"#,
chain_id.db
)
.fetch_optional(&pool)
.await?
.map(|block| {
if block.height == 0 {
if block.height.unwrap_or(0) == 0 {
info!(
self.start_height,
"no block found, starting at configured start height, or 0 if not defined"
Expand All @@ -96,7 +91,7 @@ impl Config {
self.start_height,
block.height, "block found, starting max(start_height, block_height + 1)"
);
(block.height + 1).max(self.start_height.unwrap_or_default())
(block.height.unwrap_or(0) + 1).max(self.start_height.unwrap_or_default())
}
})
.unwrap_or(self.start_height.unwrap_or_default()) as u64;
Expand Down
9 changes: 8 additions & 1 deletion hubble/src/tm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,14 @@ where
let chain_id = postgres::fetch_or_insert_chain_id(pool, chain_id)
.await?
.get_inner_logged();
let height = sqlx::query!("SELECT height FROM \"v0\".blocks WHERE chain_id = $1 ORDER BY time DESC NULLS LAST LIMIT 1", chain_id.db).fetch_optional(pool).await?.map(|block| block.height + 1).map(|h| Height::from(h as u32));
let height = sqlx::query!(
r#"SELECT MAX(height) height FROM "v0".blocks WHERE chain_id = $1"#,
chain_id.db
)
.fetch_optional(pool)
.await?
.map(|block| block.height.unwrap_or(0) + 1)
.map(|h| Height::from(h as u32));
Ok((chain_id, height))
}

Expand Down

0 comments on commit c04af33

Please sign in to comment.