@@ -99,6 +99,31 @@ enum CommitBlockHeightPlan {
9999 CommitTip { state_diff_commitment : StateDiffCommitment } ,
100100}
101101
102+ fn commit_tip_metadata_bundle (
103+ height : BlockNumber ,
104+ global_root : GlobalRoot ,
105+ state_diff_commitment : StateDiffCommitment ,
106+ ) -> ( HashMap < ForestMetadataType , DbValue > , BlockNumber ) {
107+ let next_offset = height. unchecked_next ( ) ;
108+ (
109+ HashMap :: from ( [
110+ (
111+ ForestMetadataType :: CommitmentOffset ,
112+ DbValue ( DbBlockNumber ( next_offset) . serialize ( ) . to_vec ( ) ) ,
113+ ) ,
114+ (
115+ ForestMetadataType :: StateRoot ( DbBlockNumber ( height) ) ,
116+ serialize_felt_no_packing ( global_root. 0 ) ,
117+ ) ,
118+ (
119+ ForestMetadataType :: StateDiffHash ( DbBlockNumber ( height) ) ,
120+ serialize_felt_no_packing ( state_diff_commitment. 0 . 0 ) ,
121+ ) ,
122+ ] ) ,
123+ next_offset,
124+ )
125+ }
126+
102127/// Apollo committer. Maintains the Starknet state tries in persistent storage.
103128pub struct Committer < S : Storage , ForestDB >
104129where
@@ -174,21 +199,8 @@ where
174199 block_measurements. start_measurement ( Action :: EndToEnd ) ;
175200 let CommitStateDiffOutput { filled_forest, global_root, deleted_nodes } =
176201 self . commit_state_diff ( state_diff, & mut block_measurements) . await ?;
177- let next_offset = height. unchecked_next ( ) ;
178- let metadata = HashMap :: from ( [
179- (
180- ForestMetadataType :: CommitmentOffset ,
181- DbValue ( DbBlockNumber ( next_offset) . serialize ( ) . to_vec ( ) ) ,
182- ) ,
183- (
184- ForestMetadataType :: StateRoot ( DbBlockNumber ( height) ) ,
185- serialize_felt_no_packing ( global_root. 0 ) ,
186- ) ,
187- (
188- ForestMetadataType :: StateDiffHash ( DbBlockNumber ( height) ) ,
189- serialize_felt_no_packing ( state_diff_commitment. 0 . 0 ) ,
190- ) ,
191- ] ) ;
202+ let ( metadata, next_offset) =
203+ commit_tip_metadata_bundle ( height, global_root, state_diff_commitment) ;
192204 info ! (
193205 "For block number {height}, writing filled forest to storage with metadata: \
194206 {metadata:?}, delete {} nodes",
0 commit comments