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

[builtin]: support multiple prices and activations in chain spec #11039

Merged
merged 53 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
96495f6
[builtin]: impl new builtin type
niklasad1 Sep 11, 2019
5d88fc5
[builtin]: style cleanup
niklasad1 Sep 11, 2019
dd9f23d
[builtin]: fix tests
niklasad1 Sep 11, 2019
fb4eca9
[builtin]: replace boxing with wrapper enum
niklasad1 Sep 12, 2019
4bd5491
cleanup
niklasad1 Sep 12, 2019
ebfb0ac
fix: make it backward compatible with old builtin
niklasad1 Sep 24, 2019
196f697
fix: update chain specs
niklasad1 Sep 25, 2019
daa7cf0
fix: revert use of `type alias` on enum
niklasad1 Sep 25, 2019
ea10a6d
fix: builtin tests
niklasad1 Sep 25, 2019
e89b7b7
fix: revert use of `type alias` on enum
niklasad1 Sep 25, 2019
7adde8c
[basic-authority]: update test-chainspec
niklasad1 Sep 25, 2019
343ae14
fix failing tests
niklasad1 Oct 1, 2019
4ad7ef3
[builtin]: multi-prices add `info field`
niklasad1 Oct 1, 2019
b716727
fix: bad rebase
niklasad1 Oct 4, 2019
b46e816
fix(grumbles): make it backward compatible
niklasad1 Oct 4, 2019
d6426a9
grumbles: resolve `NOTE`
niklasad1 Oct 4, 2019
38967fc
revert chain specs changes
niklasad1 Oct 4, 2019
997618e
rename test
niklasad1 Oct 4, 2019
e22c35a
[builtin docs]: price -> Fixed price
niklasad1 Oct 6, 2019
8e0d93b
[json]: address naming grumbles
niklasad1 Oct 6, 2019
330b9ec
docs: revert changes for `AltBn128ConstOperations`
niklasad1 Oct 6, 2019
e9d107a
[json]: usize -> u64
niklasad1 Oct 6, 2019
0a56937
grumble: simplify `spec_backward_compability.json`
niklasad1 Oct 6, 2019
7aa4122
docs: add issue link to `TODO`
niklasad1 Oct 6, 2019
d038bd9
[builtin]: replace `match` with `map`
niklasad1 Oct 6, 2019
354c643
[builtin]: add deprecation message `eip1108` params
niklasad1 Oct 6, 2019
bebc147
nits
niklasad1 Oct 6, 2019
184aa28
Merge remote-tracking branch 'origin/master' into na-builtin-refactor
niklasad1 Oct 7, 2019
d629563
[json spec tests]: fix json indentation
niklasad1 Oct 7, 2019
4509cf6
[json docs]: fix typos
niklasad1 Oct 8, 2019
925a281
Merge remote-tracking branch 'origin/master' into na-builtin-refactor
niklasad1 Oct 9, 2019
1a470a4
Merge remote-tracking branch 'origin/master' into na-builtin-refactor
niklasad1 Oct 11, 2019
57b9539
[json]: `compability layer` + deser to BTreeMap
niklasad1 Oct 12, 2019
5c1cc60
[json]: rename `BuiltinCombat` -> `BuiltinCompat`
niklasad1 Oct 12, 2019
65c4977
Update ethcore/builtin/src/lib.rs
niklasad1 Oct 12, 2019
647fe18
[json builtin]: improve docs
niklasad1 Oct 14, 2019
2090515
[json builtin]: improve docs
niklasad1 Oct 14, 2019
f92f642
chore(builtin): sort dependencies
niklasad1 Oct 15, 2019
d58ef61
[json builtin]: deprecate `eip1108` params
niklasad1 Oct 15, 2019
2210e82
Merge remote-tracking branch 'origin/master' into na-builtin-refactor
niklasad1 Oct 21, 2019
c011f57
Merge remote-tracking branch 'origin/master' into na-builtin-refactor
niklasad1 Oct 22, 2019
eca1dbc
Merge remote-tracking branch 'origin/master' into na-builtin-refactor
niklasad1 Oct 24, 2019
4be9685
Merge branch 'na-builtin-refactor' of github.com:paritytech/parity-et…
niklasad1 Oct 24, 2019
e557891
[machine]: add bench for calling builtin contract
niklasad1 Oct 25, 2019
519997e
[machine]: reduce calls to `Builtin::is_active`
niklasad1 Oct 26, 2019
1ab3bcc
[builtin]: fix nits
niklasad1 Oct 26, 2019
e8d8b0a
[json]: revert breakage of chain specs
niklasad1 Oct 26, 2019
fed8433
[json builtin]: remove `eip1108` params
niklasad1 Oct 15, 2019
0e83090
[chain specs]: update to new format
niklasad1 Oct 31, 2019
0bc1153
[machine]: revert changes
niklasad1 Oct 31, 2019
1bd8290
[devp2p]: revert change
niklasad1 Oct 31, 2019
279342c
[builtin]: doc nits
niklasad1 Oct 31, 2019
2be2534
Merge remote-tracking branch 'origin/master' into na-builtin-refactor
niklasad1 Oct 31, 2019
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
8 changes: 1 addition & 7 deletions ethcore/engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,7 @@ pub trait Engine: Sync + Send {
/// Attempt to get a handle to a built-in contract.
/// Only returns references to activated built-ins.
fn builtin(&self, a: &Address, block_number: BlockNumber) -> Option<&Builtin> {
self.machine().builtin(a).and_then(|b| {
if b.is_active(block_number) {
Some(b)
} else {
None
}
})
self.machine().builtin(a, block_number)
}

/// Some intrinsic operation parameters; by default they take their value from the `spec()`'s `engine_params`.
Expand Down
62 changes: 17 additions & 45 deletions ethcore/machine/src/executive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,23 +237,20 @@ pub struct CallCreateExecutive<'a> {

impl<'a> CallCreateExecutive<'a> {
/// Create a new call executive using raw data.
pub fn new_call_raw(
params: ActionParams,
info: &'a EnvInfo,
machine: &'a Machine,
schedule: &'a Schedule,
factory: &'a VmFactory,
depth: usize,
stack_depth: usize,
parent_static_flag: bool
) -> Self {
pub fn new_call_raw(params: ActionParams, info: &'a EnvInfo, machine: &'a Machine, schedule: &'a Schedule, factory: &'a VmFactory, depth: usize, stack_depth: usize, parent_static_flag: bool) -> Self {
dvdplm marked this conversation as resolved.
Show resolved Hide resolved
trace!("Executive::call(params={:?}) self.env_info={:?}, parent_static={}", params, info, parent_static_flag);

let gas = params.gas;
let static_flag = parent_static_flag || params.call_type == CallType::StaticCall;

// if destination is builtin, try to execute it
let kind = if machine.builtin(&params.code_address).map_or(false, |b| b.is_active(info.number)) {
let kind = if let Some(builtin) = machine.builtin(&params.code_address, info.number) {
// Engines aren't supposed to return builtins until activation, but
// prefer to fail rather than silently break consensus.
if !builtin.is_active(info.number) {
panic!("Consensus failure: engine implementation prematurely enabled built-in at {}", params.code_address);
}

CallCreateExecutiveKind::CallBuiltin(params)
} else {
if params.code.is_some() {
Expand All @@ -270,16 +267,7 @@ impl<'a> CallCreateExecutive<'a> {
}

/// Create a new create executive using raw data.
pub fn new_create_raw(
params: ActionParams,
info: &'a EnvInfo,
machine: &'a Machine,
schedule: &'a Schedule,
factory: &'a VmFactory,
depth: usize,
stack_depth: usize,
static_flag: bool
) -> Self {
pub fn new_create_raw(params: ActionParams, info: &'a EnvInfo, machine: &'a Machine, schedule: &'a Schedule, factory: &'a VmFactory, depth: usize, stack_depth: usize, static_flag: bool) -> Self {
dvdplm marked this conversation as resolved.
Show resolved Hide resolved
trace!("Executive::create(params={:?}) self.env_info={:?}, static={}", params, info, static_flag);

let gas = params.gas;
Expand Down Expand Up @@ -393,13 +381,7 @@ impl<'a> CallCreateExecutive<'a> {
/// then expected to call `resume_call` or `resume_create` to continue the execution.
///
/// Current-level tracing is expected to be handled by caller.
pub fn exec<B: 'a + StateBackend, T: Tracer, V: VMTracer>(
mut self,
state: &mut State<B>,
substate: &mut Substate,
tracer: &mut T,
vm_tracer: &mut V
) -> ExecutiveTrapResult<'a, FinalizationResult> {
pub fn exec<B: 'a + StateBackend, T: Tracer, V: VMTracer>(mut self, state: &mut State<B>, substate: &mut Substate, tracer: &mut T, vm_tracer: &mut V) -> ExecutiveTrapResult<'a, FinalizationResult> {
match self.kind {
CallCreateExecutiveKind::Transfer(ref params) => {
assert!(!self.is_create);
Expand All @@ -421,18 +403,16 @@ impl<'a> CallCreateExecutive<'a> {
assert!(!self.is_create);

let mut inner = || {
let builtin = self.machine.builtin(&params.code_address).expect("Builtin is_some is checked when creating this kind in new_call_raw; qed");
let builtin = self.machine.builtin(&params.code_address, self.info.number).expect("Builtin is_some is checked when creating this kind in new_call_raw; qed");

Self::check_static_flag(&params, self.static_flag, self.is_create)?;
state.checkpoint();
Self::transfer_exec_balance(&params, self.schedule, state, substate)?;

let data = if let Some(ref d) = params.data {
d as &[u8]
} else {
&[]
};
let default = [];
let data = if let Some(ref d) = params.data { d as &[u8] } else { &default as &[u8] };

// NOTE(niklasad1): block number is used by `builtin alt_bn128 ops` to enable eip1108
let cost = builtin.cost(data, self.info.number);
if cost <= params.gas {
let mut builtin_out_buffer = Vec::new();
Expand Down Expand Up @@ -745,12 +725,8 @@ impl<'a> CallCreateExecutive<'a> {
}
},
Some((_, _, Err(TrapError::Call(subparams, resume)))) => {
let builtin_active = resume
.machine
.builtin(&subparams.address)
.map_or(false, |b| b.is_active(resume.info.number));
tracer.prepare_trace_call(&subparams, resume.depth + 1, builtin_active);
vm_tracer.prepare_subtrace(subparams.code.as_ref().map_or(&[], |d| &*d as &[u8]));
tracer.prepare_trace_call(&subparams, resume.depth + 1, resume.machine.builtin(&subparams.address, resume.info.number).is_some());
vm_tracer.prepare_subtrace(subparams.code.as_ref().map_or_else(|| &[] as &[u8], |d| &*d as &[u8]));

let sub_exec = CallCreateExecutive::new_call_raw(
subparams,
Expand Down Expand Up @@ -984,11 +960,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {
tracer: &mut T,
vm_tracer: &mut V
) -> vm::Result<FinalizationResult> where T: Tracer, V: VMTracer {
let builtin_active = self
.machine
.builtin(&params.address)
.map_or(false, |b| b.is_active(self.info.number));
tracer.prepare_trace_call(&params, self.depth, builtin_active);
tracer.prepare_trace_call(&params, self.depth, self.machine.builtin(&params.address, self.info.number).is_some());
vm_tracer.prepare_subtrace(params.code.as_ref().map_or_else(|| &[] as &[u8], |d| &*d as &[u8]));

let gas = params.gas;
Expand Down
15 changes: 6 additions & 9 deletions ethcore/machine/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ impl Machine {

/// Ethereum machine with ethash extensions.
// TODO: either unify or specify to mainnet specifically and include other specific-chain HFs?
pub fn with_ethash_extensions(
params: CommonParams,
builtins: BTreeMap<Address, Builtin>,
extensions: EthashExtensions
) -> Machine {
pub fn with_ethash_extensions(params: CommonParams, builtins: BTreeMap<Address, Builtin>, extensions: EthashExtensions) -> Machine {
let mut machine = Machine::regular(params, builtins);
machine.ethash_extensions = Some(extensions);
machine
Expand Down Expand Up @@ -299,12 +295,13 @@ impl Machine {
}

/// Attempt to get a handle to a built-in contract.
/// Doesn't check whether the contract is activated or not
/// For optimization i.e, don't call `Builtin::is_active` when not needed
/// Only returns references to activated built-ins.
// TODO: builtin contract routing - to do this properly, it will require removing the built-in configuration-reading logic
// from Spec into here and removing the Spec::builtins field.
pub fn builtin(&self, a: &Address) -> Option<&Builtin> {
self.builtins().get(a)
pub fn builtin(&self, a: &Address, block_number: BlockNumber) -> Option<&Builtin> {
self.builtins()
.get(a)
.and_then(|b| if b.is_active(block_number) { Some(b) } else { None })
}

/// Some intrinsic operation parameters; by default they take their value from the `spec()`'s `engine_params`.
Expand Down