Skip to content

Commit 4850b82

Browse files
committed
graph: Remove a possible crash from the polling block stream
PollingBlockStreamContext.parent_ptr contained an expect that failed if the provider didn't return a parent pointer. Turn that panic into an error.
1 parent 171deec commit 4850b82

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

graph/src/blockchain/polling_block_stream.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ where
306306
// Note: We can safely unwrap the subgraph ptr here, because
307307
// if it was `None`, `is_on_main_chain` would be true.
308308
let from = subgraph_ptr.unwrap();
309-
let parent = self.parent_ptr(&from).await?;
309+
let parent = self.parent_ptr(&from, "is_on_main_chain").await?;
310310

311311
return Ok(ReconciliationStep::Revert(parent));
312312
}
@@ -441,7 +441,7 @@ where
441441
.await?;
442442
Ok(ReconciliationStep::ProcessDescendantBlocks(vec![block], 1))
443443
} else {
444-
let parent = self.parent_ptr(&subgraph_ptr).await?;
444+
let parent = self.parent_ptr(&subgraph_ptr, "nonfinal").await?;
445445

446446
// The subgraph ptr is not on the main chain.
447447
// We will need to step back (possibly repeatedly) one block at a time
@@ -453,12 +453,11 @@ where
453453
}
454454
}
455455

456-
async fn parent_ptr(&self, block_ptr: &BlockPtr) -> Result<BlockPtr, Error> {
457-
let ptr = self
458-
.adapter
459-
.parent_ptr(block_ptr)
460-
.await?
461-
.expect("genesis block can't be reverted");
456+
async fn parent_ptr(&self, block_ptr: &BlockPtr, reason: &str) -> Result<BlockPtr, Error> {
457+
let ptr =
458+
self.adapter.parent_ptr(block_ptr).await?.ok_or_else(|| {
459+
anyhow!("Failed to get parent pointer for {block_ptr} ({reason})")
460+
})?;
462461

463462
Ok(ptr)
464463
}

0 commit comments

Comments
 (0)