Skip to content
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

test: un-skip passing spectests #874

Merged
merged 12 commits into from
Mar 15, 2024
2 changes: 1 addition & 1 deletion .fork_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
capella
deneb
2 changes: 1 addition & 1 deletion lib/lambda_ethereum_consensus/fork_choice/handlers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@
%{message: block} = signed_block

payload = block.body.execution_payload
parent_beacon_block_root = state.latest_block_header.parent_root

Check warning on line 187 in lib/lambda_ethereum_consensus/fork_choice/handlers.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (capella, minimal)

variable "parent_beacon_block_root" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 187 in lib/lambda_ethereum_consensus/fork_choice/handlers.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (capella, minimal)

variable "parent_beacon_block_root" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 187 in lib/lambda_ethereum_consensus/fork_choice/handlers.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (capella, general)

variable "parent_beacon_block_root" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 187 in lib/lambda_ethereum_consensus/fork_choice/handlers.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (capella, general)

variable "parent_beacon_block_root" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 187 in lib/lambda_ethereum_consensus/fork_choice/handlers.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (capella, mainnet)

variable "parent_beacon_block_root" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 187 in lib/lambda_ethereum_consensus/fork_choice/handlers.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (capella, mainnet)

variable "parent_beacon_block_root" is unused (if the variable is not meant to be used, prefix it with an underscore)

# Make it a task so it runs concurrently with the state transition
payload_verification_task =
Task.async(fn ->
if HardForkAliasInjection.deneb?() do
HardForkAliasInjection.on_deneb do
versioned_hashes =
block.body.blob_kzg_commitments
|> Enum.map(&Misc.kzg_commitment_to_versioned_hash/1)
Expand Down
21 changes: 16 additions & 5 deletions lib/lambda_ethereum_consensus/hard_fork_alias_injection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,27 @@ defmodule HardForkAliasInjection do

## Examples

iex> HardForkAliasInjection.on_deneb(true, false)
iex> HardForkAliasInjection.on_deneb(do: true, else: false)
#{is_deneb}

iex> HardForkAliasInjection.on_deneb(do: true)
#{if is_deneb, do: true, else: nil}
"""
if is_deneb do
defmacro on_deneb(code, _default) do
code
defmacro on_deneb(do: do_clause) do
do_clause
end

defmacro on_deneb(do: do_clause, else: _else_clause) do
do_clause
end
else
defmacro on_deneb(_code, default) do
default
defmacro on_deneb(do: _do_clause) do
nil
end

defmacro on_deneb(do: _do_clause, else: else_clause) do
else_clause
end
end
end
4 changes: 3 additions & 1 deletion lib/lambda_ethereum_consensus/state_transition/accessors.ex
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,9 @@ defmodule LambdaEthereumConsensus.StateTransition.Accessors do
end

defp compute_target_indices(is_matching_target, inclusion_delay) do
if HardForkAliasInjection.deneb?() do
HardForkAliasInjection.on_deneb do
_ = inclusion_delay

if is_matching_target,
do: [Constants.timely_target_flag_index()],
else: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,10 @@ defmodule LambdaEthereumConsensus.StateTransition.EpochProcessing do
activation_exit_epoch = Misc.compute_activation_exit_epoch(current_epoch)

churn_limit =
if HardForkAliasInjection.deneb?(),
HardForkAliasInjection.on_deneb(
do: Accessors.get_validator_activation_churn_limit(state),
else: Accessors.get_validator_churn_limit(state)
)

result =
validators
Expand Down
9 changes: 5 additions & 4 deletions lib/lambda_ethereum_consensus/state_transition/operations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ defmodule LambdaEthereumConsensus.StateTransition.Operations do
payload.timestamp != Misc.compute_timestamp_at_slot(state, state.slot) ->
{:error, "Timestamp verification failed"}

HardForkAliasInjection.on_deneb(body.blob_kzg_commitments |> length(), -1) >
HardForkAliasInjection.on_deneb(do: body.blob_kzg_commitments |> length(), else: -1) >
ChainSpec.get("MAX_BLOBS_PER_BLOCK") ->
{:error, "Too many commitments"}

Expand Down Expand Up @@ -270,12 +270,13 @@ defmodule LambdaEthereumConsensus.StateTransition.Operations do
transactions_root: transactions_root,
withdrawals_root: withdrawals_root
] ++
if HardForkAliasInjection.deneb?(),
HardForkAliasInjection.on_deneb(
do: [
blob_gas_used: payload.blob_gas_used,
excess_blob_gas: payload.excess_blob_gas
],
else: []
)

header = struct!(ExecutionPayloadHeader, fields)

Expand Down Expand Up @@ -566,7 +567,7 @@ defmodule LambdaEthereumConsensus.StateTransition.Operations do
current_epoch < validator.activation_epoch + ChainSpec.get("SHARD_COMMITTEE_PERIOD") ->
{:error, "validator cannot exit yet"}

not ((if HardForkAliasInjection.deneb?() do
not ((HardForkAliasInjection.on_deneb do
Misc.compute_domain(
Constants.domain_voluntary_exit(),
fork_version: ChainSpec.get("CAPELLA_FORK_VERSION"),
Expand Down Expand Up @@ -846,7 +847,7 @@ defmodule LambdaEthereumConsensus.StateTransition.Operations do
end

defp check_valid_slot_range(data, state) do
if HardForkAliasInjection.deneb?() do
HardForkAliasInjection.on_deneb do
if data.slot + ChainSpec.get("MIN_ATTESTATION_INCLUSION_DELAY") <= state.slot do
:ok
else
Expand Down
5 changes: 3 additions & 2 deletions lib/types/beacon_chain/beacon_block_body_deneb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ defmodule Types.BeaconBlockBodyDeneb do
{:sync_aggregate, Types.SyncAggregate},
{:execution_payload, Types.ExecutionPayloadDeneb},
{:bls_to_execution_changes,
{:list, Types.BLSToExecutionChange, ChainSpec.get("MAX_BLS_TO_EXECUTION_CHANGES")}},
{:blob_kzg_commitments, {:list, TypeAliases.kzg_commitment()}}
{:list, Types.SignedBLSToExecutionChange, ChainSpec.get("MAX_BLS_TO_EXECUTION_CHANGES")}},
{:blob_kzg_commitments,
{:list, TypeAliases.kzg_commitment(), ChainSpec.get("MAX_BLOB_COMMITMENTS_PER_BLOCK")}}
]
end
end
144 changes: 88 additions & 56 deletions test/fixtures/block.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@ defmodule Fixtures.Block do
alias Fixtures.Random
alias LambdaEthereumConsensus.Utils.BitVector

@spec signed_beacon_block :: Types.SignedBeaconBlock.t()
alias Types.BeaconBlock
alias Types.BeaconBlockBody
alias Types.BeaconState
alias Types.ExecutionPayload
alias Types.ExecutionPayloadHeader
alias Types.SignedBeaconBlock
use HardForkAliasInjection

@spec signed_beacon_block :: SignedBeaconBlock.t()
def signed_beacon_block do
%Types.SignedBeaconBlock{
%SignedBeaconBlock{
message: beacon_block(),
signature: Random.bls_signature()
}
end

@spec beacon_block :: Types.BeaconBlock.t()
@spec beacon_block :: BeaconBlock.t()
def beacon_block do
%Types.BeaconBlock{
%BeaconBlock{
parent_root: Random.root(),
slot: Random.uint64(),
proposer_index: Random.uint64(),
Expand All @@ -25,21 +33,29 @@ defmodule Fixtures.Block do
}
end

@spec beacon_block_body :: Types.BeaconBlockBody.t()
@spec beacon_block_body :: BeaconBlockBody.t()
def beacon_block_body do
%Types.BeaconBlockBody{
randao_reveal: Random.bls_signature(),
eth1_data: eth1_data(),
graffiti: Random.hash32(),
proposer_slashings: [],
attester_slashings: [],
attestations: [],
deposits: [],
voluntary_exits: [],
sync_aggregate: sync_aggregate(),
execution_payload: execution_payload(),
bls_to_execution_changes: []
}
fields =
[
randao_reveal: Random.bls_signature(),
eth1_data: eth1_data(),
graffiti: Random.hash32(),
proposer_slashings: [],
attester_slashings: [],
attestations: [],
deposits: [],
voluntary_exits: [],
sync_aggregate: sync_aggregate(),
execution_payload: execution_payload(),
bls_to_execution_changes: []
] ++
HardForkAliasInjection.on_deneb do
[blob_kzg_commitments: []]
else
[]
end

struct!(BeaconBlockBody, fields)
end

@spec eth1_data :: Types.Eth1Data.t()
Expand All @@ -59,25 +75,33 @@ defmodule Fixtures.Block do
}
end

@spec execution_payload :: Types.ExecutionPayload.t()
@spec execution_payload :: ExecutionPayload.t()
def execution_payload do
%Types.ExecutionPayload{
parent_hash: Random.hash32(),
fee_recipient: Random.execution_address(),
state_root: Random.root(),
receipts_root: Random.root(),
logs_bloom: Random.binary(256),
prev_randao: Random.hash32(),
block_number: Random.uint64(),
gas_limit: Random.uint64(),
gas_used: Random.uint64(),
timestamp: Random.uint64(),
extra_data: Random.binary(30),
base_fee_per_gas: Random.uint64(),
block_hash: Random.binary(32),
transactions: [],
withdrawals: []
}
fields =
[
parent_hash: Random.hash32(),
fee_recipient: Random.execution_address(),
state_root: Random.root(),
receipts_root: Random.root(),
logs_bloom: Random.binary(256),
prev_randao: Random.hash32(),
block_number: Random.uint64(),
gas_limit: Random.uint64(),
gas_used: Random.uint64(),
timestamp: Random.uint64(),
extra_data: Random.binary(30),
base_fee_per_gas: Random.uint64(),
block_hash: Random.binary(32),
transactions: [],
withdrawals: []
] ++
HardForkAliasInjection.on_deneb do
[blob_gas_used: 0, excess_blob_gas: 0]
else
[]
end

struct!(ExecutionPayload, fields)
end

@spec fork :: Types.Fork.t()
Expand Down Expand Up @@ -124,30 +148,38 @@ defmodule Fixtures.Block do
}
end

@spec execution_payload_header :: Types.ExecutionPayloadHeader.t()
@spec execution_payload_header :: ExecutionPayloadHeader.t()
def execution_payload_header do
%Types.ExecutionPayloadHeader{
parent_hash: Random.binary(32),
fee_recipient: Random.binary(20),
state_root: Random.root(),
receipts_root: Random.root(),
logs_bloom: Random.binary(256),
prev_randao: Random.binary(32),
block_number: Random.uint64(),
gas_limit: Random.uint64(),
gas_used: Random.uint64(),
timestamp: Random.uint64(),
extra_data: Random.binary(30),
base_fee_per_gas: Random.uint256(),
block_hash: Random.binary(32),
transactions_root: Random.root(),
withdrawals_root: Random.root()
}
fields =
[
parent_hash: Random.binary(32),
fee_recipient: Random.binary(20),
state_root: Random.root(),
receipts_root: Random.root(),
logs_bloom: Random.binary(256),
prev_randao: Random.binary(32),
block_number: Random.uint64(),
gas_limit: Random.uint64(),
gas_used: Random.uint64(),
timestamp: Random.uint64(),
extra_data: Random.binary(30),
base_fee_per_gas: Random.uint256(),
block_hash: Random.binary(32),
transactions_root: Random.root(),
withdrawals_root: Random.root()
] ++
HardForkAliasInjection.on_deneb do
[blob_gas_used: 0, excess_blob_gas: 0]
else
[]
end

struct!(ExecutionPayloadHeader, fields)
end

@spec beacon_state :: Types.BeaconState.t()
@spec beacon_state :: BeaconState.t()
def beacon_state do
%Types.BeaconState{
%BeaconState{
genesis_time: Random.uint64(),
genesis_validators_root: Random.root(),
slot: Random.uint64(),
Expand Down
4 changes: 1 addition & 3 deletions test/spec/runners/epoch_processing.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ defmodule EpochProcessingTestRunner do
end

@impl TestRunner
def skip?(%SpecTestCase{fork: "deneb"}) do
false
end
def skip?(%SpecTestCase{fork: "deneb"}), do: false

@impl TestRunner
def skip?(_), do: true
Expand Down
5 changes: 5 additions & 0 deletions test/spec/runners/finality.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ defmodule FinalityTestRunner do
Enum.member?(@disabled_cases, testcase)
end

@impl TestRunner
MegaRedHand marked this conversation as resolved.
Show resolved Hide resolved
def skip?(%SpecTestCase{fork: "deneb", case: testcase}) do
Enum.member?(@disabled_cases, testcase)
end

@impl TestRunner
def skip?(_), do: true

Expand Down
Loading
Loading