Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
40 changes: 2 additions & 38 deletions orchestrator/src/worker/event_handler/jobs/snos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::types::jobs::metadata::{JobMetadata, JobSpecificMetadata, SnosMetadat
use crate::types::jobs::status::JobVerificationStatus;
use crate::types::jobs::types::{JobStatus, JobType};
use crate::worker::event_handler::jobs::JobHandlerTrait;
use crate::worker::utils::fact_info::{build_on_chain_data, get_fact_info, get_fact_l2, get_program_output};
use crate::worker::utils::fact_info::{get_fact_info, get_fact_l2, get_program_output};
use async_trait::async_trait;
use bytes::Bytes;
use cairo_vm::vm::runners::cairo_pie::CairoPie;
Expand Down Expand Up @@ -180,11 +180,7 @@ impl JobHandlerTrait for SnosJobHandler {
}

debug!("Storing SNOS outputs");
if config.layer() == &Layer::L3 {
// Store the on-chain data path
self.store_l2(internal_id.clone(), config.storage(), &snos_metadata, cairo_pie, os_output, program_output)
.await?;
} else if config.layer() == &Layer::L2 {
if config.layer() == &Layer::L2 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this if condition can be removed now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense updated

// Store the Cairo Pie path
self.store(internal_id.clone(), config.storage(), &snos_metadata, cairo_pie, os_output, program_output)
.await?;
Expand Down Expand Up @@ -218,38 +214,6 @@ impl JobHandlerTrait for SnosJobHandler {
}

impl SnosJobHandler {
/// Stores the [CairoPie] and the [StarknetOsOutput] and [OnChainData] in the Data Storage.
/// The paths will be:
/// - [block_number]/cairo_pie.zip
/// - [block_number]/snos_output.json
/// - [block_number]/onchain_data.json
/// - [block_number]/program_output.json
async fn store_l2(
&self,
internal_id: String,
data_storage: &dyn StorageClient,
snos_metadata: &SnosMetadata,
cairo_pie: CairoPie,
snos_output: Vec<Felt>,
program_output: Vec<Felt252>,
) -> Result<(), SnosError> {
let on_chain_data = build_on_chain_data(&cairo_pie)
.map_err(|_e| SnosError::FactCalculationError(FactError::OnChainDataCompute))?;

self.store(internal_id.clone(), data_storage, snos_metadata, cairo_pie, snos_output, program_output).await?;
let on_chain_data_key = snos_metadata
.on_chain_data_path
.as_ref()
.ok_or_else(|| SnosError::Other(OtherError(eyre!("OnChain data path is not found"))))?;

let on_chain_data_vec = serde_json::to_vec(&on_chain_data).map_err(|e| {
SnosError::OnChainDataUnserializable { internal_id: internal_id.to_string(), message: e.to_string() }
})?;
data_storage.put_data(on_chain_data_vec.into(), on_chain_data_key).await.map_err(|e| {
SnosError::OnChainDataUnstorable { internal_id: internal_id.to_string(), message: e.to_string() }
})?;
Ok(())
}
/// Stores the [CairoPie] and the [StarknetOsOutput] in the Data Storage.
/// The paths will be:
/// - [block_number]/cairo_pie.zip
Expand Down
10 changes: 0 additions & 10 deletions orchestrator/src/worker/utils/fact_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,6 @@ pub fn get_fact_l2(cairo_pie: &CairoPie, program_hash: Option<Felt>) -> color_ey
Ok(B256::from_slice(&fact_hash.to_bytes_be()))
}

pub fn build_on_chain_data(cairo_pie: &CairoPie) -> color_eyre::Result<OnChainData> {
let program_output = get_program_output(cairo_pie, false)?;
let fact_topology = get_fact_topology(cairo_pie, program_output.len())?;
let fact_root = generate_merkle_root(&program_output, &fact_topology)?;

let da_child = fact_root.children.last().expect("fact_root is empty");

Ok(OnChainData { on_chain_data_hash: da_child.node_hash, on_chain_data_size: da_child.page_size })
}

pub fn get_fact_info(
cairo_pie: &CairoPie,
program_hash: Option<Felt>,
Expand Down
Loading