Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose parent machine information in substate creation #230

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 22 additions & 16 deletions src/standard/invoker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl<'config, 'precompile, 'etable, S, G, H, Pre, Tr, F>
impl<'config, 'precompile, 'etable, S, G, H, Pre, Tr, F> InvokerT<H, Tr>
for Invoker<'config, 'precompile, 'etable, S, G, H, Pre, Tr, F>
where
S: MergeableRuntimeState,
S: MergeableRuntimeState<GasedMachine<S, G>>,
G: GasometerT<S, H> + TransactGasometer<'config, S>,
H: RuntimeEnvironment + RuntimeBackend + TransactionalBackend,
Pre: CodeResolver<S, G, H>,
Expand Down Expand Up @@ -506,12 +506,15 @@ where
submeter.analyse_code(&code);
}

let substate = machine.machine.state.substate(RuntimeState {
context: call_trap_data.context.clone(),
transaction_context,
retbuf: Vec::new(),
gas: U256::from(gas_limit),
});
let substate = machine.machine.state.substate(
RuntimeState {
context: call_trap_data.context.clone(),
transaction_context,
retbuf: Vec::new(),
gas: U256::from(gas_limit),
},
&machine,
);

Capture::Exit(routines::enter_call_substack(
self.config,
Expand All @@ -533,16 +536,19 @@ where

let caller = create_trap_data.scheme.caller();
let address = create_trap_data.scheme.address(handler);
let substate = machine.machine.state.substate(RuntimeState {
context: Context {
address,
caller,
apparent_value: create_trap_data.value,
let substate = machine.machine.state.substate(
RuntimeState {
context: Context {
address,
caller,
apparent_value: create_trap_data.value,
},
transaction_context,
retbuf: Vec::new(),
gas: U256::from(gas_limit),
},
transaction_context,
retbuf: Vec::new(),
gas: U256::from(gas_limit),
});
&machine,
);

Capture::Exit(
routines::enter_create_substack(
Expand Down
15 changes: 7 additions & 8 deletions src/standard/invoker/routines.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::{CallTrapData, CreateTrapData, Precompile, ResolvedCode, SubstackInvoke};
use crate::standard::{Config, MergeableRuntimeState};
use crate::standard::Config;
use crate::{
ExitError, ExitException, ExitResult, GasedMachine, Gasometer as GasometerT, InvokerControl,
Machine, MergeStrategy, Opcode, RuntimeBackend, RuntimeEnvironment, StaticGasometer,
TransactionalBackend, Transfer,
Machine, MergeStrategy, Opcode, RuntimeBackend, RuntimeEnvironment, RuntimeState,
StaticGasometer, TransactionalBackend, Transfer,
};
use alloc::rc::Rc;
use primitive_types::{H160, U256};
Expand All @@ -19,7 +19,7 @@ pub fn make_enter_call_machine<'config, 'precompile, S, G, H, P>(
handler: &mut H,
) -> Result<InvokerControl<GasedMachine<S, G>, (ExitResult, (S, G, Vec<u8>))>, ExitError>
where
S: MergeableRuntimeState,
S: AsRef<RuntimeState>,
G: GasometerT<S, H>,
H: RuntimeEnvironment + RuntimeBackend + TransactionalBackend,
P: Precompile<S, G, H>,
Expand Down Expand Up @@ -67,7 +67,7 @@ pub fn make_enter_create_machine<'config, S, G, H>(
handler: &mut H,
) -> Result<GasedMachine<S, G>, ExitError>
where
S: MergeableRuntimeState,
S: AsRef<RuntimeState>,
G: GasometerT<S, H>,
H: RuntimeEnvironment + RuntimeBackend + TransactionalBackend,
{
Expand Down Expand Up @@ -125,7 +125,7 @@ pub fn enter_call_substack<'config, 'precompile, S, G, H, P>(
ExitError,
>
where
S: MergeableRuntimeState,
S: AsRef<RuntimeState>,
G: GasometerT<S, H>,
H: RuntimeEnvironment + RuntimeBackend + TransactionalBackend,
P: Precompile<S, G, H>,
Expand Down Expand Up @@ -166,7 +166,7 @@ pub fn enter_create_substack<'config, S, G, H>(
handler: &mut H,
) -> Result<(SubstackInvoke, GasedMachine<S, G>), ExitError>
where
S: MergeableRuntimeState,
S: AsRef<RuntimeState>,
G: GasometerT<S, H>,
H: RuntimeEnvironment + RuntimeBackend + TransactionalBackend,
{
Expand Down Expand Up @@ -225,7 +225,6 @@ pub fn deploy_create_code<'config, S, G, H>(
handler: &mut H,
) -> Result<(), ExitError>
where
S: MergeableRuntimeState,
G: GasometerT<S, H>,
H: RuntimeEnvironment + RuntimeBackend + TransactionalBackend,
{
Expand Down
10 changes: 6 additions & 4 deletions src/standard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ pub type Efn<H> = crate::Efn<crate::RuntimeState, H, crate::Opcode>;
pub type Etable<H, F = Efn<H>> = crate::Etable<crate::RuntimeState, H, crate::Opcode, F>;
pub type GasedMachine<G> = crate::GasedMachine<crate::RuntimeState, G>;

pub trait MergeableRuntimeState: AsRef<crate::RuntimeState> + AsMut<crate::RuntimeState> {
fn substate(&self, runtime: crate::RuntimeState) -> Self;
pub trait MergeableRuntimeState<M>:
AsRef<crate::RuntimeState> + AsMut<crate::RuntimeState>
{
fn substate(&self, runtime: crate::RuntimeState, parent: &M) -> Self;
fn merge(&mut self, substate: Self, strategy: crate::MergeStrategy);
fn new_transact_call(runtime: crate::RuntimeState) -> Self;
fn new_transact_create(runtime: crate::RuntimeState) -> Self;
}

impl MergeableRuntimeState for crate::RuntimeState {
fn substate(&self, runtime: crate::RuntimeState) -> Self {
impl<M> MergeableRuntimeState<M> for crate::RuntimeState {
fn substate(&self, runtime: crate::RuntimeState, _parent: &M) -> Self {
runtime
}
fn merge(&mut self, _substate: Self, _strategy: crate::MergeStrategy) {}
Expand Down
Loading