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

Commit 014d0ac

Browse files
sorpaas5chdn
authored andcommitted
[stable] Backports (#8449)
* Use forked app_dirs crate for reverted Windows dir behavior (#8438) * Remove unused appdirs dependency in CLI * Use forked app_dirs crate for reverted Windows dir behavior * remove Tendermint extra_info due to seal inconsistencies (#8367) * Improve VM executor stack size estimation rules (#8439) * Improve VM executor stack size estimation rules * typo: docs add "(Debug build)" comment * Fix an off by one typo and set minimal stack size This avoids the case if `depth_threshold == max_depth`. Usually setting stack size to zero will just rebound it to platform minimal stack size, but we set it here just in case. * Use saturating_sub to avoid potential overflow * Upgrade crossbeam to 0.3
1 parent 302dbd5 commit 014d0ac

File tree

8 files changed

+32
-38
lines changed

8 files changed

+32
-38
lines changed

Cargo.lock

Lines changed: 7 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ toml = "0.4"
2727
serde = "1.0"
2828
serde_json = "1.0"
2929
serde_derive = "1.0"
30-
app_dirs = "1.1.1"
3130
futures = "0.1"
3231
futures-cpupool = "0.1"
3332
fdlimit = "0.1"

ethcore/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ bloomchain = { path = "../util/bloomchain" }
1212
bn = { git = "https://github.com/paritytech/bn" }
1313
byteorder = "1.0"
1414
common-types = { path = "types" }
15-
crossbeam = "0.2.9"
15+
crossbeam = "0.3"
1616
ethash = { path = "../ethash" }
1717
ethcore-bloom-journal = { path = "../util/bloom" }
1818
ethcore-bytes = { path = "../util/bytes" }

ethcore/src/engines/tendermint/mod.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mod params;
2727

2828
use std::sync::{Weak, Arc};
2929
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
30-
use std::collections::{HashSet, BTreeMap};
30+
use std::collections::HashSet;
3131
use hash::keccak;
3232
use bigint::prelude::{U128, U256};
3333
use bigint::hash::{H256, H520};
@@ -454,17 +454,6 @@ impl Engine<EthereumMachine> for Tendermint {
454454

455455
fn maximum_uncle_age(&self) -> usize { 0 }
456456

457-
/// Additional engine-specific information for the user/developer concerning `header`.
458-
fn extra_info(&self, header: &Header) -> BTreeMap<String, String> {
459-
let message = ConsensusMessage::new_proposal(header).expect("Invalid header.");
460-
map![
461-
"signature".into() => message.signature.to_string(),
462-
"height".into() => message.vote_step.height.to_string(),
463-
"view".into() => message.vote_step.view.to_string(),
464-
"block_hash".into() => message.block_hash.as_ref().map(ToString::to_string).unwrap_or("".into())
465-
]
466-
}
467-
468457
fn populate_from_parent(&self, header: &mut Header, parent: &Header) {
469458
// Chain scoring: total weight is sqrt(U256::max_value())*height - view
470459
let new_difficulty = U256::from(U128::max_value())

ethcore/src/executive.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,21 @@ use transaction::{Action, SignedTransaction};
3636
use crossbeam;
3737
pub use executed::{Executed, ExecutionResult};
3838

39-
/// Roughly estimate what stack size each level of evm depth will use
40-
/// TODO [todr] We probably need some more sophisticated calculations here (limit on my machine 132)
41-
/// Maybe something like here: `https://github.com/ethereum/libethereum/blob/4db169b8504f2b87f7d5a481819cfb959fc65f6c/libethereum/ExtVM.cpp`
42-
const STACK_SIZE_PER_DEPTH: usize = 24*1024;
39+
#[cfg(debug_assertions)]
40+
/// Roughly estimate what stack size each level of evm depth will use. (Debug build)
41+
const STACK_SIZE_PER_DEPTH: usize = 128 * 1024;
42+
43+
#[cfg(not(debug_assertions))]
44+
/// Roughly estimate what stack size each level of evm depth will use.
45+
const STACK_SIZE_PER_DEPTH: usize = 24 * 1024;
46+
47+
#[cfg(debug_assertions)]
48+
/// Entry stack overhead prior to execution. (Debug build)
49+
const STACK_SIZE_ENTRY_OVERHEAD: usize = 100 * 1024;
50+
51+
#[cfg(not(debug_assertions))]
52+
/// Entry stack overhead prior to execution.
53+
const STACK_SIZE_ENTRY_OVERHEAD: usize = 20 * 1024;
4354

4455
/// Returns new address created from address, nonce, and code hash
4556
pub fn contract_address(address_scheme: CreateContractAddress, sender: &Address, nonce: &U256, code: &[u8]) -> (Address, Option<H256>) {
@@ -334,30 +345,28 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {
334345
tracer: &mut T,
335346
vm_tracer: &mut V
336347
) -> vm::Result<FinalizationResult> where T: Tracer, V: VMTracer {
337-
338-
let depth_threshold = ::io::LOCAL_STACK_SIZE.with(|sz| sz.get() / STACK_SIZE_PER_DEPTH);
348+
let local_stack_size = ::io::LOCAL_STACK_SIZE.with(|sz| sz.get());
349+
let depth_threshold = local_stack_size.saturating_sub(STACK_SIZE_ENTRY_OVERHEAD) / STACK_SIZE_PER_DEPTH;
339350
let static_call = params.call_type == CallType::StaticCall;
340351

341352
// Ordinary execution - keep VM in same thread
342-
if (self.depth + 1) % depth_threshold != 0 {
353+
if self.depth != depth_threshold {
343354
let vm_factory = self.state.vm_factory();
344355
let mut ext = self.as_externalities(OriginInfo::from(&params), unconfirmed_substate, output_policy, tracer, vm_tracer, static_call);
345356
trace!(target: "executive", "ext.schedule.have_delegate_call: {}", ext.schedule().have_delegate_call);
346357
let mut vm = vm_factory.create(&params, &schedule);
347358
return vm.exec(params, &mut ext).finalize(ext);
348359
}
349360

350-
// Start in new thread to reset stack
351-
// TODO [todr] No thread builder yet, so we need to reset once for a while
352-
// https://github.com/aturon/crossbeam/issues/16
361+
// Start in new thread with stack size needed up to max depth
353362
crossbeam::scope(|scope| {
354363
let vm_factory = self.state.vm_factory();
355364
let mut ext = self.as_externalities(OriginInfo::from(&params), unconfirmed_substate, output_policy, tracer, vm_tracer, static_call);
356365

357-
scope.spawn(move || {
366+
scope.builder().stack_size(::std::cmp::max(schedule.max_depth.saturating_sub(depth_threshold) * STACK_SIZE_PER_DEPTH, local_stack_size)).spawn(move || {
358367
let mut vm = vm_factory.create(&params, &schedule);
359368
vm.exec(params, &mut ext).finalize(ext)
360-
})
369+
}).expect("Sub-thread creation cannot fail; the host might run out of resources; qed")
361370
}).join()
362371
}
363372

parity/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#![warn(missing_docs)]
2020

2121
extern crate ansi_term;
22-
extern crate app_dirs;
2322
extern crate ctrlc;
2423
extern crate docopt;
2524
#[macro_use]

util/dir/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ authors = ["Parity Technologies <[email protected]>"]
66
[dependencies]
77
ethcore-bigint = { path = "../bigint" }
88
journaldb = { path = "../journaldb" }
9-
app_dirs = "1.1.1"
9+
app_dirs = { git = "https://github.com/paritytech/app-dirs-rs" }

util/io/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ authors = ["Parity Technologies <[email protected]>"]
88

99
[dependencies]
1010
mio = "0.6.8"
11-
crossbeam = "0.2"
11+
crossbeam = "0.3"
1212
parking_lot = "0.4"
1313
log = "0.3"
1414
slab = "0.2"
15-

0 commit comments

Comments
 (0)