Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Split internal sealing from work preparation #2071

Merged
merged 6 commits into from
Sep 13, 2016
Merged

Conversation

keorn
Copy link

@keorn keorn commented Sep 12, 2016

Previously the "miner" attempted to generate and import seal in prepare_sealing method. Now methods are separated out more and flow is based in seals_internally Engine method.

@keorn keorn added the A0-pleasereview 🤓 Pull request needs code review. label Sep 12, 2016
@@ -411,12 +419,13 @@ impl Miner {
// | NOTE Code below requires transaction_queue and sealing_work locks. |
// | Make sure to release the locks before calling that method. |
// --------------------------------------------------------------------------
self.prepare_sealing(chain);
let (block, original_work_hash) = self.prepare_block(chain);
self.prepare_work(block, original_work_hash);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No splat/apply :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#![feature(fn_traits, unboxed_closures)]

use std::ops::Fn;

fn main() {
    Fn::call(&foo, (1, 2.0));    
}

fn foo(x: i32, y: f32) {
    println!("({}, {})", x, y);
}

(although having to account for the implicit self makes that impossible in this case)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constant interaction with Miner struct discourages pure functions though.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) to 84.768% when pulling d6e5637 on split-internal-seal into edcc408 on master.

@@ -71,6 +71,8 @@ pub trait Engine : Sync + Send {
/// Block transformation functions, after the transactions.
fn on_close_block(&self, _block: &mut ExecutedBlock) {}

/// If true, generate_seal has to be implemented.
fn seals_internally(&self) -> bool { false }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there should be a blank line following this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is plenty of methods next to each other in trait definitions in this and other files in the codebase. Id argue that for definitions its fine, as it often groups method families.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't noticed it personally, in general it is typical Rust style to provide a line of blank space between each function definition, at least if there are docs. (see an example from std: Iterator )

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, but Engine had this sort of logical grouping already. @arkpar suggested to leave it.

@keorn keorn added A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. and removed A0-pleasereview 🤓 Pull request needs code review. labels Sep 12, 2016
@keorn keorn added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Sep 12, 2016
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 84.677% when pulling 4bfdeea on split-internal-seal into edcc408 on master.

@tomusdrw tomusdrw changed the title Spilt internal sealing from work preparation Split internal sealing from work preparation Sep 12, 2016

/// Uses Engine to seal the block internally and then imports it to chain.
fn seal_and_import_block_internally(&self, chain: &MiningBlockChainClient, block: ClosedBlock) -> bool {
if !block.transactions().is_empty() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests triggering that if-path (or not triggering) would be nice

@rphmeier rphmeier added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Sep 13, 2016
@keorn keorn added A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. and removed A8-looksgood 🦄 Pull request is reviewed well. labels Sep 13, 2016
@keorn keorn added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Sep 13, 2016
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.05%) to 84.766% when pulling e41b6c4 on split-internal-seal into edcc408 on master.

@NikVolf NikVolf added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Sep 13, 2016
@@ -243,19 +245,15 @@ impl Miner {
}

/// Prepares new block for sealing including top transactions from queue.
#[cfg_attr(feature="dev", allow(match_same_arms))]
#[cfg_attr(feature="dev", allow(cyclomatic_complexity))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason to remove these?

@arkpar arkpar merged commit 341e064 into master Sep 13, 2016
@arkpar arkpar deleted the split-internal-seal branch October 3, 2016 15:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants