From b2063c3e214f340bb370d73849aae58c987bb56f Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Fri, 28 Jan 2022 15:45:44 +1100 Subject: [PATCH] More vector --- .../src/engine_api/json_structures.rs | 3 ++- beacon_node/store/src/chunked_vector.rs | 12 +++++------- beacon_node/store/src/partial_beacon_state.rs | 13 ++++++++++++- .../src/per_epoch_processing/resets.rs | 2 +- consensus/types/src/beacon_state.rs | 12 ++++++------ 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/beacon_node/execution_layer/src/engine_api/json_structures.rs b/beacon_node/execution_layer/src/engine_api/json_structures.rs index ae6d730fa5..a1625a83a1 100644 --- a/beacon_node/execution_layer/src/engine_api/json_structures.rs +++ b/beacon_node/execution_layer/src/engine_api/json_structures.rs @@ -1,6 +1,7 @@ use super::*; use serde::{Deserialize, Serialize}; -use types::{EthSpec, FixedVector, Transaction, Unsigned, VariableList}; +use ssz_types::FixedVector; +use types::{EthSpec, Transaction, Unsigned, VariableList}; #[derive(Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] diff --git a/beacon_node/store/src/chunked_vector.rs b/beacon_node/store/src/chunked_vector.rs index 6f60cf1fe3..9c248ec4f3 100644 --- a/beacon_node/store/src/chunked_vector.rs +++ b/beacon_node/store/src/chunked_vector.rs @@ -323,7 +323,7 @@ field!( |_| OncePerNSlots { n: T::SlotsPerHistoricalRoot::to_u64() }, - |state: &BeaconState<_>, index, _| safe_modulo_index_tree(state.historical_roots(), index) + |state: &BeaconState<_>, index, _| safe_modulo_index(state.historical_roots(), index) ); field!( @@ -530,7 +530,7 @@ pub fn load_vector_from_db, E: EthSpec, S: KeyValueStore< default, )?; - Ok(result.into()) + Ok(FixedVector::new(result)?) } /// The historical roots are stored in vector chunks, despite not actually being a vector. @@ -546,7 +546,7 @@ pub fn load_variable_list_from_db, E: EthSpec, S: KeyV let chunks: Vec> = range_query(store, F::column(), start_cindex, end_cindex)?; - let mut result = VList::empty(); + let mut result = VList::empty()?; for (chunk_index, chunk) in chunks.into_iter().enumerate() { for (i, value) in chunk.values.into_iter().enumerate() { @@ -562,6 +562,7 @@ pub fn load_variable_list_from_db, E: EthSpec, S: KeyV } /// Index into a field of the state, avoiding out of bounds and division by 0. +#[cfg(not(feature = "milhouse"))] fn safe_modulo_index(values: &[T], index: u64) -> Result { if values.is_empty() { Err(ChunkError::ZeroLengthVector) @@ -570,11 +571,8 @@ fn safe_modulo_index(values: &[T], index: u64) -> Result } } -#[cfg(not(feature = "milhouse"))] -use safe_modulo_index as safe_modulo_index_tree; - #[cfg(feature = "milhouse")] -fn safe_modulo_index_tree, T: Copy>(values: &V, index: u64) -> Result { +fn safe_modulo_index, T: Copy>(values: &V, index: u64) -> Result { if values.is_empty() { Err(ChunkError::ZeroLengthVector) } else { diff --git a/beacon_node/store/src/partial_beacon_state.rs b/beacon_node/store/src/partial_beacon_state.rs index 7bddca9440..aae54c4f19 100644 --- a/beacon_node/store/src/partial_beacon_state.rs +++ b/beacon_node/store/src/partial_beacon_state.rs @@ -265,7 +265,18 @@ impl PartialBeaconState { // Patch the value for the current slot into the index for the current epoch let current_epoch = self.slot().epoch(T::slots_per_epoch()); let len = randao_mixes.len(); - randao_mixes[current_epoch.as_usize() % len] = *self.latest_randao_value(); + + #[cfg(feature = "milhouse")] + { + use milhouse::interface::MutList; + randao_mixes + .replace(current_epoch.as_usize() % len, *self.latest_randao_value())?; + } + + #[cfg(not(feature = "milhouse"))] + { + randao_mixes[current_epoch.as_usize() % len] = *self.latest_randao_value(); + } *self.randao_mixes_mut() = Some(randao_mixes) } diff --git a/consensus/state_processing/src/per_epoch_processing/resets.rs b/consensus/state_processing/src/per_epoch_processing/resets.rs index 8664bd98aa..4a24a0c19e 100644 --- a/consensus/state_processing/src/per_epoch_processing/resets.rs +++ b/consensus/state_processing/src/per_epoch_processing/resets.rs @@ -13,7 +13,7 @@ pub fn process_eth1_data_reset( .safe_rem(T::SlotsPerEth1VotingPeriod::to_u64())? == 0 { - *state.eth1_data_votes_mut() = VList::empty(); + *state.eth1_data_votes_mut() = VList::empty()?; } Ok(()) } diff --git a/consensus/types/src/beacon_state.rs b/consensus/types/src/beacon_state.rs index 7918f05bce..7d0ef2302e 100644 --- a/consensus/types/src/beacon_state.rs +++ b/consensus/types/src/beacon_state.rs @@ -386,16 +386,16 @@ impl BeaconState { latest_block_header: BeaconBlock::::empty(spec).temporary_block_header(), block_roots: FixedVector::from_elem(Hash256::zero()), state_roots: FixedVector::from_elem(Hash256::zero()), - historical_roots: VList::empty(), + historical_roots: VList::default(), // Eth1 eth1_data, - eth1_data_votes: VList::empty(), + eth1_data_votes: VList::default(), eth1_deposit_index: 0, // Validator registry - validators: VList::empty(), // Set later. - balances: VList::empty(), // Set later. + validators: VList::default(), // Set later. + balances: VList::default(), // Set later. // Randomness randao_mixes: FixedVector::from_elem(Hash256::zero()), @@ -404,8 +404,8 @@ impl BeaconState { slashings: FixedVector::from_elem(0), // Attestations - previous_epoch_attestations: VList::empty(), - current_epoch_attestations: VList::empty(), + previous_epoch_attestations: VList::default(), + current_epoch_attestations: VList::default(), // Finality justification_bits: BitVector::new(),