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

Keep runtime alive for multiple executions #42

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
28 changes: 17 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,31 @@ struct Runtime<'a> {
}

impl<'a> Runtime<'a> {
fn new(
code: &'a [u8],
libraries: &'a Vec<Library>,
pre_state: &'a Bytes32,
block_data: &'a ShardBlockBody,
) -> Runtime<'a> {
fn new(code: &'a [u8], libraries: &'a Vec<Library>) -> Runtime<'a> {
Runtime {
code: code,
libraries: libraries,
ticks_left: 10_000_000, // FIXME: make this configurable
memory: None,
pre_state: pre_state,
block_data: block_data,
pre_state: &Bytes32::default(),
block_data: &ShardBlockBody::default(),
post_state: Bytes32::default(),
deposits: vec![],
}
}

fn execute(&mut self) -> Result<(Bytes32, Vec<DepositBlob>), ScoutError> {
fn execute(
&mut self,
pre_state: &'a Bytes32,
block_data: &'a ShardBlockBody,
) -> Result<(Bytes32, Vec<DepositBlob>), ScoutError> {
// FIXME: this a reset basically
self.ticks_left = 10_000_000;
self.pre_state = pre_state;
self.block_data = block_data;
self.post_state = Bytes32::default();
self.deposits = vec![];

let module = Module::from_buffer(&self.code)?;
let mut imports = ImportsBuilder::new();
// TODO: remove this and rely on Eth2ImportResolver and DebugImportResolver
Expand Down Expand Up @@ -669,8 +675,8 @@ pub fn execute_code(
block_data
);

let mut runtime = Runtime::new(&code, &libraries, pre_state, block_data);
runtime.execute()
let mut runtime = Runtime::new(&code, &libraries);
runtime.execute(pre_state, block_data)
}

pub fn process_shard_block(
Expand Down