Skip to content

Commit

Permalink
Merge pull request openethereum#71 from niklasad1/block-needless-clone
Browse files Browse the repository at this point in the history
grumble(on_seal_block): make `&mut` to avoid clone
  • Loading branch information
soc1c authored Mar 23, 2019
2 parents ff71dd8 + b27dabb commit 10755f9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
7 changes: 2 additions & 5 deletions ethcore/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,9 @@ impl LockedBlock {
}

s.block.header.set_seal(seal);

if let Some(new_header) = engine.on_seal_block(&s.block)? {
s.block.header = new_header;
}

engine.on_seal_block(&mut s.block)?;
s.block.header.compute_hash();

Ok(SealedBlock {
block: s.block
})
Expand Down
6 changes: 3 additions & 3 deletions ethcore/src/engines/clique/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,10 @@ impl Engine<EthereumMachine> for Clique {
Ok(())
}

fn on_seal_block(&self, block: &ExecutedBlock) -> Result<Option<Header>, Error> {
fn on_seal_block(&self, block: &mut ExecutedBlock) -> Result<(), Error> {
trace!(target: "engine", "on_seal_block");

let mut header = block.header.clone();
let header = &mut block.header;

let state = self.state_no_backfill(header.parent_hash())
.ok_or_else(|| BlockError::UnknownParent(*header.parent_hash()))?;
Expand Down Expand Up @@ -444,7 +444,7 @@ impl Engine<EthereumMachine> for Clique {

trace!(target: "engine", "on_seal_block: finished, final header: {:?}", header);

Ok(Some(header))
Ok(())
}

/// Clique doesn't require external work to seal, so we always return true here.
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/engines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ pub trait Engine<M: Machine>: Sync + Send {
Ok(())
}

/// Allow returning new block header after seal generation. Currently only used by Clique.
fn on_seal_block(&self, _block: &ExecutedBlock) -> Result<Option<Header>, Error> { Ok(None) }
/// Allow mutating the header during seal generation. Currently only used by Clique.
fn on_seal_block(&self, _block: &mut ExecutedBlock) -> Result<(), Error> { Ok(()) }

/// None means that it requires external input (e.g. PoW) to seal a block.
/// Some(true) means the engine is currently prime for seal generation (i.e. node is the current validator).
Expand Down

0 comments on commit 10755f9

Please sign in to comment.