Skip to content

fix: config name isn't always a base config #1047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ config :lambda_ethereum_consensus, LambdaEthereumConsensus.Store.Db, dir: datadi
{chain_config, bootnodes} =
case testnet_dir do
nil ->
config = ConfigUtils.parse_config(network)
config = ConfigUtils.parse_config!(network)
bootnodes = YamlElixir.read_from_file!("config/networks/#{network}/boot_enr.yaml")
{config, bootnodes}

Expand Down
7 changes: 5 additions & 2 deletions lib/chain_spec/configs/custom.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ defmodule CustomConfig do
def load_from_file!(path) do
config = ConfigUtils.load_config_from_file!(path)
preset = Map.fetch!(config, "PRESET_BASE") |> ConfigUtils.parse_preset()
base_config = Map.fetch!(config, "CONFIG_NAME") |> ConfigUtils.parse_config()
config_name = Map.get(config, "CONFIG_NAME") |> ConfigUtils.parse_config()

merged_config =
preset.get_preset()
|> Map.merge(base_config.get_all())
|> Map.merge(get_base_config(config_name))
|> Map.merge(config)

Application.put_env(:lambda_ethereum_consensus, __MODULE__, merged: merged_config)
Expand All @@ -37,4 +37,7 @@ defmodule CustomConfig do
end

defp parse_int(v), do: v

defp get_base_config(:unknown), do: %{}
defp get_base_config(config_name), do: config_name.get_all()
end
8 changes: 7 additions & 1 deletion lib/chain_spec/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ defmodule ConfigUtils do
def parse_config("holesky"), do: HoleskyConfig
def parse_config("minimal"), do: MinimalConfig
def parse_config("gnosis"), do: GnosisConfig
def parse_config(other), do: raise("Unknown config: #{other}")
def parse_config(_), do: :unknown

def parse_config!(config) do
with :unknown <- parse_config(config) do
raise("Unknown config: #{config}")
end
end

def parse_preset("mainnet"), do: MainnetPreset
def parse_preset("minimal"), do: MinimalPreset
Expand Down