mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-21 22:04:44 +00:00
More vector
This commit is contained in:
@@ -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")]
|
||||
|
||||
@@ -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<F: FixedLengthField<E>, 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<F: VariableLengthField<E>, E: EthSpec, S: KeyV
|
||||
|
||||
let chunks: Vec<Chunk<F::Value>> = 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<F: VariableLengthField<E>, 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<T: Copy>(values: &[T], index: u64) -> Result<T, ChunkError> {
|
||||
if values.is_empty() {
|
||||
Err(ChunkError::ZeroLengthVector)
|
||||
@@ -570,11 +571,8 @@ fn safe_modulo_index<T: Copy>(values: &[T], index: u64) -> Result<T, ChunkError>
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "milhouse"))]
|
||||
use safe_modulo_index as safe_modulo_index_tree;
|
||||
|
||||
#[cfg(feature = "milhouse")]
|
||||
fn safe_modulo_index_tree<V: ImmList<T>, T: Copy>(values: &V, index: u64) -> Result<T, ChunkError> {
|
||||
fn safe_modulo_index<V: ImmList<T>, T: Copy>(values: &V, index: u64) -> Result<T, ChunkError> {
|
||||
if values.is_empty() {
|
||||
Err(ChunkError::ZeroLengthVector)
|
||||
} else {
|
||||
|
||||
@@ -265,7 +265,18 @@ impl<T: EthSpec> PartialBeaconState<T> {
|
||||
// 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)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ pub fn process_eth1_data_reset<T: EthSpec>(
|
||||
.safe_rem(T::SlotsPerEth1VotingPeriod::to_u64())?
|
||||
== 0
|
||||
{
|
||||
*state.eth1_data_votes_mut() = VList::empty();
|
||||
*state.eth1_data_votes_mut() = VList::empty()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -386,16 +386,16 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
latest_block_header: BeaconBlock::<T>::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<T: EthSpec> BeaconState<T> {
|
||||
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(),
|
||||
|
||||
Reference in New Issue
Block a user