Skip to content

Commit

Permalink
update runtime config ref: rust-ethereum/evm#161
Browse files Browse the repository at this point in the history
  • Loading branch information
zjb0807 committed Jan 17, 2024
1 parent 25f55c1 commit 5a41d40
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 24 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions modules/evm-utility/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ sha3 = { workspace = true }

sp-std = { workspace = true }

evm = { git = "https://github.com/rust-blockchain/evm", rev = "b436a7f4b34a1bc63857938f09a32ecd397537c9", default-features = false, features = ["with-codec"] }
evm-gasometer = { git = "https://github.com/rust-blockchain/evm", rev = "b436a7f4b34a1bc63857938f09a32ecd397537c9", default-features = false }
evm-runtime = { git = "https://github.com/rust-blockchain/evm", rev = "b436a7f4b34a1bc63857938f09a32ecd397537c9", default-features = false }
evm = { git = "https://github.com/rust-blockchain/evm", rev = "e7138f7234b117d29d4e653da4967d76e51c5eaf", default-features = false, features = ["with-codec"] }
evm-gasometer = { git = "https://github.com/rust-blockchain/evm", rev = "e7138f7234b117d29d4e653da4967d76e51c5eaf", default-features = false }
evm-runtime = { git = "https://github.com/rust-blockchain/evm", rev = "e7138f7234b117d29d4e653da4967d76e51c5eaf", default-features = false }
#evm = { version = "0.41.1", default-features = false, features = ["with-codec"] }
#evm-gasometer = { version = "0.41.0", default-features = false }
#evm-runtime = { version = "0.41.0", default-features = false }
Expand Down
9 changes: 7 additions & 2 deletions modules/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,13 @@ pub mod module {
let state = SubstrateStackState::<T>::new(&vicinity, metadata);
let mut executor = StackExecutor::new_with_precompiles(state, T::config(), &());

let mut runtime =
evm::Runtime::new(Rc::new(account.code.clone()), Rc::new(Vec::new()), context, T::config());
let mut runtime = evm::Runtime::new(
Rc::new(account.code.clone()),
Rc::new(Vec::new()),
context,
T::config().stack_limit,
T::config().memory_limit,
);
let reason = executor.execute(&mut runtime);

assert!(
Expand Down
35 changes: 22 additions & 13 deletions modules/evm/src/runner/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> StackExecu
}

/// Execute the runtime until it returns.
pub fn execute(&mut self, runtime: &mut Runtime<'config>) -> ExitReason {
pub fn execute(&mut self, runtime: &mut Runtime) -> ExitReason {
let mut call_stack = Vec::with_capacity(DEFAULT_CALL_STACK_CAPACITY);
call_stack.push(TaggedRuntime {
kind: RuntimeKind::Execute,
Expand All @@ -419,10 +419,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> StackExecu
}

/// Execute using Runtimes on the call_stack until it returns.
fn execute_with_call_stack<'borrow>(
&mut self,
call_stack: &mut Vec<TaggedRuntime<'config, 'borrow>>,
) -> (ExitReason, Option<H160>, Vec<u8>) {
fn execute_with_call_stack(&mut self, call_stack: &mut Vec<TaggedRuntime>) -> (ExitReason, Option<H160>, Vec<u8>) {
// This `interrupt_runtime` is used to pass the runtime obtained from the
// `Capture::Trap` branch in the match below back to the top of the call stack.
// The reason we can't simply `push` the runtime directly onto the stack in the
Expand Down Expand Up @@ -831,7 +828,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> StackExecu
init_code: Vec<u8>,
target_gas: Option<u64>,
take_l64: bool,
) -> Capture<(ExitReason, Option<H160>, Vec<u8>), StackExecutorCreateInterrupt<'config>> {
) -> Capture<(ExitReason, Option<H160>, Vec<u8>), StackExecutorCreateInterrupt<'static>> {
macro_rules! try_or_fail {
( $e:expr ) => {
match $e {
Expand Down Expand Up @@ -937,7 +934,13 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> StackExecu
self.state.inc_nonce(address);
}

let runtime = Runtime::new(Rc::new(init_code), Rc::new(Vec::new()), context, self.config);
let runtime = Runtime::new(
Rc::new(init_code),
Rc::new(Vec::new()),
context,
self.config.stack_limit,
self.config.memory_limit,
);

Capture::Trap(StackExecutorCreateInterrupt(TaggedRuntime {
kind: RuntimeKind::Create(address),
Expand All @@ -956,7 +959,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> StackExecu
take_l64: bool,
take_stipend: bool,
context: Context,
) -> Capture<(ExitReason, Vec<u8>), StackExecutorCallInterrupt<'config>> {
) -> Capture<(ExitReason, Vec<u8>), StackExecutorCallInterrupt<'static>> {
macro_rules! try_or_fail {
( $e:expr ) => {
match $e {
Expand Down Expand Up @@ -1064,7 +1067,13 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> StackExecu
};
}

let runtime = Runtime::new(Rc::new(code), Rc::new(input), context, self.config);
let runtime = Runtime::new(
Rc::new(code),
Rc::new(input),
context,
self.config.stack_limit,
self.config.memory_limit,
);

Capture::Trap(StackExecutorCallInterrupt(TaggedRuntime {
kind: RuntimeKind::Call(code_address),
Expand Down Expand Up @@ -1162,15 +1171,15 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> StackExecu
}
}

pub struct StackExecutorCallInterrupt<'config>(TaggedRuntime<'config, 'config>);
pub struct StackExecutorCreateInterrupt<'config>(TaggedRuntime<'config, 'config>);
pub struct StackExecutorCallInterrupt<'borrow>(TaggedRuntime<'borrow>);
pub struct StackExecutorCreateInterrupt<'borrow>(TaggedRuntime<'borrow>);

impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> Handler
for StackExecutor<'config, 'precompiles, S, P>
{
type CreateInterrupt = StackExecutorCreateInterrupt<'config>;
type CreateInterrupt = StackExecutorCreateInterrupt<'static>;
type CreateFeedback = Infallible;
type CallInterrupt = StackExecutorCallInterrupt<'config>;
type CallInterrupt = StackExecutorCallInterrupt<'static>;
type CallFeedback = Infallible;

fn balance(&self, address: H160) -> U256 {
Expand Down
4 changes: 2 additions & 2 deletions modules/evm/src/runner/tagged_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
use module_evm_utility::evm::{maybe_borrowed::MaybeBorrowed, Runtime};
use sp_core::H160;

pub struct TaggedRuntime<'config, 'borrow> {
pub struct TaggedRuntime<'borrow> {
pub kind: RuntimeKind,
pub inner: MaybeBorrowed<'borrow, Runtime<'config>>,
pub inner: MaybeBorrowed<'borrow, Runtime>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down

0 comments on commit 5a41d40

Please sign in to comment.