Take into account `CHAIN_TYPE` for RSK

pull/8742/head
Maxim Filonov 1 year ago
parent 940799b5f9
commit 48bc9a16bd
  1. 1
      CHANGELOG.md
  2. 24
      apps/block_scout_web/lib/block_scout_web/views/api/v2/block_view.ex
  3. 313
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block.ex
  4. 19
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/blocks.ex
  5. 66
      apps/ethereum_jsonrpc/test/ethereum_jsonrpc/block_test.exs
  6. 1
      apps/explorer/config/config.exs
  7. 54
      apps/explorer/lib/explorer/chain/block.ex
  8. 0
      apps/explorer/priv/rsk/migrations/20230724094744_add_rootstock_fields_to_blocks.exs
  9. 226
      apps/indexer/test/indexer/fetcher/rootstock_data_test.exs
  10. 3
      config/config_helper.exs
  11. 24
      config/runtime.exs

@ -21,6 +21,7 @@
### Chore ### Chore
- [#8802](https://github.com/blockscout/blockscout/pull/8802) - Enable API v2 by default - [#8802](https://github.com/blockscout/blockscout/pull/8802) - Enable API v2 by default
- [#8742](https://github.com/blockscout/blockscout/pull/8742) - Merge rsk branch into the master branch
- [#8728](https://github.com/blockscout/blockscout/pull/8728) - Remove repos_list (default value for ecto repos) from Explorer.ReleaseTasks - [#8728](https://github.com/blockscout/blockscout/pull/8728) - Remove repos_list (default value for ecto repos) from Explorer.ReleaseTasks
<details> <details>

@ -61,7 +61,7 @@ defmodule BlockScoutWeb.API.V2.BlockView do
"tx_fees" => tx_fees, "tx_fees" => tx_fees,
"withdrawals_count" => count_withdrawals(block) "withdrawals_count" => count_withdrawals(block)
} }
|> add_rootstock_fields(block, single_block?) |> chain_type_fields(block, single_block?)
end end
def prepare_rewards(rewards, block, single_block?) do def prepare_rewards(rewards, block, single_block?) do
@ -117,14 +117,18 @@ defmodule BlockScoutWeb.API.V2.BlockView do
def count_withdrawals(%Block{withdrawals: withdrawals}) when is_list(withdrawals), do: Enum.count(withdrawals) def count_withdrawals(%Block{withdrawals: withdrawals}) when is_list(withdrawals), do: Enum.count(withdrawals)
def count_withdrawals(_), do: nil def count_withdrawals(_), do: nil
defp add_rootstock_fields(prepared_block, _block, false), do: prepared_block defp chain_type_fields(result, block, single_block?) do
case single_block? && Application.get_env(:explorer, :chain_type) do
defp add_rootstock_fields(prepared_block, block, true) do "rsk" ->
prepared_block result
|> Map.put("minimum_gas_price", block.minimum_gas_price) |> Map.put("minimum_gas_price", block.minimum_gas_price)
|> Map.put("bitcoin_merged_mining_header", block.bitcoin_merged_mining_header) |> Map.put("bitcoin_merged_mining_header", block.bitcoin_merged_mining_header)
|> Map.put("bitcoin_merged_mining_coinbase_transaction", block.bitcoin_merged_mining_coinbase_transaction) |> Map.put("bitcoin_merged_mining_coinbase_transaction", block.bitcoin_merged_mining_coinbase_transaction)
|> Map.put("bitcoin_merged_mining_merkle_proof", block.bitcoin_merged_mining_merkle_proof) |> Map.put("bitcoin_merged_mining_merkle_proof", block.bitcoin_merged_mining_merkle_proof)
|> Map.put("hash_for_merged_mining", block.hash_for_merged_mining) |> Map.put("hash_for_merged_mining", block.hash_for_merged_mining)
_ ->
result
end
end end
end end

@ -8,8 +8,23 @@ defmodule EthereumJSONRPC.Block do
alias EthereumJSONRPC.{Transactions, Uncles, Withdrawals} alias EthereumJSONRPC.{Transactions, Uncles, Withdrawals}
if Application.compile_env(:explorer, :chain_type) == "rsk" do
@rootstock_fields quote(
do: [
bitcoin_merged_mining_header: EthereumJSONRPC.data(),
bitcoin_merged_mining_coinbase_transaction: EthereumJSONRPC.data(),
bitcoin_merged_mining_merkle_proof: EthereumJSONRPC.data(),
hash_for_merged_mining: EthereumJSONRPC.data(),
minimum_gas_price: non_neg_integer()
]
)
else
@rootstock_fields quote(do: [])
end
@type elixir :: %{String.t() => non_neg_integer | DateTime.t() | String.t() | nil} @type elixir :: %{String.t() => non_neg_integer | DateTime.t() | String.t() | nil}
@type params :: %{ @type params :: %{
unquote_splicing(@rootstock_fields),
difficulty: pos_integer(), difficulty: pos_integer(),
extra_data: EthereumJSONRPC.hash(), extra_data: EthereumJSONRPC.hash(),
gas_limit: non_neg_integer(), gas_limit: non_neg_integer(),
@ -30,12 +45,7 @@ defmodule EthereumJSONRPC.Block do
transactions_root: EthereumJSONRPC.hash(), transactions_root: EthereumJSONRPC.hash(),
uncles: [EthereumJSONRPC.hash()], uncles: [EthereumJSONRPC.hash()],
base_fee_per_gas: non_neg_integer(), base_fee_per_gas: non_neg_integer(),
withdrawals_root: EthereumJSONRPC.hash(), withdrawals_root: EthereumJSONRPC.hash()
minimum_gas_price: non_neg_integer(),
bitcoin_merged_mining_header: EthereumJSONRPC.data(),
bitcoin_merged_mining_coinbase_transaction: EthereumJSONRPC.data(),
bitcoin_merged_mining_merkle_proof: EthereumJSONRPC.data(),
hash_for_merged_mining: EthereumJSONRPC.data()
} }
@typedoc """ @typedoc """
@ -74,11 +84,15 @@ defmodule EthereumJSONRPC.Block do
`t:EthereumJSONRPC.hash/0`. `t:EthereumJSONRPC.hash/0`.
* `"baseFeePerGas"` - `t:EthereumJSONRPC.quantity/0` of wei to denote amount of fee burned per unit gas used. Introduced in [EIP-1559](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md) * `"baseFeePerGas"` - `t:EthereumJSONRPC.quantity/0` of wei to denote amount of fee burned per unit gas used. Introduced in [EIP-1559](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md)
* `"withdrawalsRoot"` - `t:EthereumJSONRPC.hash/0` of the root of the withdrawals. * `"withdrawalsRoot"` - `t:EthereumJSONRPC.hash/0` of the root of the withdrawals.
* `"minimumGasPrice"` - `t:EthereumJSONRPC.quantity/0` of the minimum gas price for this block. #{if Application.compile_env(:explorer, :chain_type) == "rsk" do
* `"bitcoinMergedMiningHeader"` - `t:EthereumJSONRPC.data/0` of the Bitcoin merged mining header. """
* `"bitcoinMergedMiningCoinbaseTransaction"` - `t:EthereumJSONRPC.data/0` of the Bitcoin merged mining coinbase transaction. * `"minimumGasPrice"` - `t:EthereumJSONRPC.quantity/0` of the minimum gas price for this block.
* `"bitcoinMergedMiningMerkleProof"` - `t:EthereumJSONRPC.data/0` of the Bitcoin merged mining merkle proof. * `"bitcoinMergedMiningHeader"` - `t:EthereumJSONRPC.data/0` of the Bitcoin merged mining header.
* `"hashForMergedMining"` - `t:EthereumJSONRPC.data/0` of the hash for merged mining. * `"bitcoinMergedMiningCoinbaseTransaction"` - `t:EthereumJSONRPC.data/0` of the Bitcoin merged mining coinbase transaction.
* `"bitcoinMergedMiningMerkleProof"` - `t:EthereumJSONRPC.data/0` of the Bitcoin merged mining merkle proof.
* `"hashForMergedMining"` - `t:EthereumJSONRPC.data/0` of the hash for merged mining.
"""
end}
""" """
@type t :: %{String.t() => EthereumJSONRPC.data() | EthereumJSONRPC.hash() | EthereumJSONRPC.quantity() | nil} @type t :: %{String.t() => EthereumJSONRPC.data() | EthereumJSONRPC.hash() | EthereumJSONRPC.quantity() | nil}
@ -129,13 +143,18 @@ defmodule EthereumJSONRPC.Block do
...> "timestamp" => Timex.parse!("2017-12-15T21:03:30Z", "{ISO:Extended:Z}"), ...> "timestamp" => Timex.parse!("2017-12-15T21:03:30Z", "{ISO:Extended:Z}"),
...> "totalDifficulty" => 340282366920938463463374607431465668165, ...> "totalDifficulty" => 340282366920938463463374607431465668165,
...> "transactions" => [], ...> "transactions" => [],
...> "transactionsRoot" => "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", ...> "transactionsRoot" => "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",\
...> "uncles" => [], #{if Application.compile_env(:explorer, :chain_type) == "rsk" do
...> "minimumGasPrice" => 345786, """
...> "bitcoinMergedMiningHeader" => "0x00006d20ffd048280094a6ea0851d854036aacaa25ee0f23f0040200000000000000000078d2638fe0b4477c54601e6449051afba8228e0a88ff06b0c91f091fd34d5da57487c76402610517372c2fe9",
...> "bitcoinMergedMiningCoinbaseTransaction" => "0x00000000000000805bf0dc9203da49a3b4e3ec913806e43102cc07db991272dc8b7018da57eb5abe59a32d070000ffffffff03449a4d26000000001976a914536ffa992491508dca0354e52f32a3a7a679a53a88ac00000000000000002b6a2952534b424c4f434b3ad2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a400000000000000000266a24aa21a9ed4ae42ea6dca2687aaed665714bf58b055c4e11f2fb038605930d630b49ad7b9d00000000", ...> "minimumGasPrice" => 345786,
...> "bitcoinMergedMiningMerkleProof" => "0x8e5a4ba74eb4eb2f9ad4cabc2913aeed380a5becf7cd4d513341617efb798002bd83a783c31c66a8a8f6cc56c071c2d471cb610e3dc13054b9d216021d8c7e9112f622564449ebedcedf7d4ccb6fe0ffac861b7ed1446c310813cdf712e1e6add28b1fe1c0ae5e916194ba4f285a9340aba41e91bf847bf31acf37a9623a04a2348a37ab9faa5908122db45596bbc03e9c3644b0d4589471c4ff30fc139f3ba50506e9136fa0df799b487494de3e2b3dec937338f1a2e18da057c1f60590a9723672a4355b9914b1d01af9f582d9e856f6e1744be00f268b0b01d559329f7e0685aa63ffeb7c28486d7462292021d1345cddbf7c920ca34bb7aa4c6cdbe068806e35d0db662e7fcda03cb4d779594638c62a1fdd7ec98d1fb6d240d853958abe57561d9b9d0465cf8b9d6ee3c58b0d8b07d6c4c5d8f348e43fe3c06011b6a0008db4e0b16c77ececc3981f9008201cea5939869d648e59a09bd2094b1196ff61126bffb626153deed2563e1745436247c94a85d2947756b606d67633781c99d7", ...> "bitcoinMergedMiningHeader" => "0x00006d20ffd048280094a6ea0851d854036aacaa25ee0f23f0040200000000000000000078d2638fe0b4477c54601e6449051afba8228e0a88ff06b0c91f091fd34d5da57487c76402610517372c2fe9",
...> "hashForMergedMining" => "0xd2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a40", ...> "bitcoinMergedMiningCoinbaseTransaction" => "0x00000000000000805bf0dc9203da49a3b4e3ec913806e43102cc07db991272dc8b7018da57eb5abe59a32d070000ffffffff03449a4d26000000001976a914536ffa992491508dca0354e52f32a3a7a679a53a88ac00000000000000002b6a2952534b424c4f434b3ad2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a400000000000000000266a24aa21a9ed4ae42ea6dca2687aaed665714bf58b055c4e11f2fb038605930d630b49ad7b9d00000000",
...> "bitcoinMergedMiningMerkleProof" => "0x8e5a4ba74eb4eb2f9ad4cabc2913aeed380a5becf7cd4d513341617efb798002bd83a783c31c66a8a8f6cc56c071c2d471cb610e3dc13054b9d216021d8c7e9112f622564449ebedcedf7d4ccb6fe0ffac861b7ed1446c310813cdf712e1e6add28b1fe1c0ae5e916194ba4f285a9340aba41e91bf847bf31acf37a9623a04a2348a37ab9faa5908122db45596bbc03e9c3644b0d4589471c4ff30fc139f3ba50506e9136fa0df799b487494de3e2b3dec937338f1a2e18da057c1f60590a9723672a4355b9914b1d01af9f582d9e856f6e1744be00f268b0b01d559329f7e0685aa63ffeb7c28486d7462292021d1345cddbf7c920ca34bb7aa4c6cdbe068806e35d0db662e7fcda03cb4d779594638c62a1fdd7ec98d1fb6d240d853958abe57561d9b9d0465cf8b9d6ee3c58b0d8b07d6c4c5d8f348e43fe3c06011b6a0008db4e0b16c77ececc3981f9008201cea5939869d648e59a09bd2094b1196ff61126bffb626153deed2563e1745436247c94a85d2947756b606d67633781c99d7",
...> "hashForMergedMining" => "0xd2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a40",\
"""
end}
...> "uncles" => []
...> } ...> }
...> ) ...> )
%{ %{
@ -157,13 +176,18 @@ defmodule EthereumJSONRPC.Block do
timestamp: Timex.parse!("2017-12-15T21:03:30Z", "{ISO:Extended:Z}"), timestamp: Timex.parse!("2017-12-15T21:03:30Z", "{ISO:Extended:Z}"),
total_difficulty: 340282366920938463463374607431465668165, total_difficulty: 340282366920938463463374607431465668165,
transactions_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", transactions_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
uncles: [], uncles: [],\
withdrawals_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", #{if Application.compile_env(:explorer, :chain_type) == "rsk" do
bitcoin_merged_mining_coinbase_transaction: "0x00000000000000805bf0dc9203da49a3b4e3ec913806e43102cc07db991272dc8b7018da57eb5abe59a32d070000ffffffff03449a4d26000000001976a914536ffa992491508dca0354e52f32a3a7a679a53a88ac00000000000000002b6a2952534b424c4f434b3ad2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a400000000000000000266a24aa21a9ed4ae42ea6dca2687aaed665714bf58b055c4e11f2fb038605930d630b49ad7b9d00000000", """
bitcoin_merged_mining_header: "0x00006d20ffd048280094a6ea0851d854036aacaa25ee0f23f0040200000000000000000078d2638fe0b4477c54601e6449051afba8228e0a88ff06b0c91f091fd34d5da57487c76402610517372c2fe9",
bitcoin_merged_mining_merkle_proof: "0x8e5a4ba74eb4eb2f9ad4cabc2913aeed380a5becf7cd4d513341617efb798002bd83a783c31c66a8a8f6cc56c071c2d471cb610e3dc13054b9d216021d8c7e9112f622564449ebedcedf7d4ccb6fe0ffac861b7ed1446c310813cdf712e1e6add28b1fe1c0ae5e916194ba4f285a9340aba41e91bf847bf31acf37a9623a04a2348a37ab9faa5908122db45596bbc03e9c3644b0d4589471c4ff30fc139f3ba50506e9136fa0df799b487494de3e2b3dec937338f1a2e18da057c1f60590a9723672a4355b9914b1d01af9f582d9e856f6e1744be00f268b0b01d559329f7e0685aa63ffeb7c28486d7462292021d1345cddbf7c920ca34bb7aa4c6cdbe068806e35d0db662e7fcda03cb4d779594638c62a1fdd7ec98d1fb6d240d853958abe57561d9b9d0465cf8b9d6ee3c58b0d8b07d6c4c5d8f348e43fe3c06011b6a0008db4e0b16c77ececc3981f9008201cea5939869d648e59a09bd2094b1196ff61126bffb626153deed2563e1745436247c94a85d2947756b606d67633781c99d7", bitcoin_merged_mining_coinbase_transaction: "0x00000000000000805bf0dc9203da49a3b4e3ec913806e43102cc07db991272dc8b7018da57eb5abe59a32d070000ffffffff03449a4d26000000001976a914536ffa992491508dca0354e52f32a3a7a679a53a88ac00000000000000002b6a2952534b424c4f434b3ad2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a400000000000000000266a24aa21a9ed4ae42ea6dca2687aaed665714bf58b055c4e11f2fb038605930d630b49ad7b9d00000000",
hash_for_merged_mining: "0xd2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a40", bitcoin_merged_mining_header: "0x00006d20ffd048280094a6ea0851d854036aacaa25ee0f23f0040200000000000000000078d2638fe0b4477c54601e6449051afba8228e0a88ff06b0c91f091fd34d5da57487c76402610517372c2fe9",
minimum_gas_price: 345786 bitcoin_merged_mining_merkle_proof: "0x8e5a4ba74eb4eb2f9ad4cabc2913aeed380a5becf7cd4d513341617efb798002bd83a783c31c66a8a8f6cc56c071c2d471cb610e3dc13054b9d216021d8c7e9112f622564449ebedcedf7d4ccb6fe0ffac861b7ed1446c310813cdf712e1e6add28b1fe1c0ae5e916194ba4f285a9340aba41e91bf847bf31acf37a9623a04a2348a37ab9faa5908122db45596bbc03e9c3644b0d4589471c4ff30fc139f3ba50506e9136fa0df799b487494de3e2b3dec937338f1a2e18da057c1f60590a9723672a4355b9914b1d01af9f582d9e856f6e1744be00f268b0b01d559329f7e0685aa63ffeb7c28486d7462292021d1345cddbf7c920ca34bb7aa4c6cdbe068806e35d0db662e7fcda03cb4d779594638c62a1fdd7ec98d1fb6d240d853958abe57561d9b9d0465cf8b9d6ee3c58b0d8b07d6c4c5d8f348e43fe3c06011b6a0008db4e0b16c77ececc3981f9008201cea5939869d648e59a09bd2094b1196ff61126bffb626153deed2563e1745436247c94a85d2947756b606d67633781c99d7",
hash_for_merged_mining: "0xd2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a40",
minimum_gas_price: 345786,\
"""
end}
withdrawals_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
} }
[Geth] `elixir` can be converted to params [Geth] `elixir` can be converted to params
@ -211,39 +235,49 @@ defmodule EthereumJSONRPC.Block do
timestamp: Timex.parse!("2015-07-30T15:32:07Z", "{ISO:Extended:Z}"), timestamp: Timex.parse!("2015-07-30T15:32:07Z", "{ISO:Extended:Z}"),
total_difficulty: 1039309006117, total_difficulty: 1039309006117,
transactions_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", transactions_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
uncles: [], uncles: [],\
withdrawals_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", #{if Application.compile_env(:explorer, :chain_type) == "rsk" do
bitcoin_merged_mining_coinbase_transaction: nil, """
bitcoin_merged_mining_header: nil,
bitcoin_merged_mining_merkle_proof: nil, bitcoin_merged_mining_coinbase_transaction: nil,
hash_for_merged_mining: nil, bitcoin_merged_mining_header: nil,
minimum_gas_price: nil bitcoin_merged_mining_merkle_proof: nil,
hash_for_merged_mining: nil,
minimum_gas_price: nil,\
"""
end}
withdrawals_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
} }
""" """
@spec elixir_to_params(elixir) :: params @spec elixir_to_params(elixir) :: params
def elixir_to_params( def elixir_to_params(elixir) do
%{ elixir
"difficulty" => difficulty, |> do_elixir_to_params()
"extraData" => extra_data, |> chain_type_fields(elixir)
"gasLimit" => gas_limit, end
"gasUsed" => gas_used,
"hash" => hash, defp do_elixir_to_params(
"logsBloom" => logs_bloom, %{
"miner" => miner_hash, "difficulty" => difficulty,
"number" => number, "extraData" => extra_data,
"parentHash" => parent_hash, "gasLimit" => gas_limit,
"receiptsRoot" => receipts_root, "gasUsed" => gas_used,
"sha3Uncles" => sha3_uncles, "hash" => hash,
"size" => size, "logsBloom" => logs_bloom,
"stateRoot" => state_root, "miner" => miner_hash,
"timestamp" => timestamp, "number" => number,
"totalDifficulty" => total_difficulty, "parentHash" => parent_hash,
"transactionsRoot" => transactions_root, "receiptsRoot" => receipts_root,
"uncles" => uncles, "sha3Uncles" => sha3_uncles,
"baseFeePerGas" => base_fee_per_gas "size" => size,
} = elixir "stateRoot" => state_root,
) do "timestamp" => timestamp,
"totalDifficulty" => total_difficulty,
"transactionsRoot" => transactions_root,
"uncles" => uncles,
"baseFeePerGas" => base_fee_per_gas
} = elixir
) do
%{ %{
difficulty: difficulty, difficulty: difficulty,
extra_data: extra_data, extra_data: extra_data,
@ -266,36 +300,31 @@ defmodule EthereumJSONRPC.Block do
uncles: uncles, uncles: uncles,
base_fee_per_gas: base_fee_per_gas, base_fee_per_gas: base_fee_per_gas,
withdrawals_root: withdrawals_root:
Map.get(elixir, "withdrawalsRoot", "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"), Map.get(elixir, "withdrawalsRoot", "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
minimum_gas_price: Map.get(elixir, "minimumGasPrice"),
bitcoin_merged_mining_header: Map.get(elixir, "bitcoinMergedMiningHeader"),
bitcoin_merged_mining_coinbase_transaction: Map.get(elixir, "bitcoinMergedMiningCoinbaseTransaction"),
bitcoin_merged_mining_merkle_proof: Map.get(elixir, "bitcoinMergedMiningMerkleProof"),
hash_for_merged_mining: Map.get(elixir, "hashForMergedMining")
} }
end end
def elixir_to_params( defp do_elixir_to_params(
%{ %{
"difficulty" => difficulty, "difficulty" => difficulty,
"extraData" => extra_data, "extraData" => extra_data,
"gasLimit" => gas_limit, "gasLimit" => gas_limit,
"gasUsed" => gas_used, "gasUsed" => gas_used,
"hash" => hash, "hash" => hash,
"logsBloom" => logs_bloom, "logsBloom" => logs_bloom,
"miner" => miner_hash, "miner" => miner_hash,
"number" => number, "number" => number,
"parentHash" => parent_hash, "parentHash" => parent_hash,
"receiptsRoot" => receipts_root, "receiptsRoot" => receipts_root,
"sha3Uncles" => sha3_uncles, "sha3Uncles" => sha3_uncles,
"size" => size, "size" => size,
"stateRoot" => state_root, "stateRoot" => state_root,
"timestamp" => timestamp, "timestamp" => timestamp,
"transactionsRoot" => transactions_root, "transactionsRoot" => transactions_root,
"uncles" => uncles, "uncles" => uncles,
"baseFeePerGas" => base_fee_per_gas "baseFeePerGas" => base_fee_per_gas
} = elixir } = elixir
) do ) do
%{ %{
difficulty: difficulty, difficulty: difficulty,
extra_data: extra_data, extra_data: extra_data,
@ -317,36 +346,31 @@ defmodule EthereumJSONRPC.Block do
uncles: uncles, uncles: uncles,
base_fee_per_gas: base_fee_per_gas, base_fee_per_gas: base_fee_per_gas,
withdrawals_root: withdrawals_root:
Map.get(elixir, "withdrawalsRoot", "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"), Map.get(elixir, "withdrawalsRoot", "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
minimum_gas_price: Map.get(elixir, "minimumGasPrice"),
bitcoin_merged_mining_header: Map.get(elixir, "bitcoinMergedMiningHeader"),
bitcoin_merged_mining_coinbase_transaction: Map.get(elixir, "bitcoinMergedMiningCoinbaseTransaction"),
bitcoin_merged_mining_merkle_proof: Map.get(elixir, "bitcoinMergedMiningMerkleProof"),
hash_for_merged_mining: Map.get(elixir, "hashForMergedMining")
} }
end end
def elixir_to_params( defp do_elixir_to_params(
%{ %{
"difficulty" => difficulty, "difficulty" => difficulty,
"extraData" => extra_data, "extraData" => extra_data,
"gasLimit" => gas_limit, "gasLimit" => gas_limit,
"gasUsed" => gas_used, "gasUsed" => gas_used,
"hash" => hash, "hash" => hash,
"logsBloom" => logs_bloom, "logsBloom" => logs_bloom,
"miner" => miner_hash, "miner" => miner_hash,
"number" => number, "number" => number,
"parentHash" => parent_hash, "parentHash" => parent_hash,
"receiptsRoot" => receipts_root, "receiptsRoot" => receipts_root,
"sha3Uncles" => sha3_uncles, "sha3Uncles" => sha3_uncles,
"size" => size, "size" => size,
"stateRoot" => state_root, "stateRoot" => state_root,
"timestamp" => timestamp, "timestamp" => timestamp,
"totalDifficulty" => total_difficulty, "totalDifficulty" => total_difficulty,
"transactionsRoot" => transactions_root, "transactionsRoot" => transactions_root,
"uncles" => uncles "uncles" => uncles
} = elixir } = elixir
) do ) do
%{ %{
difficulty: difficulty, difficulty: difficulty,
extra_data: extra_data, extra_data: extra_data,
@ -368,36 +392,31 @@ defmodule EthereumJSONRPC.Block do
transactions_root: transactions_root, transactions_root: transactions_root,
uncles: uncles, uncles: uncles,
withdrawals_root: withdrawals_root:
Map.get(elixir, "withdrawalsRoot", "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"), Map.get(elixir, "withdrawalsRoot", "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
minimum_gas_price: Map.get(elixir, "minimumGasPrice"),
bitcoin_merged_mining_header: Map.get(elixir, "bitcoinMergedMiningHeader"),
bitcoin_merged_mining_coinbase_transaction: Map.get(elixir, "bitcoinMergedMiningCoinbaseTransaction"),
bitcoin_merged_mining_merkle_proof: Map.get(elixir, "bitcoinMergedMiningMerkleProof"),
hash_for_merged_mining: Map.get(elixir, "hashForMergedMining")
} }
end end
# Geth: a response from eth_getblockbyhash for uncle blocks is without `totalDifficulty` param # Geth: a response from eth_getblockbyhash for uncle blocks is without `totalDifficulty` param
def elixir_to_params( defp do_elixir_to_params(
%{ %{
"difficulty" => difficulty, "difficulty" => difficulty,
"extraData" => extra_data, "extraData" => extra_data,
"gasLimit" => gas_limit, "gasLimit" => gas_limit,
"gasUsed" => gas_used, "gasUsed" => gas_used,
"hash" => hash, "hash" => hash,
"logsBloom" => logs_bloom, "logsBloom" => logs_bloom,
"miner" => miner_hash, "miner" => miner_hash,
"number" => number, "number" => number,
"parentHash" => parent_hash, "parentHash" => parent_hash,
"receiptsRoot" => receipts_root, "receiptsRoot" => receipts_root,
"sha3Uncles" => sha3_uncles, "sha3Uncles" => sha3_uncles,
"size" => size, "size" => size,
"stateRoot" => state_root, "stateRoot" => state_root,
"timestamp" => timestamp, "timestamp" => timestamp,
"transactionsRoot" => transactions_root, "transactionsRoot" => transactions_root,
"uncles" => uncles "uncles" => uncles
} = elixir } = elixir
) do ) do
%{ %{
difficulty: difficulty, difficulty: difficulty,
extra_data: extra_data, extra_data: extra_data,
@ -418,15 +437,27 @@ defmodule EthereumJSONRPC.Block do
transactions_root: transactions_root, transactions_root: transactions_root,
uncles: uncles, uncles: uncles,
withdrawals_root: withdrawals_root:
Map.get(elixir, "withdrawalsRoot", "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"), Map.get(elixir, "withdrawalsRoot", "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
minimum_gas_price: Map.get(elixir, "minimumGasPrice"),
bitcoin_merged_mining_header: Map.get(elixir, "bitcoinMergedMiningHeader"),
bitcoin_merged_mining_coinbase_transaction: Map.get(elixir, "bitcoinMergedMiningCoinbaseTransaction"),
bitcoin_merged_mining_merkle_proof: Map.get(elixir, "bitcoinMergedMiningMerkleProof"),
hash_for_merged_mining: Map.get(elixir, "hashForMergedMining")
} }
end end
defp chain_type_fields(params, elixir) do
case Application.get_env(:explorer, :chain_type) do
"rsk" ->
params
|> Map.merge(%{
minimum_gas_price: Map.get(elixir, "minimumGasPrice"),
bitcoin_merged_mining_header: Map.get(elixir, "bitcoinMergedMiningHeader"),
bitcoin_merged_mining_coinbase_transaction: Map.get(elixir, "bitcoinMergedMiningCoinbaseTransaction"),
bitcoin_merged_mining_merkle_proof: Map.get(elixir, "bitcoinMergedMiningMerkleProof"),
hash_for_merged_mining: Map.get(elixir, "hashForMergedMining")
})
_ ->
params
end
end
@doc """ @doc """
Get `t:EthereumJSONRPC.Transactions.elixir/0` from `t:elixir/0` Get `t:EthereumJSONRPC.Transactions.elixir/0` from `t:elixir/0`

@ -116,13 +116,18 @@ defmodule EthereumJSONRPC.Blocks do
timestamp: Timex.parse!("1970-01-01T00:00:00Z", "{ISO:Extended:Z}"), timestamp: Timex.parse!("1970-01-01T00:00:00Z", "{ISO:Extended:Z}"),
total_difficulty: 131072, total_difficulty: 131072,
transactions_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", transactions_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
uncles: ["0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273311"], uncles: ["0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273311"],\
withdrawals_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", #{if Application.compile_env(:explorer, :chain_type) == "rsk" do
bitcoin_merged_mining_coinbase_transaction: nil, """
bitcoin_merged_mining_header: nil,
bitcoin_merged_mining_merkle_proof: nil, bitcoin_merged_mining_coinbase_transaction: nil,
hash_for_merged_mining: nil, bitcoin_merged_mining_header: nil,
minimum_gas_price: nil bitcoin_merged_mining_merkle_proof: nil,
hash_for_merged_mining: nil,
minimum_gas_price: nil,\
"""
end}
withdrawals_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
} }
] ]

@ -32,34 +32,44 @@ defmodule EthereumJSONRPC.BlockTest do
"uncles" => [] "uncles" => []
}) })
assert result == %{ assert result ==
difficulty: 17_561_410_778, %{
extra_data: "0x476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32", difficulty: 17_561_410_778,
gas_limit: 5000, extra_data: "0x476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32",
gas_used: 0, gas_limit: 5000,
hash: "0x4d9423080290a650eaf6db19c87c76dff83d1b4ab64aefe6e5c5aa2d1f4b6623", gas_used: 0,
logs_bloom: hash: "0x4d9423080290a650eaf6db19c87c76dff83d1b4ab64aefe6e5c5aa2d1f4b6623",
"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", logs_bloom:
mix_hash: "0xbbb93d610b2b0296a59f18474ac3d6086a9902aa7ca4b9a306692f7c3d496fdf", "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
miner_hash: "0xbb7b8287f3f0a933474a79eae42cbca977791171", mix_hash: "0xbbb93d610b2b0296a59f18474ac3d6086a9902aa7ca4b9a306692f7c3d496fdf",
nonce: 5_539_500_215_739_777_653, miner_hash: "0xbb7b8287f3f0a933474a79eae42cbca977791171",
number: 59, nonce: 5_539_500_215_739_777_653,
parent_hash: "0xcd5b5c4cecd7f18a13fe974255badffd58e737dc67596d56bc01f063dd282e9e", number: 59,
receipts_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", parent_hash: "0xcd5b5c4cecd7f18a13fe974255badffd58e737dc67596d56bc01f063dd282e9e",
sha3_uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", receipts_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
size: 542, sha3_uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
state_root: "0x6fd0a5d82ca77d9f38c3ebbde11b11d304a5fcf3854f291df64395ab38ed43ba", size: 542,
timestamp: Timex.parse!("2015-07-30T15:32:07Z", "{ISO:Extended:Z}"), state_root: "0x6fd0a5d82ca77d9f38c3ebbde11b11d304a5fcf3854f291df64395ab38ed43ba",
total_difficulty: nil, timestamp: Timex.parse!("2015-07-30T15:32:07Z", "{ISO:Extended:Z}"),
transactions_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", total_difficulty: nil,
uncles: [], transactions_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
withdrawals_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", uncles: [],
bitcoin_merged_mining_coinbase_transaction: nil, withdrawals_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
bitcoin_merged_mining_header: nil, }
bitcoin_merged_mining_merkle_proof: nil, |> (&if(Application.get_env(:explorer, :chain_type) == "rsk",
hash_for_merged_mining: nil, do:
minimum_gas_price: nil Map.merge(
} &1,
%{
bitcoin_merged_mining_coinbase_transaction: nil,
bitcoin_merged_mining_header: nil,
bitcoin_merged_mining_merkle_proof: nil,
hash_for_merged_mining: nil,
minimum_gas_price: nil
}
),
else: &1
)).()
end end
end end

@ -11,6 +11,7 @@ import Config
# General application configuration # General application configuration
config :explorer, config :explorer,
chain_type: ConfigHelper.chain_type(),
ecto_repos: ConfigHelper.repos(), ecto_repos: ConfigHelper.repos(),
token_functions_reader_max_retries: 3, token_functions_reader_max_retries: 3,
# for not fully indexed blockchains # for not fully indexed blockchains

@ -10,7 +10,15 @@ defmodule Explorer.Chain.Block do
alias Explorer.Chain.{Address, Block, Gas, Hash, PendingBlockOperation, Transaction, Wei, Withdrawal} alias Explorer.Chain.{Address, Block, Gas, Hash, PendingBlockOperation, Transaction, Wei, Withdrawal}
alias Explorer.Chain.Block.{Reward, SecondDegreeRelation} alias Explorer.Chain.Block.{Reward, SecondDegreeRelation}
@optional_attrs ~w(size refetch_needed total_difficulty difficulty base_fee_per_gas minimum_gas_price bitcoin_merged_mining_header bitcoin_merged_mining_coinbase_transaction bitcoin_merged_mining_merkle_proof hash_for_merged_mining)a @optional_attrs ~w(size refetch_needed total_difficulty difficulty base_fee_per_gas)a
|> (&(case Application.compile_env(:explorer, :chain_type) == "rsk" do
"rsk" ->
&1 ++
~w(minimum_gas_price bitcoin_merged_mining_header bitcoin_merged_mining_coinbase_transaction bitcoin_merged_mining_merkle_proof hash_for_merged_mining)a
_ ->
&1
end)).()
@required_attrs ~w(consensus gas_limit gas_used hash miner_hash nonce number parent_hash timestamp)a @required_attrs ~w(consensus gas_limit gas_used hash miner_hash nonce number parent_hash timestamp)a
@ -26,6 +34,20 @@ defmodule Explorer.Chain.Block do
""" """
@type block_number :: non_neg_integer() @type block_number :: non_neg_integer()
if Application.compile_env(:explorer, :chain_type) == "rsk" do
@rootstock_fields quote(
do: [
bitcoin_merged_mining_header: binary(),
bitcoin_merged_mining_coinbase_transaction: binary(),
bitcoin_merged_mining_merkle_proof: binary(),
hash_for_merged_mining: binary(),
minimum_gas_price: Decimal.t()
]
)
else
@rootstock_fields quote(do: [])
end
@typedoc """ @typedoc """
* `consensus` * `consensus`
* `true` - this is a block on the longest consensus agreed upon chain. * `true` - this is a block on the longest consensus agreed upon chain.
@ -47,8 +69,18 @@ defmodule Explorer.Chain.Block do
* `total_difficulty` - the total `difficulty` of the chain until this block. * `total_difficulty` - the total `difficulty` of the chain until this block.
* `transactions` - the `t:Explorer.Chain.Transaction.t/0` in this block. * `transactions` - the `t:Explorer.Chain.Transaction.t/0` in this block.
* `base_fee_per_gas` - Minimum fee required per unit of gas. Fee adjusts based on network congestion. * `base_fee_per_gas` - Minimum fee required per unit of gas. Fee adjusts based on network congestion.
#{if Application.compile_env(:explorer, :chain_type) == "rsk" do
"""
* `bitcoin_merged_mining_header` - Bitcoin merged mining header on Rootstock chains.
* `bitcoin_merged_mining_coinbase_transaction` - Bitcoin merged mining coinbase transaction on Rootstock chains.
* `bitcoin_merged_mining_merkle_proof` - Bitcoin merged mining merkle proof on Rootstock chains.
* `hash_for_merged_mining` - Hash for merged mining on Rootstock chains.
* `minimum_gas_price` - Minimum block gas price on Rootstock chains.
"""
end}
""" """
@type t :: %__MODULE__{ @type t :: %__MODULE__{
unquote_splicing(@rootstock_fields),
consensus: boolean(), consensus: boolean(),
difficulty: difficulty(), difficulty: difficulty(),
gas_limit: Gas.t(), gas_limit: Gas.t(),
@ -65,12 +97,7 @@ defmodule Explorer.Chain.Block do
transactions: %Ecto.Association.NotLoaded{} | [Transaction.t()], transactions: %Ecto.Association.NotLoaded{} | [Transaction.t()],
refetch_needed: boolean(), refetch_needed: boolean(),
base_fee_per_gas: Wei.t(), base_fee_per_gas: Wei.t(),
is_empty: boolean(), is_empty: boolean()
minimum_gas_price: Decimal.t(),
bitcoin_merged_mining_header: binary(),
bitcoin_merged_mining_coinbase_transaction: binary(),
bitcoin_merged_mining_merkle_proof: binary(),
hash_for_merged_mining: binary()
} }
@primary_key {:hash, Hash.Full, autogenerate: false} @primary_key {:hash, Hash.Full, autogenerate: false}
@ -87,11 +114,14 @@ defmodule Explorer.Chain.Block do
field(:refetch_needed, :boolean) field(:refetch_needed, :boolean)
field(:base_fee_per_gas, Wei) field(:base_fee_per_gas, Wei)
field(:is_empty, :boolean) field(:is_empty, :boolean)
field(:minimum_gas_price, :decimal)
field(:bitcoin_merged_mining_header, :binary) if Application.compile_env(:explorer, :chain_type) == "rsk" do
field(:bitcoin_merged_mining_coinbase_transaction, :binary) field(:bitcoin_merged_mining_header, :binary)
field(:bitcoin_merged_mining_merkle_proof, :binary) field(:bitcoin_merged_mining_coinbase_transaction, :binary)
field(:hash_for_merged_mining, :binary) field(:bitcoin_merged_mining_merkle_proof, :binary)
field(:hash_for_merged_mining, :binary)
field(:minimum_gas_price, :decimal)
end
timestamps() timestamps()

@ -10,125 +10,127 @@ defmodule Indexer.Fetcher.RootstockDataTest do
setup :verify_on_exit! setup :verify_on_exit!
setup :set_mox_global setup :set_mox_global
test "do not start when all old blocks are fetched", %{json_rpc_named_arguments: json_rpc_named_arguments} do if Application.compile_env(:explorer, :chain_type) == "rsk" do
RootstockData.Supervisor.Case.start_supervised!(json_rpc_named_arguments: json_rpc_named_arguments) test "do not start when all old blocks are fetched", %{json_rpc_named_arguments: json_rpc_named_arguments} do
RootstockData.Supervisor.Case.start_supervised!(json_rpc_named_arguments: json_rpc_named_arguments)
:timer.sleep(300)
:timer.sleep(300)
assert [{Indexer.Fetcher.RootstockData, :undefined, :worker, [Indexer.Fetcher.RootstockData]} | _] =
RootstockData.Supervisor |> Supervisor.which_children() assert [{Indexer.Fetcher.RootstockData, :undefined, :worker, [Indexer.Fetcher.RootstockData]} | _] =
end RootstockData.Supervisor |> Supervisor.which_children()
end
test "stops when all old blocks are fetched", %{json_rpc_named_arguments: json_rpc_named_arguments} do
block_a = insert(:block) test "stops when all old blocks are fetched", %{json_rpc_named_arguments: json_rpc_named_arguments} do
block_b = insert(:block) block_a = insert(:block)
block_b = insert(:block)
block_a_number_string = integer_to_quantity(block_a.number)
block_b_number_string = integer_to_quantity(block_b.number) block_a_number_string = integer_to_quantity(block_a.number)
block_b_number_string = integer_to_quantity(block_b.number)
EthereumJSONRPC.Mox
|> stub(:json_rpc, fn requests, _options -> EthereumJSONRPC.Mox
{:ok, |> stub(:json_rpc, fn requests, _options ->
Enum.map(requests, fn {:ok,
%{id: id, method: "eth_getBlockByNumber", params: [^block_a_number_string, false]} -> Enum.map(requests, fn
%{ %{id: id, method: "eth_getBlockByNumber", params: [^block_a_number_string, false]} ->
id: id, %{
result: %{ id: id,
"author" => "0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c", result: %{
"difficulty" => "0x6bc767dd80781", "author" => "0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c",
"extraData" => "0x5050594520737061726b706f6f6c2d6574682d7477", "difficulty" => "0x6bc767dd80781",
"gasLimit" => "0x7a121d", "extraData" => "0x5050594520737061726b706f6f6c2d6574682d7477",
"gasUsed" => "0x79cbe9", "gasLimit" => "0x7a121d",
"hash" => to_string(block_a.hash), "gasUsed" => "0x79cbe9",
"logsBloom" => "hash" => to_string(block_a.hash),
"0x044d42d008801488400e1809190200a80d06105bc0c4100b047895c0d518327048496108388040140010b8208006288102e206160e21052322440924002090c1c808a0817405ab238086d028211014058e949401012403210314896702d06880c815c3060a0f0809987c81044488292cc11d57882c912a808ca10471c84460460040000c0001012804022000a42106591881d34407420ba401e1c08a8d00a000a34c11821a80222818a4102152c8a0c044032080c6462644223104d618e0e544072008120104408205c60510542264808488220403000106281a0290404220112c10b080145028c8000300b18a2c8280701c882e702210b00410834840108084", "logsBloom" =>
"miner" => to_string(block_a.miner), "0x044d42d008801488400e1809190200a80d06105bc0c4100b047895c0d518327048496108388040140010b8208006288102e206160e21052322440924002090c1c808a0817405ab238086d028211014058e949401012403210314896702d06880c815c3060a0f0809987c81044488292cc11d57882c912a808ca10471c84460460040000c0001012804022000a42106591881d34407420ba401e1c08a8d00a000a34c11821a80222818a4102152c8a0c044032080c6462644223104d618e0e544072008120104408205c60510542264808488220403000106281a0290404220112c10b080145028c8000300b18a2c8280701c882e702210b00410834840108084",
"mixHash" => "0xda53ae7c2b3c529783d6cdacdb90587fd70eb651c0f04253e8ff17de97844010", "miner" => to_string(block_a.miner),
"nonce" => "0x0946e5f01fce12bc", "mixHash" => "0xda53ae7c2b3c529783d6cdacdb90587fd70eb651c0f04253e8ff17de97844010",
"number" => block_a_number_string, "nonce" => "0x0946e5f01fce12bc",
"parentHash" => to_string(block_a.parent_hash), "number" => block_a_number_string,
"receiptsRoot" => "0xa7d2b82bd8526de11736c18bd5cc8cfe2692106c4364526f3310ad56d78669c4", "parentHash" => to_string(block_a.parent_hash),
"sealFields" => [ "receiptsRoot" => "0xa7d2b82bd8526de11736c18bd5cc8cfe2692106c4364526f3310ad56d78669c4",
"0xa0da53ae7c2b3c529783d6cdacdb90587fd70eb651c0f04253e8ff17de97844010", "sealFields" => [
"0x880946e5f01fce12bc" "0xa0da53ae7c2b3c529783d6cdacdb90587fd70eb651c0f04253e8ff17de97844010",
], "0x880946e5f01fce12bc"
"sha3Uncles" => "0x483a8a21a5825ad270f358b3ea56e060bbb8b3082d9a92ec8fa17a5c7e6fc1b6", ],
"size" => "0x544c", "sha3Uncles" => "0x483a8a21a5825ad270f358b3ea56e060bbb8b3082d9a92ec8fa17a5c7e6fc1b6",
"stateRoot" => "0x85daa9cd528004c1609d4cb3520fd958e85983bb4183124a4a9f7137fd39c691", "size" => "0x544c",
"timestamp" => "0x5c8bc76e", "stateRoot" => "0x85daa9cd528004c1609d4cb3520fd958e85983bb4183124a4a9f7137fd39c691",
"totalDifficulty" => "0x201a42c35142ae94458", "timestamp" => "0x5c8bc76e",
"transactions" => [], "totalDifficulty" => "0x201a42c35142ae94458",
"transactionsRoot" => "0xcd6c12fa43cd4e92ad5c0bf232b30488bbcbfe273c5b4af0366fced0767d54db", "transactions" => [],
"uncles" => [], "transactionsRoot" => "0xcd6c12fa43cd4e92ad5c0bf232b30488bbcbfe273c5b4af0366fced0767d54db",
"withdrawals" => [], "uncles" => [],
"minimumGasPrice" => "0x0", "withdrawals" => [],
"bitcoinMergedMiningHeader" => "minimumGasPrice" => "0x0",
"0x00006d20ffd048280094a6ea0851d854036aacaa25ee0f23f0040200000000000000000078d2638fe0b4477c54601e6449051afba8228e0a88ff06b0c91f091fd34d5da57487c76402610517372c2fe9", "bitcoinMergedMiningHeader" =>
"bitcoinMergedMiningCoinbaseTransaction" => "0x00006d20ffd048280094a6ea0851d854036aacaa25ee0f23f0040200000000000000000078d2638fe0b4477c54601e6449051afba8228e0a88ff06b0c91f091fd34d5da57487c76402610517372c2fe9",
"0x00000000000000805bf0dc9203da49a3b4e3ec913806e43102cc07db991272dc8b7018da57eb5abe59a32d070000ffffffff03449a4d26000000001976a914536ffa992491508dca0354e52f32a3a7a679a53a88ac00000000000000002b6a2952534b424c4f434b3ad2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a400000000000000000266a24aa21a9ed4ae42ea6dca2687aaed665714bf58b055c4e11f2fb038605930d630b49ad7b9d00000000", "bitcoinMergedMiningCoinbaseTransaction" =>
"bitcoinMergedMiningMerkleProof" => "0x00000000000000805bf0dc9203da49a3b4e3ec913806e43102cc07db991272dc8b7018da57eb5abe59a32d070000ffffffff03449a4d26000000001976a914536ffa992491508dca0354e52f32a3a7a679a53a88ac00000000000000002b6a2952534b424c4f434b3ad2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a400000000000000000266a24aa21a9ed4ae42ea6dca2687aaed665714bf58b055c4e11f2fb038605930d630b49ad7b9d00000000",
"0x8e5a4ba74eb4eb2f9ad4cabc2913aeed380a5becf7cd4d513341617efb798002bd83a783c31c66a8a8f6cc56c071c2d471cb610e3dc13054b9d216021d8c7e9112f622564449ebedcedf7d4ccb6fe0ffac861b7ed1446c310813cdf712e1e6add28b1fe1c0ae5e916194ba4f285a9340aba41e91bf847bf31acf37a9623a04a2348a37ab9faa5908122db45596bbc03e9c3644b0d4589471c4ff30fc139f3ba50506e9136fa0df799b487494de3e2b3dec937338f1a2e18da057c1f60590a9723672a4355b9914b1d01af9f582d9e856f6e1744be00f268b0b01d559329f7e0685aa63ffeb7c28486d7462292021d1345cddbf7c920ca34bb7aa4c6cdbe068806e35d0db662e7fcda03cb4d779594638c62a1fdd7ec98d1fb6d240d853958abe57561d9b9d0465cf8b9d6ee3c58b0d8b07d6c4c5d8f348e43fe3c06011b6a0008db4e0b16c77ececc3981f9008201cea5939869d648e59a09bd2094b1196ff61126bffb626153deed2563e1745436247c94a85d2947756b606d67633781c99d7", "bitcoinMergedMiningMerkleProof" =>
"hashForMergedMining" => "0xd2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a40" "0x8e5a4ba74eb4eb2f9ad4cabc2913aeed380a5becf7cd4d513341617efb798002bd83a783c31c66a8a8f6cc56c071c2d471cb610e3dc13054b9d216021d8c7e9112f622564449ebedcedf7d4ccb6fe0ffac861b7ed1446c310813cdf712e1e6add28b1fe1c0ae5e916194ba4f285a9340aba41e91bf847bf31acf37a9623a04a2348a37ab9faa5908122db45596bbc03e9c3644b0d4589471c4ff30fc139f3ba50506e9136fa0df799b487494de3e2b3dec937338f1a2e18da057c1f60590a9723672a4355b9914b1d01af9f582d9e856f6e1744be00f268b0b01d559329f7e0685aa63ffeb7c28486d7462292021d1345cddbf7c920ca34bb7aa4c6cdbe068806e35d0db662e7fcda03cb4d779594638c62a1fdd7ec98d1fb6d240d853958abe57561d9b9d0465cf8b9d6ee3c58b0d8b07d6c4c5d8f348e43fe3c06011b6a0008db4e0b16c77ececc3981f9008201cea5939869d648e59a09bd2094b1196ff61126bffb626153deed2563e1745436247c94a85d2947756b606d67633781c99d7",
"hashForMergedMining" => "0xd2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a40"
}
} }
}
%{id: id, method: "eth_getBlockByNumber", params: [^block_b_number_string, false]} ->
%{id: id, method: "eth_getBlockByNumber", params: [^block_b_number_string, false]} -> %{
%{ id: id,
id: id, result: %{
result: %{ "author" => "0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c",
"author" => "0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c", "difficulty" => "0x6bc767dd80781",
"difficulty" => "0x6bc767dd80781", "extraData" => "0x5050594520737061726b706f6f6c2d6574682d7477",
"extraData" => "0x5050594520737061726b706f6f6c2d6574682d7477", "gasLimit" => "0x7a121d",
"gasLimit" => "0x7a121d", "gasUsed" => "0x79cbe9",
"gasUsed" => "0x79cbe9", "hash" => to_string(block_b.hash),
"hash" => to_string(block_b.hash), "logsBloom" =>
"logsBloom" => "0x044d42d008801488400e1809190200a80d06105bc0c4100b047895c0d518327048496108388040140010b8208006288102e206160e21052322440924002090c1c808a0817405ab238086d028211014058e949401012403210314896702d06880c815c3060a0f0809987c81044488292cc11d57882c912a808ca10471c84460460040000c0001012804022000a42106591881d34407420ba401e1c08a8d00a000a34c11821a80222818a4102152c8a0c044032080c6462644223104d618e0e544072008120104408205c60510542264808488220403000106281a0290404220112c10b080145028c8000300b18a2c8280701c882e702210b00410834840108084",
"0x044d42d008801488400e1809190200a80d06105bc0c4100b047895c0d518327048496108388040140010b8208006288102e206160e21052322440924002090c1c808a0817405ab238086d028211014058e949401012403210314896702d06880c815c3060a0f0809987c81044488292cc11d57882c912a808ca10471c84460460040000c0001012804022000a42106591881d34407420ba401e1c08a8d00a000a34c11821a80222818a4102152c8a0c044032080c6462644223104d618e0e544072008120104408205c60510542264808488220403000106281a0290404220112c10b080145028c8000300b18a2c8280701c882e702210b00410834840108084", "miner" => to_string(block_b.miner),
"miner" => to_string(block_b.miner), "mixHash" => "0xda53ae7c2b3c529783d6cdacdb90587fd70eb651c0f04253e8ff17de97844010",
"mixHash" => "0xda53ae7c2b3c529783d6cdacdb90587fd70eb651c0f04253e8ff17de97844010", "nonce" => "0x0946e5f01fce12bc",
"nonce" => "0x0946e5f01fce12bc", "number" => block_b_number_string,
"number" => block_b_number_string, "parentHash" => to_string(block_b.parent_hash),
"parentHash" => to_string(block_b.parent_hash), "receiptsRoot" => "0xa7d2b82bd8526de11736c18bd5cc8cfe2692106c4364526f3310ad56d78669c4",
"receiptsRoot" => "0xa7d2b82bd8526de11736c18bd5cc8cfe2692106c4364526f3310ad56d78669c4", "sealFields" => [
"sealFields" => [ "0xa0da53ae7c2b3c529783d6cdacdb90587fd70eb651c0f04253e8ff17de97844010",
"0xa0da53ae7c2b3c529783d6cdacdb90587fd70eb651c0f04253e8ff17de97844010", "0x880946e5f01fce12bc"
"0x880946e5f01fce12bc" ],
], "sha3Uncles" => "0x483a8a21a5825ad270f358b3ea56e060bbb8b3082d9a92ec8fa17a5c7e6fc1b6",
"sha3Uncles" => "0x483a8a21a5825ad270f358b3ea56e060bbb8b3082d9a92ec8fa17a5c7e6fc1b6", "size" => "0x544c",
"size" => "0x544c", "stateRoot" => "0x85daa9cd528004c1609d4cb3520fd958e85983bb4183124a4a9f7137fd39c691",
"stateRoot" => "0x85daa9cd528004c1609d4cb3520fd958e85983bb4183124a4a9f7137fd39c691", "timestamp" => "0x5c8bc76e",
"timestamp" => "0x5c8bc76e", "totalDifficulty" => "0x201a42c35142ae94458",
"totalDifficulty" => "0x201a42c35142ae94458", "transactions" => [],
"transactions" => [], "transactionsRoot" => "0xcd6c12fa43cd4e92ad5c0bf232b30488bbcbfe273c5b4af0366fced0767d54db",
"transactionsRoot" => "0xcd6c12fa43cd4e92ad5c0bf232b30488bbcbfe273c5b4af0366fced0767d54db", "uncles" => [],
"uncles" => [], "withdrawals" => [],
"withdrawals" => [], "minimumGasPrice" => "0x1",
"minimumGasPrice" => "0x1", "bitcoinMergedMiningHeader" =>
"bitcoinMergedMiningHeader" => "0x00006d20ffd048280094a6ea0851d854036aacaa25ee0f23f0040200000000000000000078d2638fe0b4477c54601e6449051afba8228e0a88ff06b0c91f091fd34d5da57487c76402610517372c2fe9",
"0x00006d20ffd048280094a6ea0851d854036aacaa25ee0f23f0040200000000000000000078d2638fe0b4477c54601e6449051afba8228e0a88ff06b0c91f091fd34d5da57487c76402610517372c2fe9", "bitcoinMergedMiningCoinbaseTransaction" =>
"bitcoinMergedMiningCoinbaseTransaction" => "0x00000000000000805bf0dc9203da49a3b4e3ec913806e43102cc07db991272dc8b7018da57eb5abe59a32d070000ffffffff03449a4d26000000001976a914536ffa992491508dca0354e52f32a3a7a679a53a88ac00000000000000002b6a2952534b424c4f434b3ad2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a400000000000000000266a24aa21a9ed4ae42ea6dca2687aaed665714bf58b055c4e11f2fb038605930d630b49ad7b9d00000000",
"0x00000000000000805bf0dc9203da49a3b4e3ec913806e43102cc07db991272dc8b7018da57eb5abe59a32d070000ffffffff03449a4d26000000001976a914536ffa992491508dca0354e52f32a3a7a679a53a88ac00000000000000002b6a2952534b424c4f434b3ad2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a400000000000000000266a24aa21a9ed4ae42ea6dca2687aaed665714bf58b055c4e11f2fb038605930d630b49ad7b9d00000000", "bitcoinMergedMiningMerkleProof" =>
"bitcoinMergedMiningMerkleProof" => "0x8e5a4ba74eb4eb2f9ad4cabc2913aeed380a5becf7cd4d513341617efb798002bd83a783c31c66a8a8f6cc56c071c2d471cb610e3dc13054b9d216021d8c7e9112f622564449ebedcedf7d4ccb6fe0ffac861b7ed1446c310813cdf712e1e6add28b1fe1c0ae5e916194ba4f285a9340aba41e91bf847bf31acf37a9623a04a2348a37ab9faa5908122db45596bbc03e9c3644b0d4589471c4ff30fc139f3ba50506e9136fa0df799b487494de3e2b3dec937338f1a2e18da057c1f60590a9723672a4355b9914b1d01af9f582d9e856f6e1744be00f268b0b01d559329f7e0685aa63ffeb7c28486d7462292021d1345cddbf7c920ca34bb7aa4c6cdbe068806e35d0db662e7fcda03cb4d779594638c62a1fdd7ec98d1fb6d240d853958abe57561d9b9d0465cf8b9d6ee3c58b0d8b07d6c4c5d8f348e43fe3c06011b6a0008db4e0b16c77ececc3981f9008201cea5939869d648e59a09bd2094b1196ff61126bffb626153deed2563e1745436247c94a85d2947756b606d67633781c99d7",
"0x8e5a4ba74eb4eb2f9ad4cabc2913aeed380a5becf7cd4d513341617efb798002bd83a783c31c66a8a8f6cc56c071c2d471cb610e3dc13054b9d216021d8c7e9112f622564449ebedcedf7d4ccb6fe0ffac861b7ed1446c310813cdf712e1e6add28b1fe1c0ae5e916194ba4f285a9340aba41e91bf847bf31acf37a9623a04a2348a37ab9faa5908122db45596bbc03e9c3644b0d4589471c4ff30fc139f3ba50506e9136fa0df799b487494de3e2b3dec937338f1a2e18da057c1f60590a9723672a4355b9914b1d01af9f582d9e856f6e1744be00f268b0b01d559329f7e0685aa63ffeb7c28486d7462292021d1345cddbf7c920ca34bb7aa4c6cdbe068806e35d0db662e7fcda03cb4d779594638c62a1fdd7ec98d1fb6d240d853958abe57561d9b9d0465cf8b9d6ee3c58b0d8b07d6c4c5d8f348e43fe3c06011b6a0008db4e0b16c77ececc3981f9008201cea5939869d648e59a09bd2094b1196ff61126bffb626153deed2563e1745436247c94a85d2947756b606d67633781c99d7", "hashForMergedMining" => "0xd2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a40"
"hashForMergedMining" => "0xd2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a40" }
} }
} end)}
end)} end)
end)
pid = RootstockData.Supervisor.Case.start_supervised!(json_rpc_named_arguments: json_rpc_named_arguments) pid = RootstockData.Supervisor.Case.start_supervised!(json_rpc_named_arguments: json_rpc_named_arguments)
assert [{Indexer.Fetcher.RootstockData, worker_pid, :worker, [Indexer.Fetcher.RootstockData]} | _] = assert [{Indexer.Fetcher.RootstockData, worker_pid, :worker, [Indexer.Fetcher.RootstockData]} | _] =
RootstockData.Supervisor |> Supervisor.which_children() RootstockData.Supervisor |> Supervisor.which_children()
assert is_pid(worker_pid) assert is_pid(worker_pid)
:timer.sleep(300) :timer.sleep(300)
assert [{Indexer.Fetcher.RootstockData, :undefined, :worker, [Indexer.Fetcher.RootstockData]} | _] = assert [{Indexer.Fetcher.RootstockData, :undefined, :worker, [Indexer.Fetcher.RootstockData]} | _] =
RootstockData.Supervisor |> Supervisor.which_children() RootstockData.Supervisor |> Supervisor.which_children()
# Terminates the process so it finishes all Ecto processes. # Terminates the process so it finishes all Ecto processes.
GenServer.stop(pid) GenServer.stop(pid)
end
end end
end end

@ -179,4 +179,7 @@ defmodule ConfigHelper do
rescue rescue
err -> raise "Invalid JSON in environment variable #{env_var}: #{inspect(err)}" err -> raise "Invalid JSON in environment variable #{env_var}: #{inspect(err)}"
end end
@spec chain_type() :: String.t()
def chain_type, do: System.get_env("CHAIN_TYPE") || "ethereum"
end end

@ -4,8 +4,6 @@ import Config
|> Path.join() |> Path.join()
|> Code.eval_file() |> Code.eval_file()
chain_type = System.get_env("CHAIN_TYPE") || "ethereum"
###################### ######################
### BlockScout Web ### ### BlockScout Web ###
###################### ######################
@ -162,7 +160,7 @@ config :ethereum_jsonrpc, EthereumJSONRPC.HTTP,
config :ethereum_jsonrpc, EthereumJSONRPC.Geth, config :ethereum_jsonrpc, EthereumJSONRPC.Geth,
debug_trace_transaction_timeout: System.get_env("ETHEREUM_JSONRPC_DEBUG_TRACE_TRANSACTION_TIMEOUT", "5s"), debug_trace_transaction_timeout: System.get_env("ETHEREUM_JSONRPC_DEBUG_TRACE_TRANSACTION_TIMEOUT", "5s"),
tracer: tracer:
if(chain_type == "polygon_edge", if(ConfigHelper.chain_type() == "polygon_edge",
do: "polygon_edge", do: "polygon_edge",
else: System.get_env("INDEXER_INTERNAL_TRANSACTIONS_TRACER_TYPE", "call_tracer") else: System.get_env("INDEXER_INTERNAL_TRANSACTIONS_TRACER_TYPE", "call_tracer")
) )
@ -185,7 +183,6 @@ checksum_function = System.get_env("CHECKSUM_FUNCTION")
exchange_rates_coin = System.get_env("EXCHANGE_RATES_COIN") exchange_rates_coin = System.get_env("EXCHANGE_RATES_COIN")
config :explorer, config :explorer,
chain_type: chain_type,
coin: System.get_env("COIN") || exchange_rates_coin || "ETH", coin: System.get_env("COIN") || exchange_rates_coin || "ETH",
coin_name: System.get_env("COIN_NAME") || exchange_rates_coin || "ETH", coin_name: System.get_env("COIN_NAME") || exchange_rates_coin || "ETH",
allowed_solidity_evm_versions: allowed_solidity_evm_versions:
@ -590,15 +587,19 @@ config :indexer, Indexer.Fetcher.Withdrawal.Supervisor,
config :indexer, Indexer.Fetcher.Withdrawal, first_block: System.get_env("WITHDRAWALS_FIRST_BLOCK") config :indexer, Indexer.Fetcher.Withdrawal, first_block: System.get_env("WITHDRAWALS_FIRST_BLOCK")
config :indexer, Indexer.Fetcher.PolygonEdge.Supervisor, disabled?: !(chain_type == "polygon_edge") config :indexer, Indexer.Fetcher.PolygonEdge.Supervisor, disabled?: !(ConfigHelper.chain_type() == "polygon_edge")
config :indexer, Indexer.Fetcher.PolygonEdge.Deposit.Supervisor, disabled?: !(chain_type == "polygon_edge") config :indexer, Indexer.Fetcher.PolygonEdge.Deposit.Supervisor,
disabled?: !(ConfigHelper.chain_type() == "polygon_edge")
config :indexer, Indexer.Fetcher.PolygonEdge.DepositExecute.Supervisor, disabled?: !(chain_type == "polygon_edge") config :indexer, Indexer.Fetcher.PolygonEdge.DepositExecute.Supervisor,
disabled?: !(ConfigHelper.chain_type() == "polygon_edge")
config :indexer, Indexer.Fetcher.PolygonEdge.Withdrawal.Supervisor, disabled?: !(chain_type == "polygon_edge") config :indexer, Indexer.Fetcher.PolygonEdge.Withdrawal.Supervisor,
disabled?: !(ConfigHelper.chain_type() == "polygon_edge")
config :indexer, Indexer.Fetcher.PolygonEdge.WithdrawalExit.Supervisor, disabled?: !(chain_type == "polygon_edge") config :indexer, Indexer.Fetcher.PolygonEdge.WithdrawalExit.Supervisor,
disabled?: !(ConfigHelper.chain_type() == "polygon_edge")
config :indexer, Indexer.Fetcher.PolygonEdge, config :indexer, Indexer.Fetcher.PolygonEdge,
polygon_edge_l1_rpc: System.get_env("INDEXER_POLYGON_EDGE_L1_RPC"), polygon_edge_l1_rpc: System.get_env("INDEXER_POLYGON_EDGE_L1_RPC"),
@ -630,8 +631,9 @@ config :indexer, Indexer.Fetcher.Zkevm.TransactionBatch.Supervisor,
System.get_env("CHAIN_TYPE", "ethereum") == "polygon_zkevm" && System.get_env("CHAIN_TYPE", "ethereum") == "polygon_zkevm" &&
ConfigHelper.parse_bool_env_var("INDEXER_ZKEVM_BATCHES_ENABLED") ConfigHelper.parse_bool_env_var("INDEXER_ZKEVM_BATCHES_ENABLED")
config :indexer, Indexer.Fetcher.RootstockData.Supervisor, config :indexer, Indexer.Fetcher.RootstockData.Supervisor,
disabled?: ConfigHelper.parse_bool_env_var("INDEXER_DISABLE_ROOTSTOCK_DATA_FETCHER") disabled?:
ConfigHelper.chain_type() != "rsk" || ConfigHelper.parse_bool_env_var("INDEXER_DISABLE_ROOTSTOCK_DATA_FETCHER")
config :indexer, Indexer.Fetcher.RootstockData, config :indexer, Indexer.Fetcher.RootstockData,
interval: ConfigHelper.parse_time_env_var("INDEXER_ROOTSTOCK_DATA_FETCHER_INTERVAL", "3s"), interval: ConfigHelper.parse_time_env_var("INDEXER_ROOTSTOCK_DATA_FETCHER_INTERVAL", "3s"),

Loading…
Cancel
Save