Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grumble(on_seal_block): make &mut to avoid clone #71

Merged
merged 2 commits into from
Mar 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -366,10 +366,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 @@ -440,7 +440,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