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
eth_call returns output of contract creations #6420
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b03c348
eth_call returns output of contract creations
tomusdrw d4f70a3
Fix parameters order.
tomusdrw 322dbf2
Save outputs for light client as well.
tomusdrw 9867150
Merge branch 'eth-call-result' of github.com:paritytech/parity into e…
tomusdrw ab2e6b4
Merge branch 'master' into eth-call-result
tomusdrw 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,8 @@ pub struct TransactOptions<T, V> { | |
pub vm_tracer: V, | ||
/// Check transaction nonce before execution. | ||
pub check_nonce: bool, | ||
/// Records the output from init contract calls. | ||
pub output_from_init_contract: bool, | ||
} | ||
|
||
impl<T, V> TransactOptions<T, V> { | ||
|
@@ -83,6 +85,7 @@ impl<T, V> TransactOptions<T, V> { | |
tracer, | ||
vm_tracer, | ||
check_nonce: true, | ||
output_from_init_contract: false, | ||
} | ||
} | ||
|
||
|
@@ -91,6 +94,12 @@ impl<T, V> TransactOptions<T, V> { | |
self.check_nonce = false; | ||
self | ||
} | ||
|
||
/// Saves the output from contract creation. | ||
pub fn save_output_from_contract(mut self) -> Self { | ||
self.output_from_init_contract = true; | ||
self | ||
} | ||
} | ||
|
||
impl TransactOptions<trace::ExecutiveTracer, trace::ExecutiveVMTracer> { | ||
|
@@ -100,6 +109,7 @@ impl TransactOptions<trace::ExecutiveTracer, trace::ExecutiveVMTracer> { | |
tracer: trace::ExecutiveTracer::default(), | ||
vm_tracer: trace::ExecutiveVMTracer::toplevel(), | ||
check_nonce: true, | ||
output_from_init_contract: false, | ||
} | ||
} | ||
} | ||
|
@@ -111,6 +121,7 @@ impl TransactOptions<trace::ExecutiveTracer, trace::NoopVMTracer> { | |
tracer: trace::ExecutiveTracer::default(), | ||
vm_tracer: trace::NoopVMTracer, | ||
check_nonce: true, | ||
output_from_init_contract: false, | ||
} | ||
} | ||
} | ||
|
@@ -122,6 +133,7 @@ impl TransactOptions<trace::NoopTracer, trace::ExecutiveVMTracer> { | |
tracer: trace::NoopTracer, | ||
vm_tracer: trace::ExecutiveVMTracer::toplevel(), | ||
check_nonce: true, | ||
output_from_init_contract: false, | ||
} | ||
} | ||
} | ||
|
@@ -133,6 +145,7 @@ impl TransactOptions<trace::NoopTracer, trace::NoopVMTracer> { | |
tracer: trace::NoopTracer, | ||
vm_tracer: trace::NoopVMTracer, | ||
check_nonce: true, | ||
output_from_init_contract: false, | ||
} | ||
} | ||
} | ||
|
@@ -201,7 +214,7 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> { | |
pub fn transact<T, V>(&'a mut self, t: &SignedTransaction, options: TransactOptions<T, V>) | ||
-> Result<Executed, ExecutionError> where T: Tracer, V: VMTracer, | ||
{ | ||
self.transact_with_tracer(t, options.check_nonce, options.tracer, options.vm_tracer) | ||
self.transact_with_tracer(t, options.check_nonce, options.output_from_init_contract, options.tracer, options.vm_tracer) | ||
} | ||
|
||
/// Execute a transaction in a "virtual" context. | ||
|
@@ -226,6 +239,7 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> { | |
&'a mut self, | ||
t: &SignedTransaction, | ||
check_nonce: bool, | ||
output_from_create: bool, | ||
mut tracer: T, | ||
mut vm_tracer: V | ||
) -> Result<Executed, ExecutionError> where T: Tracer, V: VMTracer { | ||
|
@@ -294,7 +308,8 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> { | |
data: None, | ||
call_type: CallType::None, | ||
}; | ||
(self.create(params, &mut substate, &mut tracer, &mut vm_tracer), vec![]) | ||
let mut out = if output_from_create { Some(vec![]) } else { None }; | ||
(self.create(params, &mut substate, &mut tracer, &mut vm_tracer, &mut out), out.unwrap_or_else(Vec::new)) | ||
}, | ||
Action::Call(ref address) => { | ||
let params = ActionParams { | ||
|
@@ -489,6 +504,7 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> { | |
substate: &mut Substate, | ||
tracer: &mut T, | ||
vm_tracer: &mut V, | ||
output: &mut Option<Bytes>, | ||
) -> vm::Result<(U256, ReturnData)> where T: Tracer, V: VMTracer { | ||
|
||
let scheme = self.engine.create_address_scheme(self.info.number); | ||
|
@@ -528,7 +544,7 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> { | |
let mut subvmtracer = vm_tracer.prepare_subtrace(params.code.as_ref().expect("two ways into create (Externalities::create and Executive::transact_with_tracer); both place `Some(...)` `code` in `params`; qed")); | ||
|
||
let res = { | ||
self.exec_vm(params, &mut unconfirmed_substate, OutputPolicy::InitContract(trace_output.as_mut()), &mut subtracer, &mut subvmtracer) | ||
self.exec_vm(params, &mut unconfirmed_substate, OutputPolicy::InitContract(output.as_mut().or(trace_output.as_mut())), &mut subtracer, &mut subvmtracer) | ||
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. does this mean that whenever saving creation output, trace output won't be saved? the two settings aren't used together yet, but something to watch out for 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. No. Because |
||
}; | ||
|
||
vm_tracer.done_subtrace(subvmtracer); | ||
|
@@ -537,7 +553,7 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> { | |
Ok(ref res) => tracer.trace_create( | ||
trace_info, | ||
gas - res.gas_left, | ||
trace_output, | ||
trace_output.map(|data| output.as_ref().map(|out| out.to_vec()).unwrap_or(data)), | ||
created, | ||
subtracer.drain() | ||
), | ||
|
@@ -696,7 +712,7 @@ mod tests { | |
|
||
let (gas_left, _) = { | ||
let mut ex = Executive::new(&mut state, &info, &engine); | ||
ex.create(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
ex.create(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer, &mut None).unwrap() | ||
}; | ||
|
||
assert_eq!(gas_left, U256::from(79_975)); | ||
|
@@ -754,7 +770,7 @@ mod tests { | |
|
||
let (gas_left, _) = { | ||
let mut ex = Executive::new(&mut state, &info, &engine); | ||
ex.create(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
ex.create(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer, &mut None).unwrap() | ||
}; | ||
|
||
assert_eq!(gas_left, U256::from(62_976)); | ||
|
@@ -921,7 +937,7 @@ mod tests { | |
|
||
let (gas_left, _) = { | ||
let mut ex = Executive::new(&mut state, &info, &engine); | ||
ex.create(params.clone(), &mut substate, &mut tracer, &mut vm_tracer).unwrap() | ||
ex.create(params.clone(), &mut substate, &mut tracer, &mut vm_tracer, &mut None).unwrap() | ||
}; | ||
|
||
assert_eq!(gas_left, U256::from(96_776)); | ||
|
@@ -1006,7 +1022,7 @@ mod tests { | |
|
||
let (gas_left, _) = { | ||
let mut ex = Executive::new(&mut state, &info, &engine); | ||
ex.create(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer).unwrap() | ||
ex.create(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer, &mut None).unwrap() | ||
}; | ||
|
||
assert_eq!(gas_left, U256::from(62_976)); | ||
|
@@ -1057,7 +1073,7 @@ mod tests { | |
|
||
{ | ||
let mut ex = Executive::new(&mut state, &info, &engine); | ||
ex.create(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer).unwrap(); | ||
ex.create(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer, &mut None).unwrap(); | ||
} | ||
|
||
assert_eq!(substate.contracts_created.len(), 1); | ||
|
@@ -1330,7 +1346,7 @@ mod tests { | |
|
||
let result = { | ||
let mut ex = Executive::new(&mut state, &info, &engine); | ||
ex.create(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer) | ||
ex.create(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer, &mut None) | ||
}; | ||
|
||
match result { | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to keep the same prototype as for
call
? (out
betweensubstate
andtracer
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Fixed.