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
43 changes: 43 additions & 0 deletions apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block.ex
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,49 @@ defmodule EthereumJSONRPC.Block do
}
end

# Some chains (e.g. Signet) do not return `size` or `totalDifficulty` in block responses.
# This catch-all clause handles blocks missing those fields by using Map.get with defaults.
defp do_elixir_to_params(
%{
"difficulty" => difficulty,
"extraData" => extra_data,
"gasLimit" => gas_limit,
"gasUsed" => gas_used,
"hash" => hash,
"logsBloom" => logs_bloom,
"miner" => miner_hash,
"number" => number,
"parentHash" => parent_hash,
"receiptsRoot" => receipts_root,
"stateRoot" => state_root,
"timestamp" => timestamp,
"transactionsRoot" => transactions_root
} = elixir
) do
%{
difficulty: difficulty,
extra_data: extra_data,
gas_limit: gas_limit,
gas_used: gas_used,
hash: hash,
logs_bloom: logs_bloom,
miner_hash: miner_hash,
mix_hash: Map.get(elixir, "mixHash", "0x0"),
nonce: Map.get(elixir, "nonce", 0),
number: number,
parent_hash: parent_hash,
receipts_root: receipts_root,
sha3_uncles: Map.get(elixir, "sha3Uncles", @sha3_uncles_empty_list),
size: Map.get(elixir, "size"),
state_root: state_root,
timestamp: timestamp,
total_difficulty: Map.get(elixir, "totalDifficulty"),
transactions_root: transactions_root,
uncles: Map.get(elixir, "uncles", []),
base_fee_per_gas: Map.get(elixir, "baseFeePerGas")
}
end

@spec chain_type_fields(params, elixir) :: params
case @chain_type do
:rsk ->
Expand Down
51 changes: 51 additions & 0 deletions apps/ethereum_jsonrpc/test/ethereum_jsonrpc/block_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,57 @@ defmodule EthereumJSONRPC.BlockTest do
|> Map.merge(chain_type_fields())
end

test "handles blocks without size, totalDifficulty, or baseFeePerGas" do
result =
Block.elixir_to_params(%{
"difficulty" => 0,
"extraData" => "0x",
"gasLimit" => 30_000_000,
"gasUsed" => 0,
"hash" => "0x52ab82bcac8b4db67f92b8caf8381ac24fb09457791617592fd82364ed0b35b3",
"logsBloom" =>
"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"miner" => "0xab30d97cc3ad91b5d3a9e7252acf411c9aeee9dc",
"mixHash" => "0xe7a8db8db2edc3823388dbe6f05f89d5187d540b3996ebe5f6be6d755c2a9bfe",
"nonce" => "0x0000000000000000",
"number" => 24_892_088,
"parentHash" => "0x7476e610c1dfef2065446e726b15e8c4d060c4e382aae27cb422fee01600d8db",
"receiptsRoot" => "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"sha3Uncles" => "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"stateRoot" => "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"timestamp" => Timex.parse!("2026-04-16T11:28:35Z", "{ISO:Extended:Z}"),
"transactions" => [],
"transactionsRoot" => "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"uncles" => []
})

assert result ==
%{
difficulty: 0,
extra_data: "0x",
gas_limit: 30_000_000,
gas_used: 0,
hash: "0x52ab82bcac8b4db67f92b8caf8381ac24fb09457791617592fd82364ed0b35b3",
logs_bloom:
"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
mix_hash: "0xe7a8db8db2edc3823388dbe6f05f89d5187d540b3996ebe5f6be6d755c2a9bfe",
miner_hash: "0xab30d97cc3ad91b5d3a9e7252acf411c9aeee9dc",
nonce: "0x0000000000000000",
number: 24_892_088,
parent_hash: "0x7476e610c1dfef2065446e726b15e8c4d060c4e382aae27cb422fee01600d8db",
receipts_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
sha3_uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
size: nil,
state_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
timestamp: Timex.parse!("2026-04-16T11:28:35Z", "{ISO:Extended:Z}"),
total_difficulty: nil,
transactions_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
uncles: [],
base_fee_per_gas: nil
}
|> Map.merge(chain_type_fields())
end

case Application.compile_env(:explorer, :chain_type) do
:rsk ->
defp chain_type_fields,
Expand Down
12 changes: 7 additions & 5 deletions apps/indexer/lib/indexer/fetcher/empty_blocks_sanitizer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,21 @@ defmodule Indexer.Fetcher.EmptyBlocksSanitizer do
defp classify_blocks_from_result(result) do
result
|> Enum.reduce({[], []}, fn %{id: _id, result: block}, {non_empty_blocks, empty_blocks} ->
if Enum.empty?(block["transactions"]) do
{non_empty_blocks, [block_fields(block) | empty_blocks]}
transactions = Map.get(block, "transactions") || []

if Enum.empty?(transactions) do
{non_empty_blocks, [block_fields(block, transactions) | empty_blocks]}
else
{[block_fields(block) | non_empty_blocks], empty_blocks}
{[block_fields(block, transactions) | non_empty_blocks], empty_blocks}
end
end)
end

defp block_fields(block) do
defp block_fields(block, transactions) do
%{
number: quantity_to_integer(block["number"]),
hash: block["hash"],
transactions_count: Enum.count(block["transactions"])
transactions_count: Enum.count(transactions)
}
end

Expand Down
Loading