Skip to content

Commit

Permalink
End the syncing state of the node when we are syncing and reach the tip
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-o committed Oct 14, 2024
1 parent 37fcb81 commit 96681a5
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/libp2p_port.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ defmodule LambdaEthereumConsensus.Libp2pPort do

@tick_time 1000
@sync_delay_millis 15_000
@head_drift_alert 12

######################
### API
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 96681a5

Please sign in to comment.