Add Brotli decompression to Indexer.Fetcher.Optimism.TxnBatch (#10410)

* Add Brotli decompression to Indexer.Fetcher.Optimism.TxnBatch

* Update spelling

---------

Co-authored-by: POA <33550681+poa@users.noreply.github.com>
pull/10419/head
varasev 4 months ago committed by GitHub
parent c6ee4719ca
commit ad78a4d57a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      apps/indexer/lib/indexer/fetcher/optimism/txn_batch.ex
  2. 2
      apps/indexer/mix.exs
  3. 1
      cspell.json
  4. 1
      mix.lock

@ -47,6 +47,8 @@ defmodule Indexer.Fetcher.Optimism.TxnBatch do
# Optimism chain block time is a constant (2 seconds) # Optimism chain block time is a constant (2 seconds)
@op_chain_block_time 2 @op_chain_block_time 2
@compressor_brotli 1
def child_spec(start_link_arguments) do def child_spec(start_link_arguments) do
spec = %{ spec = %{
id: __MODULE__, id: __MODULE__,
@ -1097,15 +1099,20 @@ defmodule Indexer.Fetcher.Optimism.TxnBatch do
genesis_block_l2, genesis_block_l2,
json_rpc_named_arguments_l2 json_rpc_named_arguments_l2
) do ) do
uncompressed_bytes = zlib_decompress(bytes) uncompressed_bytes =
if first_byte(bytes) == @compressor_brotli do
{:ok, uncompressed} = :brotli.decode(binary_part(bytes, 1, byte_size(bytes) - 1))
uncompressed
else
zlib_decompress(bytes)
end
batches = batches =
Enum.reduce_while(Stream.iterate(0, &(&1 + 1)), {uncompressed_bytes, []}, fn _i, {remainder, batch_acc} -> Enum.reduce_while(Stream.iterate(0, &(&1 + 1)), {uncompressed_bytes, []}, fn _i, {remainder, batch_acc} ->
try do try do
{decoded, new_remainder} = ExRLP.decode(remainder, stream: true) {decoded, new_remainder} = ExRLP.decode(remainder, stream: true)
<<version>> = binary_part(decoded, 0, 1) <<version::size(8), content::binary>> = decoded
content = binary_part(decoded, 1, byte_size(decoded) - 1)
new_batch_acc = new_batch_acc =
cond do cond do
@ -1310,7 +1317,6 @@ defmodule Indexer.Fetcher.Optimism.TxnBatch do
start_block = quantity_to_integer(Enum.at(responses, 0).result) start_block = quantity_to_integer(Enum.at(responses, 0).result)
"0x000000000000000000000000" <> batch_inbox = Enum.at(responses, 1).result "0x000000000000000000000000" <> batch_inbox = Enum.at(responses, 1).result
"0x000000000000000000000000" <> batch_submitter = Enum.at(responses, 2).result "0x000000000000000000000000" <> batch_submitter = Enum.at(responses, 2).result
{start_block, String.downcase("0x" <> batch_inbox), String.downcase("0x" <> batch_submitter)} {start_block, String.downcase("0x" <> batch_inbox), String.downcase("0x" <> batch_submitter)}
_ -> _ ->

@ -51,6 +51,8 @@ defmodule Indexer.MixProject do
{:decorator, "~> 1.4"}, {:decorator, "~> 1.4"},
# JSONRPC access to Nethermind for `Explorer.Indexer` # JSONRPC access to Nethermind for `Explorer.Indexer`
{:ethereum_jsonrpc, in_umbrella: true}, {:ethereum_jsonrpc, in_umbrella: true},
# Brotli compression/decompression
{:brotli, "~> 0.3.2"},
# RLP encoding # RLP encoding
{:ex_rlp, "~> 0.6.0"}, {:ex_rlp, "~> 0.6.0"},
# Importing to database # Importing to database

@ -61,6 +61,7 @@
"blockscoutuser", "blockscoutuser",
"bools", "bools",
"bridgedtokenlist", "bridgedtokenlist",
"brotli",
"browserconfig", "browserconfig",
"bsdr", "bsdr",
"Btvk", "Btvk",

@ -9,6 +9,7 @@
"benchee": {:hex, :benchee, "1.3.1", "c786e6a76321121a44229dde3988fc772bca73ea75170a73fd5f4ddf1af95ccf", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "76224c58ea1d0391c8309a8ecbfe27d71062878f59bd41a390266bf4ac1cc56d"}, "benchee": {:hex, :benchee, "1.3.1", "c786e6a76321121a44229dde3988fc772bca73ea75170a73fd5f4ddf1af95ccf", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "76224c58ea1d0391c8309a8ecbfe27d71062878f59bd41a390266bf4ac1cc56d"},
"benchee_csv": {:hex, :benchee_csv, "1.0.0", "0b3b9223290bfcb8003552705bec9bcf1a89b4a83b70bd686e45295c264f3d16", [:mix], [{:benchee, ">= 0.99.0 and < 2.0.0", [hex: :benchee, repo: "hexpm", optional: false]}, {:csv, "~> 2.0", [hex: :csv, repo: "hexpm", optional: false]}], "hexpm", "cdefb804c021dcf7a99199492026584be9b5a21d6644ac0d01c81c5d97c520d5"}, "benchee_csv": {:hex, :benchee_csv, "1.0.0", "0b3b9223290bfcb8003552705bec9bcf1a89b4a83b70bd686e45295c264f3d16", [:mix], [{:benchee, ">= 0.99.0 and < 2.0.0", [hex: :benchee, repo: "hexpm", optional: false]}, {:csv, "~> 2.0", [hex: :csv, repo: "hexpm", optional: false]}], "hexpm", "cdefb804c021dcf7a99199492026584be9b5a21d6644ac0d01c81c5d97c520d5"},
"briefly": {:git, "https://github.com/CargoSense/briefly.git", "4836ba322ffb504a102a15cc6e35d928ef97120e", []}, "briefly": {:git, "https://github.com/CargoSense/briefly.git", "4836ba322ffb504a102a15cc6e35d928ef97120e", []},
"brotli": {:hex, :brotli, "0.3.2", "59cf45a399098516f1d34f70d8e010e5c9bf326659d3ef34c7cc56793339002b", [:rebar3], [], "hexpm", "9ec3ef9c753f80d0c657b4905193c55e5198f169fa1d1c044d8601d4d931a2ad"},
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"bureaucrat": {:hex, :bureaucrat, "0.2.10", "b0de157dad540e40007b663b683f716ced21f85ff0591093aadb209ad0d967e1", [:mix], [{:inflex, ">= 1.10.0", [hex: :inflex, repo: "hexpm", optional: false]}, {:phoenix, ">= 1.2.0", [hex: :phoenix, repo: "hexpm", optional: true]}, {:plug, ">= 1.0.0", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 1.5 or ~> 2.0 or ~> 3.0 or ~> 4.0 or ~> 5.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm", "bc7e5162b911c29c8ebefee87a2c16fbf13821a58f448a8fd024eb6c17fae15c"}, "bureaucrat": {:hex, :bureaucrat, "0.2.10", "b0de157dad540e40007b663b683f716ced21f85ff0591093aadb209ad0d967e1", [:mix], [{:inflex, ">= 1.10.0", [hex: :inflex, repo: "hexpm", optional: false]}, {:phoenix, ">= 1.2.0", [hex: :phoenix, repo: "hexpm", optional: true]}, {:plug, ">= 1.0.0", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 1.5 or ~> 2.0 or ~> 3.0 or ~> 4.0 or ~> 5.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm", "bc7e5162b911c29c8ebefee87a2c16fbf13821a58f448a8fd024eb6c17fae15c"},
"bypass": {:hex, :bypass, "2.1.0", "909782781bf8e20ee86a9cabde36b259d44af8b9f38756173e8f5e2e1fabb9b1", [:mix], [{:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "d9b5df8fa5b7a6efa08384e9bbecfe4ce61c77d28a4282f79e02f1ef78d96b80"}, "bypass": {:hex, :bypass, "2.1.0", "909782781bf8e20ee86a9cabde36b259d44af8b9f38756173e8f5e2e1fabb9b1", [:mix], [{:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "d9b5df8fa5b7a6efa08384e9bbecfe4ce61c77d28a4282f79e02f1ef78d96b80"},

Loading…
Cancel
Save