Skip to content

Commit

Permalink
EIP-6110: Queue deposit requests and apply them during epoch processi…
Browse files Browse the repository at this point in the history
…ng (#8681)
  • Loading branch information
lucassaldanha authored Oct 7, 2024
1 parent dca8285 commit c76765e
Show file tree
Hide file tree
Showing 35 changed files with 653 additions and 459 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ allprojects {
}
}

def refTestVersion = 'v1.5.0-alpha.6'
def refTestVersion = 'v1.5.0-alpha.7'
def blsRefTestVersion = 'v0.1.2'
def slashingProtectionInterchangeRefTestVersion = 'v5.3.0'
def refTestBaseUrl = 'https://github.com/ethereum/consensus-spec-tests/releases/download'
Expand Down
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_requests_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" ],
"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_requests_start_index", "deposit_balance_to_consume", "exit_balance_to_consume", "earliest_exit_epoch", "consolidation_balance_to_consume", "earliest_consolidation_epoch", "pending_deposits", "pending_partial_withdrawals", "pending_consolidations" ],
"properties" : {
"genesis_time" : {
"type" : "string",
Expand Down Expand Up @@ -207,10 +207,10 @@
"example" : "1",
"format" : "uint64"
},
"pending_balance_deposits" : {
"pending_deposits" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/PendingBalanceDeposit"
"$ref" : "#/components/schemas/PendingDeposit"
}
},
"pending_partial_withdrawals" : {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"title": "PendingDeposit",
"type": "object",
"required": [
"pubkey",
"withdrawal_credentials",
"amount",
"signature",
"slot"
],
"properties": {
"pubkey": {
"type": "string",
"pattern": "^0x[a-fA-F0-9]{2,}$",
"description": "Bytes48 hexadecimal",
"format": "bytes"
},
"withdrawal_credentials": {
"type": "string",
"description": "Bytes32 hexadecimal",
"example": "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
"format": "byte"
},
"amount": {
"type": "string",
"description": "unsigned 64 bit integer",
"example": "1",
"format": "uint64"
},
"signature": {
"type": "string",
"pattern": "^0x[a-fA-F0-9]{2,}$",
"description": "SSZ hexadecimal",
"format": "bytes"
},
"slot": {
"type": "string",
"description": "unsigned 64 bit integer",
"example": "1",
"format": "uint64"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public class BeaconStateElectra extends BeaconStateAltair {
@JsonProperty("earliest_consolidation_epoch")
public final UInt64 earliestConsolidationEpoch;

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

@JsonProperty("pending_partial_withdrawals")
public final List<PendingPartialWithdrawal> pendingPartialWithdrawals;
Expand Down Expand Up @@ -118,8 +118,7 @@ public BeaconStateElectra(
@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_deposits") final List<PendingDeposit> pendingDeposits,
@JsonProperty("pending_partial_withdrawals")
final List<PendingPartialWithdrawal> pendingPartialWithdrawals,
@JsonProperty("pending_consolidations")
Expand Down Expand Up @@ -159,7 +158,7 @@ public BeaconStateElectra(
this.earliestExitEpoch = earliestExitEpoch;
this.consolidationBalanceToConsume = consolidationBalanceToConsume;
this.earliestConsolidationEpoch = earliestConsolidationEpoch;
this.pendingBalanceDeposits = pendingBalanceDeposits;
this.pendingDeposits = pendingDeposits;
this.pendingPartialWithdrawals = pendingPartialWithdrawals;
this.pendingConsolidations = pendingConsolidations;
}
Expand All @@ -182,8 +181,7 @@ public BeaconStateElectra(final BeaconState beaconState) {
this.earliestExitEpoch = electra.getEarliestExitEpoch();
this.consolidationBalanceToConsume = electra.getConsolidationBalanceToConsume();
this.earliestConsolidationEpoch = electra.getEarliestConsolidationEpoch();
this.pendingBalanceDeposits =
electra.getPendingBalanceDeposits().stream().map(PendingBalanceDeposit::new).toList();
this.pendingDeposits = electra.getPendingDeposits().stream().map(PendingDeposit::new).toList();
this.pendingPartialWithdrawals =
electra.getPendingPartialWithdrawals().stream().map(PendingPartialWithdrawal::new).toList();
this.pendingConsolidations =
Expand Down Expand Up @@ -211,7 +209,7 @@ protected void applyAdditionalFields(
.getHistoricalSummariesSchema(),
BeaconStateSchemaElectra.required(
mutableBeaconStateElectra.getBeaconStateSchema())
.getPendingBalanceDepositsSchema(),
.getPendingDepositsSchema(),
BeaconStateSchemaElectra.required(
mutableBeaconStateElectra.getBeaconStateSchema())
.getPendingPartialWithdrawalsSchema(),
Expand All @@ -230,8 +228,8 @@ protected static void applyElectraFields(
tech.pegasys.teku.spec.datastructures.state.versions.capella.HistoricalSummary, ?>
historicalSummariesSchema,
final SszListSchema<
tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingBalanceDeposit, ?>
pendingBalanceDepositsSchema,
tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingDeposit, ?>
pendingDepositsSchema,
final SszListSchema<
tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingPartialWithdrawal,
?>
Expand Down Expand Up @@ -261,12 +259,10 @@ protected static void applyElectraFields(
state.setEarliestExitEpoch(instance.earliestExitEpoch);
state.setConsolidationBalanceToConsume(instance.consolidationBalanceToConsume);
state.setEarliestConsolidationEpoch(instance.earliestConsolidationEpoch);
state.setPendingBalanceDeposits(
pendingBalanceDepositsSchema.createFromElements(
instance.pendingBalanceDeposits.stream()
.map(
pendingBalanceDeposit ->
pendingBalanceDeposit.asInternalPendingBalanceDeposit(specVersion))
state.setPendingDeposits(
pendingDepositsSchema.createFromElements(
instance.pendingDeposits.stream()
.map(pendingDeposit -> pendingDeposit.asInternalPendingDeposit(specVersion))
.toList()));
state.setPendingPartialWithdrawals(
pendingPartialWithdrawalsSchema.createFromElements(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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 static tech.pegasys.teku.api.schema.SchemaConstants.DESCRIPTION_BYTES96;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.api.schema.BLSSignature;
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.ethereum.execution.types.Eth1Address;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32;
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.datastructures.type.SszPublicKey;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsElectra;

public class PendingDeposit {

@JsonProperty("pubkey")
private final BLSPublicKey publicKey;

@JsonProperty("withdrawal_credentials")
private final Eth1Address withdrawalCredentials;

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

@Schema(type = "string", format = "byte", description = DESCRIPTION_BYTES96)
public final BLSSignature signature;

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

public PendingDeposit(
final @JsonProperty("pubkey") BLSPublicKey publicKey,
final @JsonProperty("withdrawal_credentials") Eth1Address withdrawalCredentials,
final @JsonProperty("amount") UInt64 amount,
final @JsonProperty("signature") BLSSignature signature,
final @JsonProperty("slot") UInt64 slot) {
this.publicKey = publicKey;
this.withdrawalCredentials = withdrawalCredentials;
this.amount = amount;
this.signature = signature;
this.slot = slot;
}

public PendingDeposit(
final tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingDeposit
internalPendingDeposit) {
this.publicKey = internalPendingDeposit.getPublicKey();
this.withdrawalCredentials =
Eth1Address.fromBytes(internalPendingDeposit.getWithdrawalCredentials());
this.amount = internalPendingDeposit.getAmount();
this.signature = new BLSSignature(internalPendingDeposit.getSignature());
this.slot = internalPendingDeposit.getSlot();
}

public tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingDeposit
asInternalPendingDeposit(final SpecVersion spec) {
final Optional<SchemaDefinitionsElectra> schemaDefinitionsElectra =
spec.getSchemaDefinitions().toVersionElectra();
if (schemaDefinitionsElectra.isEmpty()) {
throw new IllegalArgumentException("Could not create PendingDeposit for pre-electra spec");
}
return schemaDefinitionsElectra
.get()
.getPendingDepositSchema()
.create(
new SszPublicKey(publicKey),
SszBytes32.of(Bytes32.wrap(withdrawalCredentials.getWrappedBytes())),
SszUInt64.of(amount),
new SszSignature(signature.asInternalBLSSignature()),
SszUInt64.of(slot));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public enum EpochOperation {
PROCESS_HISTORICAL_ROOTS_UPDATE,
SYNC_COMMITTEE_UPDATES,
PROCESS_HISTORICAL_SUMMARIES_UPDATE,
PENDING_BALANCE_DEPOSITS,
PENDING_DEPOSITS,
PENDING_CONSOLIDATIONS,
INACTIVITY_UPDATES
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void executeOperation(final EpochOperation operation, final MutableBeacon
epochProcessor.processHistoricalSummariesUpdate(state);
case SYNC_COMMITTEE_UPDATES -> epochProcessor.processSyncCommitteeUpdates(state);
case INACTIVITY_UPDATES -> processInactivityUpdates(state);
case PENDING_BALANCE_DEPOSITS -> processPendingBalanceDeposits(state);
case PENDING_DEPOSITS -> processPendingDeposits(state);
case PENDING_CONSOLIDATIONS -> processPendingConsolidations(state);
default ->
throw new UnsupportedOperationException(
Expand All @@ -58,8 +58,8 @@ private void processInactivityUpdates(final MutableBeaconState state) {
state, validatorStatusFactory.createValidatorStatuses(state));
}

private void processPendingBalanceDeposits(final MutableBeaconState state) {
epochProcessor.processPendingBalanceDeposits(state);
private void processPendingDeposits(final MutableBeaconState state) {
epochProcessor.processPendingDeposits(state);
}

private void processPendingConsolidations(final MutableBeaconState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public class EpochProcessingTestExecutor implements TestExecutor {
ImmutableMap.<String, TestExecutor>builder()
.put(
"epoch_processing/slashings",
// TODO: Re-enable these tests as part of https://github.com/Consensys/teku/pull/8612
TestExecutor.IGNORE_TESTS)
new EpochProcessingTestExecutor(EpochOperation.PROCESS_SLASHINGS))
.put(
"epoch_processing/registry_updates",
new EpochProcessingTestExecutor(EpochOperation.PROCESS_REGISTRY_UPDATES))
Expand Down Expand Up @@ -79,12 +78,11 @@ public class EpochProcessingTestExecutor implements TestExecutor {
.put(
"epoch_processing/inactivity_updates",
new EpochProcessingTestExecutor(EpochOperation.INACTIVITY_UPDATES))
// TODO re-enable consolidation tests (https://github.com/Consensys/teku/issues/8617)
.put("epoch_processing/pending_consolidations", TestExecutor.IGNORE_TESTS)
.put(
"epoch_processing/pending_consolidations",
new EpochProcessingTestExecutor(EpochOperation.PENDING_CONSOLIDATIONS))
.put(
"epoch_processing/pending_balance_deposits",
new EpochProcessingTestExecutor(EpochOperation.PENDING_BALANCE_DEPOSITS))
"epoch_processing/pending_deposits",
new EpochProcessingTestExecutor(EpochOperation.PENDING_DEPOSITS))
.build();

private final EpochOperation operation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,13 @@ private enum Operation {
"operations/withdrawal_request",
new OperationsTestExecutor<>(
"withdrawal_request.ssz_snappy", Operation.WITHDRAWAL_REQUEST))
// TODO re-enable consolidation tests (https://github.com/Consensys/teku/issues/8617)
.put(
"operations/consolidation_request",
new OperationsTestExecutor<>(
"consolidation_request.ssz_snappy", Operation.CONSOLIDATION_REQUEST))
// new OperationsTestExecutor<>(
// "consolidation_request.ssz_snappy",
// Operation.CONSOLIDATION_REQUEST))
TestExecutor.IGNORE_TESTS)
.build();

private final String dataFileName;
Expand Down
Loading

0 comments on commit c76765e

Please sign in to comment.