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

Commit

Permalink
Merge branch 'master' into dp/feature/eip-152-add-blake2-precompile
Browse files Browse the repository at this point in the history
* master:
  fix: remove unused error-chain (#11028)
  fix: remove needless use of itertools (#11029)
  Convert `std::test` benchmarks to use Criterion (#10999)
  Fix block detail updating (#11015)
  [trace] introduce trace failed to Ext (#11019)
  cli: update usage and version headers (#10924)
  [private-tx] remove unused rand (#11024)
  • Loading branch information
dvdplm committed Sep 9, 2019
2 parents 5818117 + 53e590f commit bb991b5
Show file tree
Hide file tree
Showing 31 changed files with 418 additions and 388 deletions.
7 changes: 5 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,14 @@ cargo-check 2 3:
- time cargo check --target $CARGO_TARGET --locked --manifest-path util/io/Cargo.toml --features "mio" --verbose --color=always
- sccache -s

cargo-check-ethcore-benches:
cargo-check-benches:
stage: test
<<: *docker-cache-status
script:
- time cargo check -p ethcore --benches --target $CARGO_TARGET --locked --verbose --color=always
- time (
cargo check --all --benches --exclude ethash --target $CARGO_TARGET --locked --verbose --color=always;
(cd ethash; time cargo check --benches --features bench --target $CARGO_TARGET --locked --verbose --color=always)
)
- sccache -s

cargo-audit:
Expand Down
445 changes: 159 additions & 286 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ethash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ primal = "0.2.3"
static_assertions = "0.3.3"

[dev-dependencies]
criterion = "0.2"
criterion = "0.3"
rustc-hex = "1.0"
serde_json = "1.0"
tempdir = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ vm = { path = "vm" }
account-db = { path = "account-db" }
blooms-db = { path = "../util/blooms-db" }
ethcore-builtin = { path = "./builtin" }
criterion = "0.2"
criterion = "0.3"
engine = { path = "./engine", features = ["test-helpers"] }
env_logger = "0.5"
ethash = { path = "../ethash" }
Expand Down
29 changes: 24 additions & 5 deletions ethcore/blockchain/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ pub trait BlockProvider {
where F: Fn(&LogEntry) -> bool + Send + Sync, Self: Sized;
}

/// Interface for querying blocks with pending db transaction by hash and by number.
trait InTransactionBlockProvider {
/// Get the familial details concerning a block.
fn uncommitted_block_details(&self, hash: &H256) -> Option<BlockDetails>;
}

#[derive(Debug, Hash, Eq, PartialEq, Clone)]
enum CacheId {
BlockHeader(H256),
Expand Down Expand Up @@ -427,6 +433,19 @@ impl BlockProvider for BlockChain {
}
}

impl InTransactionBlockProvider for BlockChain {
fn uncommitted_block_details(&self, hash: &H256) -> Option<BlockDetails> {
let result = self.db.key_value().read_with_two_layer_cache(
db::COL_EXTRA,
&self.pending_block_details,
&self.block_details,
hash
)?;
self.cache_man.lock().note_used(CacheId::BlockDetails(*hash));
Some(result)
}
}

/// An iterator which walks the blockchain towards the genesis.
#[derive(Clone)]
pub struct AncestryIter<'a> {
Expand Down Expand Up @@ -795,7 +814,7 @@ impl BlockChain {
batch.put(db::COL_HEADERS, hash.as_bytes(), &compressed_header);
batch.put(db::COL_BODIES, hash.as_bytes(), &compressed_body);

let maybe_parent = self.block_details(&block_parent_hash);
let maybe_parent = self.uncommitted_block_details(&block_parent_hash);

if let Some(parent_details) = maybe_parent {
// parent known to be in chain.
Expand Down Expand Up @@ -1047,7 +1066,7 @@ impl BlockChain {
///
/// Used in snapshots to glue the chunks together at the end.
pub fn add_child(&self, batch: &mut DBTransaction, block_hash: H256, child_hash: H256) {
let mut parent_details = self.block_details(&block_hash)
let mut parent_details = self.uncommitted_block_details(&block_hash)
.unwrap_or_else(|| panic!("Invalid block hash: {:?}", block_hash));

parent_details.children.push(child_hash);
Expand Down Expand Up @@ -1154,7 +1173,7 @@ impl BlockChain {
/// Mark a block to be considered finalized. Returns `Some(())` if the operation succeeds, and `None` if the block
/// hash is not found.
pub fn mark_finalized(&self, batch: &mut DBTransaction, block_hash: H256) -> Option<()> {
let mut block_details = self.block_details(&block_hash)?;
let mut block_details = self.uncommitted_block_details(&block_hash)?;
block_details.is_finalized = true;

self.update_block_details(batch, block_hash, block_details);
Expand Down Expand Up @@ -1347,7 +1366,7 @@ impl BlockChain {
/// Uses the given parent details or attempts to load them from the database.
fn prepare_block_details_update(&self, parent_hash: H256, info: &BlockInfo, is_finalized: bool) -> HashMap<H256, BlockDetails> {
// update parent
let mut parent_details = self.block_details(&parent_hash).unwrap_or_else(|| panic!("Invalid parent hash: {:?}", parent_hash));
let mut parent_details = self.uncommitted_block_details(&parent_hash).unwrap_or_else(|| panic!("Invalid parent hash: {:?}", parent_hash));
parent_details.children.push(info.hash);

// create current block details.
Expand Down Expand Up @@ -1653,7 +1672,7 @@ mod tests {
let fork_choice = {
let header = block.header_view();
let parent_hash = header.parent_hash();
let parent_details = bc.block_details(&parent_hash).unwrap_or_else(|| panic!("Invalid parent hash: {:?}", parent_hash));
let parent_details = bc.uncommitted_block_details(&parent_hash).unwrap_or_else(|| panic!("Invalid parent hash: {:?}", parent_hash));
let block_total_difficulty = parent_details.total_difficulty + header.difficulty();
if block_total_difficulty > bc.best_block_total_difficulty() {
common_types::engines::ForkChoice::New
Expand Down
15 changes: 15 additions & 0 deletions ethcore/db/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,21 @@ pub trait Readable {
})
}

/// Returns value for given key either in two-layered cache or in database.
fn read_with_two_layer_cache<K, T, C>(&self, col: Option<u32>, l1_cache: &RwLock<C>, l2_cache: &RwLock<C>, key: &K) -> Option<T> where
K: Key<T> + Eq + Hash + Clone,
T: Clone + rlp::Decodable,
C: Cache<K, T> {
{
let read = l1_cache.read();
if let Some(v) = read.get(key) {
return Some(v.clone());
}
}

self.read_with_cache(col, l2_cache, key)
}

/// Returns true if given value exists.
fn exists<T, R>(&self, col: Option<u32>, key: &dyn Key<T, Target = R>) -> bool where R: AsRef<[u8]>;

Expand Down
4 changes: 2 additions & 2 deletions ethcore/engines/authority-round/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@ impl Engine for AuthorityRound {

let mut hash = *chain_head.parent_hash();

let mut ancestry = itertools::repeat_call(move || {
let mut ancestry = std::iter::repeat_with(move || {
chain(hash).and_then(|header| {
if header.number() == 0 { return None }
hash = *header.parent_hash();
Expand Down Expand Up @@ -1548,7 +1548,7 @@ impl Engine for AuthorityRound {
// to construct transition proof. author == ec_recover(sig) known
// since the blocks are in the DB.
let mut hash = chain_head.hash();
let mut finality_proof: Vec<_> = itertools::repeat_call(move || {
let mut finality_proof: Vec<_> = std::iter::repeat_with(move || {
chain(hash).and_then(|header| {
hash = *header.parent_hash();
if header.number() == 0 { None }
Expand Down
18 changes: 17 additions & 1 deletion ethcore/engines/null-engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,26 @@ use machine::{
ExecutedBlock,
Machine,
};
use common_types::snapshot::Snapshotting;
use common_types::{
ancestry_action::AncestryAction,
header::ExtendedHeader,
snapshot::Snapshotting
};

/// Params for a null engine.
#[derive(Clone, Default)]
pub struct NullEngineParams {
/// base reward for a block.
pub block_reward: U256,
/// Immediate finalization.
pub immediate_finalization: bool
}

impl From<ethjson::spec::NullEngineParams> for NullEngineParams {
fn from(p: ethjson::spec::NullEngineParams) -> Self {
NullEngineParams {
block_reward: p.block_reward.map_or_else(Default::default, Into::into),
immediate_finalization: p.immediate_finalization.unwrap_or(false)
}
}
}
Expand Down Expand Up @@ -108,4 +115,13 @@ impl Engine for NullEngine {
fn params(&self) -> &CommonParams {
self.machine.params()
}

fn ancestry_actions(&self, _header: &Header, ancestry: &mut dyn Iterator<Item=ExtendedHeader>) -> Vec<AncestryAction> {
if self.params.immediate_finalization {
// always mark parent finalized
ancestry.take(1).map(|e| AncestryAction::MarkFinalized(e.header.hash())).collect()
} else {
Vec::new()
}
}
}
2 changes: 1 addition & 1 deletion ethcore/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ memory-cache = { path = "../../util/memory-cache" }

[dev-dependencies]
rustc-hex = "1.0"
criterion = "0.2"
criterion = "0.3"
hex-literal = "0.2.0"

[features]
Expand Down
12 changes: 11 additions & 1 deletion ethcore/evm/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ impl<Cost: CostType> Interpreter<Cost> {
cache, params, reader, informant,
valid_jump_destinations, gasometer, stack,
done: false,
// Overridden in `step_inner` based on
// the result of `ext.trace_next_instruction`.
do_trace: true,
mem: Vec::new(),
return_data: ReturnData::empty(),
Expand Down Expand Up @@ -353,6 +355,9 @@ impl<Cost: CostType> Interpreter<Cost> {
ext.trace_prepare_execute(self.reader.position - 1, opcode, requirements.gas_cost.as_u256(), Self::mem_written(instruction, &self.stack), Self::store_written(instruction, &self.stack));
}
if let Err(e) = self.gasometer.as_mut().expect(GASOMETER_PROOF).verify_gas(&requirements.gas_cost) {
if self.do_trace {
ext.trace_failed();
}
return InterpreterResult::Done(Err(e));
}
self.mem.expand(requirements.memory_required_size);
Expand All @@ -366,7 +371,12 @@ impl<Cost: CostType> Interpreter<Cost> {
let result = match self.exec_instruction(
current_gas, ext, instruction, requirements.provide_gas
) {
Err(x) => return InterpreterResult::Done(Err(x)),
Err(x) => {
if self.do_trace {
ext.trace_failed();
}
return InterpreterResult::Done(Err(x));
},
Ok(x) => x,
};
evm_debug!({ self.informant.after_instruction(instruction) });
Expand Down
2 changes: 0 additions & 2 deletions ethcore/light/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ rlp_derive = { path = "../../util/rlp-derive" }
smallvec = "0.6"
futures = "0.1"
rand = "0.6"
itertools = "0.5"
bincode = "1.1"
serde = "1.0"
serde_derive = "1.0"
Expand All @@ -46,7 +45,6 @@ keccak-hasher = { path = "../../util/keccak-hasher" }
triehash-ethereum = { version = "0.2", path = "../../util/triehash-ethereum" }
kvdb = "0.1"
memory-cache = { path = "../../util/memory-cache" }
error-chain = { version = "0.12", default-features = false }
journaldb = { path = "../../util/journaldb" }
verification = { path = "../verification" }

Expand Down
2 changes: 1 addition & 1 deletion ethcore/light/src/client/header_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ impl HeaderChain {
let canon = &era_entry.candidates[0];
(canon.hash, canon.total_difficulty)
};
cht::compute_root(cht_num, ::itertools::repeat_call(iter))
cht::compute_root(cht_num, std::iter::repeat_with(iter))
.expect("fails only when too few items; this is checked; qed")
};

Expand Down
2 changes: 0 additions & 2 deletions ethcore/light/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ extern crate ethereum_types;
extern crate ethcore_miner as miner;
extern crate hash_db;
extern crate parity_util_mem;
extern crate parity_util_mem as mem;
extern crate parity_util_mem as malloc_size_of;
extern crate failsafe;
extern crate futures;
extern crate itertools;
extern crate keccak_hasher;
extern crate machine;
extern crate memory_db;
Expand Down
4 changes: 4 additions & 0 deletions ethcore/machine/src/externalities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B>
self.vm_tracer.trace_prepare_execute(pc, instruction, gas_cost, mem_written, store_written)
}

fn trace_failed(&mut self) {
self.vm_tracer.trace_failed();
}

fn trace_executed(&mut self, gas_used: U256, stack_push: &[U256], mem: &[u8]) {
self.vm_tracer.trace_executed(gas_used, stack_push, mem)
}
Expand Down
1 change: 0 additions & 1 deletion ethcore/private-tx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ parity-crypto = "0.4.0"
parking_lot = "0.8"
trie-db = "0.15.0"
patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" }
rand = "0.3"
rlp = "0.4.0"
rlp_derive = { path = "../../util/rlp-derive" }
rustc-hex = "1.0"
Expand Down
2 changes: 0 additions & 2 deletions ethcore/private-tx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ extern crate vm;
#[cfg(not(time_checked_add))]
extern crate time_utils;

#[cfg(test)]
extern crate rand;
#[cfg(test)]
extern crate env_logger;

Expand Down
38 changes: 38 additions & 0 deletions ethcore/res/null_morden_with_finality.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "Morden",
"engine": {
"null": {
"params": {
"immediateFinalization": true
}
}
},
"params": {
"gasLimitBoundDivisor": "0x0400",
"accountStartNonce": "0x0",
"maximumExtraDataSize": "0x20",
"minGasLimit": "0x1388",
"networkID" : "0x2"
},
"genesis": {
"seal": {
"ethereum": {
"nonce": "0x00006d6f7264656e",
"mixHash": "0x00000000000000000000000000000000000000647572616c65787365646c6578"
}
},
"difficulty": "0x20000",
"author": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x",
"gasLimit": "0x2fefd8"
},
"accounts": {
"0000000000000000000000000000000000000001": { "balance": "1", "nonce": "1048576", "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } },
"0000000000000000000000000000000000000002": { "balance": "1", "nonce": "1048576", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } },
"0000000000000000000000000000000000000003": { "balance": "1", "nonce": "1048576", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } },
"0000000000000000000000000000000000000004": { "balance": "1", "nonce": "1048576", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } },
"102e61f5d8f9bc71d0ad4a084df4e65e05ce0e1c": { "balance": "1606938044258990275541962092341162602522202993782792835301376", "nonce": "1048576" }
}
}
1 change: 1 addition & 0 deletions ethcore/spec/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ bundle_test_spec! {
"null" => new_null,
"null_morden" => new_test,
"null_morden_with_reward" => new_test_with_reward,
"null_morden_with_finality" => new_test_with_finality,
"validator_contract" => new_validator_contract,
"validator_multi" => new_validator_multi,
"validator_safe_contract" => new_validator_safe_contract
Expand Down
22 changes: 20 additions & 2 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2644,13 +2644,13 @@ mod tests {
receipt::{Receipt, LocalizedReceipt, TransactionOutcome},
transaction::{Transaction, LocalizedTransaction, Action},
};
use test_helpers::{generate_dummy_client, get_good_dummy_block_hash, generate_dummy_client_with_data};
use test_helpers::{generate_dummy_client, generate_dummy_client_with_data, generate_dummy_client_with_spec_and_data, get_good_dummy_block_hash};
use std::thread;
use std::time::Duration;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use kvdb::DBTransaction;
use blockchain::ExtrasInsert;
use blockchain::{BlockProvider, ExtrasInsert};
use hash::keccak;
use super::transaction_receipt;
use ethkey::KeyPair;
Expand Down Expand Up @@ -2785,4 +2785,22 @@ mod tests {
outcome: TransactionOutcome::StateRoot(state_root),
});
}

#[test]
fn should_mark_finalization_correctly_for_parent() {
let client = generate_dummy_client_with_spec_and_data(spec::new_test_with_finality, 2, 0, &[]);
let chain = client.chain();

let block1_details = chain.block_hash(1).and_then(|h| chain.block_details(&h));
assert!(block1_details.is_some());
let block1_details = block1_details.unwrap();
assert_eq!(block1_details.children.len(), 1);
assert!(block1_details.is_finalized);

let block2_details = chain.block_hash(2).and_then(|h| chain.block_details(&h));
assert!(block2_details.is_some());
let block2_details = block2_details.unwrap();
assert_eq!(block2_details.children.len(), 0);
assert!(!block2_details.is_finalized);
}
}
Loading

0 comments on commit bb991b5

Please sign in to comment.