Skip to content

chore: bump deps #713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions lib/beacon_api/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ defmodule BeaconApi.Utils do
"""
alias LambdaEthereumConsensus.ForkChoice.Helpers

@doc """
Checks if the value is 32 bytes and starting with "0x"
"""
@spec is_bytes32?(binary) :: boolean
def is_bytes32?(value) when is_binary(value) do
String.starts_with?(value, "0x") and byte_size(value) == 66
end

@spec parse_id(binary) :: Helpers.block_id()
def parse_id("genesis"), do: :genesis
def parse_id("justified"), do: :justified
Expand Down
8 changes: 4 additions & 4 deletions lib/lambda_ethereum_consensus/beacon/pending_blocks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ defmodule LambdaEthereumConsensus.Beacon.PendingBlocks do
GenServer.cast(__MODULE__, {:add_block, signed_block})
end

@spec is_pending_block(Types.root()) :: boolean()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im removing this on #709

def is_pending_block(block_root) do
GenServer.call(__MODULE__, {:is_pending_block, block_root})
@spec pending_block?(Types.root()) :: boolean()
def pending_block?(block_root) do
GenServer.call(__MODULE__, {:pending_block?, block_root})
end

##########################
Expand All @@ -56,7 +56,7 @@ defmodule LambdaEthereumConsensus.Beacon.PendingBlocks do
end

@impl true
def handle_call({:is_pending_block, block_root}, _from, state) do
def handle_call({:pending_block?, block_root}, _from, state) do
{:reply, Map.has_key?(state.pending_blocks, block_root), state}
end

Expand Down
8 changes: 4 additions & 4 deletions lib/lambda_ethereum_consensus/fork_choice/handlers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ defmodule LambdaEthereumConsensus.ForkChoice.Handlers do
end

defp check_valid_indexed_attestation(target_state, indexed_attestation) do
if Predicates.is_valid_indexed_attestation(target_state, indexed_attestation),
if Predicates.valid_indexed_attestation?(target_state, indexed_attestation),
do: :ok,
else: {:error, "invalid indexed attestation"}
end
Expand All @@ -137,13 +137,13 @@ defmodule LambdaEthereumConsensus.ForkChoice.Handlers do
state = BlockStates.get_state!(store.justified_checkpoint.root)

cond do
not Predicates.is_slashable_attestation_data(attestation_1.data, attestation_2.data) ->
not Predicates.slashable_attestation_data?(attestation_1.data, attestation_2.data) ->
{:error, "attestation is not slashable"}

not Predicates.is_valid_indexed_attestation(state, attestation_1) ->
not Predicates.valid_indexed_attestation?(state, attestation_1) ->
{:error, "attestation 1 is not valid"}

not Predicates.is_valid_indexed_attestation(state, attestation_2) ->
not Predicates.valid_indexed_attestation?(state, attestation_2) ->
{:error, "attestation 2 is not valid"}

true ->
Expand Down
4 changes: 2 additions & 2 deletions lib/lambda_ethereum_consensus/fork_choice/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ defmodule LambdaEthereumConsensus.ForkChoice.Helpers do
# If the previous epoch is justified, the block should be pulled-up. In this case, check that unrealized
# justification is higher than the store and that the voting source is not more than two epochs ago
correct_justified =
if not correct_justified and is_previous_epoch_justified(store) do
if not correct_justified and previous_epoch_justified?(store) do
store.unrealized_justifications[block_root].epoch >= store.justified_checkpoint.epoch and
voting_source.epoch + 2 >= current_epoch
else
Expand Down Expand Up @@ -171,7 +171,7 @@ defmodule LambdaEthereumConsensus.ForkChoice.Helpers do
end
end

def is_previous_epoch_justified(%Store{} = store) do
def previous_epoch_justified?(%Store{} = store) do
current_slot = Store.get_current_slot(store)
current_epoch = Misc.compute_epoch_at_slot(current_slot)
store.justified_checkpoint.epoch + 1 == current_epoch
Expand Down
10 changes: 5 additions & 5 deletions lib/lambda_ethereum_consensus/state_transition/accessors.ex
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ defmodule LambdaEthereumConsensus.StateTransition.Accessors do
compute_fn = fn ->
validators
|> Aja.Vector.with_index()
|> Aja.Vector.filter(fn {v, _} -> Predicates.is_active_validator(v, epoch) end)
|> Aja.Vector.filter(fn {v, _} -> Predicates.active_validator?(v, epoch) end)
|> Aja.Vector.map(fn {_, index} -> index end)
end

Expand Down Expand Up @@ -160,7 +160,7 @@ defmodule LambdaEthereumConsensus.StateTransition.Accessors do
participating_indices =
state.validators
|> Aja.Vector.zip_with(epoch_participation, fn v, participation ->
not v.slashed and Predicates.is_active_validator(v, epoch) and
not v.slashed and Predicates.active_validator?(v, epoch) and
Predicates.has_flag(participation, flag_index)
end)
|> Aja.Vector.with_index()
Expand Down Expand Up @@ -194,7 +194,7 @@ defmodule LambdaEthereumConsensus.StateTransition.Accessors do

Cache.lazily_compute(:total_active_balance, {epoch, root}, fn ->
state.validators
|> Stream.filter(&Predicates.is_active_validator(&1, epoch))
|> Stream.filter(&Predicates.active_validator?(&1, epoch))
|> Stream.map(fn %Validator{effective_balance: effective_balance} -> effective_balance end)
|> Enum.sum()
|> max(ChainSpec.get("EFFECTIVE_BALANCE_INCREMENT"))
Expand Down Expand Up @@ -232,7 +232,7 @@ defmodule LambdaEthereumConsensus.StateTransition.Accessors do
validators
|> Stream.with_index()
|> Stream.filter(fn {validator, _index} ->
Predicates.is_eligible_validator(validator, previous_epoch)
Predicates.eligible_validator?(validator, previous_epoch)
end)
|> Stream.map(fn {_validator, index} -> index end)
|> Enum.to_list()
Expand Down Expand Up @@ -284,7 +284,7 @@ defmodule LambdaEthereumConsensus.StateTransition.Accessors do
@spec get_active_validator_count(BeaconState.t(), Types.epoch()) :: Types.uint64()
def get_active_validator_count(%BeaconState{} = state, epoch) do
Cache.lazily_compute(:active_validator_count, {epoch, get_state_epoch_root(state)}, fn ->
Aja.Enum.count(state.validators, &Predicates.is_active_validator(&1, epoch))
Aja.Enum.count(state.validators, &Predicates.active_validator?(&1, epoch))
end)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ defmodule LambdaEthereumConsensus.StateTransition.EpochProcessing do
validators
|> Stream.with_index()
|> Stream.map(fn {v, i} ->
{{v, i}, Predicates.is_eligible_for_activation_queue(v),
Predicates.is_active_validator(v, current_epoch) and
{{v, i}, Predicates.eligible_for_activation_queue?(v),
Predicates.active_validator?(v, current_epoch) and
v.effective_balance <= ejection_balance}
end)
|> Stream.filter(&(elem(&1, 1) or elem(&1, 2)))
Expand All @@ -163,7 +163,7 @@ defmodule LambdaEthereumConsensus.StateTransition.EpochProcessing do
with {:ok, new_state} <- result do
new_state.validators
|> Stream.with_index()
|> Stream.filter(fn {v, _} -> Predicates.is_eligible_for_activation(state, v) end)
|> Stream.filter(fn {v, _} -> Predicates.eligible_for_activation?(state, v) end)
|> Enum.sort_by(fn {%{activation_eligibility_epoch: ep}, i} -> {ep, i} end)
|> Enum.slice(0..(churn_limit - 1))
|> Enum.reduce(new_state.validators, fn {v, i}, acc ->
Expand Down Expand Up @@ -223,21 +223,21 @@ defmodule LambdaEthereumConsensus.StateTransition.EpochProcessing do
{:ok, unslashed_participating_indices} =
Accessors.get_unslashed_participating_indices(state, timely_target_index, previous_epoch)

state_is_in_inactivity_leak = Predicates.is_in_inactivity_leak(state)
state_in_inactivity_leak? = Predicates.in_inactivity_leak?(state)

state.inactivity_scores
|> Stream.zip(state.validators)
|> Stream.with_index()
|> Enum.map(fn {{inactivity_score, validator}, index} ->
if Predicates.is_eligible_validator(validator, previous_epoch) do
if Predicates.eligible_validator?(validator, previous_epoch) do
inactivity_score
|> Misc.increase_inactivity_score(
index,
unslashed_participating_indices,
inactivity_score_bias
)
|> Misc.decrease_inactivity_score(
state_is_in_inactivity_leak,
state_in_inactivity_leak?,
inactivity_score_recovery_rate
)
else
Expand Down Expand Up @@ -323,7 +323,7 @@ defmodule LambdaEthereumConsensus.StateTransition.EpochProcessing do

state.validators
|> Aja.Vector.zip_with(epoch_participation, fn v, participation ->
{not v.slashed and Predicates.is_active_validator(v, epoch) and
{not v.slashed and Predicates.active_validator?(v, epoch) and
Predicates.has_flag(participation, flag_index), v.effective_balance}
end)
|> Aja.Vector.filter(&elem(&1, 0))
Expand Down
30 changes: 15 additions & 15 deletions lib/lambda_ethereum_consensus/state_transition/operations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ defmodule LambdaEthereumConsensus.StateTransition.Operations do
) do
cond do
# Verify consistency of the parent hash with respect to the previous execution payload header
Types.BeaconState.is_merge_transition_complete(state) and
Types.BeaconState.merge_transition_complete?(state) and
payload.parent_hash != state.latest_execution_payload_header.block_hash ->
{:error, "Inconsistency in parent hash"}

Expand Down Expand Up @@ -364,10 +364,10 @@ defmodule LambdaEthereumConsensus.StateTransition.Operations do
|> Stream.take(bound)
|> Stream.map(fn {{validator, balance}, index} ->
cond do
Validator.is_fully_withdrawable_validator(validator, balance, epoch) ->
Validator.fully_withdrawable_validator?(validator, balance, epoch) ->
{validator, balance, index}

Validator.is_partially_withdrawable_validator(validator, balance) ->
Validator.partially_withdrawable_validator?(validator, balance) ->
{validator, balance - max_effective_balance, index}

true ->
Expand Down Expand Up @@ -400,7 +400,7 @@ defmodule LambdaEthereumConsensus.StateTransition.Operations do
proposer = state.validators[header_1.proposer_index]

cond do
not Predicates.is_indices_available(validators_size, [header_1.proposer_index]) ->
not Predicates.indices_available?(validators_size, [header_1.proposer_index]) ->
{:error, "Too high index"}

not (header_1.slot == header_2.slot) ->
Expand All @@ -412,7 +412,7 @@ defmodule LambdaEthereumConsensus.StateTransition.Operations do
not (header_1 != header_2) ->
{:error, "Headers are same"}

not Predicates.is_slashable_validator(proposer, Accessors.get_current_epoch(state)) ->
not Predicates.slashable_validator?(proposer, Accessors.get_current_epoch(state)) ->
{:error, "Proposer is not slashable"}

not ([proposer_slashing.signed_header_1, proposer_slashing.signed_header_2]
Expand Down Expand Up @@ -458,7 +458,7 @@ defmodule LambdaEthereumConsensus.StateTransition.Operations do
{:ok, BeaconState.t()} | {:error, String.t()}
def process_deposit(state, deposit) do
with {:ok, deposit_data_root} <- Ssz.hash_tree_root(deposit.data) do
if Predicates.is_valid_merkle_branch?(
if Predicates.valid_merkle_branch?(
deposit_data_root,
deposit.proof,
Constants.deposit_contract_tree_depth() + 1,
Expand Down Expand Up @@ -487,19 +487,19 @@ defmodule LambdaEthereumConsensus.StateTransition.Operations do
validator_size = Aja.Vector.size(state.validators)

cond do
not Predicates.is_slashable_attestation_data(attestation_1.data, attestation_2.data) ->
not Predicates.slashable_attestation_data?(attestation_1.data, attestation_2.data) ->
{:error, "Attestation data is not slashable"}

not Predicates.is_valid_indexed_attestation(state, attestation_1) ->
not Predicates.valid_indexed_attestation?(state, attestation_1) ->
{:error, "Attestation 1 is not valid"}

not Predicates.is_valid_indexed_attestation(state, attestation_2) ->
not Predicates.valid_indexed_attestation?(state, attestation_2) ->
{:error, "Attestation 2 is not valid"}

not Predicates.is_indices_available(validator_size, attestation_1.attesting_indices) ->
not Predicates.indices_available?(validator_size, attestation_1.attesting_indices) ->
{:error, "Index too high attestation 1"}

not Predicates.is_indices_available(validator_size, attestation_2.attesting_indices) ->
not Predicates.indices_available?(validator_size, attestation_2.attesting_indices) ->
{:error, "Index too high attestation 2"}

true ->
Expand All @@ -521,7 +521,7 @@ defmodule LambdaEthereumConsensus.StateTransition.Operations do

defp slash_validator(slashed_any, state, i) do
if Aja.Vector.at!(state.validators, i)
|> Predicates.is_slashable_validator(Accessors.get_current_epoch(state)) do
|> Predicates.slashable_validator?(Accessors.get_current_epoch(state)) do
case Mutators.slash_validator(state, i) do
{:ok, state} -> {:cont, {true, state}}
{:error, _msg} -> {:halt, {false, nil}}
Expand All @@ -542,10 +542,10 @@ defmodule LambdaEthereumConsensus.StateTransition.Operations do
validator = state.validators[validator_index]

cond do
not Predicates.is_indices_available(Aja.Vector.size(state.validators), [validator_index]) ->
not Predicates.indices_available?(Aja.Vector.size(state.validators), [validator_index]) ->
{:error, "Too high index"}

not Predicates.is_active_validator(validator, Accessors.get_current_epoch(state)) ->
not Predicates.active_validator?(validator, Accessors.get_current_epoch(state)) ->
{:error, "Validator isn't active"}

validator.exit_epoch != Constants.far_future_epoch() ->
Expand Down Expand Up @@ -860,7 +860,7 @@ defmodule LambdaEthereumConsensus.StateTransition.Operations do
end

defp check_valid_indexed_attestation(state, indexed_attestation) do
if Predicates.is_valid_indexed_attestation(state, indexed_attestation) do
if Predicates.valid_indexed_attestation?(state, indexed_attestation) do
:ok
else
{:error, "Invalid signature"}
Expand Down
Loading