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

Method commit_built_payload

actions/harness/src/engine.rs:382–473  ·  view source on GitHub ↗

Commit a built payload to the database and register its header/state root.

(
        inner: &mut ActionEngineClientInner,
        registry: &SharedBlockHashRegistry,
        rollup_config: &RollupConfig,
        built: BaseBuiltPayload<BasePrimitives>,
    )

Source from the content-addressed store, hash-verified

380
381 /// Commit a built payload to the database and register its header/state root.
382 fn commit_built_payload(
383 inner: &mut ActionEngineClientInner,
384 registry: &SharedBlockHashRegistry,
385 rollup_config: &RollupConfig,
386 built: BaseBuiltPayload<BasePrimitives>,
387 ) -> TransportResult<(B256, L2BlockInfo)> {
388 let block: BaseBlock = built.block().clone_block();
389 let hdr = block.header.clone();
390 let block_number = hdr.number();
391 let block_hash = block.hash_slow();
392 let state_root = hdr.state_root();
393
394 if let Some(existing) = inner.executed_infos.get(&block_number)
395 && existing.block_info.hash == block_hash
396 {
397 return Ok((block_hash, *existing));
398 }
399
400 // Commit the block state to the database so subsequent blocks can build on it.
401 if let Some(executed) = built.executed_block() {
402 let execution_output = executed.execution_output;
403 let receipts = execution_output.result.receipts.clone();
404 let execution_outcome = ExecutionOutcome {
405 bundle: execution_output.state.clone(),
406 receipts: vec![receipts.clone()],
407 first_block: block_number,
408 requests: vec![execution_output.result.requests.clone()],
409 };
410
411 let state_provider = inner.provider_factory.provider().map_err(|e| {
412 TransportError::from(TransportErrorKind::custom_str(&format!(
413 "failed to get provider: {e}"
414 )))
415 })?;
416 let hashed_state = HashedPostStateProvider::hashed_post_state(
417 &LatestStateProviderRef::new(&state_provider),
418 &execution_output.state,
419 );
420 drop(state_provider);
421
422 let provider_rw = inner.provider_factory.provider_rw().map_err(|e| {
423 TransportError::from(TransportErrorKind::custom_str(&format!(
424 "failed to get provider_rw: {e}"
425 )))
426 })?;
427 provider_rw
428 .append_blocks_with_state(
429 vec![executed.recovered_block.as_ref().clone()],
430 &execution_outcome,
431 hashed_state.into_sorted(),
432 )
433 .map_err(|e| {
434 TransportError::from(TransportErrorKind::custom_str(&format!(
435 "failed to commit block state: {e}"
436 )))
437 })?;
438 provider_rw.commit().map_err(|e| {
439 TransportError::from(TransportErrorKind::custom_str(&format!(

Callers

nothing calls this directly

Calls 11

hash_slowMethod · 0.80
get_state_rootMethod · 0.80
blockMethod · 0.45
cloneMethod · 0.45
numberMethod · 0.45
state_rootMethod · 0.45
getMethod · 0.45
executed_blockMethod · 0.45
providerMethod · 0.45
commitMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected