From da40a46f5c48e913b62157b70f231a0ba5611523 Mon Sep 17 00:00:00 2001 From: Rodrigo Oliveri Date: Mon, 14 Oct 2024 15:18:02 -0300 Subject: [PATCH 1/6] small fix for block_procesing.exs execution --- Makefile | 17 +++++++++-------- lib/lambda_ethereum_consensus/application.ex | 10 ++++++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index c9fd95d65..eb9776069 100644 --- a/Makefile +++ b/Makefile @@ -166,38 +166,39 @@ test-iex: # NODE RUNNERS DISCOVERY_PORT ?= 9009 METRICS_PORT ?= 9568 +MODE ?= full #▶️ 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) + iex -S mix run -- --checkpoint-sync-url https://mainnet-checkpoint-sync.stakely.io/ --metrics --metrics-port $(METRICS_PORT) --discovery-port $(DISCOVERY_PORT) --mode $(MODE) #▶️ 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) + 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) --mode $(MODE) #▶️ 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 --metrics-port $(METRICS_PORT) --discovery-port $(DISCOVERY_PORT) + iex -S mix run -- --checkpoint-sync-url https://sepolia.beaconstate.info --network sepolia --metrics --metrics-port $(METRICS_PORT) --discovery-port $(DISCOVERY_PORT) --mode $(MODE) #▶️ 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 --metrics-port $(METRICS_PORT) --log-file ./logs/sepolia.log --discovery-port $(DISCOVERY_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) --mode $(MODE) #▶️ 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 --metrics --metrics-port $(METRICS_PORT) --discovery-port $(DISCOVERY_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) --mode $(MODE) #▶️ 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 --metrics --metrics-port $(METRICS_PORT) --discovery-port $(DISCOVERY_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) --mode $(MODE) #▶️ gnosis: @ Run an interactive terminal using gnosis network gnosis: compile-all - iex -S mix run -- --checkpoint-sync-url https://checkpoint.gnosischain.com --network gnosis --metrics --metrics-port $(METRICS_PORT) --discovery-port $(DISCOVERY_PORT) + iex -S mix run -- --checkpoint-sync-url https://checkpoint.gnosischain.com --network gnosis --metrics --metrics-port $(METRICS_PORT) --discovery-port $(DISCOVERY_PORT) --mode $(MODE) #▶️ 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 --metrics --metrics-port $(METRICS_PORT) --log-file ./logs/gnosis.log --discovery-port $(DISCOVERY_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) --mode $(MODE) #▶️ checkpoint-sync: @ Run an interactive terminal using checkpoint sync for mainnet. checkpoint-sync: mainnet diff --git a/lib/lambda_ethereum_consensus/application.ex b/lib/lambda_ethereum_consensus/application.ex index dc89954be..41607a126 100644 --- a/lib/lambda_ethereum_consensus/application.ex +++ b/lib/lambda_ethereum_consensus/application.ex @@ -33,7 +33,7 @@ defmodule LambdaEthereumConsensus.Application do :ok end - defp get_children(:db) do + defp get_children(:mixed) do CheckpointStates.new() [ @@ -43,8 +43,14 @@ defmodule LambdaEthereumConsensus.Application do ] end + defp get_children(:db) do + get_children(:mixed) ++ [ + {Task.Supervisor, name: StoreStatesSupervisor} + ] + end + defp get_children(:full) do - get_children(:db) ++ + get_children(:mixed) ++ [ BeaconApi.Endpoint, KeyStoreApi.Endpoint, From 1b496cc1864bfae903db8ef7599bc184d4c94c16 Mon Sep 17 00:00:00 2001 From: Rodrigo Oliveri Date: Mon, 14 Oct 2024 16:13:31 -0300 Subject: [PATCH 2/6] Point the eflambe line in the Readme to the correct function --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d20cdf25..ce1415037 100644 --- a/README.md +++ b/README.md @@ -449,7 +449,7 @@ In that case, you can use [eFlambè](https://github.com/Stratus3D/eflambe) to ge The following code will capture information from 10 calls to `Handlers.on_block/2`, dumping it in different files named \-eflambe-output.bggg. ```elixir -:eflambe.capture({LambdaEthereumConsensus.ForkChoice.Handlers, :on_block, 2}, 10) +:eflambe.capture({LambdaEthereumConsensus.ForkChoice, :on_block, 2}, 2) ``` The files generated can be processed via common flamegraph tools. From 96681a552af8edef9dde9c2c3511047e4e16740d Mon Sep 17 00:00:00 2001 From: Rodrigo Oliveri Date: Mon, 14 Oct 2024 18:50:48 -0300 Subject: [PATCH 3/6] End the syncing state of the node when we are syncing and reach the tip --- lib/libp2p_port.ex | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/libp2p_port.ex b/lib/libp2p_port.ex index 48f5a7758..8f03dece3 100644 --- a/lib/libp2p_port.ex +++ b/lib/libp2p_port.ex @@ -84,6 +84,7 @@ defmodule LambdaEthereumConsensus.Libp2pPort do @tick_time 1000 @sync_delay_millis 15_000 + @head_drift_alert 12 ###################### ### API @@ -792,9 +793,24 @@ defmodule LambdaEthereumConsensus.Libp2pPort do maybe_log_new_slot(slot_data, new_slot_data) - updated_state |> Map.put(:store, new_store) + updated_state + |> Map.put(:store, new_store) + |> update_syncing_status(new_slot_data, new_store) end + defp update_syncing_status(%{syncing: false} = state, {slot, _third}, %Types.Store{head_slot: head_slot}) + when slot - head_slot >= @head_drift_alert do + Logger.error("[Libp2p] Head slot drifted by #{slot - head_slot} slots.") + + # TODO: (#1194) The node is not yet ready to resync but this allows to avoid spamming errors after a drift. + %{state | syncing: true} + end + + defp update_syncing_status(%{syncing: true, blocks_remaining: 0} = state, {slot, _third}, %Types.Store{head_slot: head_slot}) + when slot - head_slot == 0, do: %{state | syncing: false} + + defp update_syncing_status(state, _slot_data, _), do: state + defp schedule_next_tick() do # For millisecond precision time_to_next_tick = @tick_time - rem(:os.system_time(:millisecond), @tick_time) From 8faf7d6e6e43a618875573cab2db598976ee45d9 Mon Sep 17 00:00:00 2001 From: Rodrigo Oliveri Date: Mon, 14 Oct 2024 18:52:44 -0300 Subject: [PATCH 4/6] format --- lib/lambda_ethereum_consensus/application.ex | 7 ++++--- lib/libp2p_port.ex | 15 +++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/lambda_ethereum_consensus/application.ex b/lib/lambda_ethereum_consensus/application.ex index 41607a126..025f87ba8 100644 --- a/lib/lambda_ethereum_consensus/application.ex +++ b/lib/lambda_ethereum_consensus/application.ex @@ -44,9 +44,10 @@ defmodule LambdaEthereumConsensus.Application do end defp get_children(:db) do - get_children(:mixed) ++ [ - {Task.Supervisor, name: StoreStatesSupervisor} - ] + get_children(:mixed) ++ + [ + {Task.Supervisor, name: StoreStatesSupervisor} + ] end defp get_children(:full) do diff --git a/lib/libp2p_port.ex b/lib/libp2p_port.ex index 8f03dece3..63931d3a0 100644 --- a/lib/libp2p_port.ex +++ b/lib/libp2p_port.ex @@ -798,16 +798,23 @@ defmodule LambdaEthereumConsensus.Libp2pPort do |> update_syncing_status(new_slot_data, new_store) end - defp update_syncing_status(%{syncing: false} = state, {slot, _third}, %Types.Store{head_slot: head_slot}) - when slot - head_slot >= @head_drift_alert do + defp update_syncing_status(%{syncing: false} = state, {slot, _third}, %Types.Store{ + head_slot: head_slot + }) + when slot - head_slot >= @head_drift_alert do Logger.error("[Libp2p] Head slot drifted by #{slot - head_slot} slots.") # TODO: (#1194) The node is not yet ready to resync but this allows to avoid spamming errors after a drift. %{state | syncing: true} end - defp update_syncing_status(%{syncing: true, blocks_remaining: 0} = state, {slot, _third}, %Types.Store{head_slot: head_slot}) - when slot - head_slot == 0, do: %{state | syncing: false} + defp update_syncing_status( + %{syncing: true, blocks_remaining: 0} = state, + {slot, _third}, + %Types.Store{head_slot: head_slot} + ) + when slot - head_slot == 0, + do: %{state | syncing: false} defp update_syncing_status(state, _slot_data, _), do: state From 88eb2d27705390a929b49ff3fa619c7712b547f5 Mon Sep 17 00:00:00 2001 From: Rodrigo Oliveri Date: Tue, 15 Oct 2024 19:21:42 -0300 Subject: [PATCH 5/6] Testing resync as a solution to #1333 --- lib/libp2p_port.ex | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/libp2p_port.ex b/lib/libp2p_port.ex index 63931d3a0..58a7be7d2 100644 --- a/lib/libp2p_port.ex +++ b/lib/libp2p_port.ex @@ -84,7 +84,7 @@ defmodule LambdaEthereumConsensus.Libp2pPort do @tick_time 1000 @sync_delay_millis 15_000 - @head_drift_alert 12 + @head_drift_alert 4 ###################### ### API @@ -804,7 +804,10 @@ defmodule LambdaEthereumConsensus.Libp2pPort do when slot - head_slot >= @head_drift_alert do Logger.error("[Libp2p] Head slot drifted by #{slot - head_slot} slots.") - # TODO: (#1194) The node is not yet ready to resync but this allows to avoid spamming errors after a drift. + # TODO: (#1194) This is a temporary fix to avoid the drift alert to be triggered and the resync to kick in + # when the node is not fully synced. We should have a better way to handle this. + Process.send_after(self(), :sync_blocks, 500) + %{state | syncing: true} end From bcffd0780f9020bc3008ccda9dbd12d727b43cba Mon Sep 17 00:00:00 2001 From: Rodrigo Oliveri Date: Tue, 15 Oct 2024 19:26:49 -0300 Subject: [PATCH 6/6] Turned the head_drift_alert to 12 again --- lib/libp2p_port.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libp2p_port.ex b/lib/libp2p_port.ex index 58a7be7d2..ef30d1f68 100644 --- a/lib/libp2p_port.ex +++ b/lib/libp2p_port.ex @@ -84,7 +84,7 @@ defmodule LambdaEthereumConsensus.Libp2pPort do @tick_time 1000 @sync_delay_millis 15_000 - @head_drift_alert 4 + @head_drift_alert 12 ###################### ### API