Skip to content

Commit d58d203

Browse files
authored
Expose parent machine information in substate creation (#230)
1 parent c239c9c commit d58d203

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

src/standard/invoker/mod.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<'config, 'precompile, 'etable, S, G, H, Pre, Tr, F>
178178
impl<'config, 'precompile, 'etable, S, G, H, Pre, Tr, F> InvokerT<H, Tr>
179179
for Invoker<'config, 'precompile, 'etable, S, G, H, Pre, Tr, F>
180180
where
181-
S: MergeableRuntimeState,
181+
S: MergeableRuntimeState<GasedMachine<S, G>>,
182182
G: GasometerT<S, H> + TransactGasometer<'config, S>,
183183
H: RuntimeEnvironment + RuntimeBackend + TransactionalBackend,
184184
Pre: CodeResolver<S, G, H>,
@@ -506,12 +506,15 @@ where
506506
submeter.analyse_code(&code);
507507
}
508508

509-
let substate = machine.machine.state.substate(RuntimeState {
510-
context: call_trap_data.context.clone(),
511-
transaction_context,
512-
retbuf: Vec::new(),
513-
gas: U256::from(gas_limit),
514-
});
509+
let substate = machine.machine.state.substate(
510+
RuntimeState {
511+
context: call_trap_data.context.clone(),
512+
transaction_context,
513+
retbuf: Vec::new(),
514+
gas: U256::from(gas_limit),
515+
},
516+
&machine,
517+
);
515518

516519
Capture::Exit(routines::enter_call_substack(
517520
self.config,
@@ -533,16 +536,19 @@ where
533536

534537
let caller = create_trap_data.scheme.caller();
535538
let address = create_trap_data.scheme.address(handler);
536-
let substate = machine.machine.state.substate(RuntimeState {
537-
context: Context {
538-
address,
539-
caller,
540-
apparent_value: create_trap_data.value,
539+
let substate = machine.machine.state.substate(
540+
RuntimeState {
541+
context: Context {
542+
address,
543+
caller,
544+
apparent_value: create_trap_data.value,
545+
},
546+
transaction_context,
547+
retbuf: Vec::new(),
548+
gas: U256::from(gas_limit),
541549
},
542-
transaction_context,
543-
retbuf: Vec::new(),
544-
gas: U256::from(gas_limit),
545-
});
550+
&machine,
551+
);
546552

547553
Capture::Exit(
548554
routines::enter_create_substack(

src/standard/invoker/routines.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use super::{CallTrapData, CreateTrapData, Precompile, ResolvedCode, SubstackInvoke};
2-
use crate::standard::{Config, MergeableRuntimeState};
2+
use crate::standard::Config;
33
use crate::{
44
ExitError, ExitException, ExitResult, GasedMachine, Gasometer as GasometerT, InvokerControl,
5-
Machine, MergeStrategy, Opcode, RuntimeBackend, RuntimeEnvironment, StaticGasometer,
6-
TransactionalBackend, Transfer,
5+
Machine, MergeStrategy, Opcode, RuntimeBackend, RuntimeEnvironment, RuntimeState,
6+
StaticGasometer, TransactionalBackend, Transfer,
77
};
88
use alloc::rc::Rc;
99
use primitive_types::{H160, U256};
@@ -19,7 +19,7 @@ pub fn make_enter_call_machine<'config, 'precompile, S, G, H, P>(
1919
handler: &mut H,
2020
) -> Result<InvokerControl<GasedMachine<S, G>, (ExitResult, (S, G, Vec<u8>))>, ExitError>
2121
where
22-
S: MergeableRuntimeState,
22+
S: AsRef<RuntimeState>,
2323
G: GasometerT<S, H>,
2424
H: RuntimeEnvironment + RuntimeBackend + TransactionalBackend,
2525
P: Precompile<S, G, H>,
@@ -67,7 +67,7 @@ pub fn make_enter_create_machine<'config, S, G, H>(
6767
handler: &mut H,
6868
) -> Result<GasedMachine<S, G>, ExitError>
6969
where
70-
S: MergeableRuntimeState,
70+
S: AsRef<RuntimeState>,
7171
G: GasometerT<S, H>,
7272
H: RuntimeEnvironment + RuntimeBackend + TransactionalBackend,
7373
{
@@ -125,7 +125,7 @@ pub fn enter_call_substack<'config, 'precompile, S, G, H, P>(
125125
ExitError,
126126
>
127127
where
128-
S: MergeableRuntimeState,
128+
S: AsRef<RuntimeState>,
129129
G: GasometerT<S, H>,
130130
H: RuntimeEnvironment + RuntimeBackend + TransactionalBackend,
131131
P: Precompile<S, G, H>,
@@ -166,7 +166,7 @@ pub fn enter_create_substack<'config, S, G, H>(
166166
handler: &mut H,
167167
) -> Result<(SubstackInvoke, GasedMachine<S, G>), ExitError>
168168
where
169-
S: MergeableRuntimeState,
169+
S: AsRef<RuntimeState>,
170170
G: GasometerT<S, H>,
171171
H: RuntimeEnvironment + RuntimeBackend + TransactionalBackend,
172172
{
@@ -225,7 +225,6 @@ pub fn deploy_create_code<'config, S, G, H>(
225225
handler: &mut H,
226226
) -> Result<(), ExitError>
227227
where
228-
S: MergeableRuntimeState,
229228
G: GasometerT<S, H>,
230229
H: RuntimeEnvironment + RuntimeBackend + TransactionalBackend,
231230
{

src/standard/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ pub type Efn<H> = crate::Efn<crate::RuntimeState, H, crate::Opcode>;
1111
pub type Etable<H, F = Efn<H>> = crate::Etable<crate::RuntimeState, H, crate::Opcode, F>;
1212
pub type GasedMachine<G> = crate::GasedMachine<crate::RuntimeState, G>;
1313

14-
pub trait MergeableRuntimeState: AsRef<crate::RuntimeState> + AsMut<crate::RuntimeState> {
15-
fn substate(&self, runtime: crate::RuntimeState) -> Self;
14+
pub trait MergeableRuntimeState<M>:
15+
AsRef<crate::RuntimeState> + AsMut<crate::RuntimeState>
16+
{
17+
fn substate(&self, runtime: crate::RuntimeState, parent: &M) -> Self;
1618
fn merge(&mut self, substate: Self, strategy: crate::MergeStrategy);
1719
fn new_transact_call(runtime: crate::RuntimeState) -> Self;
1820
fn new_transact_create(runtime: crate::RuntimeState) -> Self;
1921
}
2022

21-
impl MergeableRuntimeState for crate::RuntimeState {
22-
fn substate(&self, runtime: crate::RuntimeState) -> Self {
23+
impl<M> MergeableRuntimeState<M> for crate::RuntimeState {
24+
fn substate(&self, runtime: crate::RuntimeState, _parent: &M) -> Self {
2325
runtime
2426
}
2527
fn merge(&mut self, _substate: Self, _strategy: crate::MergeStrategy) {}

0 commit comments

Comments
 (0)