Inact clippy suggestions on beacon_chain.

This commit is contained in:
Age Manning 2019-02-12 22:00:38 +11:00
parent eae68865d1
commit 84bf5ecd74
No known key found for this signature in database
GPG Key ID: 05EED64B79E06A93

View File

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