From bd27eca07bde10838d782ef8562914484c5b3652 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 3 Dec 2019 21:06:42 +0100 Subject: [PATCH] Keep runtime alive for multiple executions --- src/main.rs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1526a7a..784b23e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -108,25 +108,31 @@ struct Runtime<'a> { } impl<'a> Runtime<'a> { - fn new( - code: &'a [u8], - libraries: &'a Vec, - pre_state: &'a Bytes32, - block_data: &'a ShardBlockBody, - ) -> Runtime<'a> { + fn new(code: &'a [u8], libraries: &'a Vec) -> 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), ScoutError> { + fn execute( + &mut self, + pre_state: &'a Bytes32, + block_data: &'a ShardBlockBody, + ) -> Result<(Bytes32, Vec), 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 @@ -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(