diff --git a/apps/block_scout_web/config/runtime/test.exs b/apps/block_scout_web/config/runtime/test.exs index d7100466c1c3..f465b5106282 100644 --- a/apps/block_scout_web/config/runtime/test.exs +++ b/apps/block_scout_web/config/runtime/test.exs @@ -1,5 +1,7 @@ import Config +alias EthereumJSONRPC.Variant + config :explorer, Explorer.ExchangeRates, enabled: false, store: :none config :explorer, Explorer.KnownTokens, enabled: false, store: :none @@ -13,15 +15,7 @@ config :ueberauth, Ueberauth, logout_url: "example.com/logout", logout_return_to_url: "example.com/return" -variant = - if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do - "parity" - else - System.get_env("ETHEREUM_JSONRPC_VARIANT") - |> String.split(".") - |> List.last() - |> String.downcase() - end +variant = Variant.get() Code.require_file("#{variant}.exs", "#{__DIR__}/../../../explorer/config/test") Code.require_file("#{variant}.exs", "#{__DIR__}/../../../indexer/config/test") diff --git a/apps/ethereum_jsonrpc/config/runtime/test.exs b/apps/ethereum_jsonrpc/config/runtime/test.exs index 476dedd9439c..e2043f6c1435 100644 --- a/apps/ethereum_jsonrpc/config/runtime/test.exs +++ b/apps/ethereum_jsonrpc/config/runtime/test.exs @@ -1,14 +1,8 @@ import Config -variant = - if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do - "parity" - else - System.get_env("ETHEREUM_JSONRPC_VARIANT") - |> String.split(".") - |> List.last() - |> String.downcase() - end +alias EthereumJSONRPC.Variant + +variant = Variant.get() Code.require_file("#{variant}.exs", "#{__DIR__}/../../../explorer/config/test") Code.require_file("#{variant}.exs", "#{__DIR__}/../../../indexer/config/test") diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/variant.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/variant.ex index 0374165477ca..7c213676b864 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/variant.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/variant.ex @@ -94,4 +94,15 @@ defmodule EthereumJSONRPC.Variant do ], EthereumJSONRPC.json_rpc_named_arguments() ) :: {:ok, [raw_trace_params]} | {:error, reason :: term} | :ignore + + def get do + if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do + "nethermind" + else + System.get_env("ETHEREUM_JSONRPC_VARIANT") + |> String.split(".") + |> List.last() + |> String.downcase() + end + end end diff --git a/apps/explorer/config/runtime/test.exs b/apps/explorer/config/runtime/test.exs index ab71c6033f64..a47fbb618092 100644 --- a/apps/explorer/config/runtime/test.exs +++ b/apps/explorer/config/runtime/test.exs @@ -1,5 +1,7 @@ import Config +alias EthereumJSONRPC.Variant + config :explorer, Explorer.ExchangeRates, enabled: false, store: :ets, fetch_btc_value: true config :explorer, Explorer.Chain.Cache.BlockNumber, enabled: false @@ -24,15 +26,7 @@ config :explorer, Explorer.Tracer, disabled?: false config :explorer, realtime_events_sender: Explorer.Chain.Events.SimpleSender -variant = - if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do - "parity" - else - System.get_env("ETHEREUM_JSONRPC_VARIANT") - |> String.split(".") - |> List.last() - |> String.downcase() - end +variant = Variant.get() Code.require_file("#{variant}.exs", "#{__DIR__}/../../../explorer/config/test") Code.require_file("#{variant}.exs", "#{__DIR__}/../../../indexer/config/test") diff --git a/apps/explorer/lib/explorer/repo/config_helper.ex b/apps/explorer/lib/explorer/repo/config_helper.ex index 3f60a1b19969..d02447f64a87 100644 --- a/apps/explorer/lib/explorer/repo/config_helper.ex +++ b/apps/explorer/lib/explorer/repo/config_helper.ex @@ -25,6 +25,19 @@ defmodule Explorer.Repo.ConfigHelper do |> Keyword.merge(extract_parameters(url)) end + def get_db_pool_size(default_pool_size), do: String.to_integer(System.get_env("POOL_SIZE", default_pool_size)) + + def get_account_db_url, do: System.get_env("ACCOUNT_DATABASE_URL") || System.get_env("DATABASE_URL") + + def get_account_db_pool_size(default_pool_size), + do: String.to_integer(System.get_env("ACCOUNT_POOL_SIZE", default_pool_size)) + + def get_api_db_url, do: System.get_env("DATABASE_READ_ONLY_API_URL") || System.get_env("DATABASE_URL") + + def get_api_db_pool_size(default_pool_size), do: String.to_integer(System.get_env("POOL_SIZE_API", default_pool_size)) + + def ssl_enabled?, do: String.equivalent?(System.get_env("ECTO_USE_SSL") || "true", "true") + defp extract_parameters(empty) when empty == nil or empty == "", do: [] # sobelow_skip ["DOS.StringToAtom"] diff --git a/apps/indexer/config/runtime/test.exs b/apps/indexer/config/runtime/test.exs index 476dedd9439c..e2043f6c1435 100644 --- a/apps/indexer/config/runtime/test.exs +++ b/apps/indexer/config/runtime/test.exs @@ -1,14 +1,8 @@ import Config -variant = - if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do - "parity" - else - System.get_env("ETHEREUM_JSONRPC_VARIANT") - |> String.split(".") - |> List.last() - |> String.downcase() - end +alias EthereumJSONRPC.Variant + +variant = Variant.get() Code.require_file("#{variant}.exs", "#{__DIR__}/../../../explorer/config/test") Code.require_file("#{variant}.exs", "#{__DIR__}/../../../indexer/config/test") diff --git a/config/runtime/dev.exs b/config/runtime/dev.exs index 8de612decbd0..22163b07cf1e 100644 --- a/config/runtime/dev.exs +++ b/config/runtime/dev.exs @@ -1,5 +1,8 @@ import Config +alias EthereumJSONRPC.Variant +alias Explorer.Repo.ConfigHelper + ###################### ### BlockScout Web ### ###################### @@ -41,15 +44,10 @@ config :block_scout_web, BlockScoutWeb.Endpoint, database = if System.get_env("DATABASE_URL"), do: nil, else: "explorer_dev" hostname = if System.get_env("DATABASE_URL"), do: nil, else: "localhost" -database_api_url = - if System.get_env("DATABASE_READ_ONLY_API_URL"), - do: System.get_env("DATABASE_READ_ONLY_API_URL"), - else: System.get_env("DATABASE_URL") - pool_size = if System.get_env("DATABASE_READ_ONLY_API_URL"), - do: String.to_integer(System.get_env("POOL_SIZE", "30")), - else: String.to_integer(System.get_env("POOL_SIZE", "40")) + do: ConfigHelper.get_db_pool_size("30"), + else: ConfigHelper.get_db_pool_size("40") # Configure your database config :explorer, Explorer.Repo, @@ -61,18 +59,12 @@ config :explorer, Explorer.Repo, database_api = if System.get_env("DATABASE_READ_ONLY_API_URL"), do: nil, else: database hostname_api = if System.get_env("DATABASE_READ_ONLY_API_URL"), do: nil, else: hostname -pool_size_api = String.to_integer(System.get_env("POOL_SIZE_API", "10")) - # Configure API database config :explorer, Explorer.Repo.Replica1, database: database_api, hostname: hostname_api, - url: database_api_url, - pool_size: pool_size_api - -database_account_url = System.get_env("ACCOUNT_DATABASE_URL") || System.get_env("DATABASE_URL") - -pool_size_account = String.to_integer(System.get_env("ACCOUNT_POOL_SIZE", "10")) + url: ConfigHelper.get_api_db_url(), + pool_size: ConfigHelper.get_api_db_pool_size("10") database_account = if System.get_env("ACCOUNT_DATABASE_URL"), do: nil, else: database hostname_account = if System.get_env("ACCOUNT_DATABASE_URL"), do: nil, else: hostname @@ -81,18 +73,10 @@ hostname_account = if System.get_env("ACCOUNT_DATABASE_URL"), do: nil, else: hos config :explorer, Explorer.Repo.Account, database: database_account, hostname: hostname_account, - url: database_account_url, - pool_size: pool_size_account - -variant = - if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do - "ganache" - else - System.get_env("ETHEREUM_JSONRPC_VARIANT") - |> String.split(".") - |> List.last() - |> String.downcase() - end + url: ConfigHelper.get_account_db_url(), + pool_size: ConfigHelper.get_account_db_pool_size("10") + +variant = Variant.get() Code.require_file("#{variant}.exs", "apps/explorer/config/dev") diff --git a/config/runtime/prod.exs b/config/runtime/prod.exs index 0e4e58f81a60..b5bdf68b66b0 100644 --- a/config/runtime/prod.exs +++ b/config/runtime/prod.exs @@ -1,5 +1,8 @@ import Config +alias EthereumJSONRPC.Variant +alias Explorer.Repo.ConfigHelper + ###################### ### BlockScout Web ### ###################### @@ -24,53 +27,33 @@ config :block_scout_web, BlockScoutWeb.Endpoint, pool_size = if System.get_env("DATABASE_READ_ONLY_API_URL"), - do: String.to_integer(System.get_env("POOL_SIZE", "50")), - else: String.to_integer(System.get_env("POOL_SIZE", "40")) + do: ConfigHelper.get_db_pool_size("50"), + else: ConfigHelper.get_db_pool_size("40") # Configures the database config :explorer, Explorer.Repo, url: System.get_env("DATABASE_URL"), pool_size: pool_size, - ssl: String.equivalent?(System.get_env("ECTO_USE_SSL") || "true", "true") - -database_api_url = - if System.get_env("DATABASE_READ_ONLY_API_URL"), - do: System.get_env("DATABASE_READ_ONLY_API_URL"), - else: System.get_env("DATABASE_URL") + ssl: ConfigHelper.ssl_enabled?() pool_size_api = if System.get_env("DATABASE_READ_ONLY_API_URL"), - do: String.to_integer(System.get_env("POOL_SIZE_API", "50")), - else: String.to_integer(System.get_env("POOL_SIZE_API", "10")) + do: ConfigHelper.get_api_db_pool_size("50"), + else: ConfigHelper.get_api_db_pool_size("10") # Configures API the database config :explorer, Explorer.Repo.Replica1, - url: database_api_url, + url: ConfigHelper.get_api_db_url(), pool_size: pool_size_api, - ssl: String.equivalent?(System.get_env("ECTO_USE_SSL") || "true", "true") - -database_account_url = - if System.get_env("ACCOUNT_DATABASE_URL"), - do: System.get_env("ACCOUNT_DATABASE_URL"), - else: System.get_env("DATABASE_URL") - -pool_size_account = String.to_integer(System.get_env("ACCOUNT_POOL_SIZE", "50")) + ssl: ConfigHelper.ssl_enabled?() # Configures Account database config :explorer, Explorer.Repo.Account, - url: database_account_url, - pool_size: pool_size_account, - ssl: String.equivalent?(System.get_env("ECTO_USE_SSL") || "true", "true") + url: ConfigHelper.get_account_db_url(), + pool_size: ConfigHelper.get_account_db_pool_size("50"), + ssl: ConfigHelper.ssl_enabled?() -variant = - if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do - "parity" - else - System.get_env("ETHEREUM_JSONRPC_VARIANT") - |> String.split(".") - |> List.last() - |> String.downcase() - end +variant = Variant.get() Code.require_file("#{variant}.exs", "apps/explorer/config/prod") diff --git a/config/runtime/test.exs b/config/runtime/test.exs index 38cd15e0dfbe..f6ba58d424f7 100644 --- a/config/runtime/test.exs +++ b/config/runtime/test.exs @@ -1,5 +1,7 @@ import Config +alias EthereumJSONRPC.Variant + ###################### ### BlockScout Web ### ###################### @@ -12,15 +14,7 @@ import Config ### Explorer ### ################ -variant = - if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do - "parity" - else - System.get_env("ETHEREUM_JSONRPC_VARIANT") - |> String.split(".") - |> List.last() - |> String.downcase() - end +variant = Variant.get() Code.require_file("#{variant}.exs", "apps/explorer/config/test") diff --git a/docker-compose/README.md b/docker-compose/README.md index 001ff7fead5f..67c1496a601c 100644 --- a/docker-compose/README.md +++ b/docker-compose/README.md @@ -32,7 +32,7 @@ Also, the repo contains built-in configs for different clients without need to b - Erigon: `docker-compose -f docker-compose-no-build-erigon.yml up -d` - Geth: `docker-compose -f docker-compose-no-build-geth.yml up -d` -- Nethermind, OpenEthereum: `docker-compose -f docker-compose-no-build-open-ethereum-nethermind up -d` +- Nethermind, OpenEthereum: `docker-compose -f docker-compose-no-build-nethermind up -d` - Ganache: `docker-compose -f docker-compose-no-build-ganache.yml up -d` - HardHat network: `docker-compose -f docker-compose-no-build-hardhat-network.yml up -d` - Running only explorer without DB: `docker-compose -f docker-compose-no-build-no-db-container.yml up -d`. In this case, one container is created - for the explorer itself. And it assumes that the DB credentials are provided through `DATABASE_URL` environment variable. diff --git a/docker-compose/docker-compose-no-build-open-ethereum-nethermind.yml b/docker-compose/docker-compose-no-build-nethermind.yml similarity index 100% rename from docker-compose/docker-compose-no-build-open-ethereum-nethermind.yml rename to docker-compose/docker-compose-no-build-nethermind.yml