@@ -154,10 +154,19 @@ impl StateSync {
154154 }
155155
156156 async fn get_block_hash ( & self , block_number : BlockNumber ) -> StateSyncResult < BlockHash > {
157- // Getting the next block because the Sync block only contains parent hash.
158- match ( self . get_block ( block_number) . await , self . starknet_client . as_ref ( ) ) {
159- ( Ok ( block) , _) => Ok ( block. block_header_without_hash . parent_hash ) ,
160- ( Err ( StateSyncError :: BlockNotFound ( _) ) , Some ( starknet_client) ) => {
157+ let storage_reader = self . storage_reader . clone ( ) ;
158+ let block_hash_opt = tokio:: task:: spawn_blocking ( move || {
159+ Ok :: < _ , StateSyncError > (
160+ storage_reader
161+ . begin_ro_txn ( ) ?
162+ . get_block_header ( block_number) ?
163+ . map ( |header| header. block_hash ) ,
164+ )
165+ } )
166+ . await ??;
167+ match ( block_hash_opt, self . starknet_client . as_ref ( ) ) {
168+ ( Some ( block_hash) , _) => Ok ( block_hash) ,
169+ ( None , Some ( starknet_client) ) => {
161170 // As a fallback, try to get the block hash through the feeder directly. This
162171 // method is faster than get_block which the sync runner uses.
163172 // TODO(shahak): Test this flow.
@@ -166,7 +175,7 @@ impl StateSync {
166175 . await ?
167176 . ok_or ( StateSyncError :: BlockNotFound ( block_number) )
168177 }
169- ( Err ( err ) , _) => Err ( err ) ,
178+ ( None , _) => Err ( StateSyncError :: BlockNotFound ( block_number ) ) ,
170179 }
171180 }
172181
0 commit comments