Inact clippy suggestions on beacon_chain.
This commit is contained in:
parent
eae68865d1
commit
84bf5ecd74
@ -102,25 +102,25 @@ where
|
|||||||
block_store.put(&block_root, &ssz_encode(&genesis_block)[..])?;
|
block_store.put(&block_root, &ssz_encode(&genesis_block)[..])?;
|
||||||
|
|
||||||
let block_graph = BlockGraph::new();
|
let block_graph = BlockGraph::new();
|
||||||
block_graph.add_leaf(&Hash256::zero(), block_root.clone());
|
block_graph.add_leaf(&Hash256::zero(), block_root);
|
||||||
|
|
||||||
let finalized_head = RwLock::new(CheckPoint::new(
|
let finalized_head = RwLock::new(CheckPoint::new(
|
||||||
genesis_block.clone(),
|
genesis_block.clone(),
|
||||||
block_root.clone(),
|
block_root,
|
||||||
genesis_state.clone(),
|
genesis_state.clone(),
|
||||||
state_root.clone(),
|
state_root,
|
||||||
));
|
));
|
||||||
let justified_head = RwLock::new(CheckPoint::new(
|
let justified_head = RwLock::new(CheckPoint::new(
|
||||||
genesis_block.clone(),
|
genesis_block.clone(),
|
||||||
block_root.clone(),
|
block_root,
|
||||||
genesis_state.clone(),
|
genesis_state.clone(),
|
||||||
state_root.clone(),
|
state_root,
|
||||||
));
|
));
|
||||||
let canonical_head = RwLock::new(CheckPoint::new(
|
let canonical_head = RwLock::new(CheckPoint::new(
|
||||||
genesis_block.clone(),
|
genesis_block.clone(),
|
||||||
block_root.clone(),
|
block_root,
|
||||||
genesis_state.clone(),
|
genesis_state.clone(),
|
||||||
state_root.clone(),
|
state_root,
|
||||||
));
|
));
|
||||||
let attestation_aggregator = RwLock::new(AttestationAggregator::new());
|
let attestation_aggregator = RwLock::new(AttestationAggregator::new());
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ where
|
|||||||
justified_head,
|
justified_head,
|
||||||
finalized_head,
|
finalized_head,
|
||||||
canonical_head,
|
canonical_head,
|
||||||
spec: spec,
|
spec,
|
||||||
fork_choice,
|
fork_choice,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ where
|
|||||||
for _ in state_slot..slot {
|
for _ in state_slot..slot {
|
||||||
self.state
|
self.state
|
||||||
.write()
|
.write()
|
||||||
.per_slot_processing(head_block_root.clone(), &self.spec)?;
|
.per_slot_processing(head_block_root, &self.spec)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -305,27 +305,25 @@ where
|
|||||||
/// Produce an `AttestationData` that is valid for the present `slot` and given `shard`.
|
/// Produce an `AttestationData` that is valid for the present `slot` and given `shard`.
|
||||||
pub fn produce_attestation_data(&self, shard: u64) -> Result<AttestationData, Error> {
|
pub fn produce_attestation_data(&self, shard: u64) -> Result<AttestationData, Error> {
|
||||||
let justified_slot = self.justified_slot();
|
let justified_slot = self.justified_slot();
|
||||||
let justified_block_root = self
|
let justified_block_root = *self
|
||||||
.state
|
.state
|
||||||
.read()
|
.read()
|
||||||
.get_block_root(justified_slot, &self.spec)
|
.get_block_root(justified_slot, &self.spec)
|
||||||
.ok_or_else(|| Error::BadRecentBlockRoots)?
|
.ok_or_else(|| Error::BadRecentBlockRoots)?;
|
||||||
.clone();
|
|
||||||
|
|
||||||
let epoch_boundary_root = self
|
let epoch_boundary_root = *self
|
||||||
.state
|
.state
|
||||||
.read()
|
.read()
|
||||||
.get_block_root(
|
.get_block_root(
|
||||||
self.state.read().current_epoch_start_slot(&self.spec),
|
self.state.read().current_epoch_start_slot(&self.spec),
|
||||||
&self.spec,
|
&self.spec,
|
||||||
)
|
)
|
||||||
.ok_or_else(|| Error::BadRecentBlockRoots)?
|
.ok_or_else(|| Error::BadRecentBlockRoots)?;
|
||||||
.clone();
|
|
||||||
|
|
||||||
Ok(AttestationData {
|
Ok(AttestationData {
|
||||||
slot: self.state.read().slot,
|
slot: self.state.read().slot,
|
||||||
shard,
|
shard,
|
||||||
beacon_block_root: self.head().beacon_block_root.clone(),
|
beacon_block_root: self.head().beacon_block_root,
|
||||||
epoch_boundary_root,
|
epoch_boundary_root,
|
||||||
shard_block_root: Hash256::zero(),
|
shard_block_root: Hash256::zero(),
|
||||||
latest_crosslink_root: Hash256::zero(),
|
latest_crosslink_root: Hash256::zero(),
|
||||||
@ -447,15 +445,11 @@ where
|
|||||||
let parent_state = self
|
let parent_state = self
|
||||||
.state_store
|
.state_store
|
||||||
.get_reader(&parent_state_root)?
|
.get_reader(&parent_state_root)?
|
||||||
.ok_or(Error::DBInconsistent(format!(
|
.ok_or_else(|| Error::DBInconsistent(format!("Missing state {}", parent_state_root)))?
|
||||||
"Missing state {}",
|
|
||||||
parent_state_root
|
|
||||||
)))?
|
|
||||||
.into_beacon_state()
|
.into_beacon_state()
|
||||||
.ok_or(Error::DBInconsistent(format!(
|
.ok_or_else(|| {
|
||||||
"State SSZ invalid {}",
|
Error::DBInconsistent(format!("State SSZ invalid {}", parent_state_root))
|
||||||
parent_state_root
|
})?;
|
||||||
)))?;
|
|
||||||
|
|
||||||
// TODO: check the block proposer signature BEFORE doing a state transition. This will
|
// TODO: check the block proposer signature BEFORE doing a state transition. This will
|
||||||
// significantly lower exposure surface to DoS attacks.
|
// significantly lower exposure surface to DoS attacks.
|
||||||
@ -463,7 +457,7 @@ where
|
|||||||
// Transition the parent state to the present slot.
|
// Transition the parent state to the present slot.
|
||||||
let mut state = parent_state;
|
let mut state = parent_state;
|
||||||
for _ in state.slot..present_slot {
|
for _ in state.slot..present_slot {
|
||||||
if let Err(e) = state.per_slot_processing(parent_block_root.clone(), &self.spec) {
|
if let Err(e) = state.per_slot_processing(parent_block_root, &self.spec) {
|
||||||
return Ok(BlockProcessingOutcome::InvalidBlock(
|
return Ok(BlockProcessingOutcome::InvalidBlock(
|
||||||
InvalidBlock::SlotProcessingError(e),
|
InvalidBlock::SlotProcessingError(e),
|
||||||
));
|
));
|
||||||
@ -491,8 +485,7 @@ where
|
|||||||
self.state_store.put(&state_root, &ssz_encode(&state)[..])?;
|
self.state_store.put(&state_root, &ssz_encode(&state)[..])?;
|
||||||
|
|
||||||
// Update the block DAG.
|
// Update the block DAG.
|
||||||
self.block_graph
|
self.block_graph.add_leaf(&parent_block_root, block_root);
|
||||||
.add_leaf(&parent_block_root, block_root.clone());
|
|
||||||
|
|
||||||
// run the fork_choice add_block logic
|
// run the fork_choice add_block logic
|
||||||
self.fork_choice.add_block(&block, &block_root)?;
|
self.fork_choice.add_block(&block, &block_root)?;
|
||||||
@ -506,7 +499,7 @@ where
|
|||||||
block.clone(),
|
block.clone(),
|
||||||
block_root.clone(),
|
block_root.clone(),
|
||||||
state.clone(),
|
state.clone(),
|
||||||
state_root.clone(),
|
state_root,
|
||||||
);
|
);
|
||||||
// Update the local state variable.
|
// Update the local state variable.
|
||||||
*self.state.write() = state.clone();
|
*self.state.write() = state.clone();
|
||||||
@ -536,15 +529,13 @@ where
|
|||||||
attestations.len()
|
attestations.len()
|
||||||
);
|
);
|
||||||
|
|
||||||
let parent_root = state
|
let parent_root = *state.get_block_root(state.slot.saturating_sub(1), &self.spec)?;
|
||||||
.get_block_root(state.slot.saturating_sub(1), &self.spec)?
|
|
||||||
.clone();
|
|
||||||
|
|
||||||
let mut block = BeaconBlock {
|
let mut block = BeaconBlock {
|
||||||
slot: state.slot,
|
slot: state.slot,
|
||||||
parent_root,
|
parent_root,
|
||||||
state_root: Hash256::zero(), // Updated after the state is calculated.
|
state_root: Hash256::zero(), // Updated after the state is calculated.
|
||||||
randao_reveal: randao_reveal,
|
randao_reveal,
|
||||||
eth1_data: Eth1Data {
|
eth1_data: Eth1Data {
|
||||||
// TODO: replace with real data
|
// TODO: replace with real data
|
||||||
deposit_root: Hash256::zero(),
|
deposit_root: Hash256::zero(),
|
||||||
@ -554,7 +545,7 @@ where
|
|||||||
body: BeaconBlockBody {
|
body: BeaconBlockBody {
|
||||||
proposer_slashings: vec![],
|
proposer_slashings: vec![],
|
||||||
casper_slashings: vec![],
|
casper_slashings: vec![],
|
||||||
attestations: attestations,
|
attestations,
|
||||||
custody_reseeds: vec![],
|
custody_reseeds: vec![],
|
||||||
custody_challenges: vec![],
|
custody_challenges: vec![],
|
||||||
custody_responses: vec![],
|
custody_responses: vec![],
|
||||||
@ -578,11 +569,11 @@ where
|
|||||||
|
|
||||||
// TODO: Left this as is, modify later
|
// TODO: Left this as is, modify later
|
||||||
pub fn fork_choice(&mut self) -> Result<(), Error> {
|
pub fn fork_choice(&mut self) -> Result<(), Error> {
|
||||||
let present_head = &self.finalized_head().beacon_block_root.clone();
|
let present_head = self.finalized_head().beacon_block_root;
|
||||||
|
|
||||||
let new_head = self.fork_choice.find_head(present_head)?;
|
let new_head = self.fork_choice.find_head(&present_head)?;
|
||||||
|
|
||||||
if new_head != *present_head {
|
if new_head != present_head {
|
||||||
let block = self
|
let block = self
|
||||||
.block_store
|
.block_store
|
||||||
.get_deserialized(&new_head)?
|
.get_deserialized(&new_head)?
|
||||||
|
Loading…
Reference in New Issue
Block a user