@@ -59,7 +59,12 @@ impl EthRelayer {
5959 let signer = InMemorySigner :: from_secret_key ( signer_account_id, secret_key) ;
6060 let client = near_fetch:: Client :: new ( & config. near . endpoint ) ;
6161
62- Ok ( ContractClient :: new ( eth_light_client_account_id, signer, client, config. relayer . clone ( ) ) )
62+ Ok ( ContractClient :: new (
63+ eth_light_client_account_id,
64+ signer,
65+ client,
66+ config. relayer . clone ( ) ,
67+ ) )
6368 }
6469
6570 pub async fn run ( & self ) -> Result < ( ) > {
@@ -179,40 +184,39 @@ impl EthRelayer {
179184 return Ok ( RelayResult :: Submitted ) ;
180185 }
181186
182- let last_block = self . near_client . get_last_block_number ( ) . await ?;
183- let max_block = self . get_max_block ( ) . await ?;
187+ let finalized_block = self . near_client . get_last_block_number ( ) . await ?;
188+ let high_block = self . get_max_block ( ) . await ?;
189+ let low_block = finalized_block + 1 ;
184190
185- if max_block <= last_block {
191+ if high_block < low_block {
186192 debug ! (
187- "No new blocks to submit (last : {}, max : {})" ,
188- last_block , max_block
193+ "No blocks to submit (finalized : {}, high : {})" ,
194+ finalized_block , high_block
189195 ) ;
190196 return Ok ( RelayResult :: Skipped ) ;
191197 }
192198
193- let start_block = last_block + 1 ;
194- let capped_max_block = std:: cmp:: min (
195- max_block,
196- start_block + self . config . relayer . max_headers_per_period as u64 - 1 ,
197- ) ;
198-
199+ let fetch_end = high_block;
200+ let fetch_start = high_block
201+ . saturating_sub ( self . config . relayer . max_headers_per_period as u64 - 1 )
202+ . max ( low_block) ;
203+
199204 info ! (
200- "Fetching {} execution headers for blocks {} to {} (capped from {})" ,
201- capped_max_block - last_block,
202- start_block,
203- capped_max_block,
204- max_block
205+ "Fetching {} execution headers for blocks {} to {}" ,
206+ fetch_end - fetch_start + 1 ,
207+ fetch_start,
208+ fetch_end
205209 ) ;
206210
207211 let mut headers = self
208212 . execution_client
209- . fetch_block_range ( start_block ..=capped_max_block )
213+ . fetch_block_range ( fetch_start ..=fetch_end )
210214 . await ?;
211215
212216 if headers. is_empty ( ) {
213217 warn ! (
214218 "No headers fetched for range {}..={}" ,
215- start_block , capped_max_block
219+ fetch_start , fetch_end
216220 ) ;
217221 return Ok ( RelayResult :: Skipped ) ;
218222 }
0 commit comments