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

Add Mutex to avoid SIGSEGV #69

Merged
merged 3 commits into from
Oct 18, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: lambdaclass/cairo_native
ref: 4355357697e9ab57ab88ae3a4282aac61455619e
ref: 4ba9e1609163c0d760f2a716244729d3116cc5ee
path: cairo_native
- name: Build Cairo Native Runtime Library
shell: bash
Expand Down
72 changes: 36 additions & 36 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions rpc-state-reader/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{
collections::HashMap,
io::{self, Read},
path::PathBuf,
sync::{Arc, OnceLock, RwLock},
sync::{Arc, Mutex, OnceLock},
};

use cairo_lang_sierra::program::Program;
Expand All @@ -25,7 +25,7 @@ pub struct MiddleSierraContractClass {
pub entry_points_by_type: ContractEntryPoints,
}

static AOT_PROGRAM_CACHE: OnceLock<RwLock<HashMap<ClassHash, Arc<AotContractExecutor>>>> =
static AOT_PROGRAM_CACHE: OnceLock<Mutex<HashMap<ClassHash, Arc<AotContractExecutor>>>> =
OnceLock::new();

pub fn map_entry_points_by_type_legacy(
Expand Down Expand Up @@ -128,14 +128,14 @@ pub fn deserialize_transaction_json(
}

pub fn get_native_executor(program: Program, class_hash: ClassHash) -> Arc<AotContractExecutor> {
let cache_lock = AOT_PROGRAM_CACHE.get_or_init(|| RwLock::new(HashMap::new()));
let cache_lock = AOT_PROGRAM_CACHE.get_or_init(|| Mutex::new(HashMap::new()));
let mut cache = cache_lock.lock().unwrap();

let executor = cache_lock.read().unwrap().get(&class_hash).map(Arc::clone);
let executor = cache.get(&class_hash).map(Arc::clone);

match executor {
Some(executor) => executor,
None => {
let mut cache = cache_lock.write().unwrap();
let path = PathBuf::from(format!(
"compiled_programs/{}.{}",
class_hash.to_hex_string(),
Expand Down
Loading