diff --git a/apps/block_scout_web/lib/block_scout_web/views/api/v2/block_view.ex b/apps/block_scout_web/lib/block_scout_web/views/api/v2/block_view.ex index 9c4b40a3516f..cf83a8eba318 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/api/v2/block_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/api/v2/block_view.ex @@ -40,6 +40,7 @@ defmodule BlockScoutWeb.API.V2.BlockView do "miner" => Helper.address_with_info(nil, block.miner, block.miner_hash, false), "size" => block.size, "hash" => block.hash, + "epoch" => block.epoch, "parent_hash" => block.parent_hash, "difficulty" => block.difficulty, "total_difficulty" => block.total_difficulty, diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block.ex index 1e0e717ab595..85b7d36a517c 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block.ex @@ -29,6 +29,7 @@ defmodule EthereumJSONRPC.Block do extra_data: EthereumJSONRPC.hash(), gas_limit: non_neg_integer(), gas_used: non_neg_integer(), + epoch: non_neg_integer(), hash: EthereumJSONRPC.hash(), logs_bloom: EthereumJSONRPC.hash(), miner_hash: EthereumJSONRPC.hash(), @@ -53,6 +54,7 @@ defmodule EthereumJSONRPC.Block do * `"difficulty"` - `t:EthereumJSONRPC.quantity/0` of the difficulty for this block. * `"extraData"` - the extra `t:EthereumJSONRPC.data/0` field of this block. * `"gasLimit" - maximum gas `t:EthereumJSONRPC.quantity/0` in this block. + * `"epoch"` - `t:EthereumJSONRPC.quantity/0` of the epoch for this block. * `"gasUsed" - the total `t:EthereumJSONRPC.quantity/0` of gas used by all transactions in this block. * `"hash"` - the `t:EthereumJSONRPC.hash/0` of the block. * `"logsBloom"` - `t:EthereumJSONRPC.data/0` for the [Bloom filter](https://en.wikipedia.org/wiki/Bloom_filter) @@ -262,6 +264,7 @@ defmodule EthereumJSONRPC.Block do "extraData" => extra_data, "gasLimit" => gas_limit, "gasUsed" => gas_used, + "epoch" => epoch, "hash" => hash, "logsBloom" => logs_bloom, "miner" => miner_hash, @@ -283,6 +286,7 @@ defmodule EthereumJSONRPC.Block do extra_data: extra_data, gas_limit: gas_limit, gas_used: gas_used, + epoch: epoch, hash: hash, logs_bloom: logs_bloom, miner_hash: miner_hash, @@ -311,6 +315,7 @@ defmodule EthereumJSONRPC.Block do "gasLimit" => gas_limit, "gasUsed" => gas_used, "hash" => hash, + "epoch" => epoch, "logsBloom" => logs_bloom, "miner" => miner_hash, "number" => number, @@ -332,6 +337,7 @@ defmodule EthereumJSONRPC.Block do gas_used: gas_used, hash: hash, logs_bloom: logs_bloom, + epoch: epoch, miner_hash: miner_hash, mix_hash: Map.get(elixir, "mixHash", "0x0"), nonce: Map.get(elixir, "nonce", 0), @@ -358,6 +364,7 @@ defmodule EthereumJSONRPC.Block do "gasUsed" => gas_used, "hash" => hash, "logsBloom" => logs_bloom, + "epoch" => epoch, "miner" => miner_hash, "number" => number, "parentHash" => parent_hash, @@ -379,6 +386,7 @@ defmodule EthereumJSONRPC.Block do hash: hash, logs_bloom: logs_bloom, miner_hash: miner_hash, + epoch: epoch, mix_hash: Map.get(elixir, "mixHash", "0x0"), nonce: Map.get(elixir, "nonce", 0), number: number, @@ -406,6 +414,7 @@ defmodule EthereumJSONRPC.Block do "hash" => hash, "logsBloom" => logs_bloom, "miner" => miner_hash, + "epoch" => epoch, "number" => number, "parentHash" => parent_hash, "receiptsRoot" => receipts_root, @@ -425,6 +434,7 @@ defmodule EthereumJSONRPC.Block do hash: hash, logs_bloom: logs_bloom, miner_hash: miner_hash, + epoch: epoch, mix_hash: Map.get(elixir, "mixHash", "0x0"), nonce: Map.get(elixir, "nonce", 0), number: number, @@ -448,6 +458,7 @@ defmodule EthereumJSONRPC.Block do "gasLimit" => gas_limit, "gasUsed" => gas_used, "hash" => hash, + "epoch" => epoch, "logsBloom" => logs_bloom, "miner" => miner_hash, "number" => number, @@ -471,6 +482,7 @@ defmodule EthereumJSONRPC.Block do mix_hash: Map.get(elixir, "mixHash", "0x0"), nonce: Map.get(elixir, "nonce", 0), number: number, + epoch: epoch, parent_hash: parent_hash, receipts_root: receipts_root, size: size, @@ -806,7 +818,7 @@ defmodule EthereumJSONRPC.Block do end defp entry_to_elixir({key, quantity}, _block) - when key in ~w(difficulty gasLimit gasUsed minimumGasPrice baseFeePerGas number size cumulativeDifficulty totalDifficulty paidFees minimumGasPrice) and + when key in ~w(difficulty gasLimit gasUsed minimumGasPrice baseFeePerGas number size cumulativeDifficulty totalDifficulty paidFees minimumGasPrice epoch) and not is_nil(quantity) do {key, quantity_to_integer(quantity)} end diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block/by_tag.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block/by_tag.ex index d257f4e506c5..575ab54d28f5 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block/by_tag.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block/by_tag.ex @@ -8,7 +8,7 @@ defmodule EthereumJSONRPC.Block.ByTag do alias EthereumJSONRPC.Blocks def request(%{id: id, tag: tag}) when is_binary(tag) do - EthereumJSONRPC.request(%{id: id, method: "eth_getBlockByNumber", params: [tag, false]}) + EthereumJSONRPC.request(%{id: id, method: "hmy_getBlockByNumber", params: [tag, false]}) end def number_from_result({:ok, %{"number" => nil}}), do: {:error, :not_found} diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/blocks.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/blocks.ex index a109a618c593..c98cc27c81f2 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/blocks.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/blocks.ex @@ -45,7 +45,6 @@ defmodule EthereumJSONRPC.Blocks do {:error, error}, %{errors: errors} = acc -> %{acc | errors: [error | errors]} end) - elixir_blocks = to_elixir(blocks) elixir_uncles = elixir_to_uncles(elixir_blocks) diff --git a/apps/explorer/lib/explorer/chain/block.ex b/apps/explorer/lib/explorer/chain/block.ex index a1558e29db10..c4f3cf75f04d 100644 --- a/apps/explorer/lib/explorer/chain/block.ex +++ b/apps/explorer/lib/explorer/chain/block.ex @@ -22,7 +22,7 @@ defmodule Explorer.Chain.Block do alias Explorer.Chain.Block.{EmissionReward, Reward, SecondDegreeRelation} alias Explorer.Repo - @optional_attrs ~w(size refetch_needed total_difficulty difficulty base_fee_per_gas)a + @optional_attrs ~w(size refetch_needed total_difficulty difficulty base_fee_per_gas epoch)a |> (&(case Application.compile_env(:explorer, :chain_type) do "rsk" -> &1 ++ @@ -104,6 +104,7 @@ defmodule Explorer.Chain.Block do number: block_number(), parent_hash: Hash.t(), size: non_neg_integer(), + epoch: non_neg_integer(), timestamp: DateTime.t(), total_difficulty: difficulty(), transactions: %Ecto.Association.NotLoaded{} | [Transaction.t()], @@ -120,6 +121,7 @@ defmodule Explorer.Chain.Block do field(:gas_used, :decimal) field(:nonce, Hash.Nonce) field(:number, :integer) + field(:epoch, :integer) field(:size, :integer) field(:timestamp, :utc_datetime_usec) field(:total_difficulty, :decimal) diff --git a/apps/explorer/priv/repo/migrations/20241011220133_add_epoch_to_block.exs b/apps/explorer/priv/repo/migrations/20241011220133_add_epoch_to_block.exs new file mode 100644 index 000000000000..3c704a47f1dc --- /dev/null +++ b/apps/explorer/priv/repo/migrations/20241011220133_add_epoch_to_block.exs @@ -0,0 +1,9 @@ +defmodule Explorer.Repo.Migrations.AddEpochToBlock do + use Ecto.Migration + + def change do + alter table(:blocks) do + add(:epoch, :bigint, null: true) + end + end +end