Skip to content

Commit

Permalink
feat : updated code for state update worker
Browse files Browse the repository at this point in the history
  • Loading branch information
ocdbytes committed Aug 27, 2024
1 parent 98a42d5 commit e48f135
Show file tree
Hide file tree
Showing 31 changed files with 7,599 additions and 2,345 deletions.
6 changes: 5 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ AWS_DEFAULT_REGION="localhost"
MADARA_RPC_URL="http://localhost:3000"
ETHEREUM_RPC_URL="http://localhost:3001"
ETHEREUM_MAINNET_RPC_URL="https://mainnet.infura.io/v3/bf9e41563a6a45e28eb60382d85ef3c9" # for forking during tests
MEMORY_PAGES_CONTRACT_ADDRESS="0x000000000000000000000000000000000001dead"
MEMORY_PAGES_CONTRACT_ADDRESS="0x47312450B3Ac8b5b8e247a6bB6d523e7605bDb60"
PRIVATE_KEY="0xdead"
# Private key of Test wallet provided by Anvil
ETHEREUM_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
Expand Down Expand Up @@ -44,3 +44,7 @@ SHARP_USER_CRT="LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUR4ekNDQXErZ0F3SUJBZ0lV
SHARP_USER_KEY="LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JSUV2UUlCQURBTkJna3Foa2lHOXcwQkFRRUZBQVNDQktjd2dnU2pBZ0VBQW9JQkFRRFJ5bVQzWTJQdkFJL0gKVkwxaTBNU011ZDVQanhuRE9UbW5tODBscWd4aXhTVHpiM1Z0cUdkUVNiQTZJWVpueEIvc25RSVFLdjZPL09QWApKMStrOWt2VjVwSjZiN0o4SUVLeFBZTW95WHNOU3dCdHhwclVpRGRXeUNhSXNtOEFBOHVKVHNDNUZ1ZDdWcDhhClVaT1ZGWDAwbHltazBEY2hzSSt3cFN4NUdxOG1HbU8vV1BjaHRFYnhRSGFFZDdOS01wR3VnQ2xocm1mRGJvTWUKZXVxUHRtV0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dOWDhvYmU0dDZjK25HRnhZMGZqamk0cGZnbU1kMWNJeGdsM3E3Nlp0ZkllRGR6alRLRXN1CjRFUTVadnEwMnJvTEZ0ZjEvL3dRVG0xNkNKdFpGWnhNZ1phYnNxc2JRc3M2dWdMUGtTTmdBWjI1L2VhcWhnQ20KTjFUV2FxL0xJMVBLSkxPK085NFlMa2FsNVpyOTJCOXk4Q0VKVUVuSTA1R1N1MmJUOFM2a0ZBMEpadEszTW9SbwpqRWZWV1lQVHR5TFR4amNvRndCcDlHaXZYSDdSdHBxMDlmSmFhU1pNekxmNGlyNHpBdXprbExBNWZvampPNXlKCllnYlVaQUU2aS81N1NFWjR3VmxTCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K"
SHARP_PROOF_LAYOUT="small"

# Test vars
# used when setting up the environment for e2e test
L2_BLOCK_NUMBER_FOR_TEST=671070
2 changes: 2 additions & 0 deletions Cargo.lock

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

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 @@ -106,7 +106,6 @@ impl DataStorage for AWSS3 {
Ok(())
}

#[cfg(test)]
async fn build_test_bucket(&self, bucket_name: &str) -> Result<()> {
self.client.create_bucket().bucket(bucket_name).send().await?;
Ok(())
Expand Down
1 change: 0 additions & 1 deletion crates/orchestrator/src/data_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use mockall::automock;
pub trait DataStorage: Send + Sync {
async fn get_data(&self, key: &str) -> Result<Bytes>;
async fn put_data(&self, data: Bytes, key: &str) -> Result<()>;
#[cfg(test)]
async fn build_test_bucket(&self, bucket_name: &str) -> Result<()>;
}

Expand Down
39 changes: 23 additions & 16 deletions crates/orchestrator/src/jobs/da_job/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::str::FromStr;
use async_trait::async_trait;
use color_eyre::eyre::WrapErr;
use lazy_static::lazy_static;
use majin_blob_types::state_diffs::DataJson;
use num_bigint::{BigUint, ToBigUint};
use num_traits::{Num, Zero};
use starknet::core::types::{BlockId, FieldElement, MaybePendingStateUpdate, StateUpdate, StorageEntry};
Expand Down Expand Up @@ -201,27 +202,25 @@ pub fn convert_to_biguint(elements: Vec<FieldElement>) -> Vec<BigUint> {
fn data_to_blobs(blob_size: u64, block_data: Vec<BigUint>) -> Result<Vec<Vec<u8>>, JobError> {
// Validate blob size
if blob_size < 32 {
Err(DaError::InsufficientBlobSize { blob_size })?
return Err(DaError::InsufficientBlobSize { blob_size })?;
}

let mut blobs: Vec<Vec<u8>> = Vec::new();

// Convert all FieldElements to bytes first
let mut bytes: Vec<u8> = block_data.iter().flat_map(|element| element.to_bytes_be().to_vec()).collect();
// Convert all BigUint to bytes more efficiently
let bytes: Vec<u8> = block_data.iter().flat_map(BigUint::to_bytes_be).collect();

// Process bytes in chunks of blob_size
while bytes.len() >= blob_size as usize {
let chunk = bytes.drain(..blob_size as usize).collect();
blobs.push(chunk);
}

// Handle any remaining bytes (not a complete blob)
if !bytes.is_empty() {
let remaining_bytes = bytes.len();
let mut last_blob = bytes;
last_blob.resize(blob_size as usize, 0); // Pad with zeros
blobs.push(last_blob);
log::debug!("Warning: Remaining {} bytes not forming a complete blob were padded", remaining_bytes);
let chunk_size = blob_size as usize;
let chunks = bytes.chunks(chunk_size);

for chunk in chunks {
let mut blob = chunk.to_vec();
if blob.len() < chunk_size {
blob.resize(chunk_size, 0);
log::debug!("Warning: Last chunk of {} bytes was padded to full blob size", chunk.len());
}
blobs.push(blob);
}

Ok(blobs)
Expand Down Expand Up @@ -270,6 +269,8 @@ pub async fn state_update_to_blob_data(
.await
.wrap_err("Failed to get nonce ".to_string())?;

log::info!("Address : {addr} | Nonce : {get_current_nonce_result}");

nonce = Some(get_current_nonce_result);
}
let da_word = da_word(class_flag.is_some(), nonce, writes.len() as u64);
Expand Down Expand Up @@ -373,7 +374,7 @@ pub mod test {
use crate::jobs::da_job::da_word;
use std::fs;
use std::fs::File;
use std::io::Read;
use std::io::{Read};
use std::sync::Arc;

use crate::config::config;
Expand Down Expand Up @@ -437,6 +438,12 @@ pub mod test {
"src/tests/jobs/da_job/test_data/test_blob/640641.txt",
"src/tests/jobs/da_job/test_data/nonces/640641.txt"
)]
#[case(
671070,
"src/tests/jobs/da_job/test_data/state_update/671070.txt",
"src/tests/jobs/da_job/test_data/test_blob/671070.txt",
"src/tests/jobs/da_job/test_data/nonces/671070.txt"
)]
#[tokio::test]
async fn test_state_update_to_blob_data(
#[case] block_no: u64,
Expand Down
6 changes: 6 additions & 0 deletions crates/orchestrator/src/jobs/state_update_job/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ impl Job for StateUpdateJob {
internal_id: String,
metadata: HashMap<String, String>,
) -> Result<JobItem, JobError> {
// Inserting the metadata (If it doesn't exist)
let mut metadata = metadata.clone();
if !metadata.contains_key(JOB_PROCESS_ATTEMPT_METADATA_KEY) {
metadata.insert(JOB_PROCESS_ATTEMPT_METADATA_KEY.to_string(), "0".to_string());
}

Ok(JobItem {
id: Uuid::new_v4(),
internal_id,
Expand Down
8 changes: 4 additions & 4 deletions crates/orchestrator/src/jobs/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use settlement_client_interface::SettlementVerificationStatus;
use uuid::Uuid;

/// An external id.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub enum ExternalId {
/// A string.
Expand Down Expand Up @@ -70,7 +70,7 @@ fn unwrap_external_id_failed(expected: &str, got: &ExternalId) -> color_eyre::ey
eyre!("wrong ExternalId type: expected {}, got {:?}", expected, got)
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub enum JobType {
/// Running SNOS for a block
SnosRun,
Expand All @@ -84,7 +84,7 @@ pub enum JobType {
StateTransition,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, PartialOrd, strum_macros::Display)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, PartialOrd, strum_macros::Display, Eq)]
pub enum JobStatus {
/// An acknowledgement that the job has been received by the
/// orchestrator and is waiting to be processed
Expand Down Expand Up @@ -115,7 +115,7 @@ pub enum JobStatus {
Failed,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct JobItem {
/// an uuid to identify a job
#[cfg_attr(feature = "with_mongodb", serde(with = "uuid_1_as_binary"))]
Expand Down
2 changes: 1 addition & 1 deletion crates/orchestrator/src/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub async fn create_sqs_queues() -> color_eyre::Result<()> {
for queue_url in queue_urls {
match sqs_client.delete_queue().queue_url(queue_url).send().await {
Ok(_) => log::debug!("Successfully deleted queue: {}", queue_url),
Err(e) => eprintln!("Error deleting queue {}: {:?}", queue_url, e),
Err(_e) => { },
}
}

Expand Down
Loading

0 comments on commit e48f135

Please sign in to comment.