From 8bf1e6dd312c29f34b9b7d5e83338d7fcfc4b8dc Mon Sep 17 00:00:00 2001 From: Ariel Elperin Date: Thu, 7 May 2026 14:51:50 +0300 Subject: [PATCH] starknet_committer: extract metadata construction to a function --- crates/apollo_committer/src/committer.rs | 42 +++++++++++++++--------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/crates/apollo_committer/src/committer.rs b/crates/apollo_committer/src/committer.rs index a1bb5a74c44..5d7f28a4b10 100644 --- a/crates/apollo_committer/src/committer.rs +++ b/crates/apollo_committer/src/committer.rs @@ -96,6 +96,31 @@ enum CommitBlockHeightPlan { CommitTip { state_diff_commitment: StateDiffCommitment }, } +fn commit_tip_metadata_bundle( + height: BlockNumber, + global_root: GlobalRoot, + state_diff_commitment: StateDiffCommitment, +) -> (HashMap, BlockNumber) { + let next_offset = height.unchecked_next(); + ( + HashMap::from([ + ( + ForestMetadataType::CommitmentOffset, + DbValue(DbBlockNumber(next_offset).serialize().to_vec()), + ), + ( + ForestMetadataType::StateRoot(DbBlockNumber(height)), + serialize_felt_no_packing(global_root.0), + ), + ( + ForestMetadataType::StateDiffHash(DbBlockNumber(height)), + serialize_felt_no_packing(state_diff_commitment.0.0), + ), + ]), + next_offset, + ) +} + /// Apollo committer. Maintains the Starknet state tries in persistent storage. pub struct Committer where @@ -223,21 +248,8 @@ where block_measurements.start_measurement(Action::EndToEnd); let CommitStateDiffOutput { filled_forest, global_root, deleted_nodes } = self.commit_state_diff(state_diff, &mut block_measurements).await?; - let next_offset = height.unchecked_next(); - let metadata = HashMap::from([ - ( - ForestMetadataType::CommitmentOffset, - DbValue(DbBlockNumber(next_offset).serialize().to_vec()), - ), - ( - ForestMetadataType::StateRoot(DbBlockNumber(height)), - serialize_felt_no_packing(global_root.0), - ), - ( - ForestMetadataType::StateDiffHash(DbBlockNumber(height)), - serialize_felt_no_packing(state_diff_commitment.0.0), - ), - ]); + let (metadata, next_offset) = + commit_tip_metadata_bundle(height, global_root, state_diff_commitment); info!( "For block number {height}, writing filled forest to storage with metadata: \ {metadata:?}, delete {} nodes",