diff --git a/config/runtime.exs b/config/runtime.exs index 7787cfd11..20cd528a2 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -90,7 +90,7 @@ config :lambda_ethereum_consensus, LambdaEthereumConsensus.Store.Db, dir: datadi testnet_dir -> Path.join(testnet_dir, "config.yaml") |> CustomConfig.load_from_file!() - bootnodes = Path.join(testnet_dir, "boot_enr.yaml") |> YamlElixir.read_from_file!() + bootnodes = ConfigUtils.load_testnet_bootnodes(testnet_dir) {CustomConfig, bootnodes} end @@ -139,8 +139,6 @@ config :lambda_ethereum_consensus, EngineApi, version: "2.0" # Beacon API -alias BeaconApi - config :lambda_ethereum_consensus, BeaconApi.Endpoint, server: enable_beacon_api, http: [port: beacon_api_port || 4000], @@ -168,6 +166,8 @@ block_time_ms = "mainnet" -> 12_000 "sepolia" -> 100 "holesky" -> 24_000 + # Default to mainnet + _ -> 12_000 end config :lambda_ethereum_consensus, LambdaEthereumConsensus.Telemetry, diff --git a/lib/chain_spec/utils.ex b/lib/chain_spec/utils.ex index 3f643b6ae..16b1a9fde 100644 --- a/lib/chain_spec/utils.ex +++ b/lib/chain_spec/utils.ex @@ -42,4 +42,14 @@ defmodule ConfigUtils do def parse_preset("minimal"), do: MinimalPreset def parse_preset("gnosis"), do: GnosisPreset def parse_preset(other), do: raise("Unknown preset: #{other}") + + def load_testnet_bootnodes(testnet_dir) do + bootnodes_file = Path.join(testnet_dir, "boot_enr.yaml") + + if File.exists?(bootnodes_file) do + YamlElixir.read_from_file!(bootnodes_file) + else + [] + end + end end diff --git a/lib/lambda_ethereum_consensus/beacon/beacon_node.ex b/lib/lambda_ethereum_consensus/beacon/beacon_node.ex index 21305e09c..cdd3917c2 100644 --- a/lib/lambda_ethereum_consensus/beacon/beacon_node.ex +++ b/lib/lambda_ethereum_consensus/beacon/beacon_node.ex @@ -23,16 +23,7 @@ defmodule LambdaEthereumConsensus.Beacon.BeaconNode do Cache.initialize_cache() - config = Application.fetch_env!(:lambda_ethereum_consensus, :discovery) - port = Keyword.fetch!(config, :port) - bootnodes = Keyword.fetch!(config, :bootnodes) - - libp2p_args = [ - listen_addr: [], - enable_discovery: true, - discovery_addr: "0.0.0.0:#{port}", - bootnodes: bootnodes - ] + libp2p_args = get_libp2p_args() time = :os.system_time(:second) @@ -86,4 +77,21 @@ defmodule LambdaEthereumConsensus.Beacon.BeaconNode do ] end end + + defp get_libp2p_args() do + config = Application.fetch_env!(:lambda_ethereum_consensus, :discovery) + port = Keyword.fetch!(config, :port) + bootnodes = Keyword.fetch!(config, :bootnodes) + + if Enum.empty?(bootnodes) do + Logger.warning("No bootnodes configured.") + end + + [ + listen_addr: [], + enable_discovery: true, + discovery_addr: "0.0.0.0:#{port}", + bootnodes: bootnodes + ] + end end