changes in executive return
This commit is contained in:
parent
bbb25fb6ce
commit
22859a04b6
@ -47,13 +47,6 @@ impl Substate {
|
||||
pub fn logs(&self) -> &[LogEntry] {
|
||||
&self.logs
|
||||
}
|
||||
|
||||
/// Appends another substate to this substate.
|
||||
fn accrue(&mut self, s: Substate) {
|
||||
self.suicides.extend(s.suicides.into_iter());
|
||||
self.logs.extend(s.logs.into_iter());
|
||||
self.refunds_count = self.refunds_count + s.refunds_count;
|
||||
}
|
||||
}
|
||||
|
||||
/// Transaction execution result.
|
||||
@ -425,17 +418,17 @@ impl<'a> Ext for Externalities<'a> {
|
||||
self.state.code(address).unwrap_or(vec![])
|
||||
}
|
||||
|
||||
fn ret(&mut self, gas: u64, data: &[u8]) -> Option<u64> {
|
||||
fn ret(&mut self, gas: u64, data: &[u8]) -> Result<u64, EvmError> {
|
||||
match &mut self.output {
|
||||
&mut OutputPolicy::Return(ref mut slice) => unsafe {
|
||||
let len = cmp::min(slice.len(), data.len());
|
||||
ptr::copy(data.as_ptr(), slice.as_mut_ptr(), len);
|
||||
Some(gas)
|
||||
Ok(gas)
|
||||
},
|
||||
&mut OutputPolicy::InitContract => {
|
||||
let return_cost = data.len() as u64 * self.schedule.create_data_gas as u64;
|
||||
if return_cost > gas {
|
||||
return None;
|
||||
return Err(EvmError::OutOfGas);
|
||||
}
|
||||
let mut code = vec![];
|
||||
code.reserve(data.len());
|
||||
@ -445,7 +438,7 @@ impl<'a> Ext for Externalities<'a> {
|
||||
}
|
||||
let address = &self.params.address;
|
||||
self.state.init_code(address, code);
|
||||
Some(gas - return_cost)
|
||||
Ok(gas - return_cost)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ pub trait Ext {
|
||||
|
||||
/// Should be called when transaction calls `RETURN` opcode.
|
||||
/// Returns gas_left if cost of returning the data is not too high.
|
||||
fn ret(&mut self, gas: u64, data: &[u8]) -> Option<u64>;
|
||||
fn ret(&mut self, gas: u64, data: &[u8]) -> Result<u64, EvmError>;
|
||||
|
||||
/// Should be called when contract commits suicide.
|
||||
fn suicide(&mut self);
|
||||
|
@ -347,10 +347,7 @@ impl evm::Evm for JitEvm {
|
||||
|
||||
match res {
|
||||
evmjit::ReturnCode::Stop => Ok(U256::from(context.gas_left())),
|
||||
evmjit::ReturnCode::Return => match ext.ret(context.gas_left(), context.output_data()) {
|
||||
Some(gas_left) => Ok(U256::from(gas_left)),
|
||||
None => Err(evm::EvmError::OutOfGas)
|
||||
},
|
||||
evmjit::ReturnCode::Return => ext.ret(context.gas_left(), context.output_data()).map(|gas_left| U256::from(gas_left)),
|
||||
evmjit::ReturnCode::Suicide => {
|
||||
// what if there is a suicide and we run out of gas just after?
|
||||
ext.suicide();
|
||||
|
Loading…
Reference in New Issue
Block a user