mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-17 04:48:21 +00:00
Make add_validator_to_registry more in line with the spec
This commit is contained in:
@@ -1550,17 +1550,19 @@ impl<E: EthSpec> BeaconState<E> {
|
||||
|
||||
pub fn add_validator_to_registry(
|
||||
&mut self,
|
||||
deposit_data: &DepositData,
|
||||
pubkey: PublicKeyBytes,
|
||||
withdrawal_credentials: Hash256,
|
||||
amount: u64,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), Error> {
|
||||
let fork = self.fork_name_unchecked();
|
||||
let amount = if fork.electra_enabled() {
|
||||
0
|
||||
} else {
|
||||
deposit_data.amount
|
||||
};
|
||||
self.validators_mut()
|
||||
.push(Validator::from_deposit(deposit_data, amount, fork, spec))?;
|
||||
let fork_name = self.fork_name_unchecked();
|
||||
self.validators_mut().push(Validator::from_deposit(
|
||||
pubkey,
|
||||
withdrawal_credentials,
|
||||
amount,
|
||||
fork_name,
|
||||
spec,
|
||||
))?;
|
||||
self.balances_mut().push(amount)?;
|
||||
|
||||
// Altair or later initializations.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
test_utils::TestRandom, Address, BeaconState, ChainSpec, Checkpoint, DepositData, Epoch,
|
||||
EthSpec, FixedBytesExtended, ForkName, Hash256, PublicKeyBytes,
|
||||
test_utils::TestRandom, Address, BeaconState, ChainSpec, Checkpoint, Epoch, EthSpec,
|
||||
FixedBytesExtended, ForkName, Hash256, PublicKeyBytes,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
@@ -37,14 +37,15 @@ pub struct Validator {
|
||||
impl Validator {
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
pub fn from_deposit(
|
||||
deposit_data: &DepositData,
|
||||
pubkey: PublicKeyBytes,
|
||||
withdrawal_credentials: Hash256,
|
||||
amount: u64,
|
||||
fork_name: ForkName,
|
||||
spec: &ChainSpec,
|
||||
) -> Self {
|
||||
let mut validator = Validator {
|
||||
pubkey: deposit_data.pubkey,
|
||||
withdrawal_credentials: deposit_data.withdrawal_credentials,
|
||||
pubkey,
|
||||
withdrawal_credentials,
|
||||
activation_eligibility_epoch: spec.far_future_epoch,
|
||||
activation_epoch: spec.far_future_epoch,
|
||||
exit_epoch: spec.far_future_epoch,
|
||||
|
||||
Reference in New Issue
Block a user