diff --git a/lib/lambda_ethereum_consensus/p2p/blob_downloader.ex b/lib/lambda_ethereum_consensus/p2p/blob_downloader.ex index 3b761c0ec..f68a4a864 100644 --- a/lib/lambda_ethereum_consensus/p2p/blob_downloader.ex +++ b/lib/lambda_ethereum_consensus/p2p/blob_downloader.ex @@ -32,7 +32,6 @@ defmodule LambdaEthereumConsensus.P2P.BlobDownloader do def request_blobs_by_range(slot, count, on_blobs, retries) do Logger.debug("Requesting blobs", slot: slot) - # FIXME: handle no-peers asynchronously! this is hanging Libp2pPort when there are no peers peer_id = get_some_peer() # NOTE: BeaconBlocksByRangeRequest == BlobSidecarsByRangeRequest @@ -62,12 +61,8 @@ defmodule LambdaEthereumConsensus.P2P.BlobDownloader do P2P.Peerbook.penalize_peer(peer_id) if retries > 0 do - Logger.info( - "Retrying request for #{count} blobs, reason: #{inspect(reason)} in 2 second", - slot: slot - ) + Logger.info("Retrying request for #{count} blobs: #{inspect(reason)}", slot: slot) - Process.sleep(2000) request_blobs_by_range(slot, count, on_blobs, retries - 1) {:ok, store} else @@ -128,8 +123,8 @@ defmodule LambdaEthereumConsensus.P2P.BlobDownloader do defp get_some_peer() do case P2P.Peerbook.get_some_peer() do nil -> - Process.sleep(100) - get_some_peer() + # TODO: handle no-peers asynchronously + raise "No peers available to request blobs from." peer_id -> peer_id diff --git a/lib/lambda_ethereum_consensus/p2p/block_downloader.ex b/lib/lambda_ethereum_consensus/p2p/block_downloader.ex index 6910d4a77..92ef93510 100644 --- a/lib/lambda_ethereum_consensus/p2p/block_downloader.ex +++ b/lib/lambda_ethereum_consensus/p2p/block_downloader.ex @@ -66,7 +66,6 @@ defmodule LambdaEthereumConsensus.P2P.BlockDownloader do def request_blocks_by_range(slot, count, on_blocks, retries) do Logger.debug("Requesting block", slot: slot) - # FIXME: handle no-peers asynchronously! this is hanging Libp2pPort when there are no peers peer_id = get_some_peer() request = @@ -174,11 +173,10 @@ defmodule LambdaEthereumConsensus.P2P.BlockDownloader do :telemetry.execute([:network, :request], %{blocks: 0}, Map.put(tags, :result, "retry")) pretty_roots = Enum.map_join(roots, ", ", &Base.encode16/1) - Logger.debug( - "Retrying request (reason: #{inspect(reason)}) for blocks with roots #{pretty_roots}, in 2 second" + Logger.info( + "Retrying request for blocks with roots #{pretty_roots}: #{inspect(reason)}" ) - Process.sleep(2000) request_blocks_by_root(roots, on_blocks, retries - 1) {:ok, store} else @@ -191,8 +189,8 @@ defmodule LambdaEthereumConsensus.P2P.BlockDownloader do defp get_some_peer() do case P2P.Peerbook.get_some_peer() do nil -> - Process.sleep(100) - get_some_peer() + # TODO: handle no-peers asynchronously + raise "No peers available to request blocks from." peer_id -> peer_id diff --git a/lib/lambda_ethereum_consensus/p2p/peerbook.ex b/lib/lambda_ethereum_consensus/p2p/peerbook.ex index d0dd89bcb..a3e755129 100644 --- a/lib/lambda_ethereum_consensus/p2p/peerbook.ex +++ b/lib/lambda_ethereum_consensus/p2p/peerbook.ex @@ -5,9 +5,10 @@ defmodule LambdaEthereumConsensus.P2P.Peerbook do require Logger alias LambdaEthereumConsensus.Libp2pPort alias LambdaEthereumConsensus.Store.KvSchema + alias LambdaEthereumConsensus.Utils @initial_score 100 - @penalize 20 + @penalize 35 @target_peers 128 @max_prune_size 8 @prune_percentage 0.05 @@ -58,9 +59,7 @@ defmodule LambdaEthereumConsensus.P2P.Peerbook do end def penalize_peer(peer_id) do - Logger.debug( - "Penalizing peer: #{inspect(LambdaEthereumConsensus.Utils.format_shorten_binary(peer_id))}" - ) + Logger.debug("[Peerbook] Penalizing peer: #{inspect(Utils.format_shorten_binary(peer_id))}") peer_score = fetch_peerbook!() |> Map.get(peer_id) @@ -69,9 +68,7 @@ defmodule LambdaEthereumConsensus.P2P.Peerbook do :ok score when score - @penalize <= 0 -> - Logger.info( - "Removing peer: #{inspect(LambdaEthereumConsensus.Utils.format_shorten_binary(peer_id))}" - ) + Logger.debug("[Peerbook] Removing peer: #{inspect(Utils.format_shorten_binary(peer_id))}") fetch_peerbook!() |> Map.delete(peer_id) @@ -88,7 +85,7 @@ defmodule LambdaEthereumConsensus.P2P.Peerbook do peerbook = fetch_peerbook!() Logger.debug( - "New peer connected: #{inspect(LambdaEthereumConsensus.Utils.format_shorten_binary(peer_id))}" + "[Peerbook] New peer connected: #{inspect(Utils.format_shorten_binary(peer_id))}" ) if not Map.has_key?(peerbook, peer_id) do diff --git a/lib/libp2p_port.ex b/lib/libp2p_port.ex index 52f51f8ed..48f5a7758 100644 --- a/lib/libp2p_port.ex +++ b/lib/libp2p_port.ex @@ -9,8 +9,6 @@ defmodule LambdaEthereumConsensus.Libp2pPort do use GenServer - @tick_time 1000 - alias LambdaEthereumConsensus.Beacon.PendingBlocks alias LambdaEthereumConsensus.Beacon.SyncBlocks alias LambdaEthereumConsensus.ForkChoice @@ -84,7 +82,8 @@ defmodule LambdaEthereumConsensus.Libp2pPort do discovery_addresses: [String.t()] } - @sync_delay_millis 10_000 + @tick_time 1000 + @sync_delay_millis 15_000 ###################### ### API