Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.
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
134 changes: 31 additions & 103 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ansi_term = "0.11"
blooms-db = { path = "../util/blooms-db", optional = true }
bn = { git = "https://github.com/paritytech/bn", default-features = false }
common-types = { path = "types" }
crossbeam = "0.4"
crossbeam-utils = "0.6"
derive_more = "0.14.0"
env_logger = { version = "0.5", optional = true }
ethabi = "8.0"
Expand Down Expand Up @@ -57,7 +57,7 @@ pod-account = { path = "pod-account" }
trie-db = "0.12.4"
patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" }
rand = "0.6"
rayon = "1.0"
rayon = "1.1"
rlp = "0.4.0"
rlp_derive = { path = "../util/rlp-derive" }
rustc-hex = "1.0"
Expand Down
36 changes: 25 additions & 11 deletions ethcore/src/executive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use externalities::*;
use trace::{self, Tracer, VMTracer};
use types::transaction::{Action, SignedTransaction};
use transaction_ext::Transaction;
use crossbeam;
use crossbeam_utils::thread;
pub use executed::{Executed, ExecutionResult};

#[cfg(debug_assertions)]
Expand Down Expand Up @@ -977,11 +977,18 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {
if stack_depth != depth_threshold {
self.call_with_stack_depth(params, substate, stack_depth, tracer, vm_tracer)
} else {
crossbeam::scope(|scope| {
scope.builder().stack_size(::std::cmp::max(self.schedule.max_depth.saturating_sub(depth_threshold) * STACK_SIZE_PER_DEPTH, local_stack_size)).spawn(move || {
self.call_with_stack_depth(params, substate, stack_depth, tracer, vm_tracer)
}).expect("Sub-thread creation cannot fail; the host might run out of resources; qed")
}).join().expect("Sub-thread never panics; qed")
thread::scope(|scope| {
let stack_size = cmp::max(self.schedule.max_depth.saturating_sub(depth_threshold) * STACK_SIZE_PER_DEPTH, local_stack_size);
scope.builder()
.stack_size(stack_size)
.spawn(|_| {
self.call_with_stack_depth(params, substate, stack_depth, tracer, vm_tracer)
})
.expect("Sub-thread creation cannot fail; the host might run out of resources; qed")
.join()
})
.expect("Sub-thread never panics; qed")
.expect("Sub-thread never panics; qed")
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

crossbeamapi has changed a bit here,

  • We have to call join inside fn scope callback, cause the join handle lifetime is now the same as scope lifetime :(
  • fn scope returns error, so that's why we have double expect here

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

fn scope returns error,

What are the conditions under which it errors?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

If the child thread panics, an error is returned.

from https://docs.rs/crossbeam/0.7.1/crossbeam/thread/struct.ScopedJoinHandle.html

and

If any of the joined threads has panicked, an Err is returned containing errors from panicked threads.

from https://docs.rs/crossbeam/0.7.1/crossbeam/fn.scope.html

}
}

Expand Down Expand Up @@ -1061,11 +1068,18 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {
if stack_depth != depth_threshold {
self.create_with_stack_depth(params, substate, stack_depth, tracer, vm_tracer)
} else {
crossbeam::scope(|scope| {
scope.builder().stack_size(::std::cmp::max(self.schedule.max_depth.saturating_sub(depth_threshold) * STACK_SIZE_PER_DEPTH, local_stack_size)).spawn(move || {
self.create_with_stack_depth(params, substate, stack_depth, tracer, vm_tracer)
}).expect("Sub-thread creation cannot fail; the host might run out of resources; qed")
}).join().expect("Sub-thread never panics; qed")
thread::scope(|scope| {
let stack_size = cmp::max(self.schedule.max_depth.saturating_sub(depth_threshold) * STACK_SIZE_PER_DEPTH, local_stack_size);
scope.builder()
.stack_size(stack_size)
.spawn(|_| {
self.create_with_stack_depth(params, substate, stack_depth, tracer, vm_tracer)
})
.expect("Sub-thread creation cannot fail; the host might run out of resources; qed")
.join()
})
.expect("Sub-thread never panics; qed")
.expect("Sub-thread never panics; qed")
}
}

Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ extern crate account_db;
extern crate ansi_term;
extern crate bn;
extern crate common_types as types;
extern crate crossbeam;
extern crate crossbeam_utils;
extern crate ethabi;
extern crate ethash;
extern crate ethcore_blockchain as blockchain;
Expand Down
10 changes: 5 additions & 5 deletions ethcore/src/snapshot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use self::io::SnapshotWriter;
use super::state_db::StateDB;
use super::state::Account as StateAccount;

use crossbeam::scope;
use crossbeam_utils::thread;
use rand::{Rng, rngs::OsRng};

pub use self::error::Error;
Expand Down Expand Up @@ -167,9 +167,9 @@ pub fn take_snapshot<W: SnapshotWriter + Send>(

let version = chunker.current_version();
let writer = Mutex::new(writer);
let (state_hashes, block_hashes) = scope(|scope| -> Result<(Vec<H256>, Vec<H256>), Error> {
let (state_hashes, block_hashes) = thread::scope(|scope| -> Result<(Vec<H256>, Vec<H256>), Error> {
let writer = &writer;
let block_guard = scope.spawn(move || {
let block_guard = scope.spawn(move |_| {
chunk_secondary(chunker, chain, block_hash, writer, p)
});

Expand All @@ -181,7 +181,7 @@ pub fn take_snapshot<W: SnapshotWriter + Send>(
let mut state_guards = Vec::with_capacity(num_threads as usize);

for thread_idx in 0..num_threads {
let state_guard = scope.spawn(move || -> Result<Vec<H256>, Error> {
let state_guard = scope.spawn(move |_| -> Result<Vec<H256>, Error> {
let mut chunk_hashes = Vec::new();

for part in (thread_idx..SNAPSHOT_SUBPARTS).step_by(num_threads) {
Expand All @@ -205,7 +205,7 @@ pub fn take_snapshot<W: SnapshotWriter + Send>(

debug!(target: "snapshot", "Took a snapshot of {} accounts", p.accounts.load(Ordering::SeqCst));
Ok((state_hashes, block_hashes))
})?;
}).expect("Sub-thread never panics; qed")?;

info!(target: "snapshot", "produced {} state chunks and {} block chunks.", state_hashes.len(), block_hashes.len());

Expand Down