Skip to content

Commit 19e4bbd

Browse files
authored
feat: make boot_enr.yaml optional (#1050)
1 parent 2a0ad72 commit 19e4bbd

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

config/runtime.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ config :lambda_ethereum_consensus, LambdaEthereumConsensus.Store.Db, dir: datadi
9090

9191
testnet_dir ->
9292
Path.join(testnet_dir, "config.yaml") |> CustomConfig.load_from_file!()
93-
bootnodes = Path.join(testnet_dir, "boot_enr.yaml") |> YamlElixir.read_from_file!()
93+
bootnodes = ConfigUtils.load_testnet_bootnodes(testnet_dir)
9494
{CustomConfig, bootnodes}
9595
end
9696

@@ -139,8 +139,6 @@ config :lambda_ethereum_consensus, EngineApi,
139139
version: "2.0"
140140

141141
# Beacon API
142-
alias BeaconApi
143-
144142
config :lambda_ethereum_consensus, BeaconApi.Endpoint,
145143
server: enable_beacon_api,
146144
http: [port: beacon_api_port || 4000],
@@ -168,6 +166,8 @@ block_time_ms =
168166
"mainnet" -> 12_000
169167
"sepolia" -> 100
170168
"holesky" -> 24_000
169+
# Default to mainnet
170+
_ -> 12_000
171171
end
172172

173173
config :lambda_ethereum_consensus, LambdaEthereumConsensus.Telemetry,

lib/chain_spec/utils.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,14 @@ defmodule ConfigUtils do
4242
def parse_preset("minimal"), do: MinimalPreset
4343
def parse_preset("gnosis"), do: GnosisPreset
4444
def parse_preset(other), do: raise("Unknown preset: #{other}")
45+
46+
def load_testnet_bootnodes(testnet_dir) do
47+
bootnodes_file = Path.join(testnet_dir, "boot_enr.yaml")
48+
49+
if File.exists?(bootnodes_file) do
50+
YamlElixir.read_from_file!(bootnodes_file)
51+
else
52+
[]
53+
end
54+
end
4555
end

lib/lambda_ethereum_consensus/beacon/beacon_node.ex

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,7 @@ defmodule LambdaEthereumConsensus.Beacon.BeaconNode do
2323

2424
Cache.initialize_cache()
2525

26-
config = Application.fetch_env!(:lambda_ethereum_consensus, :discovery)
27-
port = Keyword.fetch!(config, :port)
28-
bootnodes = Keyword.fetch!(config, :bootnodes)
29-
30-
libp2p_args = [
31-
listen_addr: [],
32-
enable_discovery: true,
33-
discovery_addr: "0.0.0.0:#{port}",
34-
bootnodes: bootnodes
35-
]
26+
libp2p_args = get_libp2p_args()
3627

3728
time = :os.system_time(:second)
3829

@@ -86,4 +77,21 @@ defmodule LambdaEthereumConsensus.Beacon.BeaconNode do
8677
]
8778
end
8879
end
80+
81+
defp get_libp2p_args() do
82+
config = Application.fetch_env!(:lambda_ethereum_consensus, :discovery)
83+
port = Keyword.fetch!(config, :port)
84+
bootnodes = Keyword.fetch!(config, :bootnodes)
85+
86+
if Enum.empty?(bootnodes) do
87+
Logger.warning("No bootnodes configured.")
88+
end
89+
90+
[
91+
listen_addr: [],
92+
enable_discovery: true,
93+
discovery_addr: "0.0.0.0:#{port}",
94+
bootnodes: bootnodes
95+
]
96+
end
8997
end

0 commit comments

Comments
 (0)