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
- [#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
<details>

@ -61,7 +61,7 @@ defmodule BlockScoutWeb.API.V2.BlockView do
"tx_fees" => tx_fees,
"withdrawals_count" => count_withdrawals(block)
}
|> add_rootstock_fields(block, single_block?)
|> chain_type_fields(block, single_block?)
end
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(_), do: nil
defp add_rootstock_fields(prepared_block, _block, false), do: prepared_block
defp add_rootstock_fields(prepared_block, block, true) do
prepared_block
|> 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_coinbase_transaction", block.bitcoin_merged_mining_coinbase_transaction)
|> Map.put("bitcoin_merged_mining_merkle_proof", block.bitcoin_merged_mining_merkle_proof)
|> Map.put("hash_for_merged_mining", block.hash_for_merged_mining)
defp chain_type_fields(result, block, single_block?) do
case single_block? && Application.get_env(:explorer, :chain_type) do
"rsk" ->
result
|> 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_coinbase_transaction", block.bitcoin_merged_mining_coinbase_transaction)
|> Map.put("bitcoin_merged_mining_merkle_proof", block.bitcoin_merged_mining_merkle_proof)
|> Map.put("hash_for_merged_mining", block.hash_for_merged_mining)
_ ->
result
end
end
end

@ -8,8 +8,23 @@ defmodule EthereumJSONRPC.Block do
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 params :: %{
unquote_splicing(@rootstock_fields),
difficulty: pos_integer(),
extra_data: EthereumJSONRPC.hash(),
gas_limit: non_neg_integer(),
@ -30,12 +45,7 @@ defmodule EthereumJSONRPC.Block do
transactions_root: EthereumJSONRPC.hash(),
uncles: [EthereumJSONRPC.hash()],
base_fee_per_gas: non_neg_integer(),
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()
withdrawals_root: EthereumJSONRPC.hash()
}
@typedoc """
@ -74,11 +84,15 @@ defmodule EthereumJSONRPC.Block do
`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)
* `"withdrawalsRoot"` - `t:EthereumJSONRPC.hash/0` of the root of the withdrawals.
* `"minimumGasPrice"` - `t:EthereumJSONRPC.quantity/0` of the minimum gas price for this block.
* `"bitcoinMergedMiningHeader"` - `t:EthereumJSONRPC.data/0` of the Bitcoin merged mining header.
* `"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.
#{if Application.compile_env(:explorer, :chain_type) == "rsk" do
"""
* `"minimumGasPrice"` - `t:EthereumJSONRPC.quantity/0` of the minimum gas price for this block.
* `"bitcoinMergedMiningHeader"` - `t:EthereumJSONRPC.data/0` of the Bitcoin merged mining header.
* `"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}
@ -129,13 +143,18 @@ defmodule EthereumJSONRPC.Block do
...> "timestamp" => Timex.parse!("2017-12-15T21:03:30Z", "{ISO:Extended:Z}"),
...> "totalDifficulty" => 340282366920938463463374607431465668165,
...> "transactions" => [],
...> "transactionsRoot" => "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
...> "uncles" => [],
...> "minimumGasPrice" => 345786,
...> "bitcoinMergedMiningHeader" => "0x00006d20ffd048280094a6ea0851d854036aacaa25ee0f23f0040200000000000000000078d2638fe0b4477c54601e6449051afba8228e0a88ff06b0c91f091fd34d5da57487c76402610517372c2fe9",
...> "bitcoinMergedMiningCoinbaseTransaction" => "0x00000000000000805bf0dc9203da49a3b4e3ec913806e43102cc07db991272dc8b7018da57eb5abe59a32d070000ffffffff03449a4d26000000001976a914536ffa992491508dca0354e52f32a3a7a679a53a88ac00000000000000002b6a2952534b424c4f434b3ad2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a400000000000000000266a24aa21a9ed4ae42ea6dca2687aaed665714bf58b055c4e11f2fb038605930d630b49ad7b9d00000000",
...> "bitcoinMergedMiningMerkleProof" => "0x8e5a4ba74eb4eb2f9ad4cabc2913aeed380a5becf7cd4d513341617efb798002bd83a783c31c66a8a8f6cc56c071c2d471cb610e3dc13054b9d216021d8c7e9112f622564449ebedcedf7d4ccb6fe0ffac861b7ed1446c310813cdf712e1e6add28b1fe1c0ae5e916194ba4f285a9340aba41e91bf847bf31acf37a9623a04a2348a37ab9faa5908122db45596bbc03e9c3644b0d4589471c4ff30fc139f3ba50506e9136fa0df799b487494de3e2b3dec937338f1a2e18da057c1f60590a9723672a4355b9914b1d01af9f582d9e856f6e1744be00f268b0b01d559329f7e0685aa63ffeb7c28486d7462292021d1345cddbf7c920ca34bb7aa4c6cdbe068806e35d0db662e7fcda03cb4d779594638c62a1fdd7ec98d1fb6d240d853958abe57561d9b9d0465cf8b9d6ee3c58b0d8b07d6c4c5d8f348e43fe3c06011b6a0008db4e0b16c77ececc3981f9008201cea5939869d648e59a09bd2094b1196ff61126bffb626153deed2563e1745436247c94a85d2947756b606d67633781c99d7",
...> "hashForMergedMining" => "0xd2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a40",
...> "transactionsRoot" => "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",\
#{if Application.compile_env(:explorer, :chain_type) == "rsk" do
"""
...> "minimumGasPrice" => 345786,
...> "bitcoinMergedMiningHeader" => "0x00006d20ffd048280094a6ea0851d854036aacaa25ee0f23f0040200000000000000000078d2638fe0b4477c54601e6449051afba8228e0a88ff06b0c91f091fd34d5da57487c76402610517372c2fe9",
...> "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}"),
total_difficulty: 340282366920938463463374607431465668165,
transactions_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
uncles: [],
withdrawals_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
bitcoin_merged_mining_coinbase_transaction: "0x00000000000000805bf0dc9203da49a3b4e3ec913806e43102cc07db991272dc8b7018da57eb5abe59a32d070000ffffffff03449a4d26000000001976a914536ffa992491508dca0354e52f32a3a7a679a53a88ac00000000000000002b6a2952534b424c4f434b3ad2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a400000000000000000266a24aa21a9ed4ae42ea6dca2687aaed665714bf58b055c4e11f2fb038605930d630b49ad7b9d00000000",
bitcoin_merged_mining_header: "0x00006d20ffd048280094a6ea0851d854036aacaa25ee0f23f0040200000000000000000078d2638fe0b4477c54601e6449051afba8228e0a88ff06b0c91f091fd34d5da57487c76402610517372c2fe9",
bitcoin_merged_mining_merkle_proof: "0x8e5a4ba74eb4eb2f9ad4cabc2913aeed380a5becf7cd4d513341617efb798002bd83a783c31c66a8a8f6cc56c071c2d471cb610e3dc13054b9d216021d8c7e9112f622564449ebedcedf7d4ccb6fe0ffac861b7ed1446c310813cdf712e1e6add28b1fe1c0ae5e916194ba4f285a9340aba41e91bf847bf31acf37a9623a04a2348a37ab9faa5908122db45596bbc03e9c3644b0d4589471c4ff30fc139f3ba50506e9136fa0df799b487494de3e2b3dec937338f1a2e18da057c1f60590a9723672a4355b9914b1d01af9f582d9e856f6e1744be00f268b0b01d559329f7e0685aa63ffeb7c28486d7462292021d1345cddbf7c920ca34bb7aa4c6cdbe068806e35d0db662e7fcda03cb4d779594638c62a1fdd7ec98d1fb6d240d853958abe57561d9b9d0465cf8b9d6ee3c58b0d8b07d6c4c5d8f348e43fe3c06011b6a0008db4e0b16c77ececc3981f9008201cea5939869d648e59a09bd2094b1196ff61126bffb626153deed2563e1745436247c94a85d2947756b606d67633781c99d7",
hash_for_merged_mining: "0xd2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a40",
minimum_gas_price: 345786
uncles: [],\
#{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",
hash_for_merged_mining: "0xd2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a40",
minimum_gas_price: 345786,\
"""
end}
withdrawals_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
}
[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}"),
total_difficulty: 1039309006117,
transactions_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
uncles: [],
withdrawals_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
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
uncles: [],\
#{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,
hash_for_merged_mining: nil,
minimum_gas_price: nil,\
"""
end}
withdrawals_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
}
"""
@spec elixir_to_params(elixir) :: params
def 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,
"sha3Uncles" => sha3_uncles,
"size" => size,
"stateRoot" => state_root,
"timestamp" => timestamp,
"totalDifficulty" => total_difficulty,
"transactionsRoot" => transactions_root,
"uncles" => uncles,
"baseFeePerGas" => base_fee_per_gas
} = elixir
) do
def elixir_to_params(elixir) do
elixir
|> do_elixir_to_params()
|> chain_type_fields(elixir)
end
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,
"sha3Uncles" => sha3_uncles,
"size" => size,
"stateRoot" => state_root,
"timestamp" => timestamp,
"totalDifficulty" => total_difficulty,
"transactionsRoot" => transactions_root,
"uncles" => uncles,
"baseFeePerGas" => base_fee_per_gas
} = elixir
) do
%{
difficulty: difficulty,
extra_data: extra_data,
@ -266,36 +300,31 @@ defmodule EthereumJSONRPC.Block do
uncles: uncles,
base_fee_per_gas: base_fee_per_gas,
withdrawals_root:
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")
Map.get(elixir, "withdrawalsRoot", "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
}
end
def 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,
"sha3Uncles" => sha3_uncles,
"size" => size,
"stateRoot" => state_root,
"timestamp" => timestamp,
"transactionsRoot" => transactions_root,
"uncles" => uncles,
"baseFeePerGas" => base_fee_per_gas
} = elixir
) do
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,
"sha3Uncles" => sha3_uncles,
"size" => size,
"stateRoot" => state_root,
"timestamp" => timestamp,
"transactionsRoot" => transactions_root,
"uncles" => uncles,
"baseFeePerGas" => base_fee_per_gas
} = elixir
) do
%{
difficulty: difficulty,
extra_data: extra_data,
@ -317,36 +346,31 @@ defmodule EthereumJSONRPC.Block do
uncles: uncles,
base_fee_per_gas: base_fee_per_gas,
withdrawals_root:
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")
Map.get(elixir, "withdrawalsRoot", "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
}
end
def 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,
"sha3Uncles" => sha3_uncles,
"size" => size,
"stateRoot" => state_root,
"timestamp" => timestamp,
"totalDifficulty" => total_difficulty,
"transactionsRoot" => transactions_root,
"uncles" => uncles
} = elixir
) do
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,
"sha3Uncles" => sha3_uncles,
"size" => size,
"stateRoot" => state_root,
"timestamp" => timestamp,
"totalDifficulty" => total_difficulty,
"transactionsRoot" => transactions_root,
"uncles" => uncles
} = elixir
) do
%{
difficulty: difficulty,
extra_data: extra_data,
@ -368,36 +392,31 @@ defmodule EthereumJSONRPC.Block do
transactions_root: transactions_root,
uncles: uncles,
withdrawals_root:
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")
Map.get(elixir, "withdrawalsRoot", "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
}
end
# Geth: a response from eth_getblockbyhash for uncle blocks is without `totalDifficulty` param
def 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,
"sha3Uncles" => sha3_uncles,
"size" => size,
"stateRoot" => state_root,
"timestamp" => timestamp,
"transactionsRoot" => transactions_root,
"uncles" => uncles
} = elixir
) do
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,
"sha3Uncles" => sha3_uncles,
"size" => size,
"stateRoot" => state_root,
"timestamp" => timestamp,
"transactionsRoot" => transactions_root,
"uncles" => uncles
} = elixir
) do
%{
difficulty: difficulty,
extra_data: extra_data,
@ -418,15 +437,27 @@ defmodule EthereumJSONRPC.Block do
transactions_root: transactions_root,
uncles: uncles,
withdrawals_root:
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")
Map.get(elixir, "withdrawalsRoot", "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
}
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 """
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}"),
total_difficulty: 131072,
transactions_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
uncles: ["0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273311"],
withdrawals_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
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
uncles: ["0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273311"],\
#{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,
hash_for_merged_mining: nil,
minimum_gas_price: nil,\
"""
end}
withdrawals_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
}
]

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

@ -11,6 +11,7 @@ import Config
# General application configuration
config :explorer,
chain_type: ConfigHelper.chain_type(),
ecto_repos: ConfigHelper.repos(),
token_functions_reader_max_retries: 3,
# 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.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
@ -26,6 +34,20 @@ defmodule Explorer.Chain.Block do
"""
@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 """
* `consensus`
* `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.
* `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.
#{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__{
unquote_splicing(@rootstock_fields),
consensus: boolean(),
difficulty: difficulty(),
gas_limit: Gas.t(),
@ -65,12 +97,7 @@ defmodule Explorer.Chain.Block do
transactions: %Ecto.Association.NotLoaded{} | [Transaction.t()],
refetch_needed: boolean(),
base_fee_per_gas: Wei.t(),
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()
is_empty: boolean()
}
@primary_key {:hash, Hash.Full, autogenerate: false}
@ -87,11 +114,14 @@ defmodule Explorer.Chain.Block do
field(:refetch_needed, :boolean)
field(:base_fee_per_gas, Wei)
field(:is_empty, :boolean)
field(:minimum_gas_price, :decimal)
field(:bitcoin_merged_mining_header, :binary)
field(:bitcoin_merged_mining_coinbase_transaction, :binary)
field(:bitcoin_merged_mining_merkle_proof, :binary)
field(:hash_for_merged_mining, :binary)
if Application.compile_env(:explorer, :chain_type) == "rsk" do
field(:bitcoin_merged_mining_header, :binary)
field(:bitcoin_merged_mining_coinbase_transaction, :binary)
field(:bitcoin_merged_mining_merkle_proof, :binary)
field(:hash_for_merged_mining, :binary)
field(:minimum_gas_price, :decimal)
end
timestamps()

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

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

@ -4,8 +4,6 @@ import Config
|> Path.join()
|> Code.eval_file()
chain_type = System.get_env("CHAIN_TYPE") || "ethereum"
######################
### BlockScout Web ###
######################
@ -162,7 +160,7 @@ config :ethereum_jsonrpc, EthereumJSONRPC.HTTP,
config :ethereum_jsonrpc, EthereumJSONRPC.Geth,
debug_trace_transaction_timeout: System.get_env("ETHEREUM_JSONRPC_DEBUG_TRACE_TRANSACTION_TIMEOUT", "5s"),
tracer:
if(chain_type == "polygon_edge",
if(ConfigHelper.chain_type() == "polygon_edge",
do: "polygon_edge",
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")
config :explorer,
chain_type: chain_type,
coin: System.get_env("COIN") || exchange_rates_coin || "ETH",
coin_name: System.get_env("COIN_NAME") || exchange_rates_coin || "ETH",
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.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,
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" &&
ConfigHelper.parse_bool_env_var("INDEXER_ZKEVM_BATCHES_ENABLED")
config :indexer, Indexer.Fetcher.RootstockData.Supervisor,
disabled?: ConfigHelper.parse_bool_env_var("INDEXER_DISABLE_ROOTSTOCK_DATA_FETCHER")
config :indexer, Indexer.Fetcher.RootstockData.Supervisor,
disabled?:
ConfigHelper.chain_type() != "rsk" || ConfigHelper.parse_bool_env_var("INDEXER_DISABLE_ROOTSTOCK_DATA_FETCHER")
config :indexer, Indexer.Fetcher.RootstockData,
interval: ConfigHelper.parse_time_env_var("INDEXER_ROOTSTOCK_DATA_FETCHER_INTERVAL", "3s"),

Loading…
Cancel
Save