Skip to content

Commit a125ce1

Browse files
committed
fix: only FirstLogBlock for non-pending blocks
1 parent e58ad19 commit a125ce1

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/event_scanner/scanner/common.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,23 +149,25 @@ pub fn spawn_log_consumers<N: Network>(
149149
}
150150

151151
if let ConsumerMode::CollectLatest { .. } = mode {
152-
if collected.is_empty() {
153-
info!("No logs found in the processed block range");
152+
// collected logs are currently in reverse chronological order
153+
let Some(first_block_hash) = collected.last().map(|log| log.block_hash) else {
154+
info!("No logs found");
154155
_ = sender.try_stream(Notification::NoPastLogsFound).await;
155-
} else {
156-
info!("Sending collected logs to consumer");
157-
collected.reverse(); // restore chronological order
158-
159-
let first_block = collected
160-
.first()
161-
.expect("we ensured 'collected' has at least 1 element")
162-
.block_hash
163-
.expect("we only filter for non-pending logs");
164-
165-
if sender.try_stream(Notification::FirstLogBlock(first_block)).await {
166-
_ = sender.try_stream(collected).await;
167-
}
156+
return;
157+
};
158+
159+
info!(count = collected.len(), "Logs found");
160+
collected.reverse(); // restore chronological order
161+
162+
// first log block hash can only be sent for non-pending logs
163+
if let Some(first_block_hash) = first_block_hash &&
164+
!sender.try_stream(Notification::FirstLogBlock(first_block_hash)).await
165+
{
166+
return;
168167
}
168+
169+
info!("Sending collected logs to consumer");
170+
_ = sender.try_stream(collected).await;
169171
}
170172
});
171173

0 commit comments

Comments
 (0)