From 1c46f3e318bac563903b41b8d6b2e704b60e34d3 Mon Sep 17 00:00:00 2001 From: Rodrigo Oliveri Date: Mon, 14 Oct 2024 13:42:54 -0300 Subject: [PATCH] chore: peerbook penalization config + node start fix (#1329) --- Makefile | 30 +++++++++++-------- config/runtime.exs | 12 ++++++++ .../beacon/checkpoint_sync.ex | 6 ++-- lib/lambda_ethereum_consensus/p2p/peerbook.ex | 11 +++++-- 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index c246ef1d8..c9fd95d65 100644 --- a/Makefile +++ b/Makefile @@ -164,39 +164,43 @@ test-iex: ################## # NODE RUNNERS -DYSCOVERY_PORT ?= 30303 +DISCOVERY_PORT ?= 9009 +METRICS_PORT ?= 9568 -#▶️ checkpoint-sync: @ Run an interactive terminal using checkpoint sync. -checkpoint-sync: compile-all - iex -S mix run -- --checkpoint-sync-url https://mainnet-checkpoint-sync.stakely.io/ --metrics --discovery-port $(DYSCOVERY_PORT) +#▶️ mainnet: @ Run an interactive terminal using checkpoint sync for mainnet. +mainnet: compile-all + iex -S mix run -- --checkpoint-sync-url https://mainnet-checkpoint-sync.stakely.io/ --metrics --metrics-port $(METRICS_PORT) --discovery-port $(DISCOVERY_PORT) -#▶️ checkpoint-sync.logfile: @ Run an interactive terminal using checkpoint sync with a log file. -checkpoint-sync.logfile: compile-all - iex -S mix run -- --checkpoint-sync-url https://mainnet-checkpoint-sync.stakely.io/ --metrics --log-file ./logs/mainnet.log --discovery-port $(DYSCOVERY_PORT) +#▶️ mainnet.logfile: @ Run an interactive terminal using checkpoint sync for mainnet with a log file. +mainnet.logfile: compile-all + iex -S mix run -- --checkpoint-sync-url https://mainnet-checkpoint-sync.stakely.io/ --metrics --metrics-port $(METRICS_PORT) --log-file ./logs/mainnet.log --discovery-port $(DISCOVERY_PORT) #▶️ sepolia: @ Run an interactive terminal using sepolia network sepolia: compile-all - iex -S mix run -- --checkpoint-sync-url https://sepolia.beaconstate.info --network sepolia --metrics --discovery-port $(DYSCOVERY_PORT) + iex -S mix run -- --checkpoint-sync-url https://sepolia.beaconstate.info --network sepolia --metrics --metrics-port $(METRICS_PORT) --discovery-port $(DISCOVERY_PORT) #▶️ sepolia.logfile: @ Run an interactive terminal using sepolia network with a log file sepolia.logfile: compile-all - iex -S mix run -- --checkpoint-sync-url https://sepolia.beaconstate.info --network sepolia --metrics --log-file ./logs/sepolia.log --discovery-port $(DYSCOVERY_PORT) + iex -S mix run -- --checkpoint-sync-url https://sepolia.beaconstate.info --network sepolia --metrics --metrics-port $(METRICS_PORT) --log-file ./logs/sepolia.log --discovery-port $(DISCOVERY_PORT) #▶️ holesky: @ Run an interactive terminal using holesky network holesky: compile-all - iex -S mix run -- --checkpoint-sync-url https://checkpoint-sync.holesky.ethpandaops.io --network holesky --discovery-port $(DYSCOVERY_PORT) + iex -S mix run -- --checkpoint-sync-url https://checkpoint-sync.holesky.ethpandaops.io --network holesky --metrics --metrics-port $(METRICS_PORT) --discovery-port $(DISCOVERY_PORT) #▶️ holesky.logfile: @ Run an interactive terminal using holesky network with a log file holesky.logfile: compile-all - iex -S mix run -- --checkpoint-sync-url https://checkpoint-sync.holesky.ethpandaops.io --network holesky --log-file ./logs/holesky.log --discovery-port $(DYSCOVERY_PORT) + iex -S mix run -- --checkpoint-sync-url https://checkpoint-sync.holesky.ethpandaops.io --network holesky --log-file ./logs/holesky.log --metrics --metrics-port $(METRICS_PORT) --discovery-port $(DISCOVERY_PORT) #▶️ gnosis: @ Run an interactive terminal using gnosis network gnosis: compile-all - iex -S mix run -- --checkpoint-sync-url https://checkpoint.gnosischain.com --network gnosis --discovery-port $(DYSCOVERY_PORT) + iex -S mix run -- --checkpoint-sync-url https://checkpoint.gnosischain.com --network gnosis --metrics --metrics-port $(METRICS_PORT) --discovery-port $(DISCOVERY_PORT) #▶️ gnosis.logfile: @ Run an interactive terminal using gnosis network with a log file gnosis.logfile: compile-all - iex -S mix run -- --checkpoint-sync-url https://checkpoint.gnosischain.com --network gnosis --log-file ./logs/gnosis.log --discovery-port $(DYSCOVERY_PORT) + iex -S mix run -- --checkpoint-sync-url https://checkpoint.gnosischain.com --network gnosis --metrics --metrics-port $(METRICS_PORT) --log-file ./logs/gnosis.log --discovery-port $(DISCOVERY_PORT) + +#▶️ checkpoint-sync: @ Run an interactive terminal using checkpoint sync for mainnet. +checkpoint-sync: mainnet #🔴 test: @ Run tests test: compile-all diff --git a/config/runtime.exs b/config/runtime.exs index ba00fe9f4..66852bc25 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -259,3 +259,15 @@ if dsn do config :sentry, dsn: dsn, release: String.trim(git_sha) end + +# Peerbook penalization + +penalizing_score = + case network do + "sepolia" -> 20 + "mainnet" -> 50 + _ -> 30 + end + +config :lambda_ethereum_consensus, LambdaEthereumConsensus.P2P.Peerbook, + penalizing_score: penalizing_score diff --git a/lib/lambda_ethereum_consensus/beacon/checkpoint_sync.ex b/lib/lambda_ethereum_consensus/beacon/checkpoint_sync.ex index 0e27b2c3f..3a782d4b3 100644 --- a/lib/lambda_ethereum_consensus/beacon/checkpoint_sync.ex +++ b/lib/lambda_ethereum_consensus/beacon/checkpoint_sync.ex @@ -19,7 +19,7 @@ defmodule LambdaEthereumConsensus.Beacon.CheckpointSync do def get_finalized_block_and_state(url, genesis_validators_root) do tasks = [Task.async(__MODULE__, :get_state, [url]), Task.async(__MODULE__, :get_block, [url])] - case Task.await_many(tasks, 60_000) do + case Task.await_many(tasks, 90_000) do [{:ok, state}, {:ok, block}] -> if state.genesis_validators_root == genesis_validators_root do check_match(url, state, block) @@ -92,8 +92,8 @@ defmodule LambdaEthereumConsensus.Beacon.CheckpointSync do defp get_json_from_url(base_url, path) do full_url = concat_url(base_url, path) - with {:ok, response} <- get(full_url) do - {:ok, response.body |> Map.fetch!("data") |> parse_json()} + with {:ok, %{body: %{"data" => data}}} <- get(full_url) do + {:ok, parse_json(data)} end end diff --git a/lib/lambda_ethereum_consensus/p2p/peerbook.ex b/lib/lambda_ethereum_consensus/p2p/peerbook.ex index f417304a0..913750fce 100644 --- a/lib/lambda_ethereum_consensus/p2p/peerbook.ex +++ b/lib/lambda_ethereum_consensus/p2p/peerbook.ex @@ -63,12 +63,13 @@ defmodule LambdaEthereumConsensus.P2P.Peerbook do Logger.debug("[Peerbook] Penalizing peer: #{inspect(Utils.format_shorten_binary(peer_id))}") peer_score = fetch_peerbook!() |> Map.get(peer_id) + penalizing_score = penalazing_score() case peer_score do nil -> :ok - score when score - @penalizing_score <= 0 -> + score when score - penalizing_score <= 0 -> Logger.debug("[Peerbook] Removing peer: #{inspect(Utils.format_shorten_binary(peer_id))}") fetch_peerbook!() @@ -77,7 +78,7 @@ defmodule LambdaEthereumConsensus.P2P.Peerbook do score -> fetch_peerbook!() - |> Map.put(peer_id, score - @penalizing_score) + |> Map.put(peer_id, score - penalizing_score) |> store_peerbook() end end @@ -142,4 +143,10 @@ defmodule LambdaEthereumConsensus.P2P.Peerbook do {:ok, peerbook} = fetch_peerbook() peerbook end + + defp penalazing_score() do + :lambda_ethereum_consensus + |> Application.get_env(__MODULE__) + |> Keyword.get(:penalizing_score, @penalizing_score) + end end