mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-19 21:04:41 +00:00
@@ -426,6 +426,23 @@ fn bench_block_processing(
|
||||
.sample_size(10),
|
||||
);
|
||||
|
||||
let mut state = initial_state.clone();
|
||||
state.drop_pubkey_cache();
|
||||
c.bench(
|
||||
&format!("{}/block_processing", desc),
|
||||
Benchmark::new("build_pubkey_cache", move |b| {
|
||||
b.iter_batched(
|
||||
|| state.clone(),
|
||||
|mut state| {
|
||||
state.update_pubkey_cache().unwrap();
|
||||
state
|
||||
},
|
||||
criterion::BatchSize::SmallInput,
|
||||
)
|
||||
})
|
||||
.sample_size(10),
|
||||
);
|
||||
|
||||
let block = initial_block.clone();
|
||||
c.bench(
|
||||
&format!("{}/block_processing", desc),
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
use criterion::Benchmark;
|
||||
use criterion::Criterion;
|
||||
use criterion::{criterion_group, criterion_main};
|
||||
use env_logger::{Builder, Env};
|
||||
use types::test_utils::TestingBeaconStateBuilder;
|
||||
use types::*;
|
||||
|
||||
mod bench_block_processing;
|
||||
mod bench_epoch_processing;
|
||||
|
||||
pub const VALIDATOR_COUNT: usize = 300_032;
|
||||
pub const VALIDATOR_COUNT: usize = 16_384;
|
||||
|
||||
// `LOG_LEVEL == "debug"` gives logs, but they're very noisy and slow down benching.
|
||||
pub const LOG_LEVEL: &str = "";
|
||||
|
||||
@@ -373,19 +373,20 @@ pub fn process_deposits(
|
||||
.map_err(|e| e.into_with_index(i))
|
||||
})?;
|
||||
|
||||
let public_key_to_index_hashmap = build_public_key_hashmap(&state);
|
||||
|
||||
// Check `state.deposit_index` and update the state in series.
|
||||
for (i, deposit) in deposits.iter().enumerate() {
|
||||
verify_deposit_index(state, deposit).map_err(|e| e.into_with_index(i))?;
|
||||
|
||||
// Ensure the state's pubkey cache is fully up-to-date, it will be used to check to see if the
|
||||
// depositing validator already exists in the registry.
|
||||
state.update_pubkey_cache()?;
|
||||
|
||||
// Get an `Option<u64>` where `u64` is the validator index if this deposit public key
|
||||
// already exists in the beacon_state.
|
||||
//
|
||||
// This function also verifies the withdrawal credentials.
|
||||
let validator_index =
|
||||
get_existing_validator_index(state, deposit, &public_key_to_index_hashmap)
|
||||
.map_err(|e| e.into_with_index(i))?;
|
||||
get_existing_validator_index(state, deposit).map_err(|e| e.into_with_index(i))?;
|
||||
|
||||
let deposit_data = &deposit.deposit_data;
|
||||
let deposit_input = &deposit.deposit_data.deposit_input;
|
||||
|
||||
@@ -294,6 +294,8 @@ impl_into_with_index_without_beacon_error!(
|
||||
pub enum DepositValidationError {
|
||||
/// Validation completed successfully and the object is invalid.
|
||||
Invalid(DepositInvalid),
|
||||
/// Encountered a `BeaconStateError` whilst attempting to determine validity.
|
||||
BeaconStateError(BeaconStateError),
|
||||
}
|
||||
|
||||
/// Describes why an object is invalid.
|
||||
@@ -313,7 +315,8 @@ pub enum DepositInvalid {
|
||||
BadMerkleProof,
|
||||
}
|
||||
|
||||
impl_into_with_index_without_beacon_error!(DepositValidationError, DepositInvalid);
|
||||
impl_from_beacon_state_error!(DepositValidationError);
|
||||
impl_into_with_index_with_beacon_error!(DepositValidationError, DepositInvalid);
|
||||
|
||||
/*
|
||||
* `Exit` Validation
|
||||
|
||||
@@ -72,11 +72,12 @@ pub fn build_public_key_hashmap(state: &BeaconState) -> PublicKeyValidatorIndexH
|
||||
pub fn get_existing_validator_index(
|
||||
state: &BeaconState,
|
||||
deposit: &Deposit,
|
||||
pubkey_map: &HashMap<PublicKey, u64>,
|
||||
) -> Result<Option<u64>, Error> {
|
||||
let deposit_input = &deposit.deposit_data.deposit_input;
|
||||
|
||||
let validator_index = pubkey_map.get(&deposit_input.pubkey).and_then(|i| Some(*i));
|
||||
let validator_index = state
|
||||
.get_validator_index(&deposit_input.pubkey)?
|
||||
.and_then(|i| Some(i));
|
||||
|
||||
match validator_index {
|
||||
None => Ok(None),
|
||||
@@ -86,7 +87,7 @@ pub fn get_existing_validator_index(
|
||||
== state.validator_registry[index as usize].withdrawal_credentials,
|
||||
Invalid::BadWithdrawalCredentials
|
||||
);
|
||||
Ok(Some(index))
|
||||
Ok(Some(index as u64))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user