Skip to content

Commit

Permalink
merge : main
Browse files Browse the repository at this point in the history
  • Loading branch information
ocdbytes committed Jul 22, 2024
2 parents 5c8fd2a + f1f1e4c commit b0979bc
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 14 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: "Changelog Workflow"
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]
branches: [main]

jobs:
# Enforces the update of a changelog file on every pull request
# skipLabel default is "Skip-Changelog"
changelog:
runs-on: ubuntu-latest
steps:
- uses: dangoslen/changelog-enforcer@v3
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## Added

## Changed

## Removed

## Fixed
6 changes: 2 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ cairo-vm = { git = "https://github.com/lambdaclass/cairo-vm", features = [
# can deserialize our snos input json into a StarknetOsInput struct.
# TODO: update back to the main repo once it's merged
# Sharp (Starkware)
snos = { git = "https://github.com/Moonsong-Labs/snos", branch = "od/os-output-serde" }
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" }
Expand Down
4 changes: 3 additions & 1 deletion crates/da-clients/da-client-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ pub trait DaClient: Send + Sync {
}

/// Trait for every new DaConfig to implement
pub trait DaConfig {
#[async_trait]
pub trait DaConfig<T> {
/// Should create a new instance of the DaConfig from the environment variables
fn new_from_env() -> Self;
async fn build_client(&self) -> T;
}
23 changes: 22 additions & 1 deletion crates/da-clients/ethereum/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
use std::str::FromStr;
use std::{env, path::Path};

use alloy::signers::wallet::LocalWallet;
use alloy::{network::Ethereum, providers::ProviderBuilder, rpc::client::RpcClient};
use async_trait::async_trait;
use c_kzg::KzgSettings;
use da_client_interface::DaConfig;
use url::Url;
use utils::env_utils::get_env_var_or_panic;

use crate::EthereumDaClient;

#[derive(Clone, Debug)]
pub struct EthereumDaConfig {
pub rpc_url: String,
pub memory_pages_contract: String,
pub private_key: String,
}

impl DaConfig for EthereumDaConfig {
#[async_trait]
impl DaConfig<EthereumDaClient> for EthereumDaConfig {
fn new_from_env() -> Self {
Self {
rpc_url: get_env_var_or_panic("ETHEREUM_RPC_URL"),
memory_pages_contract: get_env_var_or_panic("MEMORY_PAGES_CONTRACT_ADDRESS"),
private_key: get_env_var_or_panic("PRIVATE_KEY"),
}
}
async fn build_client(&self) -> EthereumDaClient {
let client =
RpcClient::new_http(Url::from_str(self.rpc_url.as_str()).expect("Failed to parse ETHEREUM_RPC_URL"));
let provider = ProviderBuilder::<_, Ethereum>::new().on_client(client);
let wallet: LocalWallet = env::var("PK").expect("PK must be set").parse().expect("issue while parsing");
// let wallet: LocalWallet = config.private_key.as_str().parse();
let trusted_setup = KzgSettings::load_trusted_setup_file(Path::new("./trusted_setup.txt"))
.expect("issue while loading the trusted setup");
EthereumDaClient { provider, wallet, trusted_setup }
}
}
7 changes: 3 additions & 4 deletions crates/orchestrator/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use arc_swap::{ArcSwap, Guard};
use da_client_interface::{DaClient, DaConfig};
use dotenvy::dotenv;
use ethereum_da_client::config::EthereumDaConfig;
use ethereum_da_client::EthereumDaClient;
use ethereum_settlement_client::EthereumSettlementClient;
use prover_client_interface::ProverClient;
use settlement_client_interface::SettlementClient;
Expand Down Expand Up @@ -60,7 +59,7 @@ pub async fn init_config() -> Config {
// init the queue
let queue = Box::new(SqsQueue {});

let da_client = build_da_client();
let da_client = build_da_client().await;

let settings_provider = DefaultSettingsProvider {};
let settlement_client = build_settlement_client(&settings_provider).await;
Expand Down Expand Up @@ -149,11 +148,11 @@ pub async fn config_force_init(config: Config) {
}

/// Builds the DA client based on the environment variable DA_LAYER
fn build_da_client() -> Box<dyn DaClient + Send + Sync> {
async fn build_da_client() -> Box<dyn DaClient + Send + Sync> {
match get_env_var_or_panic("DA_LAYER").as_str() {
"ethereum" => {
let config = EthereumDaConfig::new_from_env();
Box::new(EthereumDaClient::from(config))
Box::new(config.build_client().await)
}
_ => panic!("Unsupported DA layer"),
}
Expand Down
18 changes: 15 additions & 3 deletions crates/utils/src/env_utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use color_eyre::Result;
use std::env::VarError;

pub fn get_env_var(key: &str) -> Result<String> {
std::env::var(key).map_err(|e| e.into())
pub fn get_env_var(key: &str) -> Result<String, VarError> {
std::env::var(key)
}

pub fn get_env_var_or_panic(key: &str) -> String {
Expand All @@ -11,3 +11,15 @@ pub fn get_env_var_or_panic(key: &str) -> String {
pub fn get_env_var_or_default(key: &str, default: &str) -> String {
get_env_var(key).unwrap_or(default.to_string())
}

pub fn get_env_var_optional(key: &str) -> Result<Option<String>, VarError> {
match get_env_var(key) {
Ok(s) => Ok(Some(s)),
Err(VarError::NotPresent) => Ok(None),
Err(e) => Err(e),
}
}

pub fn get_env_car_optional_or_panic(key: &str) -> Option<String> {
get_env_var_optional(key).unwrap_or_else(|e| panic!("Failed to get env var {}: {}", key, e))
}

0 comments on commit b0979bc

Please sign in to comment.