Skip to content

Commit

Permalink
compile without warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkenan committed Jun 17, 2024
1 parent d9b300d commit fd1ed80
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
8 changes: 7 additions & 1 deletion lib/lambda_ethereum_consensus/beacon/pending_blocks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule LambdaEthereumConsensus.Beacon.PendingBlocks do
if Enum.empty?(missing_blobs) do
block_info
else
BlobDownloader.request_blobs_by_root(missing_blobs)
BlobDownloader.request_blobs_by_root(missing_blobs, &process_blobs/1)
block_info |> BlockInfo.change_status(:download_blobs)
end
|> Blocks.new_block_info()
Expand Down Expand Up @@ -132,6 +132,12 @@ defmodule LambdaEthereumConsensus.Beacon.PendingBlocks do
end
end

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

defp process_blobs({:error, reason}) do
Logger.error("Error downloading blobs: #{inspect(reason)}")
end

@spec missing_blobs(BlockInfo.t()) :: [Types.BlobIdentifier.t()]
defp missing_blobs(%BlockInfo{root: root, signed_block: signed_block}) do
signed_block.message.body.blob_kzg_commitments
Expand Down
19 changes: 12 additions & 7 deletions lib/lambda_ethereum_consensus/p2p/blob_downloader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule LambdaEthereumConsensus.P2P.BlobDownloader do
@blobs_by_root_protocol_id "/eth2/beacon_chain/req/blob_sidecars_by_root/1/ssz_snappy"

@type on_blobs :: ({:ok, [BlobSidecar.t()]} | {:error, any()} -> :ok)
@type on_blob :: ({:ok, BlobSidecar.t()} | {:error, any()} -> :ok)

# Requests to peers might fail for various reasons,
# for example they might not support the protocol or might not reply
Expand Down Expand Up @@ -59,18 +60,22 @@ defmodule LambdaEthereumConsensus.P2P.BlobDownloader do
end
end

@spec request_blob_by_root(Types.BlobIdentifier.t(), non_neg_integer()) ::
{:ok, BlobSidecar.t()} | {:error, binary()}
def request_blob_by_root(identifier, retries \\ @default_retries) do
with {:ok, [blob]} <- request_blobs_by_root([identifier], retries) do
{:ok, blob}
end
@spec request_blob_by_root(Types.BlobIdentifier.t(), on_blob(), non_neg_integer()) :: :ok
def request_blob_by_root(identifier, on_blob, retries \\ @default_retries) do
request_blobs_by_root(
[identifier],
fn
{:ok, [blob]} -> on_blob.({:ok, blob})
other -> on_blob.(other)
end,
retries
)
end

@spec request_blobs_by_root([Types.BlobIdentifier.t()], on_blobs(), non_neg_integer()) :: :ok
def request_blobs_by_root(identifiers, on_blobs, retries \\ @default_retries)

def request_blobs_by_root([], on_blobs, _retries), do: {:ok, []}
def request_blobs_by_root([], _on_blobs, _retries), do: {:ok, []}

def request_blobs_by_root(identifiers, on_blobs, retries) do
Logger.debug("Requesting #{length(identifiers)} blobs.")
Expand Down

0 comments on commit fd1ed80

Please sign in to comment.