Set BeaconChain present_slot
to read from state.
It used to read from the slot_clock, that has been replaced with `read_slot_clock`.
This commit is contained in:
parent
92753fa24e
commit
d50a8b03f8
@ -29,7 +29,6 @@ pub enum Outcome {
|
|||||||
pub enum Error {
|
pub enum Error {
|
||||||
DBError(String),
|
DBError(String),
|
||||||
UnableToDecodeBlock,
|
UnableToDecodeBlock,
|
||||||
PresentSlotIsNone,
|
|
||||||
SlotClockError(SystemTimeSlotClockError),
|
SlotClockError(SystemTimeSlotClockError),
|
||||||
MissingParentState(Hash256),
|
MissingParentState(Hash256),
|
||||||
InvalidParentState(Hash256),
|
InvalidParentState(Hash256),
|
||||||
@ -57,25 +56,19 @@ where
|
|||||||
.ok_or(Error::UnableToDecodeBlock)?;
|
.ok_or(Error::UnableToDecodeBlock)?;
|
||||||
let block_root = block.canonical_root();
|
let block_root = block.canonical_root();
|
||||||
|
|
||||||
let present_slot = self
|
let present_slot = self.present_slot();
|
||||||
.slot_clock
|
|
||||||
.present_slot()?
|
|
||||||
.ok_or(Error::PresentSlotIsNone)?;
|
|
||||||
|
|
||||||
// Block from future slots (i.e., greater than the present slot) should not be processed.
|
|
||||||
if block.slot() > present_slot {
|
if block.slot() > present_slot {
|
||||||
return Ok(Outcome::InvalidBlock(InvalidBlock::FutureSlot));
|
return Ok(Outcome::InvalidBlock(InvalidBlock::FutureSlot));
|
||||||
}
|
}
|
||||||
|
|
||||||
let parent_block_root = block.parent_root();
|
let parent_block_root = block.parent_root();
|
||||||
|
|
||||||
let parent_block = self
|
let parent_block = self
|
||||||
.block_store
|
.block_store
|
||||||
.get_reader(&parent_block_root)?
|
.get_reader(&parent_block_root)?
|
||||||
.ok_or(Error::MissingParentBlock(parent_block_root))?;
|
.ok_or(Error::MissingParentBlock(parent_block_root))?;
|
||||||
|
|
||||||
let parent_state_root = parent_block.state_root();
|
let parent_state_root = parent_block.state_root();
|
||||||
|
|
||||||
let parent_state = self
|
let parent_state = self
|
||||||
.state_store
|
.state_store
|
||||||
.get_reader(&parent_state_root)?
|
.get_reader(&parent_state_root)?
|
||||||
|
@ -35,13 +35,17 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn present_slot(&self) -> Option<u64> {
|
pub fn read_slot_clock(&self) -> Option<u64> {
|
||||||
match self.slot_clock.present_slot() {
|
match self.slot_clock.present_slot() {
|
||||||
Ok(some_slot) => some_slot,
|
Ok(some_slot) => some_slot,
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn present_slot(&self) -> u64 {
|
||||||
|
self.state.read().slot
|
||||||
|
}
|
||||||
|
|
||||||
pub fn block_proposer(&self, slot: u64) -> Result<usize, CommitteesError> {
|
pub fn block_proposer(&self, slot: u64) -> Result<usize, CommitteesError> {
|
||||||
let index = self
|
let index = self
|
||||||
.state
|
.state
|
||||||
|
@ -104,11 +104,7 @@ impl BeaconChainHarness {
|
|||||||
///
|
///
|
||||||
/// Returns the new slot.
|
/// Returns the new slot.
|
||||||
pub fn increment_beacon_chain_slot(&mut self) -> u64 {
|
pub fn increment_beacon_chain_slot(&mut self) -> u64 {
|
||||||
let slot = self
|
let slot = self.beacon_chain.present_slot() + 1;
|
||||||
.beacon_chain
|
|
||||||
.present_slot()
|
|
||||||
.expect("Unable to determine slot.")
|
|
||||||
+ 1;
|
|
||||||
|
|
||||||
debug!("Incrementing BeaconChain slot to {}.", slot);
|
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
|
/// Note: validators will only produce attestations _once per slot_. So, if you call this twice
|
||||||
/// you'll only get attestations on the first run.
|
/// you'll only get attestations on the first run.
|
||||||
pub fn gather_free_attesations(&mut self) -> Vec<FreeAttestation> {
|
pub fn gather_free_attesations(&mut self) -> Vec<FreeAttestation> {
|
||||||
let present_slot = self.beacon_chain.present_slot().unwrap();
|
let present_slot = self.beacon_chain.present_slot();
|
||||||
|
|
||||||
let attesting_validators = self
|
let attesting_validators = self
|
||||||
.beacon_chain
|
.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
|
/// Note: the validator will only produce it _once per slot_. So, if you call this twice you'll
|
||||||
/// only get a block once.
|
/// only get a block once.
|
||||||
pub fn produce_block(&mut self) -> BeaconBlock {
|
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();
|
let proposer = self.beacon_chain.block_proposer(present_slot).unwrap();
|
||||||
|
|
||||||
@ -210,13 +206,6 @@ impl BeaconChainHarness {
|
|||||||
});
|
});
|
||||||
|
|
||||||
debug!("Free attestations processed.");
|
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<Vec<SlotDump>, DumpError> {
|
pub fn chain_dump(&self) -> Result<Vec<SlotDump>, DumpError> {
|
||||||
|
Loading…
Reference in New Issue
Block a user