MCPcopy Create free account
hub / github.com/base/base / apply_flashblock

Method apply_flashblock

crates/execution/flashblocks/src/processor.rs:175–227  ·  view source on GitHub ↗
(
        &self,
        prev_pending_blocks: Option<Arc<PendingBlocks>>,
        flashblock: Flashblock,
    )

Source from the content-addressed store, hash-verified

173 }
174
175 async fn apply_flashblock(
176 &self,
177 prev_pending_blocks: Option<Arc<PendingBlocks>>,
178 flashblock: Flashblock,
179 ) {
180 let start_time = Instant::now();
181 match self.process_flashblock(prev_pending_blocks, &flashblock) {
182 Ok(new_pending_blocks) => {
183 if let Some(ref pb) = new_pending_blocks {
184 _ = self.sender.send(Arc::clone(pb));
185 }
186 self.pending_blocks.swap(new_pending_blocks);
187 Metrics::block_processing_duration().record(start_time.elapsed());
188 }
189 Err(e) => {
190 match e {
191 StateProcessorError::Provider(ProviderError::MissingCanonicalHeader {
192 ..
193 }) => {
194 if self.cache.lock().await.insert(flashblock) {
195 debug!(message = "cached flashblock pending canonical block", error = %e);
196 return;
197 }
198 }
199 StateProcessorError::MissingFirstFlashblock => {
200 let mut cache = self.cache.lock().await;
201 // this error should only occur for non-zero index flashblocks, but check here for index safety
202 if flashblock.index > 0
203 && cache.has_flashblock(
204 flashblock.metadata.block_number,
205 flashblock.index - 1,
206 )
207 && cache.insert(flashblock)
208 {
209 return;
210 }
211 // we should ignore this error since it doesn't necessarily indicate a problem
212 return;
213 }
214 _ => {}
215 }
216
217 // skip logging expected caching case
218 if !matches!(
219 e,
220 StateProcessorError::Provider(ProviderError::MissingCanonicalHeader { .. })
221 ) {
222 error!(message = "could not process Flashblock", error = %e);
223 Metrics::block_processing_error().increment(1);
224 }
225 }
226 }
227 }
228
229 #[instrument(level = "debug", skip_all, fields(block_number = block.number))]
230 fn process_canonical_block(

Callers 1

startMethod · 0.80

Calls 7

lockMethod · 0.80
has_flashblockMethod · 0.80
process_flashblockMethod · 0.45
sendMethod · 0.45
recordMethod · 0.45
insertMethod · 0.45
incrementMethod · 0.45

Tested by

no test coverage detected