From 06c7faf546e5eac57018b84d59f2bc661f9a5bec Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Tue, 10 Dec 2024 17:06:39 +0000 Subject: [PATCH] small nits --- .../common/helpers/BeaconStateMutators.java | 21 ++------------- .../logic/common/helpers/MiscHelpers.java | 19 +++++++++++++ .../helpers/BeaconStateMutatorsElectra.java | 25 ----------------- .../electra/helpers/MiscHelpersElectra.java | 27 +++++++++++++++++++ 4 files changed, 48 insertions(+), 44 deletions(-) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/helpers/BeaconStateMutators.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/helpers/BeaconStateMutators.java index fd20e98dbf1..28b04635336 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/helpers/BeaconStateMutators.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/helpers/BeaconStateMutators.java @@ -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); @@ -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); - } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/helpers/MiscHelpers.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/helpers/MiscHelpers.java index 00b40f16243..d7e3aeb0f76 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/helpers/MiscHelpers.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/helpers/MiscHelpers.java @@ -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; @@ -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; } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/helpers/BeaconStateMutatorsElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/helpers/BeaconStateMutatorsElectra.java index 1325dab899a..7b9e7b2a1ba 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/helpers/BeaconStateMutatorsElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/helpers/BeaconStateMutatorsElectra.java @@ -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; @@ -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); - } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/helpers/MiscHelpersElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/helpers/MiscHelpersElectra.java index fdb4303afa1..e5c8869e9ad 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/helpers/MiscHelpersElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/helpers/MiscHelpersElectra.java @@ -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; @@ -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)