Skip to content

Commit

Permalink
feat(snos_job): Storing outputs to S3
Browse files Browse the repository at this point in the history
  • Loading branch information
akhercha committed Jul 22, 2024
1 parent 2f3b1d8 commit 708991d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions crates/orchestrator/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub const BLOB_DATA_FILE_NAME: &str = "blob_data.txt";
pub const SNOS_OUTPUT_FILE_NAME: &str = "snos_output.json";
pub const CAIRO_PIE_FILE_NAME: &str = "cairo_pie.json";
1 change: 0 additions & 1 deletion crates/orchestrator/src/data_storage/aws_s3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub struct AWSS3 {
impl AWSS3 {
/// Initializes a new AWS S3 client by passing the config
/// and returning it.
#[allow(dead_code)]
pub async fn new(config: AWSS3Config) -> Self {
// AWS cred building
let credentials = Credentials::new(
Expand Down
35 changes: 32 additions & 3 deletions crates/orchestrator/src/jobs/snos_job/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ use blockifier::block::{pre_process_block, BlockInfo, BlockNumberHashPair, GasPr
use blockifier::context::{ChainInfo, FeeTokenAddresses};
use blockifier::versioned_constants::VersionedConstants;
use cairo_vm::types::layout_name::LayoutName;
use cairo_vm::vm::runners::cairo_pie::CairoPie;
use cairo_vm::Felt252;
use color_eyre::eyre::eyre;
use color_eyre::Result;
use num::FromPrimitive;
use snos::execution::helper::ExecutionHelperWrapper;
use snos::io::input::StarknetOsInput;
use snos::io::output::StarknetOsOutput;
use snos::run_os;
use starknet_api::block::{BlockHash, BlockNumber, BlockTimestamp};
use starknet_api::hash::StarkFelt;
Expand All @@ -24,6 +26,7 @@ use utils::conversions::try_non_zero_u128_from_u128;
use utils::time::get_current_timestamp_in_secs;

use crate::config::Config;
use crate::constants::{CAIRO_PIE_FILE_NAME, SNOS_OUTPUT_FILE_NAME};
use crate::jobs::snos_job::dummy_state::DummyState;
use crate::jobs::types::{JobItem, JobStatus, JobType, JobVerificationStatus};
use crate::jobs::Job;
Expand Down Expand Up @@ -115,7 +118,7 @@ impl Job for SnosJob {
);

// 3. Import SNOS in Rust and execute it with the input data
let (_cairo_pie, _snos_output) = match run_os(
let (cairo_pie, snos_output) = match run_os(
// TODO: what is this path?
String::from("PATH/TO/THE/OS"),
// TODO: which layout should we choose?
Expand All @@ -129,8 +132,10 @@ impl Job for SnosJob {
};

// 3. Store the received PIE in DB
// TODO: Store the PIE & the SnosOutput once S3 is implemented
todo!()
self.store_into_cloud_storage(config, &block_number, cairo_pie, snos_output).await?;

// TODO: which internal id do we want?
Ok("some_create_id?".into())
}

async fn verify_job(&self, _config: &Config, _job: &mut JobItem) -> Result<JobVerificationStatus> {
Expand Down Expand Up @@ -213,4 +218,28 @@ impl SnosJob {

Ok((try_non_zero_u128_from_u128(eth_gas_price)?, try_non_zero_u128_from_u128(avg_blob_base_fee)?))
}

/// Stores the [CairoPie] and the [StarknetOsOutput] in our Cloud storage.
/// The path will be:
/// - [block_number]/cairo_pie.json
/// - [block_number]/snos_output.json
async fn store_into_cloud_storage(
&self,
config: &Config,
block_number: &BlockNumber,
cairo_pie: CairoPie,
snos_output: StarknetOsOutput,
) -> Result<()> {
let data_storage = config.storage();

let cairo_pie_key = format!("{block_number}/{CAIRO_PIE_FILE_NAME}");
let cairo_pie_json = serde_json::to_vec(&cairo_pie)?;
data_storage.put_data(cairo_pie_json.into(), &cairo_pie_key).await?;

let snos_output_key = format!("{block_number}/{SNOS_OUTPUT_FILE_NAME}");
let snos_output_json = serde_json::to_vec(&snos_output)?;
data_storage.put_data(snos_output_json.into(), &snos_output_key).await?;

Ok(())
}
}

0 comments on commit 708991d

Please sign in to comment.