@@ -248,35 +248,12 @@ fn spawn_log_consumers_in_collection_mode<N: Network>(
248248 common_ancestor = common_ancestor,
249249 "Received ReorgDetected notification"
250250 ) ;
251-
252- // Invalidate logs from reorged blocks
253- // Logs are ordered newest -> oldest, so skip logs with
254- // block_number > common_ancestor at the front
255- // NOTE: Pending logs are not supported therefore this filter
256- // works for now (may need to update once they are). Tracked in
257- // <https://github.com/OpenZeppelin/Event-Scanner/issues/244>
258- let before_count = collected. len ( ) ;
259- collected = collected
260- . into_iter ( )
261- . skip_while ( |log| {
262- // Pending blocks aren't supported therefore this filter
263- // works for now (may need to update once they are).
264- // Tracked in <https://github.com/OpenZeppelin/Event-Scanner/issues/244>
265- log. block_number . is_some_and ( |n| n > common_ancestor)
266- } )
267- . collect ( ) ;
268- let removed_count = before_count - collected. len ( ) ;
269- if removed_count > 0 {
270- debug ! (
271- removed_count = removed_count,
272- remaining_count = collected. len( ) ,
273- "Invalidated logs from reorged blocks"
274- ) ;
275- }
276-
277251 // Track reorg state for proper log ordering
278252 reorg_ancestor = Some ( common_ancestor) ;
279253
254+ collected =
255+ discard_logs_from_orphaned_blocks ( collected, common_ancestor) ;
256+
280257 // Don't forward the notification to the user in CollectLatest mode
281258 // since logs haven't been sent yet
282259 }
@@ -337,6 +314,34 @@ fn spawn_log_consumers_in_collection_mode<N: Network>(
337314 } )
338315}
339316
317+ fn discard_logs_from_orphaned_blocks ( collected : Vec < Log > , common_ancestor : u64 ) -> Vec < Log > {
318+ // Invalidate logs from reorged blocks
319+ // Logs are ordered newest -> oldest, so skip logs with
320+ // block_number > common_ancestor at the front
321+ // NOTE: Pending logs are not supported therefore this filter
322+ // works for now (may need to update once they are). Tracked in
323+ // <https://github.com/OpenZeppelin/Event-Scanner/issues/244>
324+ let before_count = collected. len ( ) ;
325+ let collected = collected
326+ . into_iter ( )
327+ . skip_while ( |log| {
328+ // Pending blocks aren't supported therefore this filter
329+ // works for now (may need to update once they are).
330+ // Tracked in <https://github.com/OpenZeppelin/Event-Scanner/issues/244>
331+ log. block_number . is_some_and ( |n| n > common_ancestor)
332+ } )
333+ . collect :: < Vec < _ > > ( ) ;
334+ let removed_count = before_count - collected. len ( ) ;
335+ if removed_count > 0 {
336+ debug ! (
337+ removed_count = removed_count,
338+ remaining_count = collected. len( ) ,
339+ "Invalidated logs from reorged blocks"
340+ ) ;
341+ }
342+ collected
343+ }
344+
340345/// Collects logs into the buffer, either prepending (reorg recovery) or appending (normal).
341346/// Returns `true` if collection is complete (reached count limit).
342347fn collect_logs < T > ( collected : & mut Vec < T > , logs : Vec < T > , count : usize , prepend : bool ) -> bool {
0 commit comments