Hotfix for Optimism Ecotone batch blobs indexing (#9646)

* Hotfix for Optimism Ecotone batch blobs indexing

* Update changelog

---------

Co-authored-by: POA <33550681+poa@users.noreply.github.com>
pull/9264/merge
varasev 8 months ago committed by GitHub
parent ee3b9c2c28
commit a5130b38f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 8
      apps/explorer/lib/explorer/chain/optimism/txn_batch.ex
  3. 45
      apps/indexer/lib/indexer/fetcher/optimism/txn_batch.ex

@ -21,6 +21,7 @@
### Fixes
- [#9646](https://github.com/blockscout/blockscout/pull/9646) - Hotfix for Optimism Ecotone batch blobs indexing
- [#9640](https://github.com/blockscout/blockscout/pull/9640) - Fix no function clause matching in `BENS.item_to_address_hash_strings/1`
- [#9638](https://github.com/blockscout/blockscout/pull/9638) - Do not broadcast coin balance changes with empty value/delta
- [#9635](https://github.com/blockscout/blockscout/pull/9635) - Reset missing ranges collector to max number after the cycle is done

@ -102,13 +102,13 @@ defmodule Explorer.Chain.Optimism.TxnBatch do
end
end)
Enum.each(Range.new(output_len, byte_size(output) - 1), fn i ->
Enum.each(Range.new(output_len, byte_size(output) - 1, 1), fn i ->
<<0>> = binary_part(output, i, 1)
end)
output = binary_part(output, 0, output_len)
Enum.each(Range.new(ipos, @blob_size - 1), fn i ->
Enum.each(Range.new(ipos, @blob_size - 1, 1), fn i ->
<<0>> = binary_part(b, i, 1)
end)
@ -118,10 +118,10 @@ defmodule Explorer.Chain.Optimism.TxnBatch do
end
defp decode_eip4844_field_element(b, opos, ipos, output) do
<<_::binary-size(ipos), ipos_byte::size(8), insert::binary-size(32), _::binary>> = b
<<_::binary-size(ipos), ipos_byte::size(8), insert::binary-size(31), _::binary>> = b
if Bitwise.band(ipos_byte, 0b11000000) == 0 do
<<output_before_opos::binary-size(opos), _::binary-size(32), rest::binary>> = output
<<output_before_opos::binary-size(opos), _::binary-size(31), rest::binary>> = output
{ipos_byte, opos + 32, ipos + 32, output_before_opos <> insert <> rest}
end

@ -409,8 +409,9 @@ defmodule Indexer.Fetcher.Optimism.TxnBatch do
end
end
defp blobs_to_input(transaction_hash, blob_versioned_hashes, block_timestamp, blobs_api_url) do
Enum.reduce(blob_versioned_hashes, <<>>, fn blob_hash, acc ->
defp blobs_to_inputs(transaction_hash, blob_versioned_hashes, block_timestamp, blobs_api_url) do
blob_versioned_hashes
|> Enum.reduce([], fn blob_hash, acc ->
with {:ok, response} <- http_get_request(blobs_api_url <> "/" <> blob_hash),
blob_data = Map.get(response, "blob_data"),
false <- is_nil(blob_data) do
@ -425,8 +426,11 @@ defmodule Indexer.Fetcher.Optimism.TxnBatch do
Logger.warning("Cannot decode the blob #{blob_hash} taken from the Blockscout Blobs API.")
acc
else
Logger.info("The input for transaction #{transaction_hash} is taken from the Blockscout Blobs API.")
acc <> decoded
Logger.info(
"The input for transaction #{transaction_hash} is taken from the Blockscout Blobs API. Blob hash: #{blob_hash}"
)
[decoded | acc]
end
else
_ ->
@ -470,8 +474,11 @@ defmodule Indexer.Fetcher.Optimism.TxnBatch do
if is_nil(decoded_blob_data) do
raise "Invalid blob"
else
Logger.info("The input for transaction #{transaction_hash} is taken from the Beacon Node.")
acc <> decoded_blob_data
Logger.info(
"The input for transaction #{transaction_hash} is taken from the Beacon Node. Blob hash: #{blob_hash}"
)
[decoded_blob_data | acc]
end
rescue
reason ->
@ -483,6 +490,7 @@ defmodule Indexer.Fetcher.Optimism.TxnBatch do
end
end
end)
|> Enum.reverse()
end
defp get_txn_batches_inner(
@ -496,30 +504,31 @@ defmodule Indexer.Fetcher.Optimism.TxnBatch do
transactions_filtered
|> Enum.reduce({:ok, incomplete_channels, [], []}, fn tx,
{_, incomplete_channels_acc, batches_acc, sequences_acc} ->
input =
inputs =
if tx.type == 3 do
# this is EIP-4844 transaction, so we get the input from the blobs
# this is EIP-4844 transaction, so we get the inputs from the blobs
block_timestamp = get_block_timestamp_by_number(tx.block_number, blocks_params)
blobs_to_input(tx.hash, tx.blob_versioned_hashes, block_timestamp, blobs_api_url)
blobs_to_inputs(tx.hash, tx.blob_versioned_hashes, block_timestamp, blobs_api_url)
else
tx.input
[tx.input]
end
if tx.type == 3 and input == <<>> do
# skip this transaction as we cannot find or read its blobs
{:ok, incomplete_channels_acc, batches_acc, sequences_acc}
else
Enum.reduce(inputs, {:ok, incomplete_channels_acc, batches_acc, sequences_acc}, fn input,
{_,
new_incomplete_channels_acc,
new_batches_acc,
new_sequences_acc} ->
handle_input(
input,
tx,
blocks_params,
incomplete_channels_acc,
batches_acc,
sequences_acc,
new_incomplete_channels_acc,
new_batches_acc,
new_sequences_acc,
genesis_block_l2,
json_rpc_named_arguments_l2
)
end
end)
end)
end

Loading…
Cancel
Save