Skip to content

Commit

Permalink
Merge branch 'main' into key_validate
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaRedHand authored Apr 23, 2024
2 parents b404ff9 + d2728c3 commit 1c2047d
Show file tree
Hide file tree
Showing 112 changed files with 450 additions and 334 deletions.
2 changes: 1 addition & 1 deletion .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
{Credo.Check.Readability.ModuleDoc, []},
{Credo.Check.Readability.ModuleNames, []},
{Credo.Check.Readability.ParenthesesInCondition, []},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, [parens: true]},
{Credo.Check.Readability.PipeIntoAnonymousFunctions, []},
{Credo.Check.Readability.PredicateFunctionNames, []},
{Credo.Check.Readability.PreferImplicitTry, []},
Expand Down
2 changes: 1 addition & 1 deletion lib/beacon_api/api_spec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ defmodule BeaconApi.ApiSpec do
|> OpenApiSpex.OpenApi.Decode.decode()

@impl OpenApi
def spec, do: @ethspec
def spec(), do: @ethspec
end
4 changes: 2 additions & 2 deletions lib/beacon_api/beacon_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule BeaconApi do
those modules here.
"""

def router do
def router() do
quote do
use Phoenix.Router, helpers: false

Expand All @@ -27,7 +27,7 @@ defmodule BeaconApi do
end
end

def controller do
def controller() do
quote do
use Phoenix.Controller,
formats: [:json]
Expand Down
6 changes: 3 additions & 3 deletions lib/chain_spec/chain_spec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ defmodule ChainSpec do
Single entrypoint for fetching chain-specific constants.
"""

def get_config,
def get_config(),
do: Application.fetch_env!(:lambda_ethereum_consensus, __MODULE__) |> Keyword.fetch!(:config)

def get_preset, do: get_config().get("PRESET_BASE") |> String.to_atom()
def get_preset(), do: get_config().get("PRESET_BASE") |> String.to_atom()

def get_fork_version_for_epoch(epoch) do
if epoch >= get("DENEB_FORK_EPOCH") do
Expand All @@ -19,7 +19,7 @@ defmodule ChainSpec do
# NOTE: this only works correctly for Capella
def get(name), do: get_config().get(name)

def get_genesis_validators_root do
def get_genesis_validators_root() do
Application.fetch_env!(:lambda_ethereum_consensus, __MODULE__)
|> Keyword.fetch!(:genesis_validators_root)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/chain_spec/configs/custom.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule CustomConfig do
end

@impl GenConfig
def get_all do
def get_all() do
Application.get_env(:lambda_ethereum_consensus, __MODULE__)
|> Keyword.fetch!(:merged)
|> Map.new(fn {k, v} -> {k, parse_int(v)} end)
Expand Down
2 changes: 1 addition & 1 deletion lib/chain_spec/configs/gen_config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule ChainSpec.GenConfig do
def get(key), do: Map.fetch!(@__unified, key)

@impl unquote(__MODULE__)
def get_all, do: @__unified
def get_all(), do: @__unified
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/chain_spec/configs/gnosis.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ defmodule GnosisConfig do
genesis_validators_root =
Base.decode16!("F5DCB5564E829AAB27264B9BECD5DFAA017085611224CB3036F573368DBB9D47")

def genesis_validators_root, do: unquote(genesis_validators_root)
def genesis_validators_root(), do: unquote(genesis_validators_root)
end
2 changes: 1 addition & 1 deletion lib/chain_spec/configs/holesky.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ defmodule HoleskyConfig do
genesis_validators_root =
Base.decode16!("9143AA7C615A7F7115E2B6AAC319C03529DF8242AE705FBA9DF39B79C59FA8B1")

def genesis_validators_root, do: unquote(genesis_validators_root)
def genesis_validators_root(), do: unquote(genesis_validators_root)
end
2 changes: 1 addition & 1 deletion lib/chain_spec/configs/mainnet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ defmodule MainnetConfig do
genesis_validators_root =
Base.decode16!("4B363DB94E286120D76EB905340FDD4E54BFE9F06BF33FF6CF5AD27F511BFE95")

def genesis_validators_root, do: unquote(genesis_validators_root)
def genesis_validators_root(), do: unquote(genesis_validators_root)
end
2 changes: 1 addition & 1 deletion lib/chain_spec/configs/minimal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ defmodule MinimalConfig do
"""
use ChainSpec.GenConfig, file: "config/networks/minimal/config.yaml"

def genesis_validators_root, do: <<0::256>>
def genesis_validators_root(), do: <<0::256>>
end
2 changes: 1 addition & 1 deletion lib/chain_spec/configs/sepolia.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ defmodule SepoliaConfig do
genesis_validators_root =
Base.decode16!("D8EA171F3C94AEA21EBC42A1ED61052ACF3F9209C00E4EFBAADDAC09ED9B8078")

def genesis_validators_root, do: unquote(genesis_validators_root)
def genesis_validators_root(), do: unquote(genesis_validators_root)
end
2 changes: 1 addition & 1 deletion lib/chain_spec/presets/gen_preset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule ChainSpec.GenPreset do
@behaviour unquote(__MODULE__)

@impl unquote(__MODULE__)
def get_preset, do: @__parsed_preset
def get_preset(), do: @__parsed_preset
end
end

Expand Down
74 changes: 37 additions & 37 deletions lib/constants.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,126 +7,126 @@ defmodule Constants do
### Misc

@spec genesis_epoch() :: Types.slot()
def genesis_epoch, do: 0
def genesis_epoch(), do: 0

@spec genesis_slot() :: Types.slot()
def genesis_slot, do: 0
def genesis_slot(), do: 0

@far_future_epoch 2 ** 64 - 1

@spec far_future_epoch() :: non_neg_integer()
def far_future_epoch, do: @far_future_epoch
def far_future_epoch(), do: @far_future_epoch

@spec base_rewards_per_epoch() :: non_neg_integer()
def base_rewards_per_epoch, do: 4
def base_rewards_per_epoch(), do: 4

@spec deposit_contract_tree_depth() :: non_neg_integer()
def deposit_contract_tree_depth, do: 32
def deposit_contract_tree_depth(), do: 32

@spec justification_bits_length() :: non_neg_integer()
def justification_bits_length, do: 4
def justification_bits_length(), do: 4

@spec endianness() :: atom()
def endianness, do: :little
def endianness(), do: :little

@spec participation_flag_weights() :: list(non_neg_integer())
def participation_flag_weights,
def participation_flag_weights(),
do: [timely_source_weight(), timely_target_weight(), timely_head_weight()]

@spec target_aggregators_per_committee() :: non_neg_integer()
def target_aggregators_per_committee, do: 16
def target_aggregators_per_committee(), do: 16

### Withdrawal prefixes

@spec bls_withdrawal_prefix() :: Types.bytes1()
def bls_withdrawal_prefix, do: <<0>>
def bls_withdrawal_prefix(), do: <<0>>

@spec eth1_address_withdrawal_prefix() :: Types.bytes1()
def eth1_address_withdrawal_prefix, do: <<1>>
def eth1_address_withdrawal_prefix(), do: <<1>>

### Domain types

@spec domain_beacon_proposer() :: Types.domain_type()
def domain_beacon_proposer, do: <<0, 0, 0, 0>>
def domain_beacon_proposer(), do: <<0, 0, 0, 0>>

@spec domain_beacon_attester() :: Types.domain_type()
def domain_beacon_attester, do: <<1, 0, 0, 0>>
def domain_beacon_attester(), do: <<1, 0, 0, 0>>

@spec domain_randao() :: Types.domain_type()
def domain_randao, do: <<2, 0, 0, 0>>
def domain_randao(), do: <<2, 0, 0, 0>>

@spec domain_deposit() :: Types.domain_type()
def domain_deposit, do: <<3, 0, 0, 0>>
def domain_deposit(), do: <<3, 0, 0, 0>>

@spec domain_voluntary_exit() :: Types.domain_type()
def domain_voluntary_exit, do: <<4, 0, 0, 0>>
def domain_voluntary_exit(), do: <<4, 0, 0, 0>>

@spec domain_selection_proof() :: Types.domain_type()
def domain_selection_proof, do: <<5, 0, 0, 0>>
def domain_selection_proof(), do: <<5, 0, 0, 0>>

@spec domain_aggregate_and_proof() :: Types.domain_type()
def domain_aggregate_and_proof, do: <<6, 0, 0, 0>>
def domain_aggregate_and_proof(), do: <<6, 0, 0, 0>>

@spec domain_application_mask() :: Types.domain_type()
def domain_application_mask, do: <<0, 0, 0, 1>>
def domain_application_mask(), do: <<0, 0, 0, 1>>

@spec domain_sync_committee() :: Types.domain_type()
def domain_sync_committee, do: <<7, 0, 0, 0>>
def domain_sync_committee(), do: <<7, 0, 0, 0>>

@spec domain_sync_committee_selection_proof() :: Types.domain_type()
def domain_sync_committee_selection_proof, do: <<8, 0, 0, 0>>
def domain_sync_committee_selection_proof(), do: <<8, 0, 0, 0>>

@spec domain_contribution_and_proof() :: Types.domain_type()
def domain_contribution_and_proof, do: <<9, 0, 0, 0>>
def domain_contribution_and_proof(), do: <<9, 0, 0, 0>>

@spec domain_bls_to_execution_change() :: Types.domain_type()
def domain_bls_to_execution_change, do: <<10, 0, 0, 0>>
def domain_bls_to_execution_change(), do: <<10, 0, 0, 0>>

### Participation flag indices

@spec timely_source_flag_index() :: non_neg_integer()
def timely_source_flag_index, do: 0
def timely_source_flag_index(), do: 0

@spec timely_target_flag_index() :: non_neg_integer()
def timely_target_flag_index, do: 1
def timely_target_flag_index(), do: 1

@spec timely_head_flag_index() :: non_neg_integer()
def timely_head_flag_index, do: 2
def timely_head_flag_index(), do: 2

### Incentivization weights

@spec timely_source_weight() :: non_neg_integer()
def timely_source_weight, do: 14
def timely_source_weight(), do: 14

@spec timely_target_weight() :: non_neg_integer()
def timely_target_weight, do: 26
def timely_target_weight(), do: 26

@spec timely_head_weight() :: non_neg_integer()
def timely_head_weight, do: 14
def timely_head_weight(), do: 14

@spec sync_reward_weight() :: non_neg_integer()
def sync_reward_weight, do: 2
def sync_reward_weight(), do: 2

@spec proposer_weight() :: non_neg_integer()
def proposer_weight, do: 8
def proposer_weight(), do: 8

@spec weight_denominator() :: non_neg_integer()
def weight_denominator, do: 64
def weight_denominator(), do: 64

## Fork choice

@spec intervals_per_slot() :: non_neg_integer()
def intervals_per_slot, do: 3
def intervals_per_slot(), do: 3

@spec proposer_score_boost() :: non_neg_integer()
def proposer_score_boost, do: 3
def proposer_score_boost(), do: 3

@spec sync_committee_subnet_count() :: non_neg_integer()
def sync_committee_subnet_count, do: 4
def sync_committee_subnet_count(), do: 4

@spec bytes_per_field_element() :: Types.uint64()
def bytes_per_field_element, do: 32
def bytes_per_field_element(), do: 32

@spec versioned_hash_version_kzg() :: <<_::8>>
def versioned_hash_version_kzg, do: <<1>>
def versioned_hash_version_kzg(), do: <<1>>
end
2 changes: 1 addition & 1 deletion lib/lambda_ethereum_consensus/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ defmodule LambdaEthereumConsensus.Application do
]
end

defp get_operation_mode do
defp get_operation_mode() do
Application.fetch_env!(:lambda_ethereum_consensus, LambdaEthereumConsensus)
|> Keyword.fetch!(:mode)
end
Expand Down
18 changes: 9 additions & 9 deletions lib/lambda_ethereum_consensus/beacon/beacon_chain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ defmodule LambdaEthereumConsensus.Beacon.BeaconChain do
end

@spec get_current_slot() :: Types.slot()
def get_current_slot, do: GenServer.call(__MODULE__, :get_current_slot)
def get_current_slot(), do: GenServer.call(__MODULE__, :get_current_slot)

@spec get_genesis_time() :: Types.uint64()
def get_genesis_time, do: GenServer.call(__MODULE__, :get_genesis_time)
def get_genesis_time(), do: GenServer.call(__MODULE__, :get_genesis_time)

@spec update_fork_choice_cache(Types.root(), Types.slot(), Checkpoint.t(), Checkpoint.t()) ::
:ok
Expand All @@ -59,24 +59,24 @@ defmodule LambdaEthereumConsensus.Beacon.BeaconChain do
end

@spec get_finalized_checkpoint() :: Types.Checkpoint.t()
def get_finalized_checkpoint do
def get_finalized_checkpoint() do
%{finalized: finalized} = GenServer.call(__MODULE__, :get_fork_choice_cache)
finalized
end

@spec get_justified_checkpoint() :: Types.Checkpoint.t()
def get_justified_checkpoint do
def get_justified_checkpoint() do
%{justified: justified} = GenServer.call(__MODULE__, :get_fork_choice_cache)
justified
end

@spec get_current_epoch() :: integer()
def get_current_epoch do
def get_current_epoch() do
Misc.compute_epoch_at_slot(get_current_slot())
end

@spec get_fork_digest() :: Types.fork_digest()
def get_fork_digest do
def get_fork_digest() do
GenServer.call(__MODULE__, :get_fork_digest)
end

Expand All @@ -86,10 +86,10 @@ defmodule LambdaEthereumConsensus.Beacon.BeaconChain do
end

@spec get_fork_version() :: Types.version()
def get_fork_version, do: GenServer.call(__MODULE__, :get_fork_version)
def get_fork_version(), do: GenServer.call(__MODULE__, :get_fork_version)

@spec get_current_status_message() :: {:ok, Types.StatusMessage.t()} | {:error, any}
def get_current_status_message, do: GenServer.call(__MODULE__, :get_current_status_message)
def get_current_status_message(), do: GenServer.call(__MODULE__, :get_current_status_message)

##########################
### GenServer Callbacks
Expand Down Expand Up @@ -202,7 +202,7 @@ defmodule LambdaEthereumConsensus.Beacon.BeaconChain do
end
end

def schedule_next_tick do
def schedule_next_tick() do
# For millisecond precision
time_to_next_tick = 1000 - rem(:os.system_time(:millisecond), 1000)
Process.send_after(__MODULE__, :on_tick, time_to_next_tick)
Expand Down
Loading

0 comments on commit 1c2047d

Please sign in to comment.