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

Commit 7202f7a

Browse files
sorpaas5chdn
authored andcommitted
[beta] Backports (#8450)
* 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) * handle queue import errors a bit more gracefully (#8385) * 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
1 parent 45c29a2 commit 7202f7a

File tree

7 files changed

+41
-35
lines changed

7 files changed

+41
-35
lines changed

Cargo.lock

+3-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

-1
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/src/engines/tendermint/mod.rs

+1-12
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 ethereum_types::{H256, H520, U128, U256, Address};
3333
use parking_lot::RwLock;
@@ -449,17 +449,6 @@ impl Engine<EthereumMachine> for Tendermint {
449449

450450
fn maximum_uncle_age(&self) -> usize { 0 }
451451

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

ethcore/src/executive.rs

+21-12
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,21 @@ use transaction::{Action, SignedTransaction};
3434
use crossbeam;
3535
pub use executed::{Executed, ExecutionResult};
3636

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

4253
/// Returns new address created from address, nonce, and code hash
4354
pub fn contract_address(address_scheme: CreateContractAddress, sender: &Address, nonce: &U256, code: &[u8]) -> (Address, Option<H256>) {
@@ -332,30 +343,28 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {
332343
tracer: &mut T,
333344
vm_tracer: &mut V
334345
) -> vm::Result<FinalizationResult> where T: Tracer, V: VMTracer {
335-
336-
let depth_threshold = ::io::LOCAL_STACK_SIZE.with(|sz| sz.get() / STACK_SIZE_PER_DEPTH);
346+
let local_stack_size = ::io::LOCAL_STACK_SIZE.with(|sz| sz.get());
347+
let depth_threshold = local_stack_size.saturating_sub(STACK_SIZE_ENTRY_OVERHEAD) / STACK_SIZE_PER_DEPTH;
337348
let static_call = params.call_type == CallType::StaticCall;
338349

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

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

355-
scope.spawn(move || {
364+
scope.builder().stack_size(::std::cmp::max(schedule.max_depth.saturating_sub(depth_threshold) * STACK_SIZE_PER_DEPTH, local_stack_size)).spawn(move || {
356365
let mut vm = vm_factory.create(&params, &schedule);
357366
vm.exec(params, &mut ext).finalize(ext)
358-
})
367+
}).expect("Sub-thread creation cannot fail; the host might run out of resources; qed")
359368
}).join()
360369
}
361370

parity/main.rs

-1
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]

sync/src/light_sync/mod.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ impl<L: AsLightClient> LightSync<L> {
427427

428428
// handles request dispatch, block import, state machine transitions, and timeouts.
429429
fn maintain_sync(&self, ctx: &BasicContext) {
430+
use ethcore::error::{BlockImportError, ImportError};
431+
430432
const DRAIN_AMOUNT: usize = 128;
431433

432434
let client = self.client.as_light_client();
@@ -453,11 +455,20 @@ impl<L: AsLightClient> LightSync<L> {
453455
trace!(target: "sync", "Drained {} headers to import", sink.len());
454456

455457
for header in sink.drain(..) {
456-
if let Err(e) = client.queue_header(header) {
457-
debug!(target: "sync", "Found bad header ({:?}). Reset to search state.", e);
458+
match client.queue_header(header) {
459+
Ok(_) => {}
460+
Err(BlockImportError::Import(ImportError::AlreadyInChain)) => {
461+
trace!(target: "sync", "Block already in chain. Continuing.");
462+
},
463+
Err(BlockImportError::Import(ImportError::AlreadyQueued)) => {
464+
trace!(target: "sync", "Block already queued. Continuing.");
465+
},
466+
Err(e) => {
467+
debug!(target: "sync", "Found bad header ({:?}). Reset to search state.", e);
458468

459-
self.begin_search(&mut state);
460-
break 'a;
469+
self.begin_search(&mut state);
470+
break 'a;
471+
}
461472
}
462473
}
463474
}

util/dir/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ authors = ["Parity Technologies <admin@parity.io>"]
66
[dependencies]
77
ethereum-types = "0.2"
88
journaldb = { path = "../journaldb" }
9-
app_dirs = "1.1.1"
9+
app_dirs = { git = "https://github.com/paritytech/app-dirs-rs" }

0 commit comments

Comments
 (0)