This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Remove pass-by-reference return data value from executive #9211
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5bea8c5
Remove pass-by-reference return data value from executive
sorpaas 4c80086
Fix tests
sorpaas d0d6ba7
Fix a missing test output
sorpaas 0def206
typo: wasm_activation_test
sorpaas baa99b2
Tracing change in output
sorpaas 22fee50
json_tests: fix compile
sorpaas 95335d5
typo: 0..32 -> ..32 to keep it consistent with other occurance
sorpaas f235b9e
Merge branch 'master' of https://github.com/paritytech/parity into sp…
sorpaas e7e329c
Merge branch 'sp-return-data' of https://github.com/paritytech/parity…
sorpaas 35abda7
Fix tests
sorpaas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,7 +202,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { | |
&'any mut self, | ||
origin_info: OriginInfo, | ||
substate: &'any mut Substate, | ||
output: OutputPolicy<'any, 'any>, | ||
output: OutputPolicy, | ||
tracer: &'any mut T, | ||
vm_tracer: &'any mut V, | ||
static_call: bool, | ||
|
@@ -310,8 +310,12 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { | |
call_type: CallType::None, | ||
params_type: vm::ParamsType::Embedded, | ||
}; | ||
let mut out = if output_from_create { Some(vec![]) } else { None }; | ||
(self.create(params, &mut substate, &mut out, &mut tracer, &mut vm_tracer), out.unwrap_or_else(Vec::new)) | ||
let res = self.create(params, &mut substate, &mut tracer, &mut vm_tracer); | ||
let out = match &res { | ||
Ok(res) if output_from_create => res.return_data.to_vec(), | ||
_ => Vec::new(), | ||
}; | ||
(res, out) | ||
}, | ||
Action::Call(ref address) => { | ||
let params = ActionParams { | ||
|
@@ -328,8 +332,12 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { | |
call_type: CallType::Call, | ||
params_type: vm::ParamsType::Separate, | ||
}; | ||
let mut out = vec![]; | ||
(self.call(params, &mut substate, BytesRef::Flexible(&mut out), &mut tracer, &mut vm_tracer), out) | ||
let res = self.call(params, &mut substate, &mut tracer, &mut vm_tracer); | ||
let out = match &res { | ||
Ok(res) => res.return_data.to_vec(), | ||
_ => Vec::new(), | ||
}; | ||
(res, out) | ||
} | ||
}; | ||
|
||
|
@@ -381,7 +389,6 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { | |
&mut self, | ||
params: ActionParams, | ||
substate: &mut Substate, | ||
mut output: BytesRef, | ||
tracer: &mut T, | ||
vm_tracer: &mut V | ||
) -> vm::Result<FinalizationResult> where T: Tracer, V: VMTracer { | ||
|
@@ -431,7 +438,6 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { | |
Err(evm_err) | ||
} else { | ||
self.state.discard_checkpoint(); | ||
output.write(0, &builtin_out_buffer); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -1 copy 👍 |
||
|
||
// Trace only top level calls and calls with balance transfer to builtins. The reason why we don't | ||
// trace all internal calls to builtin contracts is that memcpy (IDENTITY) is a heavily used | ||
|
@@ -443,7 +449,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { | |
if self.depth == 0 || is_transferred { | ||
let mut trace_output = tracer.prepare_trace_output(); | ||
if let Some(out) = trace_output.as_mut() { | ||
*out = output.to_owned(); | ||
*out = builtin_out_buffer.clone(); | ||
} | ||
|
||
tracer.trace_call( | ||
|
@@ -484,7 +490,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { | |
let mut subvmtracer = vm_tracer.prepare_subtrace(params.code.as_ref().expect("scope is conditional on params.code.is_some(); qed")); | ||
|
||
let res = { | ||
self.exec_vm(params, &mut unconfirmed_substate, OutputPolicy::Return(output, trace_output.as_mut()), &mut subtracer, &mut subvmtracer) | ||
self.exec_vm(params, &mut unconfirmed_substate, OutputPolicy::Return, &mut subtracer, &mut subvmtracer) | ||
}; | ||
|
||
vm_tracer.done_subtrace(subvmtracer); | ||
|
@@ -493,12 +499,15 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { | |
|
||
let traces = subtracer.drain(); | ||
match res { | ||
Ok(ref res) if res.apply_state => tracer.trace_call( | ||
trace_info, | ||
gas - res.gas_left, | ||
trace_output, | ||
traces | ||
), | ||
Ok(ref res) if res.apply_state => { | ||
trace_output.as_mut().map(|d| *d = res.return_data.to_vec()); | ||
tracer.trace_call( | ||
trace_info, | ||
gas - res.gas_left, | ||
trace_output, | ||
traces | ||
); | ||
}, | ||
Ok(_) => tracer.trace_failed_call(trace_info, traces, vm::Error::Reverted.into()), | ||
Err(ref e) => tracer.trace_failed_call(trace_info, traces, e.into()), | ||
}; | ||
|
@@ -529,7 +538,6 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { | |
&mut self, | ||
params: ActionParams, | ||
substate: &mut Substate, | ||
output: &mut Option<Bytes>, | ||
tracer: &mut T, | ||
vm_tracer: &mut V, | ||
) -> vm::Result<FinalizationResult> where T: Tracer, V: VMTracer { | ||
|
@@ -578,21 +586,24 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { | |
let res = self.exec_vm( | ||
params, | ||
&mut unconfirmed_substate, | ||
OutputPolicy::InitContract(output.as_mut().or(trace_output.as_mut())), | ||
OutputPolicy::InitContract, | ||
&mut subtracer, | ||
&mut subvmtracer | ||
); | ||
|
||
vm_tracer.done_subtrace(subvmtracer); | ||
|
||
match res { | ||
Ok(ref res) if res.apply_state => tracer.trace_create( | ||
trace_info, | ||
gas - res.gas_left, | ||
trace_output.map(|data| output.as_ref().map(|out| out.to_vec()).unwrap_or(data)), | ||
created, | ||
subtracer.drain() | ||
), | ||
Ok(ref res) if res.apply_state => { | ||
trace_output.as_mut().map(|trace| *trace = res.return_data.to_vec()); | ||
tracer.trace_create( | ||
trace_info, | ||
gas - res.gas_left, | ||
trace_output, | ||
created, | ||
subtracer.drain() | ||
); | ||
} | ||
Ok(_) => tracer.trace_failed_create(trace_info, subtracer.drain(), vm::Error::Reverted.into()), | ||
Err(ref e) => tracer.trace_failed_create(trace_info, subtracer.drain(), e.into()) | ||
}; | ||
|
@@ -714,7 +725,6 @@ mod tests { | |
use ethkey::{Generator, Random}; | ||
use super::*; | ||
use ethereum_types::{H256, U256, U512, Address}; | ||
use bytes::BytesRef; | ||
use vm::{ActionParams, ActionValue, CallType, EnvInfo, CreateContractAddress}; | ||
use evm::{Factory, VMType}; | ||
use error::ExecutionError; | ||
|
@@ -765,7 +775,7 @@ mod tests { | |
|
||
let FinalizationResult { gas_left, .. } = { | ||
let mut ex = Executive::new(&mut state, &info, &machine, &schedule); | ||
ex.create(params, &mut substate, &mut None, &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
ex.create(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
}; | ||
|
||
assert_eq!(gas_left, U256::from(79_975)); | ||
|
@@ -823,7 +833,7 @@ mod tests { | |
|
||
let FinalizationResult { gas_left, .. } = { | ||
let mut ex = Executive::new(&mut state, &info, &machine, &schedule); | ||
ex.create(params, &mut substate, &mut None, &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
ex.create(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
}; | ||
|
||
assert_eq!(gas_left, U256::from(62_976)); | ||
|
@@ -867,8 +877,7 @@ mod tests { | |
let mut vm_tracer = ExecutiveVMTracer::toplevel(); | ||
|
||
let mut ex = Executive::new(&mut state, &info, &machine, &schedule); | ||
let output = BytesRef::Fixed(&mut[0u8;0]); | ||
ex.call(params, &mut substate, output, &mut tracer, &mut vm_tracer).unwrap(); | ||
ex.call(params, &mut substate, &mut tracer, &mut vm_tracer).unwrap(); | ||
|
||
assert_eq!(tracer.drain(), vec![FlatTrace { | ||
action: trace::Action::Call(trace::Call { | ||
|
@@ -895,7 +904,7 @@ mod tests { | |
call_type: CallType::Call | ||
}), result: trace::Res::Call(trace::CallResult { | ||
gas_used: 600.into(), | ||
output: vec![] | ||
output: vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 156, 17, 133, 165, 197, 233, 252, 84, 97, 40, 8, 151, 126, 232, 245, 72, 178, 37, 141, 49] | ||
}), | ||
subtraces: 0, | ||
trace_address: vec![0].into_iter().collect(), | ||
|
@@ -953,8 +962,7 @@ mod tests { | |
|
||
let FinalizationResult { gas_left, .. } = { | ||
let mut ex = Executive::new(&mut state, &info, &machine, &schedule); | ||
let output = BytesRef::Fixed(&mut[0u8;0]); | ||
ex.call(params, &mut substate, output, &mut tracer, &mut vm_tracer).unwrap() | ||
ex.call(params, &mut substate, &mut tracer, &mut vm_tracer).unwrap() | ||
}; | ||
|
||
assert_eq!(gas_left, U256::from(44_752)); | ||
|
@@ -1070,8 +1078,7 @@ mod tests { | |
|
||
let FinalizationResult { gas_left, .. } = { | ||
let mut ex = Executive::new(&mut state, &info, &machine, &schedule); | ||
let output = BytesRef::Fixed(&mut[0u8;0]); | ||
ex.call(params, &mut substate, output, &mut tracer, &mut vm_tracer).unwrap() | ||
ex.call(params, &mut substate, &mut tracer, &mut vm_tracer).unwrap() | ||
}; | ||
|
||
assert_eq!(gas_left, U256::from(62967)); | ||
|
@@ -1143,7 +1150,7 @@ mod tests { | |
|
||
let FinalizationResult { gas_left, .. } = { | ||
let mut ex = Executive::new(&mut state, &info, &machine, &schedule); | ||
ex.create(params.clone(), &mut substate, &mut None, &mut tracer, &mut vm_tracer).unwrap() | ||
ex.create(params.clone(), &mut substate, &mut tracer, &mut vm_tracer).unwrap() | ||
}; | ||
|
||
assert_eq!(gas_left, U256::from(96_776)); | ||
|
@@ -1229,7 +1236,7 @@ mod tests { | |
|
||
let FinalizationResult { gas_left, .. } = { | ||
let mut ex = Executive::new(&mut state, &info, &machine, &schedule); | ||
ex.create(params, &mut substate, &mut None, &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
ex.create(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
}; | ||
|
||
assert_eq!(gas_left, U256::from(62_976)); | ||
|
@@ -1281,7 +1288,7 @@ mod tests { | |
|
||
{ | ||
let mut ex = Executive::new(&mut state, &info, &machine, &schedule); | ||
ex.create(params, &mut substate, &mut None, &mut NoopTracer, &mut NoopVMTracer).unwrap(); | ||
ex.create(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer).unwrap(); | ||
} | ||
|
||
assert_eq!(substate.contracts_created.len(), 1); | ||
|
@@ -1342,7 +1349,7 @@ mod tests { | |
|
||
let FinalizationResult { gas_left, .. } = { | ||
let mut ex = Executive::new(&mut state, &info, &machine, &schedule); | ||
ex.call(params, &mut substate, BytesRef::Fixed(&mut []), &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
ex.call(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
}; | ||
|
||
assert_eq!(gas_left, U256::from(73_237)); | ||
|
@@ -1387,7 +1394,7 @@ mod tests { | |
|
||
let FinalizationResult { gas_left, .. } = { | ||
let mut ex = Executive::new(&mut state, &info, &machine, &schedule); | ||
ex.call(params, &mut substate, BytesRef::Fixed(&mut []), &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
ex.call(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
}; | ||
|
||
assert_eq!(gas_left, U256::from(59_870)); | ||
|
@@ -1561,7 +1568,7 @@ mod tests { | |
|
||
let result = { | ||
let mut ex = Executive::new(&mut state, &info, &machine, &schedule); | ||
ex.create(params, &mut substate, &mut None, &mut NoopTracer, &mut NoopVMTracer) | ||
ex.create(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer) | ||
}; | ||
|
||
match result { | ||
|
@@ -1594,10 +1601,11 @@ mod tests { | |
let mut substate = Substate::new(); | ||
|
||
let mut output = [0u8; 14]; | ||
let FinalizationResult { gas_left: result, .. } = { | ||
let FinalizationResult { gas_left: result, return_data, .. } = { | ||
let mut ex = Executive::new(&mut state, &info, &machine, &schedule); | ||
ex.call(params, &mut substate, BytesRef::Fixed(&mut output), &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
ex.call(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
}; | ||
(&mut output).copy_from_slice(&return_data[..(cmp::min(14, return_data.len()))]); | ||
|
||
assert_eq!(result, U256::from(1)); | ||
assert_eq!(output[..], returns[..]); | ||
|
@@ -1637,11 +1645,12 @@ mod tests { | |
let machine = ::ethereum::new_kovan_wasm_test_machine(); | ||
|
||
let mut output = [0u8; 20]; | ||
let FinalizationResult { gas_left: result, .. } = { | ||
let FinalizationResult { gas_left: result, return_data, .. } = { | ||
let schedule = machine.schedule(info.number); | ||
let mut ex = Executive::new(&mut state, &info, &machine, &schedule); | ||
ex.call(params.clone(), &mut Substate::new(), BytesRef::Fixed(&mut output), &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
ex.call(params.clone(), &mut Substate::new(), &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
}; | ||
(&mut output).copy_from_slice(&return_data[..(cmp::min(20, return_data.len()))]); | ||
|
||
assert_eq!(result, U256::from(18433)); | ||
// Transaction successfully returned sender | ||
|
@@ -1651,11 +1660,12 @@ mod tests { | |
info.number = 1; | ||
|
||
let mut output = [0u8; 20]; | ||
let FinalizationResult { gas_left: result, .. } = { | ||
let FinalizationResult { gas_left: result, return_data, .. } = { | ||
let schedule = machine.schedule(info.number); | ||
let mut ex = Executive::new(&mut state, &info, &machine, &schedule); | ||
ex.call(params, &mut Substate::new(), BytesRef::Fixed(&mut output), &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
ex.call(params, &mut Substate::new(), &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
}; | ||
(&mut output[..((cmp::min(20, return_data.len())))]).copy_from_slice(&return_data[..(cmp::min(20, return_data.len()))]); | ||
|
||
assert_eq!(result, U256::from(20025)); | ||
// Since transaction errored due to wasm was not activated, result is just empty | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as resolved.
Sorry, something went wrong.