Skip to content

Commit

Permalink
refactor: improve checkpoint-sync algorithm (#1277)
Browse files Browse the repository at this point in the history
  • Loading branch information
avilagaston9 authored Aug 19, 2024
1 parent 43a40d4 commit eab7a05
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/lambda_ethereum_consensus/beacon/store_setup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule LambdaEthereumConsensus.Beacon.StoreSetup do
end

@doc """
Gets a {store, genesis_validators_root} tuple with the configured strategy.
Gets a store with the configured strategy.
"""
@spec setup!() :: Store.t()
def setup!(), do: setup!(get_strategy!())
Expand Down
6 changes: 2 additions & 4 deletions lib/lambda_ethereum_consensus/beacon/sync_blocks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ defmodule LambdaEthereumConsensus.Beacon.SyncBlocks do
alias LambdaEthereumConsensus.ForkChoice
alias LambdaEthereumConsensus.Libp2pPort
alias LambdaEthereumConsensus.P2P.BlockDownloader
alias LambdaEthereumConsensus.StateTransition.Misc

@blocks_per_chunk 16
@retries 50
Expand All @@ -23,9 +22,8 @@ defmodule LambdaEthereumConsensus.Beacon.SyncBlocks do
"""
@spec run() :: non_neg_integer()
def run() do
# Initial sleep for faster app start
checkpoint = ForkChoice.get_finalized_checkpoint()
initial_slot = Misc.compute_start_slot_at_epoch(checkpoint.epoch) + 1
%{head_slot: head_slot} = ForkChoice.get_current_status_message()
initial_slot = head_slot + 1
last_slot = ForkChoice.get_current_chain_slot()

# If we're around genesis, we consider ourselves synced
Expand Down
2 changes: 1 addition & 1 deletion lib/lambda_ethereum_consensus/fork_choice/fork_choice.ex
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ defmodule LambdaEthereumConsensus.ForkChoice do
Logger.info("Pruning states before slot #{new_finalized_epoch}")

new_finalized_slot =
new_finalized_epoch * ChainSpec.get("SLOTS_PER_EPOCH")
Misc.compute_start_slot_at_epoch(new_finalized_epoch)

Task.Supervisor.start_child(
PruneStatesSupervisor,
Expand Down

0 comments on commit eab7a05

Please sign in to comment.