13729a0f7f
* [builtin]: impl new builtin type Have an enum to deserialize either a builtin of a single price or several prices * [builtin]: style cleanup * [builtin]: fix tests * [builtin]: replace boxing with wrapper enum * cleanup * fix: make it backward compatible with old builtin * fix: update chain specs * fix: revert use of `type alias` on enum The CI doesn't use the latest rust. This commit reverts that change * fix: builtin tests * fix: revert use of `type alias` on enum * [basic-authority]: update test-chainspec * fix failing tests * [builtin]: multi-prices add `info field` It might be hard to read chain specs with several activations points. This commit introduces a `info` field which may be used to write some information about the current activation such as: `Istanbul hardfork EIP-1108` or something similar. * fix: bad rebase Co-Authored-By: David <dvdplm@gmail.com> * fix(grumbles): make it backward compatible * grumbles: resolve `NOTE` * revert chain specs changes * rename test Co-Authored-By: David <dvdplm@gmail.com> * [builtin docs]: price -> Fixed price Co-Authored-By: Andronik Ordian <write@reusable.software> * [json]: address naming grumbles InnerPricing -> PricingInner PriceWithActivationAt -> PricingAt * docs: revert changes for `AltBn128ConstOperations` * [json]: usize -> u64 Use explicit types to cope with platform dependent issues for `usize` * grumble: simplify `spec_backward_compability.json` * docs: add issue link to `TODO` * [builtin]: replace `match` with `map` * [builtin]: add deprecation message `eip1108` params * nits * [json spec tests]: fix json indentation * [json docs]: fix typos * [json]: `compability layer` + deser to BTreeMap Previously we had to match `Pricing::Single` and `PricingMulti` which this fixes. It does by introducing a compability layer and into() implemenentation. In addition, I switched the deserialization to `BTreeMap` instead of `Vec`. That changes the format of the chain spec again * [json]: rename `BuiltinCombat` -> `BuiltinCompat` * Update ethcore/builtin/src/lib.rs Co-Authored-By: David <dvdplm@gmail.com> * [json builtin]: improve docs Co-Authored-By: David <dvdplm@gmail.com> * [json builtin]: improve docs Co-Authored-By: David <dvdplm@gmail.com> * chore(builtin): sort dependencies * [json builtin]: deprecate `eip1108` params * [machine]: add bench for calling builtin contract * [machine]: reduce calls to `Builtin::is_active` * [builtin]: fix nits * [json]: revert breakage of chain specs * [json builtin]: remove `eip1108` params * [chain specs]: update to new format * [machine]: revert changes * [devp2p]: revert change * [builtin]: doc nits
150 lines
4.6 KiB
Rust
150 lines
4.6 KiB
Rust
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
|
// This file is part of Parity Ethereum.
|
|
|
|
// Parity Ethereum is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Parity Ethereum is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! Benchmarking of calling builtin contract
|
|
|
|
use std::str::FromStr;
|
|
|
|
use account_state::State;
|
|
use parity_bytes::Bytes;
|
|
use ethcore::test_helpers::get_temp_state_db;
|
|
use ethereum_types::{H160, U256};
|
|
use criterion::{black_box, criterion_main, criterion_group, Criterion};
|
|
use machine::{test_helpers, Machine};
|
|
use machine::executive::CallCreateExecutive;
|
|
use machine::substate::Substate;
|
|
use trace::{NoopTracer, NoopVMTracer};
|
|
use trie_vm_factories::VmFactory;
|
|
use vm::{ActionParams, EnvInfo, Schedule};
|
|
|
|
const ECRECOVER: &str = "0000000000000000000000000000000000000001";
|
|
const SHA256: &str = "0000000000000000000000000000000000000002";
|
|
const SIGNED_DATA: &str = "hash000000000001v000000000000002r000000000000003s000000000000004";
|
|
|
|
fn single_builtin_pricing() -> Machine {
|
|
test_helpers::load_machine(include_bytes!("../../res/ethereum/builtin_one_activation_bench.json"))
|
|
}
|
|
|
|
fn multiple_builtin_pricing() -> Machine {
|
|
test_helpers::load_machine(include_bytes!("../../res/ethereum/builtin_multi_bench.json"))
|
|
}
|
|
|
|
fn builtin_params(address: H160, execute: bool) -> ActionParams {
|
|
let mut params = ActionParams::default();
|
|
params.code_address = address;
|
|
params.gas = u64::max_value().into();
|
|
if execute {
|
|
params.data = Some(SIGNED_DATA.bytes().collect::<Bytes>());
|
|
}
|
|
params
|
|
}
|
|
|
|
fn single_activation(c: &mut Criterion) {
|
|
let contract = H160::from_str(ECRECOVER).unwrap();
|
|
let params = builtin_params(contract, false);
|
|
|
|
let env_info = EnvInfo::default();
|
|
let machine = single_builtin_pricing();
|
|
let schedule = Schedule::default();
|
|
let factory = VmFactory::default();
|
|
let depth = 0;
|
|
let stack_depth = 0;
|
|
let parent_static_flag = false;
|
|
|
|
let db = get_temp_state_db();
|
|
let mut state = State::new(db, U256::from(0), Default::default());
|
|
let mut substate = Substate::new();
|
|
|
|
c.bench_function("single activation", move |b| {
|
|
b.iter(|| black_box(CallCreateExecutive::new_call_raw(
|
|
params.clone(),
|
|
&env_info,
|
|
&machine,
|
|
&schedule,
|
|
&factory,
|
|
depth,
|
|
stack_depth,
|
|
parent_static_flag,
|
|
).exec(&mut state, &mut substate, &mut NoopTracer, &mut NoopVMTracer))
|
|
)
|
|
});
|
|
}
|
|
|
|
fn ten_multiple_activations(c: &mut Criterion) {
|
|
let contract = H160::from_str(ECRECOVER).unwrap();
|
|
let params = builtin_params(contract, false);
|
|
|
|
let env_info = EnvInfo::default();
|
|
let machine = multiple_builtin_pricing();
|
|
let schedule = Schedule::default();
|
|
let factory = VmFactory::default();
|
|
let depth = 0;
|
|
let stack_depth = 0;
|
|
let parent_static_flag = false;
|
|
|
|
let db = get_temp_state_db();
|
|
let mut state = State::new(db, U256::from(0), Default::default());
|
|
let mut substate = Substate::new();
|
|
|
|
c.bench_function("ten activations", move |b| {
|
|
b.iter(|| black_box(CallCreateExecutive::new_call_raw(
|
|
params.clone(),
|
|
&env_info,
|
|
&machine,
|
|
&schedule,
|
|
&factory,
|
|
depth,
|
|
stack_depth,
|
|
parent_static_flag,
|
|
).exec(&mut state, &mut substate, &mut NoopTracer, &mut NoopVMTracer))
|
|
)
|
|
});
|
|
}
|
|
|
|
fn fourty_multiple_activations(c: &mut Criterion) {
|
|
let contract = H160::from_str(SHA256).unwrap();
|
|
let params = builtin_params(contract, false);
|
|
|
|
let env_info = EnvInfo::default();
|
|
let machine = multiple_builtin_pricing();
|
|
let schedule = Schedule::default();
|
|
let factory = VmFactory::default();
|
|
let depth = 0;
|
|
let stack_depth = 0;
|
|
let parent_static_flag = false;
|
|
|
|
let db = get_temp_state_db();
|
|
let mut state = State::new(db, U256::from(0), Default::default());
|
|
let mut substate = Substate::new();
|
|
|
|
c.bench_function("fourty activations", move |b| {
|
|
b.iter(|| black_box(CallCreateExecutive::new_call_raw(
|
|
params.clone(),
|
|
&env_info,
|
|
&machine,
|
|
&schedule,
|
|
&factory,
|
|
depth,
|
|
stack_depth,
|
|
parent_static_flag,
|
|
).exec(&mut state, &mut substate, &mut NoopTracer, &mut NoopVMTracer))
|
|
)
|
|
});
|
|
}
|
|
|
|
criterion_group!(benches, single_activation, ten_multiple_activations, fourty_multiple_activations);
|
|
criterion_main!(benches);
|