Add interop eth1 data stub
This commit is contained in:
parent
5616e0a239
commit
d4bf1390c9
@ -4,6 +4,7 @@ use crate::fork_choice::{Error as ForkChoiceError, ForkChoice};
|
||||
use crate::iter::{ReverseBlockRootIterator, ReverseStateRootIterator};
|
||||
use crate::metrics;
|
||||
use crate::persisted_beacon_chain::{PersistedBeaconChain, BEACON_CHAIN_DB_KEY};
|
||||
use eth2_hashing::hash;
|
||||
use lmd_ghost::LmdGhost;
|
||||
use operation_pool::DepositInsertStatus;
|
||||
use operation_pool::{OperationPool, PersistedOperationPool};
|
||||
@ -1198,11 +1199,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
body: BeaconBlockBody {
|
||||
randao_reveal,
|
||||
// TODO: replace with real data.
|
||||
eth1_data: Eth1Data {
|
||||
deposit_count: state.eth1_data.deposit_count,
|
||||
deposit_root: Hash256::zero(),
|
||||
block_hash: Hash256::zero(),
|
||||
},
|
||||
eth1_data: Self::eth1_data_stub(&state),
|
||||
graffiti,
|
||||
proposer_slashings: proposer_slashings.into(),
|
||||
attester_slashings: attester_slashings.into(),
|
||||
@ -1231,6 +1228,22 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
Ok((block, state))
|
||||
}
|
||||
|
||||
fn eth1_data_stub(state: &BeaconState<T::EthSpec>) -> Eth1Data {
|
||||
let current_epoch = state.current_epoch();
|
||||
let slots_per_voting_period = T::EthSpec::slots_per_eth1_voting_period() as u64;
|
||||
let current_voting_period: u64 = current_epoch.as_u64() / slots_per_voting_period;
|
||||
|
||||
// TODO: confirm that `int_to_bytes32` is correct.
|
||||
let deposit_root = hash(&int_to_bytes32(current_voting_period));
|
||||
let block_hash = hash(&deposit_root);
|
||||
|
||||
Eth1Data {
|
||||
deposit_root: Hash256::from_slice(&deposit_root),
|
||||
deposit_count: state.eth1_deposit_index,
|
||||
block_hash: Hash256::from_slice(&block_hash),
|
||||
}
|
||||
}
|
||||
|
||||
/// Execute the fork choice algorithm and enthrone the result as the canonical head.
|
||||
pub fn fork_choice(&self) -> Result<(), Error> {
|
||||
metrics::inc_counter(&metrics::FORK_CHOICE_REQUESTS);
|
||||
@ -1426,6 +1439,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `int` as little-endian bytes with a length of 32.
|
||||
fn int_to_bytes32(int: u64) -> Vec<u8> {
|
||||
let mut vec = int.to_le_bytes().to_vec();
|
||||
vec.resize(32, 0);
|
||||
vec
|
||||
}
|
||||
|
||||
impl From<DBError> for Error {
|
||||
fn from(e: DBError) -> Error {
|
||||
Error::DBError(e)
|
||||
|
@ -120,6 +120,13 @@ pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq {
|
||||
fn epochs_per_historical_vector() -> usize {
|
||||
Self::EpochsPerHistoricalVector::to_usize()
|
||||
}
|
||||
|
||||
/// Returns the `SLOTS_PER_ETH1_VOTING_PERIOD` constant for this specification.
|
||||
///
|
||||
/// Spec v0.8.1
|
||||
fn slots_per_eth1_voting_period() -> usize {
|
||||
Self::EpochsPerHistoricalVector::to_usize()
|
||||
}
|
||||
}
|
||||
|
||||
/// Macro to inherit some type values from another EthSpec.
|
||||
|
Loading…
Reference in New Issue
Block a user