diff --git a/beacon_node/beacon_chain/src/block_processing.rs b/beacon_node/beacon_chain/src/block_processing.rs index 2c637031e..6dd48abda 100644 --- a/beacon_node/beacon_chain/src/block_processing.rs +++ b/beacon_node/beacon_chain/src/block_processing.rs @@ -29,7 +29,6 @@ pub enum Outcome { pub enum Error { DBError(String), UnableToDecodeBlock, - PresentSlotIsNone, SlotClockError(SystemTimeSlotClockError), MissingParentState(Hash256), InvalidParentState(Hash256), @@ -57,25 +56,19 @@ where .ok_or(Error::UnableToDecodeBlock)?; let block_root = block.canonical_root(); - let present_slot = self - .slot_clock - .present_slot()? - .ok_or(Error::PresentSlotIsNone)?; + let present_slot = self.present_slot(); - // Block from future slots (i.e., greater than the present slot) should not be processed. if block.slot() > present_slot { return Ok(Outcome::InvalidBlock(InvalidBlock::FutureSlot)); } let parent_block_root = block.parent_root(); - let parent_block = self .block_store .get_reader(&parent_block_root)? .ok_or(Error::MissingParentBlock(parent_block_root))?; let parent_state_root = parent_block.state_root(); - let parent_state = self .state_store .get_reader(&parent_state_root)? diff --git a/beacon_node/beacon_chain/src/info.rs b/beacon_node/beacon_chain/src/info.rs index 34ac64c8e..70405ab32 100644 --- a/beacon_node/beacon_chain/src/info.rs +++ b/beacon_node/beacon_chain/src/info.rs @@ -35,13 +35,17 @@ where } } - pub fn present_slot(&self) -> Option { + pub fn read_slot_clock(&self) -> Option { match self.slot_clock.present_slot() { Ok(some_slot) => some_slot, _ => None, } } + pub fn present_slot(&self) -> u64 { + self.state.read().slot + } + pub fn block_proposer(&self, slot: u64) -> Result { let index = self .state diff --git a/beacon_node/beacon_chain/test_harness/src/harness.rs b/beacon_node/beacon_chain/test_harness/src/harness.rs index 7d05c7b89..ce88395cb 100644 --- a/beacon_node/beacon_chain/test_harness/src/harness.rs +++ b/beacon_node/beacon_chain/test_harness/src/harness.rs @@ -104,11 +104,7 @@ impl BeaconChainHarness { /// /// Returns the new slot. pub fn increment_beacon_chain_slot(&mut self) -> u64 { - let slot = self - .beacon_chain - .present_slot() - .expect("Unable to determine slot.") - + 1; + let slot = self.beacon_chain.present_slot() + 1; debug!("Incrementing BeaconChain slot to {}.", slot); @@ -122,7 +118,7 @@ impl BeaconChainHarness { /// Note: validators will only produce attestations _once per slot_. So, if you call this twice /// you'll only get attestations on the first run. pub fn gather_free_attesations(&mut self) -> Vec { - let present_slot = self.beacon_chain.present_slot().unwrap(); + let present_slot = self.beacon_chain.present_slot(); let attesting_validators = self .beacon_chain @@ -169,7 +165,7 @@ impl BeaconChainHarness { /// Note: the validator will only produce it _once per slot_. So, if you call this twice you'll /// only get a block once. pub fn produce_block(&mut self) -> BeaconBlock { - let present_slot = self.beacon_chain.present_slot().unwrap(); + let present_slot = self.beacon_chain.present_slot(); let proposer = self.beacon_chain.block_proposer(present_slot).unwrap(); @@ -210,13 +206,6 @@ impl BeaconChainHarness { }); debug!("Free attestations processed."); - /* - for free_attestation in free_attestations { - self.beacon_chain - .process_free_attestation(free_attestation) - .unwrap(); - } - */ } pub fn chain_dump(&self) -> Result, DumpError> {