Skip to content

Commit

Permalink
feat : added l3 appchain functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ocdbytes committed Dec 27, 2024
1 parent f79c7e1 commit c485251
Show file tree
Hide file tree
Showing 15 changed files with 339 additions and 21 deletions.
31 changes: 31 additions & 0 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"crates/orchestrator",
"crates/da-clients/da-client-interface",
"crates/da-clients/ethereum",
"crates/da-clients/starknet",
"crates/prover-clients/prover-client-interface",
"crates/prover-clients/gps-fact-checker",
"crates/prover-clients/sharp-service",
Expand Down Expand Up @@ -147,6 +148,7 @@ majin-blob-types = { git = "https://github.com/AbdelStark/majin-blob", branch =
# Project
da-client-interface = { path = "crates/da-clients/da-client-interface" }
ethereum-da-client = { path = "crates/da-clients/ethereum" }
starknet-da-client = { path = "crates/da-clients/starknet" }

settlement-client-interface = { path = "crates/settlement-clients/settlement-client-interface" }
ethereum-settlement-client = { path = "crates/settlement-clients/ethereum" }
Expand Down
49 changes: 49 additions & 0 deletions crates/da-clients/starknet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[package]
name = "starknet-da-client"
version.workspace = true
edition.workspace = true

[dependencies]
# TODO: update this to the workspace
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "68952c0", features = [
"consensus",
"providers",
"rpc-client",
"transport-http",
"network",
"eips",
"signers",
"signer-wallet",
] }
async-trait = { workspace = true }
c-kzg = { workspace = true }
color-eyre = { workspace = true }
da-client-interface = { workspace = true }
dotenvy.workspace = true
mockall = { workspace = true }
reqwest = { workspace = true }
rstest = { workspace = true }
serde = { workspace = true, features = ["derive"] }
starknet = { workspace = true }
tokio = { workspace = true }
url = { workspace = true }
utils = { workspace = true }

#Instrumentation
opentelemetry = { workspace = true, features = ["metrics", "logs"] }
opentelemetry-appender-tracing = { workspace = true, default-features = false }
opentelemetry-otlp = { workspace = true, features = [
"tonic",
"metrics",
"logs",
] }
opentelemetry-semantic-conventions = { workspace = true }
opentelemetry_sdk = { workspace = true, features = ["rt-tokio", "logs"] }
tracing = { workspace = true }
tracing-core = { workspace = true, default-features = false }
tracing-opentelemetry = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }


[dev-dependencies]
tokio-test = "*"
56 changes: 56 additions & 0 deletions crates/da-clients/starknet/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#![allow(missing_docs)]
#![allow(clippy::missing_docs_in_private_items)]

use std::str::FromStr;
use std::sync::Arc;

use async_trait::async_trait;
use color_eyre::Result;
use da_client_interface::{DaClient, DaVerificationStatus};
use mockall::automock;
use mockall::predicate::*;
use serde::{Deserialize, Serialize};
use starknet::providers::jsonrpc::HttpTransport;
use starknet::providers::JsonRpcClient;
use url::Url;

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct StarknetDaValidatedArgs {
pub starknet_da_rpc_url: Url,
}

pub struct StarknetDaClient {
#[allow(dead_code)]
provider: Arc<JsonRpcClient<HttpTransport>>,
}

impl StarknetDaClient {
pub async fn new_with_args(starknet_da_params: &StarknetDaValidatedArgs) -> Self {
let client = JsonRpcClient::new(HttpTransport::new(
Url::from_str(starknet_da_params.starknet_da_rpc_url.as_str()).expect("invalid url provided"),
));
Self { provider: Arc::new(client) }
}
}

#[automock]
#[async_trait]
impl DaClient for StarknetDaClient {
async fn publish_state_diff(&self, _state_diff: Vec<Vec<u8>>, _to: &[u8; 32]) -> Result<String> {
// Here in case of starknet we are not publishing the state diff because we are doing it all
// together in proving and update_state job. So we don't need to send anything here.
Ok("NA".to_string())
}

async fn verify_inclusion(&self, _external_id: &str) -> Result<DaVerificationStatus> {
Ok(DaVerificationStatus::Verified)
}

async fn max_blob_per_txn(&self) -> u64 {
6
}

async fn max_bytes_per_blob(&self) -> u64 {
131072
}
}
4 changes: 3 additions & 1 deletion crates/orchestrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ color-eyre = { workspace = true }
da-client-interface = { workspace = true }
dotenvy = { workspace = true }
ethereum-da-client = { workspace = true, optional = true }
starknet-da-client = { workspace = true, optional = true }
ethereum-settlement-client = { workspace = true }
futures = { workspace = true }
hex = { workspace = true }
Expand Down Expand Up @@ -94,8 +95,9 @@ tracing-opentelemetry = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }

[features]
default = ["ethereum", "with_mongodb", "with_sqs"]
default = ["ethereum", "with_mongodb", "with_sqs", "starknet"]
ethereum = ["ethereum-da-client"]
starknet = ["starknet-da-client"]
with_mongodb = ["mongodb"]
with_sqs = ["omniqueue"]
testing = []
Expand Down
3 changes: 3 additions & 0 deletions crates/orchestrator/src/cli/da/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use ethereum_da_client::EthereumDaValidatedArgs;
use starknet_da_client::StarknetDaValidatedArgs;

pub mod ethereum;
pub mod starknet;

#[derive(Debug, Clone)]
pub enum DaValidatedArgs {
Ethereum(EthereumDaValidatedArgs),
Starknet(StarknetDaValidatedArgs),
}
15 changes: 15 additions & 0 deletions crates/orchestrator/src/cli/da/starknet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use clap::Args;
use url::Url;

/// Parameters used to config Starknet.
#[derive(Debug, Clone, Args)]
#[group(requires_all = ["starknet_da_rpc_url"])]
pub struct StarknetDaCliArgs {
/// Use the Starknet DA layer.
#[arg(long)]
pub da_on_starknet: bool,

/// The RPC URL of the Ethereum node.
#[arg(env = "MADARA_ORCHESTRATOR_STARKNET_DA_RPC_URL", long)]
pub starknet_da_rpc_url: Option<Url>,
}
52 changes: 37 additions & 15 deletions crates/orchestrator/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub enum Commands {
),
group(
ArgGroup::new("da_layer")
.args(&["da_on_ethereum"])
.args(&["da_on_ethereum", "da_on_starknet"])
.required(true)
.multiple(false)
),
Expand Down Expand Up @@ -136,6 +136,9 @@ pub struct RunCmd {
#[clap(flatten)]
pub ethereum_da_args: da::ethereum::EthereumDaCliArgs,

#[clap(flatten)]
pub starknet_da_args: da::starknet::StarknetDaCliArgs,

// Prover
#[clap(flatten)]
pub sharp_args: prover::sharp::SharpCliArgs,
Expand Down Expand Up @@ -182,7 +185,7 @@ impl RunCmd {
}

pub fn validate_da_params(&self) -> Result<DaValidatedArgs, String> {
validate_params::validate_da_params(&self.ethereum_da_args)
validate_params::validate_da_params(&self.ethereum_da_args, &self.starknet_da_args)
}

pub fn validate_settlement_params(&self) -> Result<settlement::SettlementValidatedArgs, String> {
Expand Down Expand Up @@ -306,6 +309,7 @@ pub mod validate_params {
use ethereum_da_client::EthereumDaValidatedArgs;
use ethereum_settlement_client::EthereumSettlementValidatedArgs;
use sharp_service::SharpValidatedArgs;
use starknet_da_client::StarknetDaValidatedArgs;
use starknet_settlement_client::StarknetSettlementValidatedArgs;
use url::Url;

Expand Down Expand Up @@ -334,6 +338,7 @@ pub mod validate_params {
use super::storage::aws_s3::AWSS3CliArgs;
use super::storage::StorageValidatedArgs;
use crate::alerts::aws_sns::AWSSNSValidatedArgs;
use crate::cli::da::starknet::StarknetDaCliArgs;
use crate::cli::prover_layout::ProverLayoutCliArgs;
use crate::config::ServiceParams;
use crate::cron::event_bridge::AWSEventBridgeValidatedArgs;
Expand Down Expand Up @@ -451,16 +456,25 @@ pub mod validate_params {
}
}

pub(crate) fn validate_da_params(ethereum_da_args: &EthereumDaCliArgs) -> Result<DaValidatedArgs, String> {
if ethereum_da_args.da_on_ethereum {
Ok(DaValidatedArgs::Ethereum(EthereumDaValidatedArgs {
pub(crate) fn validate_da_params(
ethereum_da_args: &EthereumDaCliArgs,
starknet_da_args: &StarknetDaCliArgs,
) -> Result<DaValidatedArgs, String> {
match (ethereum_da_args.da_on_ethereum, starknet_da_args.da_on_starknet) {
(true, true) => Err("Cannot use both Ethereum and Starknet as DA Layer".to_string()),
(true, false) => Ok(DaValidatedArgs::Ethereum(EthereumDaValidatedArgs {
ethereum_da_rpc_url: ethereum_da_args
.ethereum_da_rpc_url
.clone()
.expect("Ethereum DA RPC URL is required"),
}))
} else {
Err("Only Ethereum is supported as of now".to_string())
})),
(false, true) => Ok(DaValidatedArgs::Starknet(StarknetDaValidatedArgs {
starknet_da_rpc_url: starknet_da_args
.starknet_da_rpc_url
.clone()
.expect("Starknet DA RPC URL is required"),
})),
(false, false) => Err("Settlement layer is required".to_string()),
}
}

Expand Down Expand Up @@ -615,7 +629,7 @@ pub mod validate_params {
}

pub(crate) fn validate_snos_params(snos_args: &SNOSCliArgs) -> Result<SNOSParams, String> {
Ok(SNOSParams { rpc_for_snos: snos_args.rpc_for_snos.clone() })
Ok(SNOSParams { rpc_for_snos: snos_args.rpc_for_snos.clone(), snos_full_output: snos_args.snos_full_output })
}

#[cfg(test)]
Expand All @@ -627,6 +641,7 @@ pub mod validate_params {
use crate::cli::alert::aws_sns::AWSSNSCliArgs;
use crate::cli::cron::event_bridge::AWSEventBridgeCliArgs;
use crate::cli::da::ethereum::EthereumDaCliArgs;
use crate::cli::da::starknet::StarknetDaCliArgs;
use crate::cli::database::mongodb::MongoDBCliArgs;
use crate::cli::instrumentation::InstrumentationCliArgs;
use crate::cli::prover::atlantic::AtlanticCliArgs;
Expand Down Expand Up @@ -756,15 +771,21 @@ pub mod validate_params {
}

#[rstest]
#[case(true)]
#[case(false)]
fn test_validate_da_params(#[case] is_ethereum: bool) {
#[case(true, false)]
#[case(false, true)]
#[case(false, false)]
#[case(true, true)]
fn test_validate_da_params(#[case] is_ethereum: bool, #[case] is_starknet: bool) {
let ethereum_da_args: EthereumDaCliArgs = EthereumDaCliArgs {
da_on_ethereum: is_ethereum,
ethereum_da_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()),
};
let da_params = validate_da_params(&ethereum_da_args);
if is_ethereum {
let starknet_da_args: StarknetDaCliArgs = StarknetDaCliArgs {
da_on_starknet: is_starknet,
starknet_da_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()),
};
let da_params = validate_da_params(&ethereum_da_args, &starknet_da_args);
if is_ethereum ^ is_starknet {
assert!(da_params.is_ok());
} else {
assert!(da_params.is_err());
Expand Down Expand Up @@ -879,7 +900,8 @@ pub mod validate_params {

#[rstest]
fn test_validate_snos_params() {
let snos_args: SNOSCliArgs = SNOSCliArgs { rpc_for_snos: Url::parse("http://localhost:8545").unwrap() };
let snos_args: SNOSCliArgs =
SNOSCliArgs { rpc_for_snos: Url::parse("http://localhost:8545").unwrap(), snos_full_output: true };
let snos_params = validate_snos_params(&snos_args);
assert!(snos_params.is_ok());
}
Expand Down
3 changes: 3 additions & 0 deletions crates/orchestrator/src/cli/snos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ use url::Url;
#[derive(Debug, Clone, Args)]
#[group(requires_all = ["rpc_for_snos"])]
pub struct SNOSCliArgs {
pub snos_full_output: bool,

/// The RPC URL for SNOS.
#[arg(env = "MADARA_ORCHESTRATOR_RPC_FOR_SNOS", long)]
pub rpc_for_snos: Url,
}

#[derive(Debug, Clone)]
pub struct SNOSParams {
pub snos_full_output: bool,
pub rpc_for_snos: Url,
}
4 changes: 4 additions & 0 deletions crates/orchestrator/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use settlement_client_interface::SettlementClient;
use sharp_service::SharpProverService;
use starknet::providers::jsonrpc::HttpTransport;
use starknet::providers::{JsonRpcClient, Url};
use starknet_da_client::StarknetDaClient;
use starknet_settlement_client::StarknetSettlementClient;

use crate::alerts::aws_sns::AWSSNS;
Expand Down Expand Up @@ -288,6 +289,9 @@ pub async fn build_da_client(da_params: &DaValidatedArgs) -> Box<dyn DaClient +
DaValidatedArgs::Ethereum(ethereum_da_params) => {
Box::new(EthereumDaClient::new_with_args(ethereum_da_params).await)
}
DaValidatedArgs::Starknet(starknet_da_params) => {
Box::new(StarknetDaClient::new_with_args(starknet_da_params).await)
}
}
}

Expand Down
Loading

0 comments on commit c485251

Please sign in to comment.