Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-o committed Oct 16, 2024
1 parent e3d47ab commit 13a5bc1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
3 changes: 3 additions & 0 deletions lib/beacon_api/controllers/error_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule BeaconApi.ErrorController do
@spec bad_request(Plug.Conn.t(), binary()) :: Plug.Conn.t()
def bad_request(conn, message) do
Logger.error("Bad request: #{message}, path: #{conn.request_path}")

conn
|> put_status(400)
|> json(%{
Expand All @@ -16,6 +17,7 @@ defmodule BeaconApi.ErrorController do
@spec not_found(Plug.Conn.t(), any) :: Plug.Conn.t()
def not_found(conn, _params) do
Logger.error("Not found resource, path: #{conn.request_path}")

conn
|> put_status(404)
|> json(%{
Expand All @@ -27,6 +29,7 @@ defmodule BeaconApi.ErrorController do
@spec internal_error(Plug.Conn.t(), any) :: Plug.Conn.t()
def internal_error(conn, _params) do
Logger.error("Internal server error, path: #{conn.request_path}")

conn
|> put_status(500)
|> json(%{
Expand Down
20 changes: 11 additions & 9 deletions lib/beacon_api/controllers/v1/config_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ defmodule BeaconApi.V1.ConfigController do
require Logger

alias BeaconApi.ApiSpec
alias BeaconApi.ErrorController
alias BeaconApi.Helpers
alias BeaconApi.Utils
alias LambdaEthereumConsensus.Store.BlockBySlot
alias LambdaEthereumConsensus.Store.Blocks
alias LambdaEthereumConsensus.Store.StoreDb

plug(OpenApiSpex.Plug.CastAndValidate, json_render_error_v2: true)

@chain_spec_removed_keys ["ATTESTATION_SUBNET_COUNT", "KZG_COMMITMENT_INCLUSION_PROOF_DEPTH", "UPDATE_TIMEOUT"]
@chain_spec_renamed_keys [{"MAXIMUM_GOSSIP_CLOCK_DISPARITY", "MAXIMUM_GOSSIP_CLOCK_DISPARITY_MILLIS"}]
@chain_spec_removed_keys [
"ATTESTATION_SUBNET_COUNT",
"KZG_COMMITMENT_INCLUSION_PROOF_DEPTH",
"UPDATE_TIMEOUT"
]
@chain_spec_renamed_keys [
{"MAXIMUM_GOSSIP_CLOCK_DISPARITY", "MAXIMUM_GOSSIP_CLOCK_DISPARITY_MILLIS"}
]
@chain_spec_hex_fields [
"TERMINAL_BLOCK_HASH",
"GENESIS_FORK_VERSION",
Expand All @@ -24,7 +25,7 @@ defmodule BeaconApi.V1.ConfigController do
"ELECTRA_FORK_VERSION",
"DEPOSIT_CONTRACT_ADDRESS",
"MESSAGE_DOMAIN_INVALID_SNAPPY",
"MESSAGE_DOMAIN_VALID_SNAPPY",
"MESSAGE_DOMAIN_VALID_SNAPPY"
]

# NOTE: this function is required by OpenApiSpex, and should return the information
Expand All @@ -49,7 +50,8 @@ defmodule BeaconApi.V1.ConfigController do
end

defp rename_keys(config, renamed_keys) do
renamed_keys |> Enum.reduce(config, fn {old_key, new_key}, config ->
renamed_keys
|> Enum.reduce(config, fn {old_key, new_key}, config ->
case Map.get(config, old_key) do
nil -> config
value -> Map.put_new(config, new_key, value) |> Map.delete(old_key)
Expand Down
16 changes: 9 additions & 7 deletions lib/beacon_api/controllers/v1/node_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ defmodule BeaconApi.V1.NodeController do
sync_distance: sync_distance
} = SyncBlocks.status()

json(conn, %{"data" => %{
"is_syncing" => is_syncing,
"is_optimistic" => is_optimistic,
"el_offline" => el_offline,
"head_slot" => head_slot |> Integer.to_string(),
"sync_distance" => sync_distance |> Integer.to_string()
}})
json(conn, %{
"data" => %{
"is_syncing" => is_syncing,
"is_optimistic" => is_optimistic,
"el_offline" => el_offline,
"head_slot" => head_slot |> Integer.to_string(),
"sync_distance" => sync_distance |> Integer.to_string()
}
})
end
end
6 changes: 4 additions & 2 deletions lib/lambda_ethereum_consensus/beacon/sync_blocks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ defmodule LambdaEthereumConsensus.Beacon.SyncBlocks do
distance = last_slot - initial_slot + 1
syncing? = distance > 0

%{is_syncing: syncing?,
%{
is_syncing: syncing?,
is_optimistic: syncing?,
el_offline: false,
head_slot: head_slot,
sync_distance: distance}
sync_distance: distance
}
end
end

0 comments on commit 13a5bc1

Please sign in to comment.