Skip to content

Commit

Permalink
Merge pull request #159 from NethermindEth/feature/map-flushing
Browse files Browse the repository at this point in the history
Implement map purging
  • Loading branch information
stranger80 authored Oct 18, 2023
2 parents 39884bd + 2b42e8c commit 988f694
Show file tree
Hide file tree
Showing 14 changed files with 510 additions and 210 deletions.
4 changes: 3 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
[submodule "api/cairo_compilers/v2.1.1"]
path = api/cairo_compilers/v2.1.1
url = https://github.com/starkware-libs/cairo.git
branch = v2.1.1

[submodule "api/cairo_compilers/v2.2.0"]
path = api/cairo_compilers/v2.2.0
url = https://github.com/starkware-libs/cairo.git
url = https://github.com/starkware-libs/cairo.git
branch = v2.2.0
167 changes: 167 additions & 0 deletions api/Cargo.lock

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

2 changes: 2 additions & 0 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ crossbeam-queue = "0.3.8"
crossbeam-skiplist = "0.1.1"
fmt = "0.1.0"
yansi = "0.5.1"
thiserror = "1.0.49"
chrono = "0.4.31"
11 changes: 6 additions & 5 deletions api/src/handlers/cairo_version.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::handlers::process::{do_process_command, fetch_process_result};
use crate::handlers::types::{ApiCommand, ApiCommandResult};
use crate::types::{ApiError, Result};
use crate::utils::lib::DEFAULT_CAIRO_DIR;
use crate::worker::WorkerEngine;
use rocket::State;
Expand All @@ -11,7 +12,7 @@ use tracing::{error, info, instrument};
#[get("/cairo_version")]
pub async fn cairo_version() -> String {
info!("/cairo_version");
do_cairo_version().unwrap_or_else(|e| e)
do_cairo_version().unwrap_or_else(|e| format!("Failed to get cairo version: {:?}", e))
}

// Read the version from the cairo Cargo.toml file.
Expand All @@ -36,7 +37,7 @@ pub async fn get_cairo_version_result(process_id: String, engine: &State<WorkerE
///
/// ## Note
/// (default Cairo version will be used)
pub fn do_cairo_version() -> Result<String, String> {
pub fn do_cairo_version() -> Result<String> {
let mut version_caller = Command::new("cargo");
version_caller.current_dir(DEFAULT_CAIRO_DIR);
match String::from_utf8(
Expand All @@ -50,15 +51,15 @@ pub fn do_cairo_version() -> Result<String, String> {
.arg("--version")
.stdout(Stdio::piped())
.spawn()
.map_err(|e| format!("Failed to get cairo version: {:?}", e))?
.map_err(|e| ApiError::FailedToExecuteCommand(e))?
.wait_with_output()
.map_err(|e| format!("Failed to get cairo version: {:?}", e))?
.map_err(|e| ApiError::FailedToReadOutput(e))?
.stdout,
) {
Ok(version) => Ok(version),
Err(e) => {
error!("{:?}", e.to_string());
Err(e.to_string())
Err(ApiError::UTF8Error(e))
}
}
}
11 changes: 8 additions & 3 deletions api/src/handlers/cairo_versions.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::types::{ApiError, Result};
use crate::utils::lib::CAIRO_COMPILERS_DIR;
use rocket::tokio::fs::read_dir;
use std::path::Path;
Expand All @@ -6,14 +7,18 @@ use tracing::instrument;
#[instrument]
#[get("/cairo_versions")]
pub async fn cairo_versions() -> String {
do_cairo_versions().await.unwrap_or_else(|e| e)
do_cairo_versions()
.await
.unwrap_or_else(|e| format!("Failed to get cairo versions: {:?}", e))
}

/// Get cairo versions
pub async fn do_cairo_versions() -> Result<String, String> {
pub async fn do_cairo_versions() -> Result<String> {
let path = Path::new(CAIRO_COMPILERS_DIR);

let mut dir = read_dir(path).await.unwrap();
let mut dir = read_dir(path)
.await
.map_err(|e| ApiError::FailedToReadDir(e))?;
let mut result = vec![];

while let Ok(Some(entry)) = dir.next_entry().await {
Expand Down
Loading

0 comments on commit 988f694

Please sign in to comment.