@@ -96,6 +96,31 @@ enum CommitBlockHeightPlan {
9696 CommitTip { state_diff_commitment : StateDiffCommitment } ,
9797}
9898
99+ fn commit_tip_metadata_bundle (
100+ height : BlockNumber ,
101+ global_root : GlobalRoot ,
102+ state_diff_commitment : StateDiffCommitment ,
103+ ) -> ( HashMap < ForestMetadataType , DbValue > , BlockNumber ) {
104+ let next_offset = height. unchecked_next ( ) ;
105+ (
106+ HashMap :: from ( [
107+ (
108+ ForestMetadataType :: CommitmentOffset ,
109+ DbValue ( DbBlockNumber ( next_offset) . serialize ( ) . to_vec ( ) ) ,
110+ ) ,
111+ (
112+ ForestMetadataType :: StateRoot ( DbBlockNumber ( height) ) ,
113+ serialize_felt_no_packing ( global_root. 0 ) ,
114+ ) ,
115+ (
116+ ForestMetadataType :: StateDiffHash ( DbBlockNumber ( height) ) ,
117+ serialize_felt_no_packing ( state_diff_commitment. 0 . 0 ) ,
118+ ) ,
119+ ] ) ,
120+ next_offset,
121+ )
122+ }
123+
99124/// Apollo committer. Maintains the Starknet state tries in persistent storage.
100125pub struct Committer < S : Storage , ForestDB >
101126where
@@ -223,21 +248,8 @@ where
223248 block_measurements. start_measurement ( Action :: EndToEnd ) ;
224249 let CommitStateDiffOutput { filled_forest, global_root, deleted_nodes } =
225250 self . commit_state_diff ( state_diff, & mut block_measurements) . await ?;
226- let next_offset = height. unchecked_next ( ) ;
227- let metadata = HashMap :: from ( [
228- (
229- ForestMetadataType :: CommitmentOffset ,
230- DbValue ( DbBlockNumber ( next_offset) . serialize ( ) . to_vec ( ) ) ,
231- ) ,
232- (
233- ForestMetadataType :: StateRoot ( DbBlockNumber ( height) ) ,
234- serialize_felt_no_packing ( global_root. 0 ) ,
235- ) ,
236- (
237- ForestMetadataType :: StateDiffHash ( DbBlockNumber ( height) ) ,
238- serialize_felt_no_packing ( state_diff_commitment. 0 . 0 ) ,
239- ) ,
240- ] ) ;
251+ let ( metadata, next_offset) =
252+ commit_tip_metadata_bundle ( height, global_root, state_diff_commitment) ;
241253 info ! (
242254 "For block number {height}, writing filled forest to storage with metadata: \
243255 {metadata:?}, delete {} nodes",
0 commit comments