Skip to content

Commit

Permalink
format and removal of store changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-o committed Oct 2, 2024
1 parent 4d4bc34 commit d1846dd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
9 changes: 5 additions & 4 deletions lib/lambda_ethereum_consensus/p2p/blob_downloader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ 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, reason: #{inspect(reason)} in 2 second",
slot: slot
)

Process.sleep(2000)
request_blobs_by_range(slot, count, on_blobs, retries - 1)
{:ok, store}
Expand Down Expand Up @@ -124,9 +128,6 @@ defmodule LambdaEthereumConsensus.P2P.BlobDownloader do
defp get_some_peer() do
case P2P.Peerbook.get_some_peer() do
nil ->
stacktrace = Process.info(self(), :current_stacktrace)
IO.inspect(stacktrace, label: "Current stacktrace")

Process.sleep(100)
get_some_peer()

Expand Down
9 changes: 5 additions & 4 deletions lib/lambda_ethereum_consensus/p2p/block_downloader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ defmodule LambdaEthereumConsensus.P2P.BlockDownloader do
if retries > 0 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.debug(
"Retrying request (reason: #{inspect(reason)}) for blocks with roots #{pretty_roots}, in 2 second"
)

Process.sleep(2000)
request_blocks_by_root(roots, on_blocks, retries - 1)
{:ok, store}
Expand All @@ -187,9 +191,6 @@ defmodule LambdaEthereumConsensus.P2P.BlockDownloader do
defp get_some_peer() do
case P2P.Peerbook.get_some_peer() do
nil ->
stacktrace = Process.info(self(), :current_stacktrace)
IO.inspect(stacktrace, label: "Current stacktrace")

Process.sleep(100)
get_some_peer()

Expand Down
15 changes: 12 additions & 3 deletions lib/lambda_ethereum_consensus/p2p/peerbook.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,21 @@ 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(
"Penalizing peer: #{inspect(LambdaEthereumConsensus.Utils.format_shorten_binary(peer_id))}"
)

peer_score = fetch_peerbook!() |> Map.get(peer_id)

case peer_score do
nil ->
:ok

score when score - @penalize <= 0 ->
Logger.info("Removing peer: #{inspect(LambdaEthereumConsensus.Utils.format_shorten_binary(peer_id))}")
Logger.info(
"Removing peer: #{inspect(LambdaEthereumConsensus.Utils.format_shorten_binary(peer_id))}"
)

fetch_peerbook!()
|> Map.delete(peer_id)
|> store_peerbook()
Expand All @@ -80,7 +86,10 @@ defmodule LambdaEthereumConsensus.P2P.Peerbook do

def handle_new_peer(peer_id) do
peerbook = fetch_peerbook!()
Logger.debug("New peer connected: #{inspect(LambdaEthereumConsensus.Utils.format_shorten_binary(peer_id))}")

Logger.debug(
"New peer connected: #{inspect(LambdaEthereumConsensus.Utils.format_shorten_binary(peer_id))}"
)

if not Map.has_key?(peerbook, peer_id) do
:telemetry.execute([:peers, :connection], %{id: peer_id}, %{result: "success"})
Expand Down
9 changes: 1 addition & 8 deletions lib/types/store.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ defmodule Types.Store do
The Store struct is used to track information required for the fork choice algorithm.
"""

alias LambdaEthereumConsensus.ForkChoice
alias LambdaEthereumConsensus.ForkChoice.Head
alias LambdaEthereumConsensus.ForkChoice.Simple.Tree
alias LambdaEthereumConsensus.StateTransition
Expand Down Expand Up @@ -246,15 +245,9 @@ defmodule Types.Store do
end
end

@spec update_head_info(t()) :: t()
def update_head_info(store) do
defp update_head_info(store) do
{:ok, head_root} = Head.get_head(store)
%{slot: head_slot} = Blocks.get_block!(head_root)
update_head_info(store, head_slot, head_root)
end

@spec update_head_info(t(), Types.slot(), Types.root()) :: t()
def update_head_info(store, head_slot, head_root) do
%{store | head_root: head_root, head_slot: head_slot}
end

Expand Down

0 comments on commit d1846dd

Please sign in to comment.