Skip to content

fix(evmreader): avoid delaying work by skiping old blocks notifications#781

Draft
renatomaia wants to merge 1 commit into
next/2.0from
fix/HandleSlowProcessingOfNewBlocks
Draft

fix(evmreader): avoid delaying work by skiping old blocks notifications#781
renatomaia wants to merge 1 commit into
next/2.0from
fix/HandleSlowProcessingOfNewBlocks

Conversation

@renatomaia
Copy link
Copy Markdown

EVM Reader was processing each single new chain block notification, therefore when the processing was too slow (>2 seconds) the notifications accumulated and the EVM Reader could not keep up since worked one block at time. The fix is to skip old block notifications when a more recent is already available.

@renatomaia renatomaia requested review from mpolitzer and vfusco May 27, 2026 12:31
@renatomaia renatomaia force-pushed the fix/HandleSlowProcessingOfNewBlocks branch 2 times, most recently from c323cc3 to 1baa9f1 Compare May 27, 2026 14:38
Comment thread internal/evmreader/evmreader.go Outdated
// Discard accumulated block notifications to work only the most recent.
blockNumber, err := r.client.BlockNumber(ctx)
if err == nil {
for header.Number.Uint64() != blockNumber {
Copy link
Copy Markdown

@mpolitzer mpolitzer May 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UNTESTED

You can drain the channel without relying on block number retrieval:

for {
    select {
    case header = <-headers:
    default:
        break
    }
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that but the notification thread does not execute fast enough to keed the channel from blocking.
I added a size to the channel (buffer of notifications) to be able to mitigate this problem, but it should be a size large enough that the notification thread will be scheduled before our for discarding the notifications can finish.

Anyhow, @vfusco suggested I poll the block number and remove the use of single block notification.

@renatomaia renatomaia marked this pull request as draft May 27, 2026 18:03
@renatomaia renatomaia force-pushed the fix/HandleSlowProcessingOfNewBlocks branch from 1baa9f1 to a7bbab4 Compare May 27, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants