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: handle keys with no deposits #1266

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions lib/lambda_ethereum_consensus/validator/validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,7 @@ defmodule LambdaEthereumConsensus.Validator do
payload_builder: nil
}

case try_setup_validator(state, head_slot, head_root) do
nil ->
# TODO: Previously this was handled by the validator continously trying to setup itself,
# but now that they are processed syncronously, we should handle this case different.
# Right now it's just omitted and logged.
Logger.error("[Validator] Public key not found in the validator set")
state

new_state ->
new_state
end
try_setup_validator(state, head_slot, head_root)
end

@spec try_setup_validator(t(), Types.slot(), Types.root()) :: t() | nil
Expand All @@ -76,7 +66,11 @@ defmodule LambdaEthereumConsensus.Validator do

case fetch_validator_index(beacon, state.keystore.pubkey) do
nil ->
nil
Logger.warning(
"[Validator] Public key #{inspect(state.keystore.pubkey)} not found in the validator set"
)

state

validator_index ->
log_info(validator_index, "setup validator", slot: slot, root: root)
Expand All @@ -97,13 +91,14 @@ defmodule LambdaEthereumConsensus.Validator do
end

@spec handle_new_head(Types.slot(), Types.root(), t()) :: t()
def handle_new_head(slot, head_root, %{index: nil} = state) do
log_error("-1", "setup validator", "index not present handle block",
slot: slot,
root: head_root
)
def handle_new_head(slot, head_root, %{index: nil, epoch: last_epoch} = state) do
epoch = Misc.compute_epoch_at_slot(slot)

state
if last_epoch == epoch do
%{state | slot: slot, root: head_root}
else
try_setup_validator(state, slot, head_root)
end
end

def handle_new_head(slot, head_root, state) do
Expand All @@ -117,11 +112,6 @@ defmodule LambdaEthereumConsensus.Validator do
end

@spec handle_tick({Types.slot(), atom()}, t()) :: t()
def handle_tick(_logical_time, %{index: nil} = state) do
log_error("-1", "setup validator", "index not present for handle tick")
state
end

def handle_tick({slot, :first_third}, state) do
log_debug(state.index, "started first third", slot: slot)
# Here we may:
Expand Down Expand Up @@ -167,6 +157,9 @@ defmodule LambdaEthereumConsensus.Validator do
end

@spec recompute_duties(t(), Types.epoch(), Types.epoch(), Types.slot(), Types.root()) :: t()
defp recompute_duties(%{index: nil} = state, _last_epoch, _epoch, slot, head_root),
do: try_setup_validator(state, slot, head_root)

defp recompute_duties(%{root: last_root} = state, last_epoch, epoch, slot, head_root) do
start_slot = Misc.compute_start_slot_at_epoch(epoch)
target_root = if slot == start_slot, do: head_root, else: last_root
Expand Down Expand Up @@ -385,6 +378,7 @@ defmodule LambdaEthereumConsensus.Validator do
Enum.find_index(beacon.validators, &(&1.pubkey == pubkey))
end

defp proposer?(%{index: nil}, _slot), do: false
defp proposer?(%{duties: %{proposer: slots}}, slot), do: Enum.member?(slots, slot)

@spec maybe_build_payload(t(), Types.slot()) :: t()
Expand Down
Loading