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
4 changes: 2 additions & 2 deletions app/jobs/gap_detection_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def get_import_range
return nil if latest_l2_block_number == 0

# Get L1 attributes to find the corresponding L1 block
l1_attributes = GethDriver.client.get_l1_attributes(latest_l2_block_number)
l1_attributes = GethDriver.get_l1_attributes(latest_l2_block_number)
current_l1_block = l1_attributes[:number]

# Check the last validated block
Expand Down Expand Up @@ -92,7 +92,7 @@ def get_l2_blocks_for_l1_block(l1_block_number)
# Search backwards from current L2 tip to find blocks from this L1 block
# This is expensive but necessary for gap filling
(0..latest_l2_block_number).reverse_each do |l2_block_num|
l1_attributes = GethDriver.client.get_l1_attributes(l2_block_num)
l1_attributes = GethDriver.get_l1_attributes(l2_block_num)

if l1_attributes[:number] == l1_block_number
l2_block = GethDriver.client.call("eth_getBlockByNumber", ["0x#{l2_block_num.to_s(16)}", false])
Expand Down
10 changes: 5 additions & 5 deletions app/services/eth_block_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def populate_ethscriptions_block_cache
current_block = EthscriptionsBlock.from_rpc_result(block_data)

ImportProfiler.start("l1_attributes_fetch")
l1_attributes = GethDriver.client.get_l1_attributes(current_block.number)
l1_attributes = GethDriver.get_l1_attributes(current_block.number)
ImportProfiler.stop("l1_attributes_fetch")
current_block.assign_l1_attributes(l1_attributes)

Expand Down Expand Up @@ -107,7 +107,7 @@ def current_block_number
# Removed batch processing - now imports one block at a time

def find_first_l2_block_in_epoch(l2_block_number_candidate)
l1_attributes = GethDriver.client.get_l1_attributes(l2_block_number_candidate)
l1_attributes = GethDriver.get_l1_attributes(l2_block_number_candidate)

if l1_attributes[:sequence_number] == 0
return l2_block_number_candidate
Expand All @@ -124,7 +124,7 @@ def set_eth_block_starting_points
l1_block = EthRpcClient.l1.get_block(SysConfig.l1_genesis_block_number)
eth_block = EthBlock.from_rpc_result(l1_block)
ethscriptions_block = EthscriptionsBlock.from_rpc_result(latest_l2_block)
l1_attributes = GethDriver.client.get_l1_attributes(latest_l2_block_number)
l1_attributes = GethDriver.get_l1_attributes(latest_l2_block_number)

ethscriptions_block.assign_l1_attributes(l1_attributes)

Expand All @@ -134,7 +134,7 @@ def set_eth_block_starting_points
return [eth_block.number, 0]
end

l1_attributes = GethDriver.client.get_l1_attributes(latest_l2_block_number)
l1_attributes = GethDriver.get_l1_attributes(latest_l2_block_number)

l1_candidate = l1_attributes[:number]
l2_candidate = latest_l2_block_number
Expand All @@ -148,7 +148,7 @@ def set_eth_block_starting_points
l1_result = ethereum_client.get_block(l1_candidate)
l1_hash = Hash32.from_hex(l1_result['hash'])

l1_attributes = GethDriver.client.get_l1_attributes(l2_candidate)
l1_attributes = GethDriver.get_l1_attributes(l2_candidate)

l2_block = GethDriver.client.call("eth_getBlockByNumber", ["0x#{l2_candidate.to_s(16)}", false])

Expand Down
35 changes: 31 additions & 4 deletions app/services/geth_driver.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
module GethDriver
extend self
attr_reader :password

include Memery

def client
@_client ||= GethClient.new(ENV.fetch('GETH_RPC_URL'))
@_client ||= EthRpcClient.l2_engine
end

def non_auth_client
@_non_auth_client ||= GethClient.new(non_authed_rpc_url)
@_non_auth_client ||= EthRpcClient.l2
end

def get_l1_attributes(l2_block_number)
if l2_block_number > 0
l2_block = EthRpcClient.l2.call("eth_getBlockByNumber", ["0x#{l2_block_number.to_s(16)}", true])
l2_attributes_tx = l2_block['transactions'].first
L1AttributesTxCalldata.decode(
ByteString.from_hex(l2_attributes_tx['input']),
l2_block_number
)
else
l1_block = EthRpcClient.l1.get_block(SysConfig.l1_genesis_block_number)
eth_block = EthBlock.from_rpc_result(l1_block)
{
timestamp: eth_block.timestamp,
number: eth_block.number,
base_fee: eth_block.base_fee_per_gas,
blob_base_fee: 1,
hash: eth_block.block_hash,
batcher_hash: Hash32.from_bin("\x00".b * 32),
sequence_number: 0,
base_fee_scalar: 0,
blob_base_fee_scalar: 1
}.with_indifferent_access
end
end
memoize :get_l1_attributes

def non_authed_rpc_url
ENV.fetch('NON_AUTH_GETH_RPC_URL')
Expand Down
Loading