Tidy, fix clippy lints
This commit is contained in:
parent
8e13237b7f
commit
3a196f3fdc
@ -240,17 +240,6 @@ mod test {
|
|||||||
.expect(&format!("should set state_b slot {}", slot));
|
.expect(&format!("should set state_b slot {}", slot));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
for root in &mut state_a.latest_state_roots[..] {
|
|
||||||
state_a.set_state_root(slots.next().unwrap(), hashes.next().unwrap());
|
|
||||||
// *root = hashes.next().unwrap()
|
|
||||||
}
|
|
||||||
for root in &mut state_b.latest_state_roots[..] {
|
|
||||||
state_b.set_state_root(slots.next().unwrap(), hashes.next().unwrap());
|
|
||||||
*root = hashes.next().unwrap()
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
let state_a_root = Hash256::from(slots_per_historical_root as u64);
|
let state_a_root = Hash256::from(slots_per_historical_root as u64);
|
||||||
let state_b_root = Hash256::from(slots_per_historical_root as u64 * 2);
|
let state_b_root = Hash256::from(slots_per_historical_root as u64 * 2);
|
||||||
|
|
||||||
|
@ -173,20 +173,14 @@ where
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if slot >= self.root_slot() {
|
if slot >= self.root_slot() {
|
||||||
if let Some(previous_vote) = self.latest_votes.get(validator_index) {
|
if let Some(previous_vote) = self.latest_votes.get(validator_index) {
|
||||||
if previous_vote.slot > slot {
|
// Note: it is possible to do a cheap equivocation check here:
|
||||||
// Given vote is earier than known vote, nothing to do.
|
//
|
||||||
return Ok(());
|
// slashable = (previous_vote.slot == slot) && (previous_vote.hash != block_hash)
|
||||||
} else if previous_vote.slot == slot && previous_vote.hash == block_hash {
|
|
||||||
// Given vote is identical to known vote, nothing to do.
|
if previous_vote.slot < slot {
|
||||||
return Ok(());
|
|
||||||
} else if previous_vote.slot == slot && previous_vote.hash != block_hash {
|
|
||||||
// Vote is an equivocation (double-vote), ignore it.
|
|
||||||
//
|
|
||||||
// TODO: this is slashable.
|
|
||||||
return Ok(());
|
|
||||||
} else {
|
|
||||||
// Given vote is newer or different to current vote, replace the current vote.
|
|
||||||
self.remove_latest_message(validator_index)?;
|
self.remove_latest_message(validator_index)?;
|
||||||
|
} else {
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,11 +286,8 @@ where
|
|||||||
let node = self.get_node(vote.hash)?.clone();
|
let node = self.get_node(vote.hash)?.clone();
|
||||||
|
|
||||||
if let Some(parent_hash) = node.parent_hash {
|
if let Some(parent_hash) = node.parent_hash {
|
||||||
if node.has_votes() {
|
if node.has_votes() || node.children.len() > 1 {
|
||||||
// A node with votes is never removed.
|
// A node with votes or more than one child is never removed.
|
||||||
false
|
|
||||||
} else if node.children.len() > 1 {
|
|
||||||
// A node with more than one child is never removed.
|
|
||||||
false
|
false
|
||||||
} else if node.children.len() == 1 {
|
} else if node.children.len() == 1 {
|
||||||
// A node which has only one child may be removed.
|
// A node which has only one child may be removed.
|
||||||
@ -313,7 +304,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
true
|
true
|
||||||
} else if node.children.len() == 0 {
|
} else if node.children.is_empty() {
|
||||||
// A node which has no children may be deleted and potentially it's parent
|
// A node which has no children may be deleted and potentially it's parent
|
||||||
// too.
|
// too.
|
||||||
self.maybe_delete_node(parent_hash)?;
|
self.maybe_delete_node(parent_hash)?;
|
||||||
@ -394,18 +385,16 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn add_weightless_node(&mut self, slot: Slot, hash: Hash256) -> Result<()> {
|
fn add_weightless_node(&mut self, slot: Slot, hash: Hash256) -> Result<()> {
|
||||||
if slot >= self.root_slot() {
|
if slot >= self.root_slot() && !self.nodes.contains_key(&hash) {
|
||||||
if !self.nodes.contains_key(&hash) {
|
let node = Node {
|
||||||
let node = Node {
|
block_hash: hash,
|
||||||
block_hash: hash,
|
..Node::default()
|
||||||
..Node::default()
|
};
|
||||||
};
|
|
||||||
|
|
||||||
self.add_node(node)?;
|
self.add_node(node)?;
|
||||||
|
|
||||||
if let Some(parent_hash) = self.get_node(hash)?.parent_hash {
|
if let Some(parent_hash) = self.get_node(hash)?.parent_hash {
|
||||||
self.maybe_delete_node(parent_hash)?;
|
self.maybe_delete_node(parent_hash)?;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user