mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-25 16:58:28 +00:00
Merge branch 'master' into paul-sync
This commit is contained in:
@@ -82,7 +82,7 @@ where
|
||||
let state_root = genesis_state.canonical_root();
|
||||
state_store.put(&state_root, &ssz_encode(&genesis_state)[..])?;
|
||||
|
||||
let block_root = genesis_block.into_header().canonical_root();
|
||||
let block_root = genesis_block.block_header().canonical_root();
|
||||
block_store.put(&block_root, &ssz_encode(&genesis_block)[..])?;
|
||||
|
||||
let finalized_head = RwLock::new(CheckPoint::new(
|
||||
@@ -189,7 +189,7 @@ where
|
||||
pub fn advance_state(&self, slot: Slot) -> Result<(), SlotProcessingError> {
|
||||
let state_slot = self.state.read().slot;
|
||||
|
||||
let latest_block_header = self.head().beacon_block.into_header();
|
||||
let latest_block_header = self.head().beacon_block.block_header();
|
||||
|
||||
for _ in state_slot.as_u64()..slot.as_u64() {
|
||||
per_slot_processing(&mut *self.state.write(), &latest_block_header, &self.spec)?;
|
||||
@@ -246,7 +246,10 @@ where
|
||||
/// Information is read from the present `beacon_state` shuffling, so only information from the
|
||||
/// present and prior epoch is available.
|
||||
pub fn block_proposer(&self, slot: Slot) -> Result<usize, BeaconStateError> {
|
||||
trace!("BeaconChain::block_proposer: slot: {}", slot);
|
||||
self.state
|
||||
.write()
|
||||
.build_epoch_cache(RelativeEpoch::Current, &self.spec)?;
|
||||
|
||||
let index = self.state.read().get_beacon_proposer_index(
|
||||
slot,
|
||||
RelativeEpoch::Current,
|
||||
@@ -561,7 +564,7 @@ where
|
||||
pub fn process_block(&self, block: BeaconBlock) -> Result<BlockProcessingOutcome, Error> {
|
||||
debug!("Processing block with slot {}...", block.slot);
|
||||
|
||||
let block_root = block.into_header().canonical_root();
|
||||
let block_root = block.block_header().canonical_root();
|
||||
|
||||
let present_slot = self.present_slot();
|
||||
|
||||
@@ -596,7 +599,7 @@ where
|
||||
|
||||
// Transition the parent state to the present slot.
|
||||
let mut state = parent_state;
|
||||
let previous_block_header = parent_block.into_header();
|
||||
let previous_block_header = parent_block.block_header();
|
||||
for _ in state.slot.as_u64()..present_slot.as_u64() {
|
||||
if let Err(e) = per_slot_processing(&mut state, &previous_block_header, &self.spec) {
|
||||
return Ok(BlockProcessingOutcome::InvalidBlock(
|
||||
@@ -662,6 +665,8 @@ where
|
||||
|
||||
let mut state = self.state.read().clone();
|
||||
|
||||
state.build_epoch_cache(RelativeEpoch::Current, &self.spec)?;
|
||||
|
||||
trace!("Finding attestations for new block...");
|
||||
|
||||
let attestations = self
|
||||
|
||||
@@ -28,6 +28,8 @@ pub enum BeaconChainError {
|
||||
pub enum BlockProductionError {
|
||||
UnableToGetBlockRootFromState,
|
||||
BlockProcessingError(BlockProcessingError),
|
||||
BeaconStateError(BeaconStateError),
|
||||
}
|
||||
|
||||
easy_from_to!(BlockProcessingError, BlockProductionError);
|
||||
easy_from_to!(BeaconStateError, BlockProductionError);
|
||||
|
||||
@@ -9,6 +9,7 @@ test_cases:
|
||||
deposits_for_chain_start: 1000
|
||||
num_slots: 64
|
||||
skip_slots: [2, 3]
|
||||
persistent_committee_period: 0
|
||||
deposits:
|
||||
# At slot 1, create a new validator deposit of 5 ETH.
|
||||
- slot: 1
|
||||
|
||||
@@ -51,11 +51,24 @@ impl BeaconChainHarness {
|
||||
let slot_clock = TestingSlotClock::new(spec.genesis_slot.as_u64());
|
||||
let fork_choice = BitwiseLMDGhost::new(block_store.clone(), state_store.clone());
|
||||
|
||||
let (genesis_state, keypairs) = state_builder.build();
|
||||
let (mut genesis_state, keypairs) = state_builder.build();
|
||||
|
||||
let mut genesis_block = BeaconBlock::empty(&spec);
|
||||
genesis_block.state_root = Hash256::from_slice(&genesis_state.hash_tree_root());
|
||||
|
||||
genesis_state
|
||||
.build_epoch_cache(RelativeEpoch::Previous, &spec)
|
||||
.unwrap();
|
||||
genesis_state
|
||||
.build_epoch_cache(RelativeEpoch::Current, &spec)
|
||||
.unwrap();
|
||||
genesis_state
|
||||
.build_epoch_cache(RelativeEpoch::NextWithoutRegistryChange, &spec)
|
||||
.unwrap();
|
||||
genesis_state
|
||||
.build_epoch_cache(RelativeEpoch::NextWithRegistryChange, &spec)
|
||||
.unwrap();
|
||||
|
||||
// Create the Beacon Chain
|
||||
let beacon_chain = Arc::new(
|
||||
BeaconChain::from_genesis(
|
||||
@@ -194,7 +207,6 @@ impl BeaconChainHarness {
|
||||
self.increment_beacon_chain_slot();
|
||||
|
||||
// Produce a new block.
|
||||
debug!("Producing block...");
|
||||
let block = self.produce_block();
|
||||
debug!("Submitting block for processing...");
|
||||
match self.beacon_chain.process_block(block) {
|
||||
|
||||
@@ -62,6 +62,10 @@ impl TestCase {
|
||||
spec.slots_per_epoch = n;
|
||||
}
|
||||
|
||||
if let Some(n) = self.config.persistent_committee_period {
|
||||
spec.persistent_committee_period = n;
|
||||
}
|
||||
|
||||
spec
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ pub struct Config {
|
||||
pub deposits_for_chain_start: usize,
|
||||
/// Number of slots in an epoch.
|
||||
pub slots_per_epoch: Option<u64>,
|
||||
/// Affects the number of epochs a validator must be active before they can withdraw.
|
||||
pub persistent_committee_period: Option<u64>,
|
||||
/// Number of slots to build before ending execution.
|
||||
pub num_slots: u64,
|
||||
/// Number of slots that should be skipped due to inactive validator.
|
||||
@@ -45,6 +47,7 @@ impl Config {
|
||||
deposits_for_chain_start: as_usize(&yaml, "deposits_for_chain_start")
|
||||
.expect("Must specify validator count"),
|
||||
slots_per_epoch: as_u64(&yaml, "slots_per_epoch"),
|
||||
persistent_committee_period: as_u64(&yaml, "persistent_committee_period"),
|
||||
num_slots: as_u64(&yaml, "num_slots").expect("Must specify `config.num_slots`"),
|
||||
skip_slots: as_vec_u64(yaml, "skip_slots"),
|
||||
deposits: parse_deposits(&yaml),
|
||||
|
||||
Reference in New Issue
Block a user