Skip to content
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

feat: make boot_enr.yaml optional #1050

Merged
merged 10 commits into from
Apr 29, 2024
6 changes: 3 additions & 3 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions lib/chain_spec/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 18 additions & 10 deletions lib/lambda_ethereum_consensus/beacon/beacon_node.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Loading