From c695b650d0bc40b4eafcf15ca014d617bd456da5 Mon Sep 17 00:00:00 2001 From: avilagaston9 Date: Tue, 4 Jun 2024 11:35:08 -0300 Subject: [PATCH] Return error message in ForkChoice.on_block --- .../beacon/pending_blocks.ex | 12 ++++++++++-- .../fork_choice/fork_choice.ex | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/lambda_ethereum_consensus/beacon/pending_blocks.ex b/lib/lambda_ethereum_consensus/beacon/pending_blocks.ex index 77d48ad42..7e2ce69eb 100644 --- a/lib/lambda_ethereum_consensus/beacon/pending_blocks.ex +++ b/lib/lambda_ethereum_consensus/beacon/pending_blocks.ex @@ -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 diff --git a/lib/lambda_ethereum_consensus/fork_choice/fork_choice.ex b/lib/lambda_ethereum_consensus/fork_choice/fork_choice.ex index 762199d58..3d492779a 100644 --- a/lib/lambda_ethereum_consensus/fork_choice/fork_choice.ex +++ b/lib/lambda_ethereum_consensus/fork_choice/fork_choice.ex @@ -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 @@ -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