Skip to content

Commit

Permalink
fix(ethexe): allocation failure on huge journal returned from runtime (
Browse files Browse the repository at this point in the history
  • Loading branch information
breathx authored Dec 12, 2024
1 parent 20ac111 commit 0e966fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 11 additions & 1 deletion ethexe/processor/src/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,17 @@ impl InstanceWrapper {
maybe_instrumented_code,
);

self.call("run", arg.encode())
// Peaces of resulting journal. Hack to avoid single allocation limit.
let ptr_lens: Vec<i64> = self.call("run", arg.encode())?;

let mut journal = Vec::new();

for ptr_len in ptr_lens {
let journal_chunk: Vec<JournalNote> = self.get_call_output(ptr_len)?;
journal.extend(journal_chunk);
}

Ok(journal)
}

fn call<D: Decode>(&mut self, name: &'static str, input: impl AsRef<[u8]>) -> Result<D> {
Expand Down
7 changes: 6 additions & 1 deletion ethexe/runtime/src/wasm/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,18 @@ fn _run(arg_ptr: i32, arg_len: i32) -> i64 {
let (program_id, original_code_id, state_root, maybe_instrumented_code) =
Decode::decode(&mut get_slice(arg_ptr, arg_len)).unwrap();

let res = run::run(
let journal = run::run(
program_id,
original_code_id,
state_root,
maybe_instrumented_code,
);

let chunks = journal.encoded_size() / 32 * 1024 * 1024 + 1; // never zero
let chunk_size = (journal.len() / chunks).max(1); // never zero

let res: Vec<_> = journal.chunks(chunk_size).map(return_val).collect();

return_val(res)
}

Expand Down

0 comments on commit 0e966fa

Please sign in to comment.