Skip to content

Commit

Permalink
small nits
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Dec 10, 2024
1 parent e2be7d4 commit 347a42e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ public void addValidatorToRegistry(
final BLSPublicKey pubkey,
final Bytes32 withdrawalCredentials,
final UInt64 amount) {
final Validator validator = getValidatorFromDeposit(pubkey, withdrawalCredentials, amount);
final Validator validator =
miscHelpers.getValidatorFromDeposit(pubkey, withdrawalCredentials, amount);
LOG.debug("Adding new validator with index {} to state", state.getValidators().size());
state.getValidators().append(validator);
state.getBalances().appendElement(amount);
Expand Down Expand Up @@ -304,22 +305,4 @@ protected int getMinSlashingPenaltyQuotient() {
protected int getWhistleblowerRewardQuotient() {
return specConfig.getWhistleblowerRewardQuotient();
}

/** get_validator_from_deposit */
protected Validator getValidatorFromDeposit(
final BLSPublicKey pubkey, final Bytes32 withdrawalCredentials, final UInt64 amount) {
final UInt64 effectiveBalance =
amount
.minus(amount.mod(specConfig.getEffectiveBalanceIncrement()))
.min(specConfig.getMaxEffectiveBalance());
return new Validator(
pubkey,
withdrawalCredentials,
effectiveBalance,
false,
FAR_FUTURE_EPOCH,
FAR_FUTURE_EPOCH,
FAR_FUTURE_EPOCH,
FAR_FUTURE_EPOCH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static com.google.common.base.Preconditions.checkArgument;
import static tech.pegasys.teku.infrastructure.crypto.Hash.getSha256Instance;
import static tech.pegasys.teku.spec.config.SpecConfig.FAR_FUTURE_EPOCH;
import static tech.pegasys.teku.spec.logic.common.block.AbstractBlockProcessor.depositSignatureVerifier;
import static tech.pegasys.teku.spec.logic.common.helpers.MathHelpers.bytesToUInt64;
import static tech.pegasys.teku.spec.logic.common.helpers.MathHelpers.uint64ToBytes;
Expand Down Expand Up @@ -377,6 +378,24 @@ public boolean isValidDepositSignature(
}
}

/** get_validator_from_deposit */
public Validator getValidatorFromDeposit(
final BLSPublicKey pubkey, final Bytes32 withdrawalCredentials, final UInt64 amount) {
final UInt64 effectiveBalance =
amount
.minus(amount.mod(specConfig.getEffectiveBalanceIncrement()))
.min(specConfig.getMaxEffectiveBalance());
return new Validator(
pubkey,
withdrawalCredentials,
effectiveBalance,
false,
FAR_FUTURE_EPOCH,
FAR_FUTURE_EPOCH,
FAR_FUTURE_EPOCH,
FAR_FUTURE_EPOCH);
}

public boolean isMergeTransitionComplete(final BeaconState state) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
package tech.pegasys.teku.spec.logic.versions.electra.helpers;

import static com.google.common.base.Preconditions.checkArgument;
import static tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO;
import static tech.pegasys.teku.spec.config.SpecConfig.FAR_FUTURE_EPOCH;
import static tech.pegasys.teku.spec.constants.WithdrawalPrefixes.COMPOUNDING_WITHDRAWAL_BYTE;

import java.util.function.Supplier;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64;
Expand Down Expand Up @@ -270,27 +268,4 @@ protected int getWhistleblowerRewardQuotient() {
protected int getMinSlashingPenaltyQuotient() {
return specConfigElectra.getMinSlashingPenaltyQuotientElectra();
}

@Override
protected 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@

package tech.pegasys.teku.spec.logic.versions.electra.helpers;

import static tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO;
import static tech.pegasys.teku.spec.config.SpecConfig.FAR_FUTURE_EPOCH;

import it.unimi.dsi.fastutil.ints.IntList;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.config.SpecConfigElectra;
Expand Down Expand Up @@ -64,6 +68,29 @@ public int computeProposerIndex(
SpecConfigElectra.required(specConfig).getMaxEffectiveBalanceElectra());
}

@Override
public 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 = getMaxEffectiveBalance(validator);
final UInt64 validatorEffectiveBalance =
amount
.minusMinZero(amount.mod(specConfig.getEffectiveBalanceIncrement()))
.min(maxEffectiveBalance);

return validator.withEffectiveBalance(validatorEffectiveBalance);
}

@Override
public UInt64 getMaxEffectiveBalance(final Validator validator) {
return predicatesElectra.hasCompoundingWithdrawalCredential(validator)
Expand Down

0 comments on commit 347a42e

Please sign in to comment.