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

Method build_pending_state_for_next_block

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

Source from the content-addressed store, hash-verified

560 )
561 )]
562 fn build_pending_state_for_next_block(
563 &self,
564 prev_pending_blocks: &Arc<PendingBlocks>,
565 flashblock: &Flashblock,
566 ) -> Result<Option<Arc<PendingBlocks>>> {
567 let Some(base) = flashblock.base.clone() else {
568 return Err(StateProcessorError::MissingFirstFlashblock);
569 };
570
571 let mut live_state = self.lock_live_state();
572 let Some(LivePendingState { mut db, state_overrides }) = live_state.take() else {
573 warn!(
574 message = "live pending state unavailable, falling back to full rebuild",
575 block_number = flashblock.metadata.block_number,
576 flashblock_index = flashblock.index,
577 path = "next_block"
578 );
579 let mut flashblocks = prev_pending_blocks.get_flashblocks();
580 flashblocks.push(flashblock.clone());
581 return self.build_pending_state(Some(Arc::clone(prev_pending_blocks)), &flashblocks);
582 };
583 drop(live_state);
584
585 let previous_header = prev_pending_blocks.latest_header();
586 let current_block = BlockAssembler::assemble(std::slice::from_ref(flashblock))?;
587 let l1_block_info = current_block.l1_block_info()?;
588 let AssembledBlock { block: assembled_block, header: assembled_header, .. } = current_block;
589 let pending_block = Block {
590 header: Header {
591 parent_hash: base.parent_hash,
592 number: base.block_number,
593 timestamp: base.timestamp,
594 gas_limit: base.gas_limit,
595 base_fee_per_gas: Some(base.base_fee_per_gas.saturating_to()),
596 ..Default::default()
597 },
598 body: assembled_block.body,
599 };
600
601 db.block_hashes.insert(base.block_number - 1, base.parent_hash);
602
603 let evm_config = BaseEvmConfig::base(self.client.chain_spec());
604 let block_env_attributes = BaseNextBlockEnvAttributes {
605 timestamp: base.timestamp,
606 suggested_fee_recipient: base.fee_recipient,
607 prev_randao: base.prev_randao,
608 gas_limit: base.gas_limit,
609 parent_beacon_block_root: Some(base.parent_beacon_block_root),
610 extra_data: base.extra_data.clone(),
611 };
612 let evm_env = evm_config
613 .next_evm_env(&previous_header, &block_env_attributes)
614 .map_err(|e| ExecutionError::EvmEnv(e.to_string()))?;
615 let evm = evm_config.evm_with_env(db, evm_env);
616
617 let recovery_start = Instant::now();
618 let txs_with_senders: Vec<(BaseTxEnvelope, Address)> = pending_block
619 .body

Callers 1

process_flashblockMethod · 0.80

Calls 15

lock_live_stateMethod · 0.80
build_pending_stateMethod · 0.80
with_headerMethod · 0.80
into_iterMethod · 0.80
execute_transactionMethod · 0.80
with_execution_timeMethod · 0.80
with_account_balanceMethod · 0.80
with_transactionMethod · 0.80
with_receiptMethod · 0.80

Tested by

no test coverage detected