Skip to content

Commit

Permalink
fix(hubble): improve reorg handling - use indexer_id
Browse files Browse the repository at this point in the history
  • Loading branch information
qlp committed Sep 12, 2024
1 parent fc275c2 commit 057cf91
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.

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.

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

12 changes: 6 additions & 6 deletions hubble/hubble.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@
indexers = mkOption {
type = types.listOf (
types.submodule {
options.indexer_id = mkOption {
type = types.nullOr types.str;
options.indexer_id = mkOption {
type = types.nullOr types.str;
description = "Id of the indexer which is used by the internal administration of Hubble. Should never change.";
example = "amazing-testnet";
default = null;
};
options.internal_chain_id = mkOption {
type = types.nullOr types.number;
options.internal_chain_id = mkOption {
type = types.nullOr types.number;
description = "Hubble internal chain id, used to fetch the current height when migrating to fetchers.";
example = "4";
default = null;
};
options.new_chain_override = mkOption {
type = types.nullOr types.bool;
options.new_chain_override = mkOption {
type = types.nullOr types.bool;
description = "Indicator that this is a new chain, so the current height must not be used when migrating to fetchers.";
example = "false";
default = null;
Expand Down
4 changes: 2 additions & 2 deletions hubble/src/fetcher/eth/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ impl BlockHandle for EthBlock {
let block_to_insert = self.fetch_block().await?;

if let Some(block_to_insert) = block_to_insert {
debug!("{}: exists", block_height);
debug!("{}: exists => upsert", block_height);
insert_batch_logs(tx, vec![block_to_insert.into()], InsertMode::Upsert).await?;
} else {
debug!("{}: empty", block_height);
debug!("{}: empty => delete", block_height);
delete_eth_log(tx, self.eth_client.chain_id.db, block_height).await?;
}

Expand Down
2 changes: 1 addition & 1 deletion hubble/src/fetcher/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ impl<T: FetcherClient> Indexer<T> {
if block_range_to_finalize.end - block_range_to_finalize.start
< self.chunk_size as u64
{
info!("not much to finalize => sleep a bit");
info!("not much to finalize => retry later");
sleep(Duration::from_millis(1000)).await;
}
} else {
Expand Down
16 changes: 8 additions & 8 deletions hubble/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ pub async fn get_next_block_to_refresh(

pub async fn get_block_range_to_fix(
tx: &mut sqlx::Transaction<'_, Postgres>,
label: String,
indexer_id: IndexerId,
) -> sqlx::Result<Option<BlockRange>> {
let record = sqlx::query!(
"
Expand All @@ -698,11 +698,11 @@ pub async fn get_block_range_to_fix(
WHERE start_height = (
SELECT min(start_height)
FROM hubble.block_fix
WHERE label = $1
WHERE indexer_id = $1
)
GROUP BY start_height
",
label,
indexer_id,
)
.fetch_optional(tx.as_mut())
.await?;
Expand All @@ -715,18 +715,18 @@ pub async fn get_block_range_to_fix(

pub async fn update_block_range_to_fix(
tx: &mut sqlx::Transaction<'_, Postgres>,
label: String,
indexer_id: IndexerId,
range: BlockRange,
) -> sqlx::Result<()> {
// update start of ranges
sqlx::query!(
"
UPDATE hubble.block_fix
SET start_height = $3
WHERE label = $1
WHERE indexer_id = $1
AND start_height = $2
",
label,
indexer_id,
range.start as i64,
range.end as i64,
)
Expand All @@ -737,11 +737,11 @@ pub async fn update_block_range_to_fix(
sqlx::query!(
"
DELETE FROM hubble.block_fix
WHERE label = $1
WHERE indexer_id = $1
AND start_height = $2
AND end_height <= $2
",
label,
indexer_id,
range.end as i64,
)
.execute(tx.as_mut())
Expand Down

0 comments on commit 057cf91

Please sign in to comment.