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