fix propose collect locking

This commit is contained in:
keorn 2016-09-05 17:06:43 +02:00
parent 83c371e6d4
commit 8851acec7c

View File

@ -49,12 +49,12 @@ impl ProposeCollect {
/// Vote on hash using the signed hash, true if vote counted. /// Vote on hash using the signed hash, true if vote counted.
pub fn vote(&self, voter: Address) -> bool { pub fn vote(&self, voter: Address) -> bool {
match self.votes.try_read().unwrap().contains(&voter) || !self.voters.contains(&voter) { let is_known = self.votes.try_read().unwrap().contains(&voter);
true => false, if !is_known && self.voters.contains(&voter) {
false => {
self.votes.try_write().unwrap().insert(voter); self.votes.try_write().unwrap().insert(voter);
true true
}, } else {
false
} }
} }
@ -66,11 +66,6 @@ impl ProposeCollect {
}; };
self.is_won.load(Ordering::Relaxed) || threshold_checker() self.is_won.load(Ordering::Relaxed) || threshold_checker()
} }
/// Get addresses backing given hash.
pub fn votes(&self) -> HashSet<Address> {
self.votes.try_read().unwrap().clone()
}
} }
#[cfg(test)] #[cfg(test)]