Skip to content

Improve prefetcher#117

Merged
RogerPodacter merged 1 commit into
evm-backend-demofrom
improve_prefetcher
Oct 13, 2025
Merged

Improve prefetcher#117
RogerPodacter merged 1 commit into
evm-backend-demofrom
improve_prefetcher

Conversation

@RogerPodacter

@RogerPodacter RogerPodacter commented Oct 13, 2025

Copy link
Copy Markdown
Member

Note

Enhances L1 prefetcher fetch semantics, chain-tip caching, and shutdown, updates importer to handle new errors, and hardens the clockwork loop with cleaner shutdown and reorg handling.

  • Prefetcher (lib/l1_rpc_prefetcher.rb):
    • Add BlockFetchError and raise on nil/not-ready results; use :not_ready_sentinel.
    • Dynamic chain-tip strategy with memoized cached_l1_block_number and @last_chain_tip; lower ahead default to 20.
    • Improve shutdown: short timeout, cancel pending promises, clear state, and structured logging; return boolean.
    • Simplify fetch: delete failed promises; keep timeout behavior via value! exceptions.
  • Importer (app/services/eth_block_importer.rb):
    • Wrap prefetch call with profiling (prefetcher_fetch) and map L1RpcPrefetcher::BlockFetchError to BlockNotReadyToImportError.
  • Runner (config/derive_ethscriptions_blocks.rb):
    • Remove signal traps; wrap loop in begin...ensure to shutdown importer.
    • On reorg, explicitly shutdown then reinitialize importer; add concise wait/retry logging and sleep placement.
    • Cleanup minor counters/flow; keep session summaries and validation reporting.

Written by Cursor Bugbot for commit b260fa9. This will update automatically on new commits. Configure here.

@RogerPodacter RogerPodacter requested a review from Copilot October 13, 2025 17:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the L1RpcPrefetcher by making it more resilient and efficient. The changes focus on better error handling, performance optimization, and more graceful shutdown behavior.

Key changes:

  • Enhanced error handling with a custom BlockFetchError class and better timeout/availability handling
  • Performance optimization by implementing smarter chain tip caching and reducing the default prefetch distance
  • Improved shutdown process with proper promise cancellation and resource cleanup

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
lib/l1_rpc_prefetcher.rb Core improvements to prefetcher with better error handling, optimized caching, and enhanced shutdown
app/services/eth_block_importer.rb Updated to handle new BlockFetchError from the prefetcher
config/derive_ethscriptions_blocks.rb Improved cleanup with proper shutdown handling and removed redundant signal trapping

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread lib/l1_rpc_prefetcher.rb
end

def cached_l1_block_number
current_l1_block_number

Copilot AI Oct 13, 2025

Copy link

Choose a reason for hiding this comment

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

The cached_l1_block_number method calls current_l1_block_number, which updates @last_chain_tip, defeating the purpose of caching. This should return @last_chain_tip directly or have a different implementation that doesn't trigger side effects.

Suggested change
current_l1_block_number
@last_chain_tip

Copilot uses AI. Check for mistakes.
Comment thread lib/l1_rpc_prefetcher.rb
else
Rails.logger.warn "L1 RPC Prefetcher shutdown timed out, forcing kill"
@pool.kill
terminated = @pool.wait_for_termination(3)

Copilot AI Oct 13, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] The hardcoded timeout value of 3 seconds should be extracted to a constant or configuration parameter to make it more maintainable and configurable.

Copilot uses AI. Check for mistakes.
Comment thread lib/l1_rpc_prefetcher.rb
end

Rails.logger.debug "Got result for block #{block_number}"
result

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Unhandled Timeouts in Block Fetch

The fetch method no longer catches Concurrent::TimeoutError raised by promise.value!(timeout). This means timeouts now propagate as unhandled exceptions, bypassing the intended BlockFetchError conversion for "block not ready" conditions. The result.nil? check doesn't account for these timeouts, leading to incorrect error handling.

Fix in Cursor Fix in Web

Comment thread lib/l1_rpc_prefetcher.rb
current_l1_block_number
end
memoize :cached_l1_block_number, ttl: 12.seconds
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Memoization Causes Stale Chain Tip

The cached_l1_block_number method is memoized, but it calls current_l1_block_number which updates @last_chain_tip. This means @last_chain_tip only updates when the cache expires, potentially leaving it stale and causing inconsistent behavior for logic relying on its value.

Fix in Cursor Fix in Web

@RogerPodacter RogerPodacter merged commit d86287e into evm-backend-demo Oct 13, 2025
3 checks passed
@RogerPodacter RogerPodacter deleted the improve_prefetcher branch October 13, 2025 17:30
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