Skip to content

Commit

Permalink
fix(comments)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trantorian1 committed Oct 29, 2024
1 parent 72fa73f commit e8b8a09
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions crates/client/rpc/src/versions/v0_8_0/methods/ws/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,35 @@ impl StarknetWsRpcApiV0_8_0Server for crate::Starknet {
block_n = block_n.saturating_add(1);
}

// We need to check the block number at each iteration as the first
// time this is exectued we might already have received some blocks
// from the backend which we manually fecthed from db
// Catching up with the backend
loop {
tokio::select! {
block_info = rx.recv() => {
let block_info = block_info.or_internal_server_error("Failed to retrieve block info")?;
if block_info.header.block_number == block_n {
break send_block_header(&sink, block_info, block_n).await?;
}
},
_ = sink.closed() => {
return Ok(())
}
}
}

// New block headers
loop {
tokio::select! {
block_info = rx.recv() => {
let block_info = block_info.or_internal_server_error("Failed to retrieve block info")?;
if block_info.header.block_number == block_n + 1 {
send_block_header(&sink, block_info, block_n).await?;
} else {
let err = format!(
"Received non-sequential block {}, expected {}",
block_info.header.block_number,
block_n + 1
);
return Err(StarknetWsApiError::internal_server_error(err).into());
}
block_n = block_n.saturating_add(1);
},
Expand Down

0 comments on commit e8b8a09

Please sign in to comment.