Skip to content

Commit

Permalink
Electra MaxEB state changes (#8186)
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Harris <paul.harris@consensys.net>
  • Loading branch information
rolfyone authored Apr 11, 2024
1 parent ad5e63f commit 8ac4353
Show file tree
Hide file tree
Showing 21 changed files with 896 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title" : "BeaconStateElectra",
"type" : "object",
"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" ],
"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" ],
"properties" : {
"genesis_time" : {
"type" : "string",
Expand Down Expand Up @@ -176,6 +176,54 @@
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
},
"deposit_balance_to_consume" : {
"type" : "string",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
},
"exit_balance_to_consume" : {
"type" : "string",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
},
"earliest_exit_epoch" : {
"type" : "string",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
},
"consolidation_balance_to_consume" : {
"type" : "string",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
},
"earliest_consolidation_epoch" : {
"type" : "string",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
},
"pending_balance_deposits" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/PendingBalanceDeposit"
}
},
"pending_partial_withdrawals" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/PendingPartialWithdrawal"
}
},
"pending_consolidations" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/PendingConsolidation"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"title" : "PendingBalanceDeposit",
"type" : "object",
"required" : [ "index", "amount" ],
"properties" : {
"index" : {
"type" : "string",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
},
"amount" : {
"type" : "string",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"title" : "PendingConsolidation",
"type" : "object",
"required" : [ "source_index", "target_index" ],
"properties" : {
"source_index" : {
"type" : "string",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
},
"target_index" : {
"type" : "string",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"title" : "PendingPartialWithdrawal",
"type" : "object",
"required" : [ "index", "amount", "withdrawable_epoch" ],
"properties" : {
"index" : {
"type" : "string",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
},
"amount" : {
"type" : "string",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
},
"withdrawable_epoch" : {
"type" : "string",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ public class BeaconStateElectra extends BeaconStateAltair {
@JsonProperty("deposit_receipts_start_index")
public final UInt64 depositReceiptsStartIndex;

@JsonProperty("deposit_balance_to_consume")
public final UInt64 depositBalanceToConsume;

@JsonProperty("exit_balance_to_consume")
public final UInt64 exitBalanceToConsume;

@JsonProperty("earliest_exit_epoch")
public final UInt64 earliestExitEpoch;

@JsonProperty("consolidation_balance_to_consume")
public final UInt64 consolidationBalanceToConsume;

@JsonProperty("earliest_consolidation_epoch")
public final UInt64 earliestConsolidationEpoch;

@JsonProperty("pending_balance_deposits")
public final List<PendingBalanceDeposit> pendingBalanceDeposits;

@JsonProperty("pending_partial_withdrawals")
public final List<PendingPartialWithdrawal> pendingPartialWithdrawals;

@JsonProperty("pending_consolidations")
public final List<PendingConsolidation> pendingConsolidations;

public BeaconStateElectra(
@JsonProperty("genesis_time") final UInt64 genesisTime,
@JsonProperty("genesis_validators_root") final Bytes32 genesisValidatorsRoot,
Expand Down Expand Up @@ -87,7 +111,18 @@ public BeaconStateElectra(
@JsonProperty("next_withdrawal_index") final UInt64 nextWithdrawalIndex,
@JsonProperty("next_withdrawal_validator_index") final UInt64 nextWithdrawalValidatorIndex,
@JsonProperty("historical_summaries") final List<HistoricalSummary> historicalSummaries,
@JsonProperty("deposit_receipts_start_index") final UInt64 depositReceiptsStartIndex) {
@JsonProperty("deposit_receipts_start_index") final UInt64 depositReceiptsStartIndex,
@JsonProperty("deposit_balance_to_consume") final UInt64 depositBalanceToConsume,
@JsonProperty("exit_balance_to_consume") final UInt64 exitBalanceToConsume,
@JsonProperty("earliest_exit_epoch") final UInt64 earliestExitEpoch,
@JsonProperty("consolidation_balance_to_consume") final UInt64 consolidationBalanceToConsume,
@JsonProperty("earliest_consolidation_epoch") final UInt64 earliestConsolidationEpoch,
@JsonProperty("pending_balance_deposits")
final List<PendingBalanceDeposit> pendingBalanceDeposits,
@JsonProperty("pending_partial_withdrawals")
final List<PendingPartialWithdrawal> pendingPartialWithdrawals,
@JsonProperty("pending_consolidations")
final List<PendingConsolidation> pendingConsolidations) {
super(
genesisTime,
genesisValidatorsRoot,
Expand Down Expand Up @@ -118,6 +153,14 @@ public BeaconStateElectra(
this.nextWithdrawalValidatorIndex = nextWithdrawalValidatorIndex;
this.historicalSummaries = historicalSummaries;
this.depositReceiptsStartIndex = depositReceiptsStartIndex;
this.depositBalanceToConsume = depositBalanceToConsume;
this.exitBalanceToConsume = exitBalanceToConsume;
this.earliestExitEpoch = earliestExitEpoch;
this.consolidationBalanceToConsume = consolidationBalanceToConsume;
this.earliestConsolidationEpoch = earliestConsolidationEpoch;
this.pendingBalanceDeposits = pendingBalanceDeposits;
this.pendingPartialWithdrawals = pendingPartialWithdrawals;
this.pendingConsolidations = pendingConsolidations;
}

public BeaconStateElectra(final BeaconState beaconState) {
Expand All @@ -132,6 +175,17 @@ public BeaconStateElectra(final BeaconState beaconState) {
this.historicalSummaries =
electra.getHistoricalSummaries().stream().map(HistoricalSummary::new).toList();
this.depositReceiptsStartIndex = electra.getDepositReceiptsStartIndex();
this.depositBalanceToConsume = electra.getDepositBalanceToConsume();
this.exitBalanceToConsume = electra.getExitBalanceToConsume();
this.earliestExitEpoch = electra.getEarliestExitEpoch();
this.consolidationBalanceToConsume = electra.getConsolidationBalanceToConsume();
this.earliestConsolidationEpoch = electra.getEarliestConsolidationEpoch();
this.pendingBalanceDeposits =
electra.getPendingBalanceDeposits().stream().map(PendingBalanceDeposit::new).toList();
this.pendingPartialWithdrawals =
electra.getPendingPartialWithdrawals().stream().map(PendingPartialWithdrawal::new).toList();
this.pendingConsolidations =
electra.getPendingConsolidations().stream().map(PendingConsolidation::new).toList();
}

@Override
Expand All @@ -153,6 +207,15 @@ protected void applyAdditionalFields(
BeaconStateSchemaElectra.required(
mutableBeaconStateElectra.getBeaconStateSchema())
.getHistoricalSummariesSchema(),
BeaconStateSchemaElectra.required(
mutableBeaconStateElectra.getBeaconStateSchema())
.getPendingBalanceDepositsSchema(),
BeaconStateSchemaElectra.required(
mutableBeaconStateElectra.getBeaconStateSchema())
.getPendingPartialWithdrawalsSchema(),
BeaconStateSchemaElectra.required(
mutableBeaconStateElectra.getBeaconStateSchema())
.getPendingConsolidationsSchema(),
this));
}

Expand All @@ -164,6 +227,16 @@ protected static void applyElectraFields(
final SszListSchema<
tech.pegasys.teku.spec.datastructures.state.versions.capella.HistoricalSummary, ?>
historicalSummariesSchema,
final SszListSchema<
tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingBalanceDeposit, ?>
pendingBalanceDepositsSchema,
final SszListSchema<
tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingPartialWithdrawal,
?>
pendingPartialWithdrawalsSchema,
final SszListSchema<
tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingConsolidation, ?>
pendingConsolidationsSchema,
final BeaconStateElectra instance) {

BeaconStateAltair.applyAltairFields(state, syncCommitteeSchema, instance);
Expand All @@ -181,5 +254,31 @@ protected static void applyElectraFields(
historicalSummary -> historicalSummary.asInternalHistoricalSummary(specVersion))
.toList()));
state.setDepositReceiptsStartIndex(instance.depositReceiptsStartIndex);
state.setDepositBalanceToConsume(instance.depositBalanceToConsume);
state.setExitBalanceToConsume(instance.exitBalanceToConsume);
state.setEarliestExitEpoch(instance.earliestExitEpoch);
state.setConsolidationBalanceToConsume(instance.consolidationBalanceToConsume);
state.setEarliestConsolidationEpoch(instance.earliestConsolidationEpoch);
state.setPendingBalanceDeposits(
pendingBalanceDepositsSchema.createFromElements(
instance.pendingBalanceDeposits.stream()
.map(
pendingBalanceDeposit ->
pendingBalanceDeposit.asInternalPendingBalanceDeposit(specVersion))
.toList()));
state.setPendingPartialWithdrawals(
pendingPartialWithdrawalsSchema.createFromElements(
instance.pendingPartialWithdrawals.stream()
.map(
pendingPartialWithdrawal ->
pendingPartialWithdrawal.asInternalPendingPartialWithdrawal(specVersion))
.toList()));
state.setPendingConsolidations(
pendingConsolidationsSchema.createFromElements(
instance.pendingConsolidations.stream()
.map(
pendingConsolidation ->
pendingConsolidation.asInternalPendingConsolidation(specVersion))
.toList()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright Consensys Software Inc., 2024
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.api.schema.electra;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Optional;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.SpecVersion;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsElectra;

public class PendingBalanceDeposit {

@JsonProperty("index")
public final int index;

@JsonProperty("amount")
public final UInt64 amount;

public PendingBalanceDeposit(
@JsonProperty("index") int index, @JsonProperty("amount") UInt64 amount) {
this.index = index;
this.amount = amount;
}

public PendingBalanceDeposit(
final tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingBalanceDeposit
internalPendingBalanceDeposit) {
this.index = internalPendingBalanceDeposit.getIndex();
this.amount = internalPendingBalanceDeposit.getAmount();
}

public tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingBalanceDeposit
asInternalPendingBalanceDeposit(final SpecVersion spec) {
final Optional<SchemaDefinitionsElectra> schemaDefinitionsElectra =
spec.getSchemaDefinitions().toVersionElectra();
if (schemaDefinitionsElectra.isEmpty()) {
throw new IllegalArgumentException(
"Could not create PendingBalanceDeposit for pre-electra spec");
}
return schemaDefinitionsElectra
.get()
.getPendingBalanceDepositSchema()
.create(SszUInt64.of(UInt64.valueOf(this.index)), SszUInt64.of(this.amount));
}
}
Loading

0 comments on commit 8ac4353

Please sign in to comment.