Skip to content

Commit

Permalink
fix(indexer): don't panic when failed to get ethereum block timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
ptisserand committed Apr 12, 2024
1 parent 11bf920 commit bfc9e82
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
31 changes: 19 additions & 12 deletions apps/indexer/src/ethereum_indexer/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,27 @@ impl EthereumClient {
}
}

pub async fn get_block_timestamp(&self, block_id: u64) -> u64 {
match self
.provider
.get_block(block_id)
.await
.expect(&format!("Can't fetch block {}", block_id))
{
None => 0,
Some(block) => block
.timestamp
.try_into()
.expect("Can't convert block timestamp to u64"),
pub async fn get_block_timestamp(&self, block_id: u64) -> Result<u64> {
let block = self.provider.get_block(block_id).await;
if block.is_ok() {
match block.unwrap() {
None => Ok(0),
Some(block) => match block.timestamp.try_into() {
Ok(v) => Ok(v),
Err(e) => {
let msg = format!("Failed to convert timestamp {}: {:?}", block_id, e);
log::warn!("{}", msg);
Err(anyhow!(msg))
}
},
}
} else {
let msg = format!("Eth retrieving block timestamp {}: {:?}", block_id, block);
log::error!("{}", msg);
Err(anyhow!(msg))
}
}

/// Fetches logs for the given block options.
///
/// There is not pagination in ethereum, and no hard limit on block range.
Expand Down
2 changes: 1 addition & 1 deletion apps/indexer/src/ethereum_indexer/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ where

async fn process_pending_withdraws(&self, block_number: u64) -> Result<()> {
let pendings = self.store.get_pending_withdraws().await?;
let timestamp = self.client.get_block_timestamp(block_number).await;
let timestamp = self.client.get_block_timestamp(block_number).await?;
for pending in pendings {
let status = self
.client
Expand Down

0 comments on commit bfc9e82

Please sign in to comment.