Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ GEM
tzinfo
coderay (1.1.3)
concurrent-ruby (1.3.3)
connection_pool (2.4.1)
connection_pool (3.0.2)
crass (1.0.6)
csv (3.3.0)
date (3.4.1)
Expand Down Expand Up @@ -171,8 +171,8 @@ GEM
multi_xml (0.7.1)
bigdecimal (~> 3.1)
mutex_m (0.3.0)
net-http-persistent (4.0.2)
connection_pool (~> 2.2)
net-http-persistent (4.0.8)
connection_pool (>= 2.2.4, < 4)
net-imap (0.5.8)
date
net-protocol
Expand Down
28 changes: 15 additions & 13 deletions app/services/eth_block_importer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'l1_rpc_prefetcher'

class EthBlockImporter
include SysConfig
include Memery
Expand All @@ -15,7 +13,7 @@ def initialize
@facet_block_cache = {}
@eth_block_cache = {}

@ethereum_client ||= EthRpcClient.new(ENV.fetch('L1_RPC_URL'))
@ethereum_client ||= EthRpcClient.l1

@geth_driver = GethDriver

Expand All @@ -26,7 +24,14 @@ def initialize
set_eth_block_starting_points
populate_facet_block_cache

@prefetcher = L1RpcPrefetcher.new(ethereum_client: @ethereum_client)
@prefetcher = L1RpcPrefetcher.new(ethereum_client: EthRpcClient.l1_prefetch)

unless Rails.env.test?
max_block = current_max_eth_block_number
if max_block && max_block > 0
@prefetcher.ensure_prefetched(max_block + 1)
end
end
end

def current_max_facet_block_number
Expand Down Expand Up @@ -271,17 +276,17 @@ def import_single_block(block_number)
start = Time.current

# Fetch block data from prefetcher
response = prefetcher.fetch(block_number)
begin
response = prefetcher.fetch(block_number)
rescue L1RpcPrefetcher::BlockFetchError => e
raise BlockNotReadyToImportError.new(e.message)
end

# Handle cancellation, fetch failure, or block not ready
# Handle cancellation or fetch failure
if response.nil?
raise BlockNotReadyToImportError.new("Block #{block_number} fetch was cancelled or failed")
end

if response[:error] == :not_ready
raise BlockNotReadyToImportError.new("Block #{block_number} not yet available on L1")
end

eth_block = response[:eth_block]
facet_block = response[:facet_block]
facet_txs = response[:facet_txs]
Expand Down Expand Up @@ -329,9 +334,6 @@ def import_blocks(block_numbers)

def import_next_block
block_number = next_block_to_import

prefetcher.ensure_prefetched(block_number)

import_single_block(block_number)
end

Expand Down
25 changes: 15 additions & 10 deletions config/derive_facet_blocks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,24 @@ module Clockwork
end
end

every(6.seconds, 'import_blocks_until_done') do
every(2.seconds, 'import_blocks_until_done') do
importer = EthBlockImporter.new

loop do
begin
importer.import_blocks_until_done
rescue EthBlockImporter::ReorgDetectedError
Rails.logger.warn 'Reorg detected – reinitialising EthBlockImporter'
importer = EthBlockImporter.new
retry
end
begin
loop do
begin
importer.import_blocks_until_done
rescue EthBlockImporter::ReorgDetectedError
Rails.logger.warn 'Reorg detected – reinitialising EthBlockImporter'
importer.shutdown
importer = EthBlockImporter.new
retry
end

sleep 6
sleep 6
end
ensure
importer&.shutdown
end
end
end
2 changes: 1 addition & 1 deletion docker-compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
start_period: 10s

node:
image: ghcr.io/0xfacet/facet-node:v2.0.1
image: ghcr.io/0xfacet/facet-node:v2.0.2
environment:
JWT_SECRET: ${JWT_SECRET}
L1_NETWORK: ${L1_NETWORK}
Expand Down
Loading