Skip to content

Commit

Permalink
fix: config name isn't always a base config
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaRedHand committed Apr 25, 2024
1 parent 4efec4f commit 31ac7b2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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

0 comments on commit 31ac7b2

Please sign in to comment.