Skip to content

[clarity-wasm] fix function context rollback #6277

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

Merged
Show file tree
Hide file tree
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
16 changes: 8 additions & 8 deletions Cargo.lock

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

27 changes: 5 additions & 22 deletions clarity/src/vm/clarity_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,28 +428,11 @@ pub fn initialize_contract(
results.push(placeholder_for_type(result_ty));
}

let top_level_result = top_level.call(&mut store, &[], results.as_mut_slice());
match top_level_result {
Ok(_) => {}
Err(e) => {
// Before propagating the error, attempt to roll back the function context.
// If the rollback fails, immediately return a rollback-specific error.
if store.data_mut().global_context.roll_back().is_err() {
return Err(Error::Wasm(WasmError::Expect(
"Expected entry to rollback".into(),
)));
}

// Rollback succeeded, so resolve and return the original runtime error.
return Err(error_mapping::resolve_error(
e,
instance,
&mut store,
&epoch,
&clarity_version,
));
}
}
top_level
.call(&mut store, &[], results.as_mut_slice())
.map_err(|e| {
error_mapping::resolve_error(e, instance, &mut store, &epoch, &clarity_version)
})?;

// Save the compiled Wasm module into the contract context
store.data_mut().contract_context_mut()?.set_wasm_module(
Expand Down
Loading