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

Prover service trait, SHARP client, fact checker, Stone stubs #6

Merged
merged 4 commits into from
Jun 19, 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
Binary file removed .github/.DS_Store
Binary file not shown.
4,351 changes: 3,681 additions & 670 deletions Cargo.lock

Large diffs are not rendered by default.

74 changes: 53 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
resolver = "2"
members = [
"crates/orchestrator",
"crates/da_clients/da-client-interface",
"crates/da_clients/ethereum",
"crates/da-clients/da-client-interface",
"crates/da-clients/ethereum",
"crates/prover-services/prover-client-interface",
"crates/prover-services/gps-fact-checker",
"crates/prover-services/sharp-service",
"crates/utils",
"crates/settlement_clients/settlement-client-interface",
"crates/settlement-clients/settlement-client-interface",
"e2e-tests",
]

[workspace.package]
Expand All @@ -16,32 +20,60 @@ authors = ["Apoorv Sadana <@apoorvsadana>"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[workspace.dependencies]


num = { version = "0.4.1" }
ethereum-da-client = { path = "crates/da_clients/ethereum" }
async-trait = { version = "0.1.77" }
da-client-interface = { path = "crates/da_clients/da-client-interface" }
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "7373f6db761d5a19888e3a0c527e8a3ca31e7a1e" }
alloy-primitives = "0.7.4"
axum = { version = "0.7.4" }
axum-macros = { version = "0.4.1" }
color-eyre = { version = "0.6.2" }
dotenvy = { version = "0.15.7" }
futures = { version = "0.3.30" }
axum-macros = "0.4.1"
color-eyre = "0.6.2"
dotenvy = "0.15.7"
futures = "0.3.30"
mongodb = { version = "2.8.1" }
omniqueue = { version = "0.2.0" }
rstest = { version = "0.18.2" }
reqwest = { version = "0.11.24" }
rstest = "0.18.2"
serde = { version = "1.0.197" }
serde_json = { version = "1.0.114" }
starknet = { version = "0.9.0" }
thiserror = { version = "1.0.57" }
tokio = { version = "1.36.0" }
tracing = { version = "0.1.40" }
serde_json = "1.0.114"
starknet = "0.9.0"
tempfile = "3.8.1"
thiserror = "1.0.57"
tokio = { version = "1.37.0" }
tokio-stream = "0.1.15"
tokio-util = "0.7.11"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18" }
url = { version = "2.5.0" }
uuid = { version = "1.7.0" }
num-bigint = { version = "0.4.4" }
url = { version = "2.5.0", features = ["serde"] }
uuid = { version = "1.7.0", features = ["v4", "serde"] }
httpmock = { version = "0.7.0" }
utils = { path = "crates/utils" }
num-bigint = { version = "0.4.4" }
arc-swap = { version = "1.7.1" }
num-traits = "0.2"
lazy_static = "1.4.0"
stark_evm_adapter = "0.1.1"
hex = "0.4"
itertools = "0.13.0"
mockall = "0.12.1"
testcontainers = "0.18.0"

# Cairo VM
cairo-vm = { git = "https://github.com/lambdaclass/cairo-vm", features = [
"extensive_hints",
"cairo-1-hints",
] }

# Sharp (Starkware)
snos = { git = "https://github.com/keep-starknet-strange/snos" }

# Madara prover API
madara-prover-common = { git = "https://github.com/Moonsong-Labs/madara-prover-api", branch = "od/use-latest-cairo-vm" }
madara-prover-rpc-client = { git = "https://github.com/Moonsong-Labs/madara-prover-api", branch = "od/use-latest-cairo-vm" }

# Project
da-client-interface = { path = "crates/da-clients/da-client-interface" }
ethereum-da-client = { path = "crates/da-clients/ethereum" }
utils = { path = "crates/utils" }
prover-client-interface = { path = "crates/prover-services/prover-client-interface" }
gps-fact-checker = { path = "crates/prover-services/gps-fact-checker" }
sharp-service = { path = "crates/prover-services/sharp-service" }
orchestrator = { path = "crates/orchestrator" }
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ edition.workspace = true
async-trait = { workspace = true }
axum = { workspace = true }
color-eyre = { workspace = true }
mockall = "0.12.1"
mockall = { workspace = true }
starknet = { workspace = true }
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use async_trait::async_trait;
use color_eyre::Result;
use mockall::{automock, predicate::*};
use mockall::automock;
use mockall::predicate::*;

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum DaVerificationStatus {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
#![allow(missing_docs)]
#![allow(clippy::missing_docs_in_private_items)]
use std::env;
use std::path::Path;
use std::str::FromStr;

use alloy::consensus::{
BlobTransactionSidecar, SignableTransaction, TxEip4844, TxEip4844Variant, TxEip4844WithSidecar, TxEnvelope,
};
use alloy::eips::{eip2718::Encodable2718, eip2930::AccessList, eip4844::BYTES_PER_BLOB};
use alloy::eips::eip2718::Encodable2718;
use alloy::eips::eip2930::AccessList;
use alloy::eips::eip4844::BYTES_PER_BLOB;
use alloy::network::{Ethereum, TxSigner};
use alloy::primitives::{bytes, Address, FixedBytes, TxHash, U256, U64};
use alloy::providers::{Provider, ProviderBuilder, RootProvider};
use alloy::rpc::client::RpcClient;
use alloy::signers::wallet::LocalWallet;
use alloy::transports::http::Http;
use async_trait::async_trait;

use color_eyre::Result;
use mockall::{automock, predicate::*};
use reqwest::Client;
use std::str::FromStr;
use url::Url;

use c_kzg::{Blob, KzgCommitment, KzgProof, KzgSettings};
use color_eyre::Result;
use config::EthereumDaConfig;
use da_client_interface::{DaClient, DaVerificationStatus};
use dotenv::dotenv;
use std::{env, path::Path};
use mockall::automock;
use mockall::predicate::*;
use reqwest::Client;
use url::Url;
pub mod config;
pub struct EthereumDaClient {
#[allow(dead_code)]
Expand Down Expand Up @@ -143,10 +146,11 @@ async fn prepare_sidecar(

#[cfg(test)]
mod tests {
use super::*;
use std::fs::File;
use std::io::{self, BufRead};

use super::*;

#[tokio::test]
async fn test_kzg() {
let trusted_setup = KzgSettings::load_trusted_setup_file(Path::new("./trusted_setup.txt"))
Expand Down
4 changes: 4 additions & 0 deletions crates/orchestrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ async-std = "1.12.0"
async-trait = { workspace = true }
axum = { workspace = true, features = ["macros"] }
axum-macros = { workspace = true }
cairo-vm = { workspace = true }
color-eyre = { workspace = true }
da-client-interface = { workspace = true }
dotenvy = { workspace = true }
Expand All @@ -31,15 +32,18 @@ num = { workspace = true }
num-bigint = { workspace = true }
num-traits = { workspace = true }
omniqueue = { workspace = true, optional = true }
prover-client-interface = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
sharp-service = { workspace = true }
starknet = { workspace = true }
starknet-core = "0.9.0"
thiserror = { workspace = true }
tokio = { workspace = true, features = ["sync", "macros", "rt-multi-thread"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
url = { workspace = true }
utils = { workspace = true }
uuid = { workspace = true, features = ["v4", "serde"] }

[features]
Expand Down
46 changes: 35 additions & 11 deletions crates/orchestrator/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
use crate::database::mongodb::config::MongoDbConfig;
use crate::database::mongodb::MongoDb;
use crate::database::{Database, DatabaseConfig};
use crate::queue::sqs::SqsQueue;
use crate::queue::QueueProvider;
use crate::utils::env_utils::get_env_var_or_panic;
use std::sync::Arc;

use arc_swap::{ArcSwap, Guard};
use da_client_interface::DaClient;
use da_client_interface::DaConfig;
use da_client_interface::{DaClient, DaConfig};
use dotenvy::dotenv;
use ethereum_da_client::config::EthereumDaConfig;
use ethereum_da_client::EthereumDaClient;
use prover_client_interface::ProverClient;
use sharp_service::SharpProverService;
use starknet::providers::jsonrpc::HttpTransport;
use starknet::providers::{JsonRpcClient, Url};
use std::sync::Arc;
use tokio::sync::OnceCell;
use utils::env_utils::get_env_var_or_panic;
use utils::settings::default::DefaultSettingsProvider;
use utils::settings::SettingsProvider;

use crate::database::mongodb::config::MongoDbConfig;
use crate::database::mongodb::MongoDb;
use crate::database::{Database, DatabaseConfig};
use crate::queue::sqs::SqsQueue;
use crate::queue::QueueProvider;

/// The app config. It can be accessed from anywhere inside the service
/// by calling `config` function.
Expand All @@ -22,6 +27,8 @@ pub struct Config {
starknet_client: Arc<JsonRpcClient<HttpTransport>>,
/// The DA client to interact with the DA layer
da_client: Box<dyn DaClient>,
/// The service that produces proof and registers it onchain
prover_client: Box<dyn ProverClient>,
/// The database client
database: Box<dyn Database>,
/// The queue provider
Expand All @@ -43,18 +50,22 @@ pub async fn init_config() -> Config {
// init the queue
let queue = Box::new(SqsQueue {});

Config { starknet_client: Arc::new(provider), da_client: build_da_client(), database, queue }
let settings_provider = DefaultSettingsProvider {};
let prover = create_prover_service(&settings_provider);

Config { starknet_client: Arc::new(provider), da_client: build_da_client(), prover_client: prover, database, queue }
}

impl Config {
/// Create a new config
pub fn new(
starknet_client: Arc<JsonRpcClient<HttpTransport>>,
da_client: Box<dyn DaClient>,
prover_client: Box<dyn ProverClient>,
database: Box<dyn Database>,
queue: Box<dyn QueueProvider>,
) -> Self {
Self { starknet_client, da_client, database, queue }
Self { starknet_client, da_client, prover_client, database, queue }
}

/// Returns the starknet client
Expand All @@ -67,6 +78,11 @@ impl Config {
self.da_client.as_ref()
}

/// Returns the proving service
pub fn prover_client(&self) -> &dyn ProverClient {
self.prover_client.as_ref()
}

/// Returns the database client
pub fn database(&self) -> &dyn Database {
self.database.as_ref()
Expand Down Expand Up @@ -115,3 +131,11 @@ fn build_da_client() -> Box<dyn DaClient + Send + Sync> {
_ => panic!("Unsupported DA layer"),
}
}

/// Creates prover service based on the environment variable PROVER_SERVICE
fn create_prover_service(settings_provider: &impl SettingsProvider) -> Box<dyn ProverClient> {
match get_env_var_or_panic("PROVER_SERVICE").as_str() {
"sharp" => Box::new(SharpProverService::with_settings(settings_provider)),
_ => panic!("Unsupported prover service"),
}
}
8 changes: 5 additions & 3 deletions crates/orchestrator/src/controllers/jobs_controller.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::controllers::errors::AppError;
use crate::jobs::types::JobType;
use std::collections::HashMap;

use axum::extract::Json;
use serde::Deserialize;
use std::collections::HashMap;

use crate::controllers::errors::AppError;
use crate::jobs::types::JobType;

/// Client request to create a job
#[derive(Debug, Deserialize)]
Expand Down
6 changes: 4 additions & 2 deletions crates/orchestrator/src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::jobs::types::{JobItem, JobStatus, JobType};
use std::collections::HashMap;

use async_trait::async_trait;
use color_eyre::Result;
use mockall::automock;
use std::collections::HashMap;
use uuid::Uuid;

use crate::jobs::types::{JobItem, JobStatus, JobType};

/// MongoDB
pub mod mongodb;

Expand Down
3 changes: 2 additions & 1 deletion crates/orchestrator/src/database/mongodb/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use utils::env_utils::get_env_var_or_panic;
apoorvsadana marked this conversation as resolved.
Show resolved Hide resolved

use crate::database::DatabaseConfig;
use crate::utils::env_utils::get_env_var_or_panic;

pub struct MongoDbConfig {
pub url: String,
Expand Down
29 changes: 14 additions & 15 deletions crates/orchestrator/src/database/mongodb/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use crate::database::mongodb::config::MongoDbConfig;
use crate::database::Database;
use crate::jobs::types::{JobItem, JobStatus, JobType};
use std::collections::HashMap;

use async_trait::async_trait;
use color_eyre::eyre::eyre;
use color_eyre::Result;
use mongodb::bson::Document;
use mongodb::options::{FindOneOptions, UpdateOptions};
use mongodb::{
bson::doc,
options::{ClientOptions, ServerApi, ServerApiVersion},
Client, Collection,
};
use std::collections::HashMap;
use mongodb::bson::{doc, Document};
use mongodb::options::{ClientOptions, FindOneOptions, ServerApi, ServerApiVersion, UpdateOptions};
use mongodb::{Client, Collection};
use uuid::Uuid;

use crate::database::mongodb::config::MongoDbConfig;
use crate::database::Database;
use crate::jobs::types::{JobItem, JobStatus, JobType};

pub mod config;

pub struct MongoDb {
Expand All @@ -23,7 +21,8 @@ pub struct MongoDb {
impl MongoDb {
pub async fn new(config: MongoDbConfig) -> Self {
let mut client_options = ClientOptions::parse(config.url).await.expect("Failed to parse MongoDB Url");
// Set the server_api field of the client_options object to set the version of the Stable API on the client
// Set the server_api field of the client_options object to set the version of the Stable API on the
// client
let server_api = ServerApi::builder().version(ServerApiVersion::V1).build();
client_options.server_api = Some(server_api);
// Get a handle to the cluster
Expand All @@ -39,9 +38,9 @@ impl MongoDb {
self.client.database("orchestrator").collection("jobs")
}

/// Updates the job in the database optimistically. This means that the job is updated only if the
/// version of the job in the database is the same as the version of the job passed in. If the version
/// is different, the update fails.
/// Updates the job in the database optimistically. This means that the job is updated only if
/// the version of the job in the database is the same as the version of the job passed in.
/// If the version is different, the update fails.
async fn update_job_optimistically(&self, current_job: &JobItem, update: Document) -> Result<()> {
let filter = doc! {
"id": current_job.id,
Expand Down
1 change: 1 addition & 0 deletions crates/orchestrator/src/jobs/constants.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub const JOB_PROCESS_ATTEMPT_METADATA_KEY: &str = "process_attempt_no";
pub const JOB_VERIFICATION_ATTEMPT_METADATA_KEY: &str = "verification_attempt_no";
pub const JOB_METADATA_CAIRO_PIE_PATH_KEY: &str = "cairo_pie_path";
Loading
Loading