Skip to content

Commit

Permalink
Minor engine cleanup.
Browse files Browse the repository at this point in the history
In `AuthorityRound::on_prepare_block`, return immediately if not a
validator, avoid unnecessary `String` allocation and clone the
header only when needed.
  • Loading branch information
afck committed Aug 2, 2019
1 parent a653b03 commit a7fd6b3
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions ethcore/src/engines/authority_round/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ use rlp::{encode, Decodable, DecoderError, Encodable, RlpStream, Rlp};
use ethereum_types::{H256, H520, Address, U128, U256};
use parking_lot::{Mutex, RwLock};
use time_utils::CheckedSystemTime;
use tx_filter::transact_acl_gas_price;
use types::BlockNumber;
use types::ancestry_action::AncestryAction;
use types::header::{Header, ExtendedHeader};
Expand Down Expand Up @@ -1420,9 +1419,7 @@ impl Engine<EthereumMachine> for AuthorityRound {
trace!(target: "engine", "Skipping calls to POSDAO randomness and validator set contracts");
return Ok(Vec::new());
}
// Genesis is never a new block, but might as well check.
let header = block.header.clone();
let first = header.number() == 0;

let opt_signer = self.signer.read();
let signer = match opt_signer.as_ref() {
Some(signer) => signer,
Expand All @@ -1434,7 +1431,7 @@ impl Engine<EthereumMachine> for AuthorityRound {
EngineError::RequiresClient
})?;
let full_client = client.as_full_client()
.ok_or(EngineError::FailedSystemCall("Failed to upgrade to BlockchainClient.".to_string()))?;
.ok_or_else(|| EngineError::FailedSystemCall("Failed to upgrade to BlockchainClient.".to_string()))?;

// Makes a constant contract call.
let mut call = |to: Address, data: Bytes| {
Expand Down Expand Up @@ -1465,7 +1462,9 @@ impl Engine<EthereumMachine> for AuthorityRound {
}
}

for (addr, data) in self.validators.on_prepare_block(first, &header, &mut call)? {
// Genesis is never a new block, but might as well check.
let first = block.header.number() == 0;
for (addr, data) in self.validators.on_prepare_block(first, &block.header, &mut call)? {
transactions.push(make_transaction(addr, data)?);
}

Expand Down Expand Up @@ -2161,7 +2160,6 @@ mod tests {
#[should_panic(expected="counter is too high")]
fn test_counter_increment_too_high() {
use super::Step;
use std::sync::atomic::AtomicU16;

let step = Step {
calibrate: false,
Expand Down

0 comments on commit a7fd6b3

Please sign in to comment.