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

feat(wasm): use only one Engine per global context #5447

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
4 changes: 2 additions & 2 deletions clarity/src/vm/clarity_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ pub fn initialize_contract(
let mut call_stack = CallStack::new();
let epoch = global_context.epoch_id;
let clarity_version = *contract_context.get_clarity_version();
let engine = global_context.engine.clone();
let init_context = ClarityWasmContext::new_init(
global_context,
contract_context,
Expand All @@ -408,7 +409,6 @@ pub fn initialize_contract(
sponsor.clone(),
Some(contract_analysis),
);
let engine = Engine::default();
let module = init_context
.contract_context()
.with_wasm_module(|wasm_module| {
Expand Down Expand Up @@ -485,6 +485,7 @@ pub fn call_function<'a>(
) -> Result<Value, Error> {
let epoch = global_context.epoch_id;
let clarity_version = *contract_context.get_clarity_version();
let engine = global_context.engine.clone();
let context = ClarityWasmContext::new_run(
global_context,
contract_context,
Expand All @@ -499,7 +500,6 @@ pub fn call_function<'a>(
.contract_context()
.lookup_function(function_name)
.ok_or(CheckErrors::UndefinedFunction(function_name.to_string()))?;
let engine = Engine::default();
let module = context
.contract_context()
.with_wasm_module(|wasm_module| unsafe {
Expand Down
7 changes: 6 additions & 1 deletion clarity/src/vm/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ use serde_json::json;
use stacks_common::consts::CHAIN_ID_TESTNET;
use stacks_common::types::chainstate::StacksBlockId;
use stacks_common::types::StacksEpochId;
use wasmtime::{Engine, Linker};

use super::analysis::{self, ContractAnalysis};
#[cfg(feature = "clarity-wasm")]
use super::clarity_wasm::call_function;
use super::clarity_wasm::{call_function, ClarityWasmContext};
use super::EvalHook;
use crate::vm::ast::{ASTRules, ContractAST};
use crate::vm::callables::{DefinedFunction, FunctionIdentifier};
Expand Down Expand Up @@ -206,6 +207,7 @@ pub struct GlobalContext<'a> {
/// This is the chain ID of the transaction
pub chain_id: u32,
pub eval_hooks: Option<Vec<&'a mut dyn EvalHook>>,
pub engine: Engine,
}

#[derive(Serialize, Deserialize, Clone)]
Expand Down Expand Up @@ -1653,6 +1655,8 @@ impl<'a> GlobalContext<'a> {
cost_track: LimitedCostTracker,
epoch_id: StacksEpochId,
) -> GlobalContext {
let engine = Engine::default();

GlobalContext {
database,
cost_track,
Expand All @@ -1663,6 +1667,7 @@ impl<'a> GlobalContext<'a> {
epoch_id,
chain_id,
eval_hooks: None,
engine,
}
}

Expand Down
Loading