Skip to content

Commit

Permalink
refactor commands
Browse files Browse the repository at this point in the history
  • Loading branch information
karasakalmt committed Dec 6, 2023
1 parent 75ee8f7 commit 762597b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions lib/lambda_ethereum_consensus/fork_choice/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ defmodule LambdaEthereumConsensus.ForkChoice.Helpers do
alias SszTypes.Checkpoint
alias SszTypes.Store

@spec current_status_message() ::
@spec current_status_message(Store.t()) ::
{:ok, SszTypes.StatusMessage.t()} | {:error, any}
def current_status_message do
with head_root <- LambdaEthereumConsensus.ForkChoice.Store.get_head(),
def current_status_message(store) do
with {:ok, head_root} <- get_head(store),
{:ok, state} <- LambdaEthereumConsensus.Store.StateStore.get_state(head_root),
{:ok, signed_head_block} <-
LambdaEthereumConsensus.Store.BlockStore.get_block(head_root),
Expand Down
16 changes: 8 additions & 8 deletions lib/lambda_ethereum_consensus/fork_choice/store.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ defmodule LambdaEthereumConsensus.ForkChoice.Store do
div(time - genesis_time, ChainSpec.get("SECONDS_PER_SLOT"))
end

@spec get_head_root() :: SszTypes.root()
def get_head_root do
get_head()
@spec get_current_status_message() :: {:ok, SszTypes.StatusMessage.t()} | {:error, any}
def get_current_status_message do
get_current_status_message_from_store()
end

@spec has_block?(SszTypes.root()) :: boolean()
Expand Down Expand Up @@ -95,8 +95,8 @@ defmodule LambdaEthereumConsensus.ForkChoice.Store do
end

@impl GenServer
def handle_call({:get_head}, _from, state) do
{:reply, Helpers.get_head(state)}
def handle_call({:get_current_status_message}, _from, state) do
{:reply, Helpers.current_status_message(state)}
end

def handle_call({:get_block, block_root}, _from, state) do
Expand Down Expand Up @@ -195,9 +195,9 @@ defmodule LambdaEthereumConsensus.ForkChoice.Store do
GenServer.call(__MODULE__, {:get_store_attrs, attrs}, @default_timeout)
end

@spec get_head() :: SszTypes.root()
def get_head do
GenServer.call(__MODULE__, {:get_head}, @default_timeout)
@spec get_current_status_message_from_store() :: SszTypes.root()
def get_current_status_message_from_store do
GenServer.call(__MODULE__, {:get_current_status_message}, @default_timeout)
end

@spec on_tick_now(Store.t()) :: Store.t()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do
@spec handle_req(String.t(), String.t(), binary()) ::
:ok | :not_implemented | {:error, binary()}
defp handle_req("status/1/ssz_snappy", message_id, message) do
with {:ok, current_status} <-
LambdaEthereumConsensus.ForkChoice.Helpers.current_status_message(),
<<84, snappy_status::binary>> <- message,
with <<84, snappy_status::binary>> <- message,
{:ok, current_status} <-
LambdaEthereumConsensus.ForkChoice.Store.current_status_message(),
{:ok, ssz_status} <- Snappy.decompress(snappy_status),
{:ok, status} <- Ssz.from_ssz(ssz_status, SszTypes.StatusMessage),
status
Expand Down

0 comments on commit 762597b

Please sign in to comment.