Commit a built payload to the database and register its header/state root.
(
inner: &mut ActionEngineClientInner,
registry: &SharedBlockHashRegistry,
rollup_config: &RollupConfig,
built: BaseBuiltPayload<BasePrimitives>,
)
| 422 | |
| 423 | /// Commit a built payload to the database and register its header/state root. |
| 424 | fn commit_built_payload( |
| 425 | inner: &mut ActionEngineClientInner, |
| 426 | registry: &SharedBlockHashRegistry, |
| 427 | rollup_config: &RollupConfig, |
| 428 | built: BaseBuiltPayload<BasePrimitives>, |
| 429 | ) -> TransportResult<(B256, L2BlockInfo)> { |
| 430 | let block: BaseBlock = built.block().clone_block(); |
| 431 | let hdr = block.header.clone(); |
| 432 | let block_number = hdr.number(); |
| 433 | let block_hash = block.hash_slow(); |
| 434 | let state_root = hdr.state_root(); |
| 435 | |
| 436 | if let Some(existing) = inner.executed_infos.get(&block_number) |
| 437 | && existing.block_info.hash == block_hash |
| 438 | { |
| 439 | return Ok((block_hash, *existing)); |
| 440 | } |
| 441 | |
| 442 | // Commit the block state to the database so subsequent blocks can build on it. |
| 443 | if let Some(executed) = built.executed_block() { |
| 444 | let execution_output = executed.execution_output; |
| 445 | let receipts = execution_output.result.receipts.clone(); |
| 446 | let execution_outcome = ExecutionOutcome { |
| 447 | bundle: execution_output.state.clone(), |
| 448 | receipts: vec![receipts.clone()], |
| 449 | first_block: block_number, |
| 450 | requests: vec![execution_output.result.requests.clone()], |
| 451 | }; |
| 452 | |
| 453 | let state_provider = inner.provider_factory.provider().map_err(|e| { |
| 454 | TransportError::from(TransportErrorKind::custom_str(&format!( |
| 455 | "failed to get provider: {e}" |
| 456 | ))) |
| 457 | })?; |
| 458 | let hashed_state = HashedPostStateProvider::hashed_post_state( |
| 459 | &LatestStateProviderRef::new(&state_provider), |
| 460 | &execution_output.state, |
| 461 | ) |
| 462 | .map_err(|e| { |
| 463 | TransportError::from(TransportErrorKind::custom_str(&format!( |
| 464 | "failed to calculate hashed_post_state: {e}" |
| 465 | ))) |
| 466 | })?; |
| 467 | drop(state_provider); |
| 468 | |
| 469 | let provider_rw = inner.provider_factory.provider_rw().map_err(|e| { |
| 470 | TransportError::from(TransportErrorKind::custom_str(&format!( |
| 471 | "failed to get provider_rw: {e}" |
| 472 | ))) |
| 473 | })?; |
| 474 | provider_rw |
| 475 | .append_blocks_with_state( |
| 476 | vec![executed.recovered_block.as_ref().clone()], |
| 477 | &execution_outcome, |
| 478 | hashed_state.into_sorted(), |
| 479 | ) |
| 480 | .map_err(|e| { |
| 481 | TransportError::from(TransportErrorKind::custom_str(&format!( |
nothing calls this directly
no test coverage detected