From d5ff25b59d33a42fe6323b072cc14394e4aad8a0 Mon Sep 17 00:00:00 2001 From: Justin Traglia <95511699+jtraglia@users.noreply.github.com> Date: Sat, 2 Nov 2024 10:35:40 -0500 Subject: [PATCH] Fix order & add slashed=false to new validator instances (#14595) * Fix order & add slashed=false to new validator instances * Add a line to the changelog * Update godocs --- CHANGELOG.md | 1 + beacon-chain/core/altair/deposit.go | 6 ++++-- beacon-chain/core/electra/deposits.go | 6 ++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e0d00851e0..d4c4ca276cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve - Use read only validator for core processing to avoid unnecessary copying. - Use ROBlock across block processing pipeline. - Added missing Eth-Consensus-Version headers to GetBlockAttestationsV2 and GetAttesterSlashingsV2 endpoints. +- When instantiating new validators, explicit set `Slashed` to false and move `EffectiveBalance` to match struct definition. - Updated pgo profile for beacon chain with holesky data. This improves the profile guided optimizations in the go compiler. - Use read only state when computing the active validator list. diff --git a/beacon-chain/core/altair/deposit.go b/beacon-chain/core/altair/deposit.go index 084643324e4..5aeb23c100c 100644 --- a/beacon-chain/core/altair/deposit.go +++ b/beacon-chain/core/altair/deposit.go @@ -187,11 +187,12 @@ func AddValidatorToRegistry(beaconState state.BeaconState, pubKey []byte, withdr // return Validator( // pubkey=pubkey, // withdrawal_credentials=withdrawal_credentials, +// effective_balance=effective_balance, +// slashed=False, // activation_eligibility_epoch=FAR_FUTURE_EPOCH, // activation_epoch=FAR_FUTURE_EPOCH, // exit_epoch=FAR_FUTURE_EPOCH, // withdrawable_epoch=FAR_FUTURE_EPOCH, -// effective_balance=effective_balance, // ) func GetValidatorFromDeposit(pubKey []byte, withdrawalCredentials []byte, amount uint64) *ethpb.Validator { effectiveBalance := amount - (amount % params.BeaconConfig().EffectiveBalanceIncrement) @@ -202,10 +203,11 @@ func GetValidatorFromDeposit(pubKey []byte, withdrawalCredentials []byte, amount return ðpb.Validator{ PublicKey: pubKey, WithdrawalCredentials: withdrawalCredentials, + EffectiveBalance: effectiveBalance, + Slashed: false, ActivationEligibilityEpoch: params.BeaconConfig().FarFutureEpoch, ActivationEpoch: params.BeaconConfig().FarFutureEpoch, ExitEpoch: params.BeaconConfig().FarFutureEpoch, WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch, - EffectiveBalance: effectiveBalance, } } diff --git a/beacon-chain/core/electra/deposits.go b/beacon-chain/core/electra/deposits.go index 31fec1191af..098f2ceaf56 100644 --- a/beacon-chain/core/electra/deposits.go +++ b/beacon-chain/core/electra/deposits.go @@ -508,11 +508,12 @@ func AddValidatorToRegistry(beaconState state.BeaconState, pubKey []byte, withdr // validator = Validator( // pubkey=pubkey, // withdrawal_credentials=withdrawal_credentials, +// effective_balance=Gwei(0), +// slashed=False, // activation_eligibility_epoch=FAR_FUTURE_EPOCH, // activation_epoch=FAR_FUTURE_EPOCH, // exit_epoch=FAR_FUTURE_EPOCH, // withdrawable_epoch=FAR_FUTURE_EPOCH, -// effective_balance=Gwei(0), // ) // // # [Modified in Electra:EIP7251] @@ -524,11 +525,12 @@ func GetValidatorFromDeposit(pubKey []byte, withdrawalCredentials []byte, amount validator := ðpb.Validator{ PublicKey: pubKey, WithdrawalCredentials: withdrawalCredentials, + EffectiveBalance: 0, + Slashed: false, ActivationEligibilityEpoch: params.BeaconConfig().FarFutureEpoch, ActivationEpoch: params.BeaconConfig().FarFutureEpoch, ExitEpoch: params.BeaconConfig().FarFutureEpoch, WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch, - EffectiveBalance: 0, } v, err := state_native.NewValidator(validator) if err != nil {