Skip to content

Commit

Permalink
feat: Now, we do not prefetch the block in the block handlers. To get…
Browse files Browse the repository at this point in the history
… the current block you have to call `ctx.block()` instead of `ctx.block`
  • Loading branch information
luis-herasme committed Jul 23, 2024
1 parent 753420d commit 8c237ad
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions ghost-crab/src/block_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ use std::time::Duration;
pub struct BlockContext {
pub provider: CacheProvider,
pub templates: TemplateManager,
pub block: Block,
pub block: u64,
}

impl BlockContext {
pub async fn block(&self) -> Result<Option<Block>, TransportError> {
self.provider.get_block_by_number(BlockNumberOrTag::Number(self.block), false).await
}
}

pub type BlockHandlerInstance = Arc<Box<(dyn BlockHandler + Send + Sync)>>;
Expand Down Expand Up @@ -53,27 +59,24 @@ pub async fn process_blocks(
continue;
}

let block = provider
.get_block_by_number(BlockNumberOrTag::Number(current_block), false)
.await?
.unwrap();

match execution_mode {
ExecutionMode::Parallel => {
let handler = handler.clone();
let provider = provider.clone();
let templates = templates.clone();

tokio::spawn(async move {
handler.handle(BlockContext { provider, templates, block }).await;
handler
.handle(BlockContext { provider, templates, block: current_block })
.await;
});
}
ExecutionMode::Serial => {
let templates = templates.clone();
let provider = provider.clone();
let templates = templates.clone();

handler.handle(BlockContext { provider, templates, block }).await;
handler.handle(BlockContext { provider, templates, block: current_block }).await;
}
}

Expand Down

0 comments on commit 8c237ad

Please sign in to comment.