Skip to content

Commit

Permalink
more delete
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Nov 27, 2024
1 parent 67efcc0 commit 862f98c
Showing 1 changed file with 1 addition and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.ssz.SszMutableList;
import tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszByte;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.config.SpecConfig;
Expand Down Expand Up @@ -200,7 +196,7 @@ public void applyPendingDeposits(final MutableBeaconState state, final PendingDe
beaconStateMutators.increaseBalance(state, validatorIndex, deposit.getAmount()),
() -> {
if (isValidPendingDepositSignature(deposit)) {
addValidatorToRegistry(
beaconStateMutators.addValidatorToRegistry(
state,
deposit.getPublicKey(),
deposit.getWithdrawalCredentials(),
Expand All @@ -217,46 +213,6 @@ private boolean isValidPendingDepositSignature(final PendingDeposit deposit) {
deposit.getSignature());
}

// TODO-lucas Duplicates method addValidatorToRegistry from BlockProcessor
/** add_validator_to_registry */
public void addValidatorToRegistry(
final MutableBeaconState state,
final BLSPublicKey pubkey,
final Bytes32 withdrawalCredentials,
final UInt64 amount) {
final Validator validator = getValidatorFromDeposit(pubkey, withdrawalCredentials, amount);

final MutableBeaconStateElectra stateElectra = MutableBeaconStateElectra.required(state);
stateElectra.getValidators().append(validator);
stateElectra.getBalances().appendElement(amount);
stateElectra.getPreviousEpochParticipation().append(SszByte.ZERO);
stateElectra.getCurrentEpochParticipation().append(SszByte.ZERO);
stateElectra.getInactivityScores().append(SszUInt64.ZERO);
}

/** get_validator_from_deposit */
private Validator getValidatorFromDeposit(
final BLSPublicKey pubkey, final Bytes32 withdrawalCredentials, final UInt64 amount) {
final Validator validator =
new Validator(
pubkey,
withdrawalCredentials,
ZERO,
false,
FAR_FUTURE_EPOCH,
FAR_FUTURE_EPOCH,
FAR_FUTURE_EPOCH,
FAR_FUTURE_EPOCH);

final UInt64 maxEffectiveBalance = miscHelpers.getMaxEffectiveBalance(validator);
final UInt64 validatorEffectiveBalance =
amount
.minusMinZero(amount.mod(specConfig.getEffectiveBalanceIncrement()))
.min(maxEffectiveBalance);

return validator.withEffectiveBalance(validatorEffectiveBalance);
}

/** process_pending_deposits */
@Override
public void processPendingDeposits(final MutableBeaconState state) {
Expand Down

0 comments on commit 862f98c

Please sign in to comment.