Skip to content

Commit 1c46f3e

Browse files
authored
chore: peerbook penalization config + node start fix (#1329)
1 parent 3e7ce05 commit 1c46f3e

File tree

4 files changed

+41
-18
lines changed

4 files changed

+41
-18
lines changed

Makefile

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,39 +164,43 @@ test-iex:
164164

165165
##################
166166
# NODE RUNNERS
167-
DYSCOVERY_PORT ?= 30303
167+
DISCOVERY_PORT ?= 9009
168+
METRICS_PORT ?= 9568
168169

169-
#▶️ checkpoint-sync: @ Run an interactive terminal using checkpoint sync.
170-
checkpoint-sync: compile-all
171-
iex -S mix run -- --checkpoint-sync-url https://mainnet-checkpoint-sync.stakely.io/ --metrics --discovery-port $(DYSCOVERY_PORT)
170+
#▶️ mainnet: @ Run an interactive terminal using checkpoint sync for mainnet.
171+
mainnet: compile-all
172+
iex -S mix run -- --checkpoint-sync-url https://mainnet-checkpoint-sync.stakely.io/ --metrics --metrics-port $(METRICS_PORT) --discovery-port $(DISCOVERY_PORT)
172173

173-
#▶️ checkpoint-sync.logfile: @ Run an interactive terminal using checkpoint sync with a log file.
174-
checkpoint-sync.logfile: compile-all
175-
iex -S mix run -- --checkpoint-sync-url https://mainnet-checkpoint-sync.stakely.io/ --metrics --log-file ./logs/mainnet.log --discovery-port $(DYSCOVERY_PORT)
174+
#▶️ mainnet.logfile: @ Run an interactive terminal using checkpoint sync for mainnet with a log file.
175+
mainnet.logfile: compile-all
176+
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)
176177

177178
#▶️ sepolia: @ Run an interactive terminal using sepolia network
178179
sepolia: compile-all
179-
iex -S mix run -- --checkpoint-sync-url https://sepolia.beaconstate.info --network sepolia --metrics --discovery-port $(DYSCOVERY_PORT)
180+
iex -S mix run -- --checkpoint-sync-url https://sepolia.beaconstate.info --network sepolia --metrics --metrics-port $(METRICS_PORT) --discovery-port $(DISCOVERY_PORT)
180181

181182
#▶️ sepolia.logfile: @ Run an interactive terminal using sepolia network with a log file
182183
sepolia.logfile: compile-all
183-
iex -S mix run -- --checkpoint-sync-url https://sepolia.beaconstate.info --network sepolia --metrics --log-file ./logs/sepolia.log --discovery-port $(DYSCOVERY_PORT)
184+
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)
184185

185186
#▶️ holesky: @ Run an interactive terminal using holesky network
186187
holesky: compile-all
187-
iex -S mix run -- --checkpoint-sync-url https://checkpoint-sync.holesky.ethpandaops.io --network holesky --discovery-port $(DYSCOVERY_PORT)
188+
iex -S mix run -- --checkpoint-sync-url https://checkpoint-sync.holesky.ethpandaops.io --network holesky --metrics --metrics-port $(METRICS_PORT) --discovery-port $(DISCOVERY_PORT)
188189

189190
#▶️ holesky.logfile: @ Run an interactive terminal using holesky network with a log file
190191
holesky.logfile: compile-all
191-
iex -S mix run -- --checkpoint-sync-url https://checkpoint-sync.holesky.ethpandaops.io --network holesky --log-file ./logs/holesky.log --discovery-port $(DYSCOVERY_PORT)
192+
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)
192193

193194
#▶️ gnosis: @ Run an interactive terminal using gnosis network
194195
gnosis: compile-all
195-
iex -S mix run -- --checkpoint-sync-url https://checkpoint.gnosischain.com --network gnosis --discovery-port $(DYSCOVERY_PORT)
196+
iex -S mix run -- --checkpoint-sync-url https://checkpoint.gnosischain.com --network gnosis --metrics --metrics-port $(METRICS_PORT) --discovery-port $(DISCOVERY_PORT)
196197

197198
#▶️ gnosis.logfile: @ Run an interactive terminal using gnosis network with a log file
198199
gnosis.logfile: compile-all
199-
iex -S mix run -- --checkpoint-sync-url https://checkpoint.gnosischain.com --network gnosis --log-file ./logs/gnosis.log --discovery-port $(DYSCOVERY_PORT)
200+
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)
201+
202+
#▶️ checkpoint-sync: @ Run an interactive terminal using checkpoint sync for mainnet.
203+
checkpoint-sync: mainnet
200204

201205
#🔴 test: @ Run tests
202206
test: compile-all

config/runtime.exs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,15 @@ if dsn do
259259

260260
config :sentry, dsn: dsn, release: String.trim(git_sha)
261261
end
262+
263+
# Peerbook penalization
264+
265+
penalizing_score =
266+
case network do
267+
"sepolia" -> 20
268+
"mainnet" -> 50
269+
_ -> 30
270+
end
271+
272+
config :lambda_ethereum_consensus, LambdaEthereumConsensus.P2P.Peerbook,
273+
penalizing_score: penalizing_score

lib/lambda_ethereum_consensus/beacon/checkpoint_sync.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defmodule LambdaEthereumConsensus.Beacon.CheckpointSync do
1919
def get_finalized_block_and_state(url, genesis_validators_root) do
2020
tasks = [Task.async(__MODULE__, :get_state, [url]), Task.async(__MODULE__, :get_block, [url])]
2121

22-
case Task.await_many(tasks, 60_000) do
22+
case Task.await_many(tasks, 90_000) do
2323
[{:ok, state}, {:ok, block}] ->
2424
if state.genesis_validators_root == genesis_validators_root do
2525
check_match(url, state, block)
@@ -92,8 +92,8 @@ defmodule LambdaEthereumConsensus.Beacon.CheckpointSync do
9292
defp get_json_from_url(base_url, path) do
9393
full_url = concat_url(base_url, path)
9494

95-
with {:ok, response} <- get(full_url) do
96-
{:ok, response.body |> Map.fetch!("data") |> parse_json()}
95+
with {:ok, %{body: %{"data" => data}}} <- get(full_url) do
96+
{:ok, parse_json(data)}
9797
end
9898
end
9999

lib/lambda_ethereum_consensus/p2p/peerbook.ex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ defmodule LambdaEthereumConsensus.P2P.Peerbook do
6363
Logger.debug("[Peerbook] Penalizing peer: #{inspect(Utils.format_shorten_binary(peer_id))}")
6464

6565
peer_score = fetch_peerbook!() |> Map.get(peer_id)
66+
penalizing_score = penalazing_score()
6667

6768
case peer_score do
6869
nil ->
6970
:ok
7071

71-
score when score - @penalizing_score <= 0 ->
72+
score when score - penalizing_score <= 0 ->
7273
Logger.debug("[Peerbook] Removing peer: #{inspect(Utils.format_shorten_binary(peer_id))}")
7374

7475
fetch_peerbook!()
@@ -77,7 +78,7 @@ defmodule LambdaEthereumConsensus.P2P.Peerbook do
7778

7879
score ->
7980
fetch_peerbook!()
80-
|> Map.put(peer_id, score - @penalizing_score)
81+
|> Map.put(peer_id, score - penalizing_score)
8182
|> store_peerbook()
8283
end
8384
end
@@ -142,4 +143,10 @@ defmodule LambdaEthereumConsensus.P2P.Peerbook do
142143
{:ok, peerbook} = fetch_peerbook()
143144
peerbook
144145
end
146+
147+
defp penalazing_score() do
148+
:lambda_ethereum_consensus
149+
|> Application.get_env(__MODULE__)
150+
|> Keyword.get(:penalizing_score, @penalizing_score)
151+
end
145152
end

0 commit comments

Comments
 (0)