Skip to content

Commit

Permalink
Genesis reftests (Consensys#8287)
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Harris <[email protected]>
  • Loading branch information
rolfyone authored May 3, 2024
1 parent 9e7c10e commit 3004a66
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package tech.pegasys.teku.spec.genesis;

import static tech.pegasys.teku.spec.config.SpecConfig.GENESIS_EPOCH;
import static tech.pegasys.teku.spec.config.SpecConfigElectra.UNSET_DEPOSIT_RECEIPTS_START_INDEX;

import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
Expand All @@ -29,7 +30,6 @@
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.SpecVersion;
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.config.SpecConfigElectra;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader;
import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
Expand Down Expand Up @@ -95,7 +95,7 @@ public void updateCandidateState(
// Process deposits
deposits.forEach(
deposit -> {
LOG.trace("About to process deposit: {}", depositDataList::size);
LOG.trace("About to process deposit: {}", depositDataList.size());
depositDataList.append(deposit.getData());

// Skip verifying the merkle proof as these deposits come directly from an Eth1 event.
Expand Down Expand Up @@ -123,17 +123,19 @@ private void consumePendingBalance(
genesisSpec.beaconStateAccessors(),
schemaDefinitionsElectra);
final List<PendingBalanceDeposit> pendingBalanceDeposits =
stateElectra.getPendingBalanceDeposits().stream().toList();
stateElectra.getPendingBalanceDeposits().asList();

final UInt64 depositAmount =
pendingBalanceDeposits.stream()
.filter(z -> z.getIndex() == validatorIndex)
.map(z -> z.getAmount())
.map(PendingBalanceDeposit::getAmount)
.reduce(UInt64::plus)
.get();
if (depositAmount.isGreaterThanOrEqualTo(
SpecConfigElectra.required(specConfig).getMinActivationBalance())) {
mutatorsElectra.increaseBalance(state, validatorIndex, depositAmount);
.orElse(UInt64.ZERO);
mutatorsElectra.increaseBalance(state, validatorIndex, depositAmount);
if (pendingBalanceDeposits.isEmpty()) {
stateElectra.setPendingBalanceDeposits(
schemaDefinitionsElectra.getPendingBalanceDepositsSchema().createFromElements(List.of()));
} else {
stateElectra.setPendingBalanceDeposits(
schemaDefinitionsElectra
.getPendingBalanceDepositsSchema()
Expand All @@ -150,7 +152,7 @@ private void processActivation(final Deposit deposit) {
// Could be absent if the deposit was invalid
return;
}
Validator validator = state.getValidators().get(index);
final Validator validator = state.getValidators().get(index);
if (validator.getActivationEpoch().equals(GENESIS_EPOCH)) {
// Validator is already activated (and thus already has the max effective balance)
return;
Expand All @@ -159,6 +161,8 @@ private void processActivation(final Deposit deposit) {
if (genesisSpec.getMilestone().equals(SpecMilestone.ELECTRA)) {
consumePendingBalance(
MutableBeaconStateElectra.required(state), specConfig, genesisSpec, index);
MutableBeaconStateElectra.required(state)
.setDepositReceiptsStartIndex(UNSET_DEPOSIT_RECEIPTS_START_INDEX);
}
final UInt64 balance = state.getBalances().getElement(index);
final UInt64 effectiveBalance =
Expand Down

0 comments on commit 3004a66

Please sign in to comment.