Skip to content

Commit 11a8762

Browse files
authored
feat: set .fork_version to "deneb" (lambdaclass#880)
1 parent 5e2259b commit 11a8762

File tree

8 files changed

+119
-71
lines changed

8 files changed

+119
-71
lines changed

.fork_version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
capella
1+
deneb

lib/lambda_ethereum_consensus/fork_choice/handlers.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ defmodule LambdaEthereumConsensus.ForkChoice.Handlers do
189189
# Make it a task so it runs concurrently with the state transition
190190
payload_verification_task =
191191
Task.async(fn ->
192-
if HardForkAliasInjection.deneb?() do
192+
HardForkAliasInjection.on_deneb do
193193
versioned_hashes =
194194
block.body.blob_kzg_commitments
195195
|> Enum.map(&Misc.kzg_commitment_to_versioned_hash/1)

lib/lambda_ethereum_consensus/hard_fork_alias_injection.ex

+16-5
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,27 @@ defmodule HardForkAliasInjection do
3434
3535
## Examples
3636
37-
iex> HardForkAliasInjection.on_deneb(true, false)
37+
iex> HardForkAliasInjection.on_deneb(do: true, else: false)
3838
#{is_deneb}
39+
40+
iex> HardForkAliasInjection.on_deneb(do: true)
41+
#{if is_deneb, do: true, else: nil}
3942
"""
4043
if is_deneb do
41-
defmacro on_deneb(code, _default) do
42-
code
44+
defmacro on_deneb(do: do_clause) do
45+
do_clause
46+
end
47+
48+
defmacro on_deneb(do: do_clause, else: _else_clause) do
49+
do_clause
4350
end
4451
else
45-
defmacro on_deneb(_code, default) do
46-
default
52+
defmacro on_deneb(do: _do_clause) do
53+
nil
54+
end
55+
56+
defmacro on_deneb(do: _do_clause, else: else_clause) do
57+
else_clause
4758
end
4859
end
4960
end

lib/lambda_ethereum_consensus/state_transition/accessors.ex

+3-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,9 @@ defmodule LambdaEthereumConsensus.StateTransition.Accessors do
392392
end
393393

394394
defp compute_target_indices(is_matching_target, inclusion_delay) do
395-
if HardForkAliasInjection.deneb?() do
395+
HardForkAliasInjection.on_deneb do
396+
_ = inclusion_delay
397+
396398
if is_matching_target,
397399
do: [Constants.timely_target_flag_index()],
398400
else: []

lib/lambda_ethereum_consensus/state_transition/epoch_processing.ex

+2-1
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ defmodule LambdaEthereumConsensus.StateTransition.EpochProcessing do
142142
activation_exit_epoch = Misc.compute_activation_exit_epoch(current_epoch)
143143

144144
churn_limit =
145-
if HardForkAliasInjection.deneb?(),
145+
HardForkAliasInjection.on_deneb(
146146
do: Accessors.get_validator_activation_churn_limit(state),
147147
else: Accessors.get_validator_churn_limit(state)
148+
)
148149

149150
result =
150151
validators

lib/lambda_ethereum_consensus/state_transition/operations.ex

+5-4
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ defmodule LambdaEthereumConsensus.StateTransition.Operations do
235235
payload.timestamp != Misc.compute_timestamp_at_slot(state, state.slot) ->
236236
{:error, "Timestamp verification failed"}
237237

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

@@ -270,12 +270,13 @@ defmodule LambdaEthereumConsensus.StateTransition.Operations do
270270
transactions_root: transactions_root,
271271
withdrawals_root: withdrawals_root
272272
] ++
273-
if HardForkAliasInjection.deneb?(),
273+
HardForkAliasInjection.on_deneb(
274274
do: [
275275
blob_gas_used: payload.blob_gas_used,
276276
excess_blob_gas: payload.excess_blob_gas
277277
],
278278
else: []
279+
)
279280

280281
header = struct!(ExecutionPayloadHeader, fields)
281282

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

569-
not ((if HardForkAliasInjection.deneb?() do
570+
not ((HardForkAliasInjection.on_deneb do
570571
Misc.compute_domain(
571572
Constants.domain_voluntary_exit(),
572573
fork_version: ChainSpec.get("CAPELLA_FORK_VERSION"),
@@ -846,7 +847,7 @@ defmodule LambdaEthereumConsensus.StateTransition.Operations do
846847
end
847848

848849
defp check_valid_slot_range(data, state) do
849-
if HardForkAliasInjection.deneb?() do
850+
HardForkAliasInjection.on_deneb do
850851
if data.slot + ChainSpec.get("MIN_ATTESTATION_INCLUSION_DELAY") <= state.slot do
851852
:ok
852853
else

lib/types/beacon_chain/beacon_block_body_deneb.ex

+3-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ defmodule Types.BeaconBlockBodyDeneb do
6262
{:sync_aggregate, Types.SyncAggregate},
6363
{:execution_payload, Types.ExecutionPayloadDeneb},
6464
{:bls_to_execution_changes,
65-
{:list, Types.BLSToExecutionChange, ChainSpec.get("MAX_BLS_TO_EXECUTION_CHANGES")}},
66-
{:blob_kzg_commitments, {:list, TypeAliases.kzg_commitment()}}
65+
{:list, Types.SignedBLSToExecutionChange, ChainSpec.get("MAX_BLS_TO_EXECUTION_CHANGES")}},
66+
{:blob_kzg_commitments,
67+
{:list, TypeAliases.kzg_commitment(), ChainSpec.get("MAX_BLOB_COMMITMENTS_PER_BLOCK")}}
6768
]
6869
end
6970
end

test/fixtures/block.ex

+88-56
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,25 @@ defmodule Fixtures.Block do
66
alias Fixtures.Random
77
alias LambdaEthereumConsensus.Utils.BitVector
88

9-
@spec signed_beacon_block :: Types.SignedBeaconBlock.t()
9+
alias Types.BeaconBlock
10+
alias Types.BeaconBlockBody
11+
alias Types.BeaconState
12+
alias Types.ExecutionPayload
13+
alias Types.ExecutionPayloadHeader
14+
alias Types.SignedBeaconBlock
15+
use HardForkAliasInjection
16+
17+
@spec signed_beacon_block :: SignedBeaconBlock.t()
1018
def signed_beacon_block do
11-
%Types.SignedBeaconBlock{
19+
%SignedBeaconBlock{
1220
message: beacon_block(),
1321
signature: Random.bls_signature()
1422
}
1523
end
1624

17-
@spec beacon_block :: Types.BeaconBlock.t()
25+
@spec beacon_block :: BeaconBlock.t()
1826
def beacon_block do
19-
%Types.BeaconBlock{
27+
%BeaconBlock{
2028
parent_root: Random.root(),
2129
slot: Random.uint64(),
2230
proposer_index: Random.uint64(),
@@ -25,21 +33,29 @@ defmodule Fixtures.Block do
2533
}
2634
end
2735

28-
@spec beacon_block_body :: Types.BeaconBlockBody.t()
36+
@spec beacon_block_body :: BeaconBlockBody.t()
2937
def beacon_block_body do
30-
%Types.BeaconBlockBody{
31-
randao_reveal: Random.bls_signature(),
32-
eth1_data: eth1_data(),
33-
graffiti: Random.hash32(),
34-
proposer_slashings: [],
35-
attester_slashings: [],
36-
attestations: [],
37-
deposits: [],
38-
voluntary_exits: [],
39-
sync_aggregate: sync_aggregate(),
40-
execution_payload: execution_payload(),
41-
bls_to_execution_changes: []
42-
}
38+
fields =
39+
[
40+
randao_reveal: Random.bls_signature(),
41+
eth1_data: eth1_data(),
42+
graffiti: Random.hash32(),
43+
proposer_slashings: [],
44+
attester_slashings: [],
45+
attestations: [],
46+
deposits: [],
47+
voluntary_exits: [],
48+
sync_aggregate: sync_aggregate(),
49+
execution_payload: execution_payload(),
50+
bls_to_execution_changes: []
51+
] ++
52+
HardForkAliasInjection.on_deneb do
53+
[blob_kzg_commitments: []]
54+
else
55+
[]
56+
end
57+
58+
struct!(BeaconBlockBody, fields)
4359
end
4460

4561
@spec eth1_data :: Types.Eth1Data.t()
@@ -59,25 +75,33 @@ defmodule Fixtures.Block do
5975
}
6076
end
6177

62-
@spec execution_payload :: Types.ExecutionPayload.t()
78+
@spec execution_payload :: ExecutionPayload.t()
6379
def execution_payload do
64-
%Types.ExecutionPayload{
65-
parent_hash: Random.hash32(),
66-
fee_recipient: Random.execution_address(),
67-
state_root: Random.root(),
68-
receipts_root: Random.root(),
69-
logs_bloom: Random.binary(256),
70-
prev_randao: Random.hash32(),
71-
block_number: Random.uint64(),
72-
gas_limit: Random.uint64(),
73-
gas_used: Random.uint64(),
74-
timestamp: Random.uint64(),
75-
extra_data: Random.binary(30),
76-
base_fee_per_gas: Random.uint64(),
77-
block_hash: Random.binary(32),
78-
transactions: [],
79-
withdrawals: []
80-
}
80+
fields =
81+
[
82+
parent_hash: Random.hash32(),
83+
fee_recipient: Random.execution_address(),
84+
state_root: Random.root(),
85+
receipts_root: Random.root(),
86+
logs_bloom: Random.binary(256),
87+
prev_randao: Random.hash32(),
88+
block_number: Random.uint64(),
89+
gas_limit: Random.uint64(),
90+
gas_used: Random.uint64(),
91+
timestamp: Random.uint64(),
92+
extra_data: Random.binary(30),
93+
base_fee_per_gas: Random.uint64(),
94+
block_hash: Random.binary(32),
95+
transactions: [],
96+
withdrawals: []
97+
] ++
98+
HardForkAliasInjection.on_deneb do
99+
[blob_gas_used: 0, excess_blob_gas: 0]
100+
else
101+
[]
102+
end
103+
104+
struct!(ExecutionPayload, fields)
81105
end
82106

83107
@spec fork :: Types.Fork.t()
@@ -124,30 +148,38 @@ defmodule Fixtures.Block do
124148
}
125149
end
126150

127-
@spec execution_payload_header :: Types.ExecutionPayloadHeader.t()
151+
@spec execution_payload_header :: ExecutionPayloadHeader.t()
128152
def execution_payload_header do
129-
%Types.ExecutionPayloadHeader{
130-
parent_hash: Random.binary(32),
131-
fee_recipient: Random.binary(20),
132-
state_root: Random.root(),
133-
receipts_root: Random.root(),
134-
logs_bloom: Random.binary(256),
135-
prev_randao: Random.binary(32),
136-
block_number: Random.uint64(),
137-
gas_limit: Random.uint64(),
138-
gas_used: Random.uint64(),
139-
timestamp: Random.uint64(),
140-
extra_data: Random.binary(30),
141-
base_fee_per_gas: Random.uint256(),
142-
block_hash: Random.binary(32),
143-
transactions_root: Random.root(),
144-
withdrawals_root: Random.root()
145-
}
153+
fields =
154+
[
155+
parent_hash: Random.binary(32),
156+
fee_recipient: Random.binary(20),
157+
state_root: Random.root(),
158+
receipts_root: Random.root(),
159+
logs_bloom: Random.binary(256),
160+
prev_randao: Random.binary(32),
161+
block_number: Random.uint64(),
162+
gas_limit: Random.uint64(),
163+
gas_used: Random.uint64(),
164+
timestamp: Random.uint64(),
165+
extra_data: Random.binary(30),
166+
base_fee_per_gas: Random.uint256(),
167+
block_hash: Random.binary(32),
168+
transactions_root: Random.root(),
169+
withdrawals_root: Random.root()
170+
] ++
171+
HardForkAliasInjection.on_deneb do
172+
[blob_gas_used: 0, excess_blob_gas: 0]
173+
else
174+
[]
175+
end
176+
177+
struct!(ExecutionPayloadHeader, fields)
146178
end
147179

148-
@spec beacon_state :: Types.BeaconState.t()
180+
@spec beacon_state :: BeaconState.t()
149181
def beacon_state do
150-
%Types.BeaconState{
182+
%BeaconState{
151183
genesis_time: Random.uint64(),
152184
genesis_validators_root: Random.root(),
153185
slot: Random.uint64(),

0 commit comments

Comments
 (0)