Skip to content

Commit 7a12460

Browse files
authored
fix: ValidatorManager initialization (#1099)
1 parent 0acfd0b commit 7a12460

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ ENV MIX_ENV=prod
7676
# To avoid recompiling rustler NIFs
7777
ENV RUSTLER_SKIP_COMPILE=yes
7878

79-
RUN mix local.hex --force
79+
# https://github.com/hexpm/hex/issues/1029#issuecomment-2124545292
80+
RUN mix local.hex 2.0.6 --force
8081

8182
# Install dependencies
8283
RUN apt-get update && apt-get install -y cmake protobuf-compiler

lib/lambda_ethereum_consensus/validator/validator_manager.ex

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,28 @@ defmodule LambdaEthereumConsensus.Validator.ValidatorManager do
1313
@impl true
1414
def init({slot, head_root}) do
1515
config = Application.get_env(:lambda_ethereum_consensus, __MODULE__, [])
16-
1716
keystore_dir = Keyword.get(config, :keystore_dir)
1817
keystore_pass_dir = Keyword.get(config, :keystore_pass_dir)
19-
validator_keys = decode_validator_keys(keystore_dir, keystore_pass_dir)
2018

21-
children =
22-
validator_keys
23-
|> Enum.map(fn {pubkey, privkey} ->
24-
Supervisor.child_spec({Validator, {slot, head_root, {pubkey, privkey}}},
25-
id: pubkey
26-
)
27-
end)
19+
if is_nil(keystore_dir) or is_nil(keystore_pass_dir) do
20+
Logger.warning(
21+
"[Validator Manager] No keystore_dir or keystore_pass_dir provided. Validator will not start."
22+
)
23+
24+
:ignore
25+
else
26+
validator_keys = decode_validator_keys(keystore_dir, keystore_pass_dir)
27+
28+
children =
29+
validator_keys
30+
|> Enum.map(fn {pubkey, privkey} ->
31+
Supervisor.child_spec({Validator, {slot, head_root, {pubkey, privkey}}},
32+
id: pubkey
33+
)
34+
end)
2835

29-
Supervisor.init(children, strategy: :one_for_one)
36+
Supervisor.init(children, strategy: :one_for_one)
37+
end
3038
end
3139

3240
def notify_new_block(slot, head_root) do
@@ -38,9 +46,15 @@ defmodule LambdaEthereumConsensus.Validator.ValidatorManager do
3846
end
3947

4048
defp cast_to_children(msg) do
41-
__MODULE__
42-
|> Supervisor.which_children()
43-
|> Enum.each(fn {_, pid, _, _} -> GenServer.cast(pid, msg) end)
49+
case Process.whereis(__MODULE__) do
50+
nil ->
51+
# No active validators
52+
nil
53+
54+
pid ->
55+
Supervisor.which_children(pid)
56+
|> Enum.each(fn {_, pid, _, _} -> GenServer.cast(pid, msg) end)
57+
end
4458
end
4559

4660
@doc """
@@ -49,8 +63,10 @@ defmodule LambdaEthereumConsensus.Validator.ValidatorManager do
4963
- <keystore_dir>/<public_key>.json
5064
- <keystore_pass_dir>/<public_key>.txt
5165
"""
52-
@spec decode_validator_keys(binary(), binary()) :: list({Bls.pubkey(), Bls.privkey()})
53-
def decode_validator_keys(keystore_dir, keystore_pass_dir) do
66+
@spec decode_validator_keys(binary(), binary()) ::
67+
list({Bls.pubkey(), Bls.privkey()})
68+
def decode_validator_keys(keystore_dir, keystore_pass_dir)
69+
when is_binary(keystore_dir) and is_binary(keystore_pass_dir) do
5470
File.ls!(keystore_dir)
5571
|> Enum.map(fn filename ->
5672
if String.ends_with?(filename, ".json") do

0 commit comments

Comments
 (0)