Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(indexer): don't panic when failed to get ethereum block timestamp #187

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading