From 13a5bc1abd83ec94f8bc3b2f134840e04c0b98e2 Mon Sep 17 00:00:00 2001 From: Rodrigo Oliveri Date: Wed, 16 Oct 2024 16:53:26 -0300 Subject: [PATCH] format --- .../controllers/error_controller.ex | 3 +++ .../controllers/v1/config_controller.ex | 20 ++++++++++--------- .../controllers/v1/node_controller.ex | 16 ++++++++------- .../beacon/sync_blocks.ex | 6 ++++-- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/lib/beacon_api/controllers/error_controller.ex b/lib/beacon_api/controllers/error_controller.ex index d7429659c..3faad5bc1 100644 --- a/lib/beacon_api/controllers/error_controller.ex +++ b/lib/beacon_api/controllers/error_controller.ex @@ -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(%{ @@ -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(%{ @@ -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(%{ diff --git a/lib/beacon_api/controllers/v1/config_controller.ex b/lib/beacon_api/controllers/v1/config_controller.ex index 84167ac1e..727442ea0 100644 --- a/lib/beacon_api/controllers/v1/config_controller.ex +++ b/lib/beacon_api/controllers/v1/config_controller.ex @@ -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", @@ -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 @@ -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) diff --git a/lib/beacon_api/controllers/v1/node_controller.ex b/lib/beacon_api/controllers/v1/node_controller.ex index 19fb1eab7..0c0447cfe 100644 --- a/lib/beacon_api/controllers/v1/node_controller.ex +++ b/lib/beacon_api/controllers/v1/node_controller.ex @@ -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 diff --git a/lib/lambda_ethereum_consensus/beacon/sync_blocks.ex b/lib/lambda_ethereum_consensus/beacon/sync_blocks.ex index 76778bcc2..b5273749f 100644 --- a/lib/lambda_ethereum_consensus/beacon/sync_blocks.ex +++ b/lib/lambda_ethereum_consensus/beacon/sync_blocks.ex @@ -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