Skip to content

Commit

Permalink
chore: peerbook penalization config + node start fix (#1329)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-o authored Oct 14, 2024
1 parent 3e7ce05 commit 1c46f3e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
30 changes: 17 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions lib/lambda_ethereum_consensus/beacon/checkpoint_sync.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
11 changes: 9 additions & 2 deletions lib/lambda_ethereum_consensus/p2p/peerbook.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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!()
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 1c46f3e

Please sign in to comment.