Skip to content

Commit 788e1c6

Browse files
authored
fix: re-sync on drifted head + sentry alert (#1332)
1 parent 988b261 commit 788e1c6

File tree

4 files changed

+46
-12
lines changed

4 files changed

+46
-12
lines changed

Makefile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,38 +166,39 @@ test-iex:
166166
# NODE RUNNERS
167167
DISCOVERY_PORT ?= 9009
168168
METRICS_PORT ?= 9568
169+
MODE ?= full
169170

170171
#▶️ mainnet: @ Run an interactive terminal using checkpoint sync for mainnet.
171172
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)
173+
iex -S mix run -- --checkpoint-sync-url https://mainnet-checkpoint-sync.stakely.io/ --metrics --metrics-port $(METRICS_PORT) --discovery-port $(DISCOVERY_PORT) --mode $(MODE)
173174

174175
#▶️ mainnet.logfile: @ Run an interactive terminal using checkpoint sync for mainnet with a log file.
175176
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)
177+
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)
177178

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

182183
#▶️ sepolia.logfile: @ Run an interactive terminal using sepolia network with a log file
183184
sepolia.logfile: compile-all
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)
185+
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)
185186

186187
#▶️ holesky: @ Run an interactive terminal using holesky network
187188
holesky: compile-all
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)
189+
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)
189190

190191
#▶️ holesky.logfile: @ Run an interactive terminal using holesky network with a log file
191192
holesky.logfile: compile-all
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)
193+
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)
193194

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

198199
#▶️ gnosis.logfile: @ Run an interactive terminal using gnosis network with a log file
199200
gnosis.logfile: compile-all
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+
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)
201202

202203
#▶️ checkpoint-sync: @ Run an interactive terminal using checkpoint sync for mainnet.
203204
checkpoint-sync: mainnet

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ In that case, you can use [eFlambè](https://github.com/Stratus3D/eflambe) to ge
449449
The following code will capture information from 10 calls to `Handlers.on_block/2`, dumping it in different files named \<timestamp\>-eflambe-output.bggg.
450450

451451
```elixir
452-
:eflambe.capture({LambdaEthereumConsensus.ForkChoice.Handlers, :on_block, 2}, 10)
452+
:eflambe.capture({LambdaEthereumConsensus.ForkChoice, :on_block, 2}, 2)
453453
```
454454

455455
The files generated can be processed via common flamegraph tools.

lib/lambda_ethereum_consensus/application.ex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ defmodule LambdaEthereumConsensus.Application do
3333
:ok
3434
end
3535

36-
defp get_children(:db) do
36+
defp get_children(:mixed) do
3737
CheckpointStates.new()
3838

3939
[
@@ -43,8 +43,15 @@ defmodule LambdaEthereumConsensus.Application do
4343
]
4444
end
4545

46+
defp get_children(:db) do
47+
get_children(:mixed) ++
48+
[
49+
{Task.Supervisor, name: StoreStatesSupervisor}
50+
]
51+
end
52+
4653
defp get_children(:full) do
47-
get_children(:db) ++
54+
get_children(:mixed) ++
4855
[
4956
BeaconApi.Endpoint,
5057
KeyStoreApi.Endpoint,

lib/libp2p_port.ex

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ defmodule LambdaEthereumConsensus.Libp2pPort do
8484

8585
@tick_time 1000
8686
@sync_delay_millis 15_000
87+
@head_drift_alert 12
8788

8889
######################
8990
### API
@@ -792,9 +793,34 @@ defmodule LambdaEthereumConsensus.Libp2pPort do
792793

793794
maybe_log_new_slot(slot_data, new_slot_data)
794795

795-
updated_state |> Map.put(:store, new_store)
796+
updated_state
797+
|> Map.put(:store, new_store)
798+
|> update_syncing_status(new_slot_data, new_store)
796799
end
797800

801+
defp update_syncing_status(%{syncing: false} = state, {slot, _third}, %Types.Store{
802+
head_slot: head_slot
803+
})
804+
when slot - head_slot >= @head_drift_alert do
805+
Logger.error("[Libp2p] Head slot drifted by #{slot - head_slot} slots.")
806+
807+
# TODO: (#1194) This is a temporary fix to avoid the drift alert to be triggered and the resync to kick in
808+
# when the node is not fully synced. We should have a better way to handle this.
809+
Process.send_after(self(), :sync_blocks, 500)
810+
811+
%{state | syncing: true}
812+
end
813+
814+
defp update_syncing_status(
815+
%{syncing: true, blocks_remaining: 0} = state,
816+
{slot, _third},
817+
%Types.Store{head_slot: head_slot}
818+
)
819+
when slot - head_slot == 0,
820+
do: %{state | syncing: false}
821+
822+
defp update_syncing_status(state, _slot_data, _), do: state
823+
798824
defp schedule_next_tick() do
799825
# For millisecond precision
800826
time_to_next_tick = @tick_time - rem(:os.system_time(:millisecond), @tick_time)

0 commit comments

Comments
 (0)