@@ -15,7 +15,7 @@ use katana_provider::api::block::{BlockHashProvider, BlockWriter};
1515use katana_provider:: ProviderError ;
1616use num_traits:: ToPrimitive ;
1717use starknet:: core:: types:: ResourcePrice ;
18- use tracing:: debug ;
18+ use tracing:: { error , info_span , Instrument } ;
1919
2020use crate :: { Stage , StageExecutionInput , StageExecutionOutput , StageResult } ;
2121
@@ -104,26 +104,30 @@ where
104104 let blocks = self
105105 . downloader
106106 . download_blocks ( input. from ( ) , input. to ( ) )
107+ . instrument ( info_span ! ( target: "stage" , "blocks.download" , from = %input. from( ) , to = %input. to( ) ) )
107108 . await
108109 . map_err ( Error :: Gateway ) ?;
109110
110- if ! blocks. is_empty ( ) {
111- debug ! ( target : "stage" , id = % self . id ( ) , total = %blocks . len ( ) , "Storing blocks to storage." ) ;
111+ let span = info_span ! ( target : "stage" , " blocks.insert" , from = %input . from ( ) , to = %input . to ( ) ) ;
112+ let _enter = span . enter ( ) ;
112113
113- // Validate chain invariant before storing
114- self . validate_chain_invariant ( & blocks) ?;
114+ // TODO: spawn onto a blocking thread pool
115+ self . validate_chain_invariant ( & blocks) ?;
115116
116- // Store blocks to storage
117- for block in blocks {
118- let ( block , receipts , state_updates ) = extract_block_data ( block) ? ;
117+ for block in blocks {
118+ let ( block, receipts , state_updates ) = extract_block_data ( block ) ? ;
119+ let block_number = block. block . header . number ;
119120
120- self . provider . insert_block_with_states_and_receipts (
121+ self . provider
122+ . insert_block_with_states_and_receipts (
121123 block,
122124 state_updates,
123125 receipts,
124126 Vec :: new ( ) ,
127+ )
128+ . inspect_err (
129+ |e| error ! ( error = %e, block = %block_number, "Error storing block." ) ,
125130 ) ?;
126- }
127131 }
128132
129133 Ok ( StageExecutionOutput { last_block_processed : input. to ( ) } )
@@ -151,8 +155,13 @@ fn extract_block_data(
151155 data : StateUpdateWithBlock ,
152156) -> Result < ( SealedBlockWithStatus , Vec < Receipt > , StateUpdatesWithClasses ) > {
153157 fn to_gas_prices ( prices : ResourcePrice ) -> GasPrices {
154- let eth = prices. price_in_fri . to_u128 ( ) . expect ( "valid u128" ) ;
158+ let eth = prices. price_in_wei . to_u128 ( ) . expect ( "valid u128" ) ;
155159 let strk = prices. price_in_fri . to_u128 ( ) . expect ( "valid u128" ) ;
160+ // older blocks might have zero gas prices (recent Starknet upgrade has made the minimum gas
161+ // prices to 1) we may need to handle this case if we want to be able to compute the
162+ // block hash correctly
163+ let eth = if eth == 0 { 1 } else { eth } ;
164+ let strk = if strk == 0 { 1 } else { strk } ;
156165 unsafe { GasPrices :: new_unchecked ( eth, strk) }
157166 }
158167
0 commit comments