diff --git a/types/src/v0/impls/l1.rs b/types/src/v0/impls/l1.rs index 436fe1f8e0..3d3e1c059d 100644 --- a/types/src/v0/impls/l1.rs +++ b/types/src/v0/impls/l1.rs @@ -79,6 +79,34 @@ impl L1Client { L1Snapshot { head, finalized } } + pub async fn wait_for_block(&self, number: u64) -> L1BlockInfo { + let interval = self.provider.get_interval(); + loop { + let block = match self.provider.get_block(number).await { + Ok(Some(block)) => block, + Ok(None) => { + tracing::error!(number, "no such block"); + sleep(interval).await; + continue; + } + Err(err) => { + tracing::error!(%err, number, "failed to get L1 block"); + sleep(interval).await; + continue; + } + }; + let Some(hash) = block.hash else { + tracing::error!(number, ?block, "L1 block has no hash"); + sleep(interval).await; + continue; + }; + break L1BlockInfo { + number, + hash, + timestamp: block.timestamp, + }; + } + } /// Get information about the given block. /// /// If the desired block number is not finalized yet, this function will block until it becomes @@ -107,31 +135,7 @@ impl L1Client { // The finalized block may have skipped over the block of interest. In this case, our block // is still finalized, since it is before the finalized block. We just need to fetch it. - loop { - let block = match self.provider.get_block(number).await { - Ok(Some(block)) => block, - Ok(None) => { - tracing::error!(number, "no such block"); - sleep(interval).await; - continue; - } - Err(err) => { - tracing::error!(%err, number, "failed to get L1 block"); - sleep(interval).await; - continue; - } - }; - let Some(hash) = block.hash else { - tracing::error!(number, ?block, "L1 block has no hash"); - sleep(interval).await; - continue; - }; - break L1BlockInfo { - number, - hash, - timestamp: block.timestamp, - }; - } + self.wait_for_block(number).await } /// Proxy to `Provider.get_block_number`. diff --git a/types/src/v0/impls/state.rs b/types/src/v0/impls/state.rs index 5024ad43f4..61eedee7bd 100644 --- a/types/src/v0/impls/state.rs +++ b/types/src/v0/impls/state.rs @@ -714,16 +714,11 @@ impl HotShotState for ValidatedState { return Err(BlockError::InvalidBlockHeader); } - let l1_head = instance + let _ = instance .l1_client - .wait_for_finalized_block(proposed_header.l1_head()) + .wait_for_block(proposed_header.l1_head()) .await; - if l1_head.number() != proposed_header.l1_head() { - tracing::error!("Invalid proposal: l1_head mismatch"); - return Err(BlockError::InvalidBlockHeader); - } - // validate the proposal if let Err(err) = validate_proposal( &validated_state,