diff --git a/ethcore/src/engines/authority_round.rs b/ethcore/src/engines/authority_round.rs index 364bd7dd2..9c52753b1 100644 --- a/ethcore/src/engines/authority_round.rs +++ b/ethcore/src/engines/authority_round.rs @@ -72,16 +72,13 @@ pub struct AuthorityRound { proposed: AtomicBool, } -impl Header { - fn step(&self) -> Result { - UntrustedRlp::new(&self.seal()[0]).as_val() - } - - fn signature(&self) -> Result { - UntrustedRlp::new(&self.seal()[1]).as_val::().map(Into::into) - } +fn step(header: &Header) -> Result { + UntrustedRlp::new(&self.seal()[0]).as_val() } +fn signature(header: &Header) -> Result { + UntrustedRlp::new(&self.seal()[1]).as_val::().map(Into::into) +} trait AsMillis { fn as_millis(&self) -> u64; @@ -128,7 +125,7 @@ impl AuthorityRound { fn step_proposer(&self, step: usize) -> &Address { let ref p = self.our_params; - p.authorities.get(step%p.authority_n).unwrap() + p.authorities.get(step % p.authority_n).expect("There are authority_n authorities; taking number modulo authority_n gives number in authority_n range; qed") } fn is_step_proposer(&self, step: usize, address: &Address) -> bool { @@ -250,10 +247,10 @@ impl Engine for AuthorityRound { /// Check if the signature belongs to the correct proposer. fn verify_block_unordered(&self, header: &Header, _block: Option<&[u8]>) -> Result<(), Error> { - let header_step = try!(header.step()); + let header_step = try!(step(header)); // Give one step slack if step is lagging, double vote is still not possible. if header_step <= self.step() + 1 { - let ok_sig = try!(verify_address(self.step_proposer(header_step), &try!(header.signature()), &header.bare_hash())); + let ok_sig = try!(verify_address(self.step_proposer(header_step), &try!(signature(header)), &header.bare_hash())); if ok_sig { Ok(()) } else { @@ -272,9 +269,9 @@ impl Engine for AuthorityRound { return Err(From::from(BlockError::RidiculousNumber(OutOfBounds { min: Some(1), max: None, found: header.number() }))); } - let step = try!(header.step()); + let step = try!(step(header)); // Check if parent is from a previous step. - if step == try!(parent.step()) { + if step == try!(step(parent)) { trace!(target: "poa", "Multiple blocks proposed for step {}.", step); try!(Err(BlockError::DoubleVote(header.author().clone()))); } diff --git a/ethcore/src/error.rs b/ethcore/src/error.rs index 6b3a12fc7..261eab268 100644 --- a/ethcore/src/error.rs +++ b/ethcore/src/error.rs @@ -168,7 +168,7 @@ pub enum BlockError { /// Uncle parent given is unknown. UnknownUncleParent(H256), /// The same author issued different votes at the same step. - DoubleVote(H160) + DoubleVote(H160), } impl fmt::Display for BlockError { @@ -202,7 +202,7 @@ impl fmt::Display for BlockError { RidiculousNumber(ref oob) => format!("Implausible block number. {}", oob), UnknownParent(ref hash) => format!("Unknown parent: {}", hash), UnknownUncleParent(ref hash) => format!("Unknown uncle parent: {}", hash), - DoubleVote(ref address) => format!("Author {} issued to many blocks.", address), + DoubleVote(ref address) => format!("Author {} issued too many blocks.", address), }; f.write_fmt(format_args!("Block error ({})", msg))