Skip to content

Commit

Permalink
Return error message in ForkChoice.on_block
Browse files Browse the repository at this point in the history
  • Loading branch information
avilagaston9 committed Jun 4, 2024
1 parent 5b1c27b commit c695b65
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions lib/lambda_ethereum_consensus/beacon/pending_blocks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,16 @@ defmodule LambdaEthereumConsensus.Beacon.PendingBlocks do

defp process_block(state, block_info) do
case ForkChoice.on_block(block_info) do
:ok -> state |> Map.delete(block_info.root)
:error -> state |> Map.put(block_info.root, {nil, :invalid})
:ok ->
state |> Map.delete(block_info.root)

{:error, reason} ->
Logger.error("[PendingBlocks] Saving block as invalid #{reason}",
slot: block_info.signed_block.message.slot,
root: block_info.root
)

state |> Map.put(block_info.root, {nil, :invalid})
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/lambda_ethereum_consensus/fork_choice/fork_choice.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule LambdaEthereumConsensus.ForkChoice do
persist_store(store)
end

@spec on_block(BlockInfo.t()) :: :ok | :error
@spec on_block(BlockInfo.t()) :: :ok | {:error, String.t()}
def on_block(%BlockInfo{} = block_info) do
store = fetch_store!()
slot = block_info.signed_block.message.slot
Expand Down Expand Up @@ -67,7 +67,7 @@ defmodule LambdaEthereumConsensus.ForkChoice do

{:error, reason} ->
Logger.error("[Fork choice] Failed to add block: #{reason}", slot: slot, root: block_root)
:error
{:error, reason}
end
end

Expand Down

0 comments on commit c695b65

Please sign in to comment.