Skip to content

Commit

Permalink
fix: download missing parents
Browse files Browse the repository at this point in the history
  • Loading branch information
avilagaston9 committed Jul 12, 2024
1 parent 9b4eee6 commit bf5aeee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
28 changes: 26 additions & 2 deletions lib/lambda_ethereum_consensus/beacon/pending_blocks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ defmodule LambdaEthereumConsensus.Beacon.PendingBlocks do
require Logger

alias LambdaEthereumConsensus.ForkChoice
alias LambdaEthereumConsensus.Libp2pPort
alias LambdaEthereumConsensus.P2P.BlockDownloader

alias LambdaEthereumConsensus.Metrics
alias LambdaEthereumConsensus.P2P.BlobDownloader
alias LambdaEthereumConsensus.Store.BlobDb
Expand All @@ -20,6 +23,8 @@ defmodule LambdaEthereumConsensus.Beacon.PendingBlocks do
| {nil, :invalid | :download}
@type state :: nil

@download_retries 100

@doc """
If the block is not present, it will be stored as pending.
Expand All @@ -45,7 +50,7 @@ defmodule LambdaEthereumConsensus.Beacon.PendingBlocks do
Blocks.new_block_info(block_info)
process_block_and_check_children(block_info)
else
BlobDownloader.request_blobs_by_root(missing_blobs, &process_blobs/1, 30)
BlobDownloader.request_blobs_by_root(missing_blobs, &process_blobs/1, @download_retries)

block_info
|> BlockInfo.change_status(:download_blobs)
Expand Down Expand Up @@ -91,9 +96,18 @@ defmodule LambdaEthereumConsensus.Beacon.PendingBlocks do

case Blocks.get_block_info(parent_root) do
nil ->
Logger.info("Add parent to download #{inspect(parent_root)}")
Logger.debug("[PendingBlocks] Add parent to download #{inspect(parent_root)}")
Blocks.add_block_to_download(parent_root)

BlockDownloader.request_blocks_by_range(
block_info.signed_block.message.slot - 1,
1,
fn result ->
process_downloaded_block(result)
end,
@download_retries
)

Metrics.block_relationship(
parent_root,
block_info.root
Expand Down Expand Up @@ -126,6 +140,16 @@ defmodule LambdaEthereumConsensus.Beacon.PendingBlocks do
end
end

defp process_downloaded_block({:ok, [block]}) do
Libp2pPort.add_block(block)
end

defp process_downloaded_block({:error, reason}) do
Logger.error("Error downloading block: #{inspect(reason)}")

# We might want to declare a block invalid here.
end

defp process_blobs({:ok, blobs}), do: add_blobs(blobs)

defp process_blobs({:error, reason}) do
Expand Down
2 changes: 1 addition & 1 deletion lib/lambda_ethereum_consensus/metrics.ex
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ defmodule LambdaEthereumConsensus.Metrics do
defp block_status_execute(root, status, slot, value) do
hex_root = Base.encode16(root)

Logger.info(
Logger.debug(
"[Metrics] slot = #{inspect(slot)}, status = #{inspect(status)}, value = #{inspect(value)}"
)

Expand Down

0 comments on commit bf5aeee

Please sign in to comment.