Skip to content

Commit 8ac4353

Browse files
authored
Electra MaxEB state changes (Consensys#8186)
Signed-off-by: Paul Harris <[email protected]>
1 parent ad5e63f commit 8ac4353

File tree

21 files changed

+896
-26
lines changed

21 files changed

+896
-26
lines changed

Diff for: data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/schema/BeaconStateElectra.json

+49-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"title" : "BeaconStateElectra",
33
"type" : "object",
4-
"required" : [ "genesis_time", "genesis_validators_root", "slot", "fork", "latest_block_header", "block_roots", "state_roots", "historical_roots", "eth1_data", "eth1_data_votes", "eth1_deposit_index", "validators", "balances", "randao_mixes", "slashings", "previous_epoch_participation", "current_epoch_participation", "justification_bits", "previous_justified_checkpoint", "current_justified_checkpoint", "finalized_checkpoint", "inactivity_scores", "current_sync_committee", "next_sync_committee", "latest_execution_payload_header", "next_withdrawal_index", "next_withdrawal_validator_index", "historical_summaries", "deposit_receipts_start_index" ],
4+
"required" : [ "genesis_time", "genesis_validators_root", "slot", "fork", "latest_block_header", "block_roots", "state_roots", "historical_roots", "eth1_data", "eth1_data_votes", "eth1_deposit_index", "validators", "balances", "randao_mixes", "slashings", "previous_epoch_participation", "current_epoch_participation", "justification_bits", "previous_justified_checkpoint", "current_justified_checkpoint", "finalized_checkpoint", "inactivity_scores", "current_sync_committee", "next_sync_committee", "latest_execution_payload_header", "next_withdrawal_index", "next_withdrawal_validator_index", "historical_summaries", "deposit_receipts_start_index", "deposit_balance_to_consume", "exit_balance_to_consume", "earliest_exit_epoch", "consolidation_balance_to_consume", "earliest_consolidation_epoch", "pending_balance_deposits", "pending_partial_withdrawals", "pending_consolidations" ],
55
"properties" : {
66
"genesis_time" : {
77
"type" : "string",
@@ -176,6 +176,54 @@
176176
"description" : "unsigned 64 bit integer",
177177
"example" : "1",
178178
"format" : "uint64"
179+
},
180+
"deposit_balance_to_consume" : {
181+
"type" : "string",
182+
"description" : "unsigned 64 bit integer",
183+
"example" : "1",
184+
"format" : "uint64"
185+
},
186+
"exit_balance_to_consume" : {
187+
"type" : "string",
188+
"description" : "unsigned 64 bit integer",
189+
"example" : "1",
190+
"format" : "uint64"
191+
},
192+
"earliest_exit_epoch" : {
193+
"type" : "string",
194+
"description" : "unsigned 64 bit integer",
195+
"example" : "1",
196+
"format" : "uint64"
197+
},
198+
"consolidation_balance_to_consume" : {
199+
"type" : "string",
200+
"description" : "unsigned 64 bit integer",
201+
"example" : "1",
202+
"format" : "uint64"
203+
},
204+
"earliest_consolidation_epoch" : {
205+
"type" : "string",
206+
"description" : "unsigned 64 bit integer",
207+
"example" : "1",
208+
"format" : "uint64"
209+
},
210+
"pending_balance_deposits" : {
211+
"type" : "array",
212+
"items" : {
213+
"$ref" : "#/components/schemas/PendingBalanceDeposit"
214+
}
215+
},
216+
"pending_partial_withdrawals" : {
217+
"type" : "array",
218+
"items" : {
219+
"$ref" : "#/components/schemas/PendingPartialWithdrawal"
220+
}
221+
},
222+
"pending_consolidations" : {
223+
"type" : "array",
224+
"items" : {
225+
"$ref" : "#/components/schemas/PendingConsolidation"
226+
}
179227
}
180228
}
181229
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"title" : "PendingBalanceDeposit",
3+
"type" : "object",
4+
"required" : [ "index", "amount" ],
5+
"properties" : {
6+
"index" : {
7+
"type" : "string",
8+
"description" : "unsigned 64 bit integer",
9+
"example" : "1",
10+
"format" : "uint64"
11+
},
12+
"amount" : {
13+
"type" : "string",
14+
"description" : "unsigned 64 bit integer",
15+
"example" : "1",
16+
"format" : "uint64"
17+
}
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"title" : "PendingConsolidation",
3+
"type" : "object",
4+
"required" : [ "source_index", "target_index" ],
5+
"properties" : {
6+
"source_index" : {
7+
"type" : "string",
8+
"description" : "unsigned 64 bit integer",
9+
"example" : "1",
10+
"format" : "uint64"
11+
},
12+
"target_index" : {
13+
"type" : "string",
14+
"description" : "unsigned 64 bit integer",
15+
"example" : "1",
16+
"format" : "uint64"
17+
}
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"title" : "PendingPartialWithdrawal",
3+
"type" : "object",
4+
"required" : [ "index", "amount", "withdrawable_epoch" ],
5+
"properties" : {
6+
"index" : {
7+
"type" : "string",
8+
"description" : "unsigned 64 bit integer",
9+
"example" : "1",
10+
"format" : "uint64"
11+
},
12+
"amount" : {
13+
"type" : "string",
14+
"description" : "unsigned 64 bit integer",
15+
"example" : "1",
16+
"format" : "uint64"
17+
},
18+
"withdrawable_epoch" : {
19+
"type" : "string",
20+
"description" : "unsigned 64 bit integer",
21+
"example" : "1",
22+
"format" : "uint64"
23+
}
24+
}
25+
}

Diff for: data/serializer/src/main/java/tech/pegasys/teku/api/schema/electra/BeaconStateElectra.java

+100-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,30 @@ public class BeaconStateElectra extends BeaconStateAltair {
5757
@JsonProperty("deposit_receipts_start_index")
5858
public final UInt64 depositReceiptsStartIndex;
5959

60+
@JsonProperty("deposit_balance_to_consume")
61+
public final UInt64 depositBalanceToConsume;
62+
63+
@JsonProperty("exit_balance_to_consume")
64+
public final UInt64 exitBalanceToConsume;
65+
66+
@JsonProperty("earliest_exit_epoch")
67+
public final UInt64 earliestExitEpoch;
68+
69+
@JsonProperty("consolidation_balance_to_consume")
70+
public final UInt64 consolidationBalanceToConsume;
71+
72+
@JsonProperty("earliest_consolidation_epoch")
73+
public final UInt64 earliestConsolidationEpoch;
74+
75+
@JsonProperty("pending_balance_deposits")
76+
public final List<PendingBalanceDeposit> pendingBalanceDeposits;
77+
78+
@JsonProperty("pending_partial_withdrawals")
79+
public final List<PendingPartialWithdrawal> pendingPartialWithdrawals;
80+
81+
@JsonProperty("pending_consolidations")
82+
public final List<PendingConsolidation> pendingConsolidations;
83+
6084
public BeaconStateElectra(
6185
@JsonProperty("genesis_time") final UInt64 genesisTime,
6286
@JsonProperty("genesis_validators_root") final Bytes32 genesisValidatorsRoot,
@@ -87,7 +111,18 @@ public BeaconStateElectra(
87111
@JsonProperty("next_withdrawal_index") final UInt64 nextWithdrawalIndex,
88112
@JsonProperty("next_withdrawal_validator_index") final UInt64 nextWithdrawalValidatorIndex,
89113
@JsonProperty("historical_summaries") final List<HistoricalSummary> historicalSummaries,
90-
@JsonProperty("deposit_receipts_start_index") final UInt64 depositReceiptsStartIndex) {
114+
@JsonProperty("deposit_receipts_start_index") final UInt64 depositReceiptsStartIndex,
115+
@JsonProperty("deposit_balance_to_consume") final UInt64 depositBalanceToConsume,
116+
@JsonProperty("exit_balance_to_consume") final UInt64 exitBalanceToConsume,
117+
@JsonProperty("earliest_exit_epoch") final UInt64 earliestExitEpoch,
118+
@JsonProperty("consolidation_balance_to_consume") final UInt64 consolidationBalanceToConsume,
119+
@JsonProperty("earliest_consolidation_epoch") final UInt64 earliestConsolidationEpoch,
120+
@JsonProperty("pending_balance_deposits")
121+
final List<PendingBalanceDeposit> pendingBalanceDeposits,
122+
@JsonProperty("pending_partial_withdrawals")
123+
final List<PendingPartialWithdrawal> pendingPartialWithdrawals,
124+
@JsonProperty("pending_consolidations")
125+
final List<PendingConsolidation> pendingConsolidations) {
91126
super(
92127
genesisTime,
93128
genesisValidatorsRoot,
@@ -118,6 +153,14 @@ public BeaconStateElectra(
118153
this.nextWithdrawalValidatorIndex = nextWithdrawalValidatorIndex;
119154
this.historicalSummaries = historicalSummaries;
120155
this.depositReceiptsStartIndex = depositReceiptsStartIndex;
156+
this.depositBalanceToConsume = depositBalanceToConsume;
157+
this.exitBalanceToConsume = exitBalanceToConsume;
158+
this.earliestExitEpoch = earliestExitEpoch;
159+
this.consolidationBalanceToConsume = consolidationBalanceToConsume;
160+
this.earliestConsolidationEpoch = earliestConsolidationEpoch;
161+
this.pendingBalanceDeposits = pendingBalanceDeposits;
162+
this.pendingPartialWithdrawals = pendingPartialWithdrawals;
163+
this.pendingConsolidations = pendingConsolidations;
121164
}
122165

123166
public BeaconStateElectra(final BeaconState beaconState) {
@@ -132,6 +175,17 @@ public BeaconStateElectra(final BeaconState beaconState) {
132175
this.historicalSummaries =
133176
electra.getHistoricalSummaries().stream().map(HistoricalSummary::new).toList();
134177
this.depositReceiptsStartIndex = electra.getDepositReceiptsStartIndex();
178+
this.depositBalanceToConsume = electra.getDepositBalanceToConsume();
179+
this.exitBalanceToConsume = electra.getExitBalanceToConsume();
180+
this.earliestExitEpoch = electra.getEarliestExitEpoch();
181+
this.consolidationBalanceToConsume = electra.getConsolidationBalanceToConsume();
182+
this.earliestConsolidationEpoch = electra.getEarliestConsolidationEpoch();
183+
this.pendingBalanceDeposits =
184+
electra.getPendingBalanceDeposits().stream().map(PendingBalanceDeposit::new).toList();
185+
this.pendingPartialWithdrawals =
186+
electra.getPendingPartialWithdrawals().stream().map(PendingPartialWithdrawal::new).toList();
187+
this.pendingConsolidations =
188+
electra.getPendingConsolidations().stream().map(PendingConsolidation::new).toList();
135189
}
136190

137191
@Override
@@ -153,6 +207,15 @@ protected void applyAdditionalFields(
153207
BeaconStateSchemaElectra.required(
154208
mutableBeaconStateElectra.getBeaconStateSchema())
155209
.getHistoricalSummariesSchema(),
210+
BeaconStateSchemaElectra.required(
211+
mutableBeaconStateElectra.getBeaconStateSchema())
212+
.getPendingBalanceDepositsSchema(),
213+
BeaconStateSchemaElectra.required(
214+
mutableBeaconStateElectra.getBeaconStateSchema())
215+
.getPendingPartialWithdrawalsSchema(),
216+
BeaconStateSchemaElectra.required(
217+
mutableBeaconStateElectra.getBeaconStateSchema())
218+
.getPendingConsolidationsSchema(),
156219
this));
157220
}
158221

@@ -164,6 +227,16 @@ protected static void applyElectraFields(
164227
final SszListSchema<
165228
tech.pegasys.teku.spec.datastructures.state.versions.capella.HistoricalSummary, ?>
166229
historicalSummariesSchema,
230+
final SszListSchema<
231+
tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingBalanceDeposit, ?>
232+
pendingBalanceDepositsSchema,
233+
final SszListSchema<
234+
tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingPartialWithdrawal,
235+
?>
236+
pendingPartialWithdrawalsSchema,
237+
final SszListSchema<
238+
tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingConsolidation, ?>
239+
pendingConsolidationsSchema,
167240
final BeaconStateElectra instance) {
168241

169242
BeaconStateAltair.applyAltairFields(state, syncCommitteeSchema, instance);
@@ -181,5 +254,31 @@ protected static void applyElectraFields(
181254
historicalSummary -> historicalSummary.asInternalHistoricalSummary(specVersion))
182255
.toList()));
183256
state.setDepositReceiptsStartIndex(instance.depositReceiptsStartIndex);
257+
state.setDepositBalanceToConsume(instance.depositBalanceToConsume);
258+
state.setExitBalanceToConsume(instance.exitBalanceToConsume);
259+
state.setEarliestExitEpoch(instance.earliestExitEpoch);
260+
state.setConsolidationBalanceToConsume(instance.consolidationBalanceToConsume);
261+
state.setEarliestConsolidationEpoch(instance.earliestConsolidationEpoch);
262+
state.setPendingBalanceDeposits(
263+
pendingBalanceDepositsSchema.createFromElements(
264+
instance.pendingBalanceDeposits.stream()
265+
.map(
266+
pendingBalanceDeposit ->
267+
pendingBalanceDeposit.asInternalPendingBalanceDeposit(specVersion))
268+
.toList()));
269+
state.setPendingPartialWithdrawals(
270+
pendingPartialWithdrawalsSchema.createFromElements(
271+
instance.pendingPartialWithdrawals.stream()
272+
.map(
273+
pendingPartialWithdrawal ->
274+
pendingPartialWithdrawal.asInternalPendingPartialWithdrawal(specVersion))
275+
.toList()));
276+
state.setPendingConsolidations(
277+
pendingConsolidationsSchema.createFromElements(
278+
instance.pendingConsolidations.stream()
279+
.map(
280+
pendingConsolidation ->
281+
pendingConsolidation.asInternalPendingConsolidation(specVersion))
282+
.toList()));
184283
}
185284
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright Consensys Software Inc., 2024
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package tech.pegasys.teku.api.schema.electra;
15+
16+
import com.fasterxml.jackson.annotation.JsonProperty;
17+
import java.util.Optional;
18+
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64;
19+
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
20+
import tech.pegasys.teku.spec.SpecVersion;
21+
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsElectra;
22+
23+
public class PendingBalanceDeposit {
24+
25+
@JsonProperty("index")
26+
public final int index;
27+
28+
@JsonProperty("amount")
29+
public final UInt64 amount;
30+
31+
public PendingBalanceDeposit(
32+
@JsonProperty("index") int index, @JsonProperty("amount") UInt64 amount) {
33+
this.index = index;
34+
this.amount = amount;
35+
}
36+
37+
public PendingBalanceDeposit(
38+
final tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingBalanceDeposit
39+
internalPendingBalanceDeposit) {
40+
this.index = internalPendingBalanceDeposit.getIndex();
41+
this.amount = internalPendingBalanceDeposit.getAmount();
42+
}
43+
44+
public tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingBalanceDeposit
45+
asInternalPendingBalanceDeposit(final SpecVersion spec) {
46+
final Optional<SchemaDefinitionsElectra> schemaDefinitionsElectra =
47+
spec.getSchemaDefinitions().toVersionElectra();
48+
if (schemaDefinitionsElectra.isEmpty()) {
49+
throw new IllegalArgumentException(
50+
"Could not create PendingBalanceDeposit for pre-electra spec");
51+
}
52+
return schemaDefinitionsElectra
53+
.get()
54+
.getPendingBalanceDepositSchema()
55+
.create(SszUInt64.of(UInt64.valueOf(this.index)), SszUInt64.of(this.amount));
56+
}
57+
}

0 commit comments

Comments
 (0)