Skip to content

Commit

Permalink
Use min_activation_balance instead of max_effective_balance for activ…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
dapplion committed Jan 30, 2024
1 parent 0f345c7 commit f73cd56
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion account_manager/src/validator/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub fn cli_run<T: EthSpec>(
};

let deposit_gwei = clap_utils::parse_optional(matches, DEPOSIT_GWEI_FLAG)?
.unwrap_or(spec.max_effective_balance);
.unwrap_or(spec.min_activation_balance);
let count: Option<usize> = clap_utils::parse_optional(matches, COUNT_FLAG)?;
let at_most: Option<usize> = clap_utils::parse_optional(matches, AT_MOST_FLAG)?;

Expand Down
4 changes: 2 additions & 2 deletions beacon_node/beacon_chain/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,8 +1225,8 @@ mod test {

for b in state.balances() {
assert_eq!(
*b, spec.max_effective_balance,
"validator balances should be max effective balance"
*b, spec.min_activation_balance,
"validator balances should be min activation balance"
);
}

Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/eth1_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ mod test {
let mut deposit = DepositData {
pubkey: keypair.pk.into(),
withdrawal_credentials: Hash256::zero(),
amount: spec.max_effective_balance,
amount: spec.min_activation_balance,
signature: Signature::empty().into(),
};

Expand Down
10 changes: 5 additions & 5 deletions beacon_node/genesis/src/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn interop_genesis_state_with_withdrawal_credentials<T: EthSpec>(
}

let eth1_timestamp = 2_u64.pow(40);
let amount = spec.max_effective_balance;
let amount = spec.min_activation_balance;

let datas = keypairs
.into_par_iter()
Expand Down Expand Up @@ -172,8 +172,8 @@ mod test {

for b in state.balances() {
assert_eq!(
*b, spec.max_effective_balance,
"validator balances should be max effective balance"
*b, spec.min_activation_balance,
"validator balances should be min activation balance"
);
}

Expand Down Expand Up @@ -234,8 +234,8 @@ mod test {

for b in state.balances() {
assert_eq!(
*b, spec.max_effective_balance,
"validator balances should be max effective balance"
*b, spec.min_activation_balance,
"validator balances should be min activation balance"
);
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/state_processing/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub fn process_activations<T: EthSpec>(
balance.safe_sub(balance.safe_rem(spec.effective_balance_increment)?)?,
spec.max_effective_balance,
);
if validator.effective_balance == spec.max_effective_balance {
if validator.effective_balance >= spec.min_activation_balance {
validator.activation_eligibility_epoch = T::genesis_epoch();
validator.activation_epoch = T::genesis_epoch();
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn get_state<E: EthSpec>(validator_count: usize) -> BeaconState<E> {
.map(|&i| Validator {
pubkey: generate_deterministic_keypair(i).pk.into(),
withdrawal_credentials: Hash256::from_low_u64_le(i as u64),
effective_balance: spec.max_effective_balance,
effective_balance: spec.min_activation_balance,
slashed: false,
activation_eligibility_epoch: Epoch::new(0),
activation_epoch: Epoch::new(0),
Expand Down
9 changes: 9 additions & 0 deletions consensus/types/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub struct ChainSpec {
*/
pub min_deposit_amount: u64,
pub max_effective_balance: u64,
pub min_activation_balance: u64,
pub ejection_balance: u64,
pub effective_balance_increment: u64,

Expand Down Expand Up @@ -566,6 +567,10 @@ impl ChainSpec {
u64::checked_pow(2, 5)?.checked_mul(u64::checked_pow(10, 9)?)
})
.expect("calculation does not overflow"),
min_activation_balance: option_wrapper(|| {
u64::checked_pow(2, 5)?.checked_mul(u64::checked_pow(10, 9)?)
})
.expect("calculation does not overflow"),
ejection_balance: option_wrapper(|| {
u64::checked_pow(2, 4)?.checked_mul(u64::checked_pow(10, 9)?)
})
Expand Down Expand Up @@ -825,6 +830,10 @@ impl ChainSpec {
u64::checked_pow(2, 5)?.checked_mul(u64::checked_pow(10, 9)?)
})
.expect("calculation does not overflow"),
min_activation_balance: option_wrapper(|| {
u64::checked_pow(2, 5)?.checked_mul(u64::checked_pow(10, 9)?)
})
.expect("calculation does not overflow"),
ejection_balance: option_wrapper(|| {
u64::checked_pow(2, 4)?.checked_mul(u64::checked_pow(10, 9)?)
})
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Validator {
/// Spec v0.12.1
pub fn is_eligible_for_activation_queue(&self, spec: &ChainSpec) -> bool {
self.activation_eligibility_epoch == spec.far_future_epoch
&& self.effective_balance == spec.max_effective_balance
&& self.effective_balance >= spec.min_activation_balance
}

/// Returns `true` if the validator is eligible to be activated.
Expand Down
2 changes: 1 addition & 1 deletion lcli/src/deploy_deposit_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn run<T: EthSpec>(env: Environment<T>, matches: &ArgMatches<'_>) -> Result<

// Deposit insecure validators to the deposit contract created
if let Some(validator_count) = validator_count {
let amount = env.eth2_config.spec.max_effective_balance;
let amount = env.eth2_config.spec.min_activation_balance;
for i in 0..validator_count {
println!("Submitting deposit for validator {}...", i);
contract.deposit_deterministic_async::<T>(i, amount).await?;
Expand Down
2 changes: 1 addition & 1 deletion lcli/src/new_testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ fn initialize_state_with_validators<T: EthSpec>(
credentials[0] = spec.bls_withdrawal_prefix_byte;
Hash256::from_slice(&credentials)
};
let amount = spec.max_effective_balance;
let amount = spec.min_activation_balance;
// Create a new validator.
let validator = Validator {
pubkey: keypair.0.pk.clone().into(),
Expand Down
2 changes: 1 addition & 1 deletion lighthouse/tests/validator_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub fn validator_create_defaults() {
output_path: PathBuf::from("./meow"),
first_index: 0,
count: 1,
deposit_gwei: MainnetEthSpec::default_spec().max_effective_balance,
deposit_gwei: MainnetEthSpec::default_spec().min_activation_balance,
mnemonic_path: None,
stdin_inputs: cfg!(windows) || false,
disable_deposits: false,
Expand Down
2 changes: 1 addition & 1 deletion testing/simulator/src/eth1_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn run_eth1_sim(matches: &ArgMatches) -> Result<(), String> {
let seconds_per_slot = spec.seconds_per_slot;
let slot_duration = Duration::from_secs(spec.seconds_per_slot);
let initial_validator_count = spec.min_genesis_active_validator_count as usize;
let deposit_amount = env.eth2_config.spec.max_effective_balance;
let deposit_amount = env.eth2_config.spec.min_activation_balance;

let context = env.core_context();

Expand Down
4 changes: 2 additions & 2 deletions validator_client/src/http_api/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl ApiTester {
builder_proposals: None,
builder_boost_factor: None,
prefer_builder_proposals: None,
deposit_gwei: E::default_spec().max_effective_balance,
deposit_gwei: E::default_spec().min_activation_balance,
})
.collect::<Vec<_>>();

Expand Down Expand Up @@ -399,7 +399,7 @@ impl ApiTester {
let deposit_bytes = serde_utils::hex::decode(&item.eth1_deposit_tx_data).unwrap();

let (deposit_data, _) =
decode_eth1_tx_data(&deposit_bytes, E::default_spec().max_effective_balance)
decode_eth1_tx_data(&deposit_bytes, E::default_spec().min_activation_balance)
.unwrap();

assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions validator_client/src/http_api/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl ApiTester {
builder_proposals: None,
builder_boost_factor: None,
prefer_builder_proposals: None,
deposit_gwei: E::default_spec().max_effective_balance,
deposit_gwei: E::default_spec().min_activation_balance,
})
.collect::<Vec<_>>();

Expand Down Expand Up @@ -360,7 +360,7 @@ impl ApiTester {
serde_utils::hex::decode(&response[i].eth1_deposit_tx_data).unwrap();

let (deposit_data, _) =
decode_eth1_tx_data(&deposit_bytes, E::default_spec().max_effective_balance)
decode_eth1_tx_data(&deposit_bytes, E::default_spec().min_activation_balance)
.unwrap();

assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions validator_manager/src/create_validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl CreateConfig {
Ok(Self {
output_path: clap_utils::parse_required(matches, OUTPUT_PATH_FLAG)?,
deposit_gwei: clap_utils::parse_optional(matches, DEPOSIT_GWEI_FLAG)?
.unwrap_or(spec.max_effective_balance),
.unwrap_or(spec.min_activation_balance),
first_index: clap_utils::parse_required(matches, FIRST_INDEX_FLAG)?,
count: clap_utils::parse_required(matches, COUNT_FLAG)?,
mnemonic_path: clap_utils::parse_optional(matches, MNEMONIC_FLAG)?,
Expand Down Expand Up @@ -615,7 +615,7 @@ pub mod tests {
output_path: output_dir.path().into(),
first_index: 0,
count: 1,
deposit_gwei: spec.max_effective_balance,
deposit_gwei: spec.min_activation_balance,
mnemonic_path: Some(mnemonic_path),
stdin_inputs: false,
disable_deposits: false,
Expand Down

0 comments on commit f73cd56

Please sign in to comment.