From 0dffedfb97e62f0f8d07aaba7a34ab993b7993f8 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Tue, 5 Nov 2024 17:57:46 +0530 Subject: [PATCH 01/63] update: basic cli setup --- .env.test | 60 ++++++---- Cargo.lock | 1 + crates/da-clients/ethereum/src/config.rs | 2 +- crates/orchestrator/Cargo.toml | 1 + crates/orchestrator/src/cli/alert/aws_sns.rs | 13 +++ crates/orchestrator/src/cli/alert/mod.rs | 1 + crates/orchestrator/src/cli/aws_config.rs | 25 ++++ crates/orchestrator/src/cli/da/ethereum.rs | 9 ++ crates/orchestrator/src/cli/da/mod.rs | 1 + crates/orchestrator/src/cli/database/mod.rs | 1 + .../orchestrator/src/cli/database/mongodb.rs | 13 +++ .../orchestrator/src/cli/instrumentation.rs | 13 +++ crates/orchestrator/src/cli/mod.rs | 107 ++++++++++++++++++ crates/orchestrator/src/cli/prover/mod.rs | 1 + crates/orchestrator/src/cli/prover/sharp.rs | 34 ++++++ crates/orchestrator/src/cli/queue/aws_sqs.rs | 33 ++++++ crates/orchestrator/src/cli/queue/mod.rs | 1 + crates/orchestrator/src/cli/server.rs | 14 +++ .../src/cli/settlement/ethereum.rs | 27 +++++ crates/orchestrator/src/cli/settlement/mod.rs | 2 + .../src/cli/settlement/starknet.rs | 38 +++++++ crates/orchestrator/src/cli/snos.rs | 16 +++ crates/orchestrator/src/cli/storage/aws_s3.rs | 9 ++ crates/orchestrator/src/cli/storage/mod.rs | 2 + crates/orchestrator/src/lib.rs | 3 + crates/orchestrator/src/main.rs | 1 + 26 files changed, 405 insertions(+), 23 deletions(-) create mode 100644 crates/orchestrator/src/cli/alert/aws_sns.rs create mode 100644 crates/orchestrator/src/cli/alert/mod.rs create mode 100644 crates/orchestrator/src/cli/aws_config.rs create mode 100644 crates/orchestrator/src/cli/da/ethereum.rs create mode 100644 crates/orchestrator/src/cli/da/mod.rs create mode 100644 crates/orchestrator/src/cli/database/mod.rs create mode 100644 crates/orchestrator/src/cli/database/mongodb.rs create mode 100644 crates/orchestrator/src/cli/instrumentation.rs create mode 100644 crates/orchestrator/src/cli/mod.rs create mode 100644 crates/orchestrator/src/cli/prover/mod.rs create mode 100644 crates/orchestrator/src/cli/prover/sharp.rs create mode 100644 crates/orchestrator/src/cli/queue/aws_sqs.rs create mode 100644 crates/orchestrator/src/cli/queue/mod.rs create mode 100644 crates/orchestrator/src/cli/server.rs create mode 100644 crates/orchestrator/src/cli/settlement/ethereum.rs create mode 100644 crates/orchestrator/src/cli/settlement/mod.rs create mode 100644 crates/orchestrator/src/cli/settlement/starknet.rs create mode 100644 crates/orchestrator/src/cli/snos.rs create mode 100644 crates/orchestrator/src/cli/storage/aws_s3.rs create mode 100644 crates/orchestrator/src/cli/storage/mod.rs diff --git a/.env.test b/.env.test index dd61c0db..7a4349bd 100644 --- a/.env.test +++ b/.env.test @@ -1,26 +1,25 @@ -##### ORCHESTRATOR ##### +##### ORCHESTRATOR ##### DONE HOST=127.0.0.1 PORT=3000 -MAX_BLOCK_TO_PROCESS= -MIN_BLOCK_TO_PROCESS= -##### AWS CONFIG ##### +##### AWS CONFIG ##### DONE AWS_ACCESS_KEY_ID="AWS_ACCESS_KEY_ID" AWS_SECRET_ACCESS_KEY="AWS_SECRET_ACCESS_KEY" AWS_REGION="us-east-1" - -##### Omniqueue ##### - +# pick up by AWS sdk +AWS_ENDPOINT_URL="http://localhost.localstack.cloud:4566" +# Omniqueue AWS_DEFAULT_REGION="localhost" -##### STORAGE ##### +##### STORAGE ##### DONE DATA_STORAGE="s3" + AWS_S3_BUCKET_NAME="madara-orchestrator-test-bucket" -##### QUEUE ##### +##### QUEUE ##### QUEUE_PROVIDER="sqs" @@ -42,17 +41,20 @@ SQS_WORKER_TRIGGER_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:45 ##### SNS ##### ALERTS="sns" + AWS_SNS_ARN="arn:aws:sns:us-east-1:000000000000:madara-orchestrator-arn" ##### DATABASE ##### DATABASE="mongodb" + MONGODB_CONNECTION_STRING="mongodb://localhost:27017" DATABASE_NAME="orchestrator" ##### PROVER ##### PROVER_SERVICE="sharp" + SHARP_CUSTOMER_ID="sharp_consumer_id" SHARP_URL="http://127.0.0.1:6000" # [IMP!!!] These are test certificates (they don't work) @@ -60,34 +62,48 @@ SHARP_USER_CRT="LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUR4ekNDQXErZ0F3SUJBZ0lV SHARP_USER_KEY="LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JSUV2UUlCQURBTkJna3Foa2lHOXcwQkFRRUZBQVNDQktjd2dnU2pBZ0VBQW9JQkFRRFJ5bVQzWTJQdkFJL0gKVkwxaTBNU011ZDVQanhuRE9UbW5tODBscWd4aXhTVHpiM1Z0cUdkUVNiQTZJWVpueEIvc25RSVFLdjZPL09QWApKMStrOWt2VjVwSjZiN0o4SUVLeFBZTW95WHNOU3dCdHhwclVpRGRXeUNhSXNtOEFBOHVKVHNDNUZ1ZDdWcDhhClVaT1ZGWDAwbHltazBEY2hzSSt3cFN4NUdxOG1HbU8vV1BjaHRFYnhRSGFFZDdOS01wR3VnQ2xocm1mRGJvTWUKZXVxUHRtV0VNNjVzbmpFa2hXeHpMcG1VUzE2QjRwUEFDU25xN1o3QUEveXRVVUc2T0hKcDVhb1RFMmdTbXl3RgpGZVpzVktObWFNVHlGRHBnd1BlNjl0blVtdzNSVkhNZjNmRDZkTTFMSzZzRDZ3WHFwMGRjQ3ZEdU5TQm8rZHhiCnQxWlFzdjhkQWdNQkFBRUNnZ0VBQU9mcDFiT2xLOVFKeXVlUHhjeDIvTkNVcUMxTEJDL01FdkEyUzVKWGFWbkcKbGhLR0pFb1U0Q0RoVk83dUlLYVZLTFZvMjk4RHFHUnBLM1d0RVE1TE40bytXYTcveTA5c1drMlVzbWxrVWFOZwpSaGtVZEJSK2dLNXVsQ3FKRml2dUJoTEQvRWlnQ1VWUGZKS2JtNG96TnpYcjVSMU5ENlV1aWFtODdtenlFcTBLCmZsVXlhR0RZNGdIdFNBOVBENVBFYlUveFpKeitKaHk5T2l3aVRXV0MrSHoyb2c3UWRDRDE2RlhGcit2VHpQN0MKb2tFb0VDZFNPRWlMalVENjBhS2ZxRmFCVm5MTkVudC9QSytmY1RBM05mNGtSMnFDNk9ZWjVFb09zYm1ka29ZTgpyU3NJZW9XblMxOEhvekZud2w3Z05wTUtjNmRzQzRBTldOVDFsTkhCb1FLQmdRRHlaUDFJSlppZUh6NlExaUVTCm5zd2tnblZCQUQ0SlVLR1ZDMHA3dk4yclNDZXh4c05ZZXFPTEEyZGZCUGpOVjd3blFKcUgxT05XellOMUJVSUUKeThLTCtFZVl6Q3RZa21LL21wSGJIMzNjd2tJODBuMHJROU1BalZMTlJ2YVVEOWp1NFBsRzFqaEFZUVVyTkViZQpKRlVpSk83aDVQa1llZG50SitqSHFpQnRoUUtCZ1FEZGtPbndmL0szYk4xenR0bXZQd0VicjhkVWJjRVh5NDFOCkl5VWwrZW1WSlgzYktKM0duNDZnQ2RsTTdkYmpwS3JVZ3oxL2JsZTgvMkVFckJvSEFRNkMrU2pEaGhvL01CbnIKekZheTBoK3YxbjBnZnNNVzRoOEF4cEFwc25OYnh6K2g1Wm5uSnRTd0srUjB3U0VJVVEzRjAxL2hMWWhLQ2l5OApwbW5HQi9hU3VRS0JnRzdxd1cvVExGd214ZlYyMXBsenFzeUdHZXVObGRXalhOMGIxcEI2b3lDdW11TmhwYUFHCk5uSDFNOGNxT2tPVWd4ZWZHMWRPbGx6eEc5ZGZlWTlDUWhyVW1NYVZucndmK0NuZkxDRU43d1VtcXpLenl1MFMKVXlwc2dOaElRYXNNK1dLTjllTnhRVHBNYXhZVERONjMxM0VSWDNKazJZdFdydDh6cFBSQXFDZ1ZBb0dCQU54egpUa0NMbmJ6aFphbTNlZm9DenlCMEVma3dSdHBkSGxkc3E0NlFqTmRuK1VSd3NpTXBLR2lWeEE3bDZsU1B4NlV3CmU2VHA3Z1JQZUlHRWwxVDJ1VENacGZSODNtcVdlb1FCeVJXZE9nZmplcFkxYWZpL3ZhY3c2Y21ERTRKeXloNVUKYTMveFE5ZVJwSHFDbWxKREMxZ1V5eVlwL3B2a2FjUytNeW5sVEhHSkFvR0FQekdTSzdXOHBUYldSVEFoaTVrSQpwZk5kWk1tcnRodUxNT3F6TGhyRjZublpldk9OdTBoYXVhZktlVElFd2w0clhYZHFKQlJBaWZKMFFsLzZKWFFkCmd1VzFrZWk1Ui8rUFZ5eUhab042c3NXSTNWYklwUUloUmt6UENnTDZhbHEwSzFpT1dlV1lIOHdORGRRdlB1T2UKRkZPOEovSzNxV0NtWjU0ODBBbTNhT0U9Ci0tLS0tRU5EIFBSSVZBVEUgS0VZLS0tLS0K" SHARP_SERVER_CRT="LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURhekNDQWxPZ0F3SUJBZ0lVRUR0Rjd0YVNTUnVQQTJ6Uk1aNWNzY2JCRm5jd0RRWUpLb1pJaHZjTkFRRUwKQlFBd1JURUxNQWtHQTFVRUJoTUNTVTR4RXpBUkJnTlZCQWdNQ2xOdmJXVXRVM1JoZEdVeElUQWZCZ05WQkFvTQpHRWx1ZEdWeWJtVjBJRmRwWkdkcGRITWdVSFI1SUV4MFpEQWVGdzB5TkRBNE1UTXhNekEzTVROYUZ3MHlOVEE0Ck1UTXhNekEzTVROYU1FVXhDekFKQmdOVkJBWVRBa2xPTVJNd0VRWURWUVFJREFwVGIyMWxMVk4wWVhSbE1TRXcKSHdZRFZRUUtEQmhKYm5SbGNtNWxkQ0JYYVdSbmFYUnpJRkIwZVNCTWRHUXdnZ0VpTUEwR0NTcUdTSWIzRFFFQgpBUVVBQTRJQkR3QXdnZ0VLQW9JQkFRRFRHcEEwNEZ1QlNFaE5PNVYvMGxTaDkvSEgxeVRZT2dRVFdoOG43eDlRCnZGMHpvZFZueVFIdjE5elU5eVdia2xvOEkvOXFBVm9lRzdXTnpUVFg2Q295ZlNjb1YvazN0Q2UwVnVWMlFJTVQKdW82SzJSU05CVHB1TlNqNTlzUiszVTQ2OFRBQnY0YVpsYjU4TU5CRXM3MVRieVpLRHBGRVRkMkg3T0ZKajg4QQpNRi9MaXJkeDZPOFdZL0tDeisxd1ZXL1JRdytYYjRJSWx4bXJFOC9UZ3FNSEo4dFUxYkZiOWJNcTEvOTN5YWtJClU1V2J2NVhXKzFwZFVyTUFNcTFFaC9vZThMN2pFaFdvZXZrNzgyU0kwUk0xeG5MaEtrUUVBYXd6Zkg2ODZiR2YKUHQ3RkFIQ1pGaWJ4KzZzSkg0R1M3S25iK0x5bk9ud3phMWZPUXZEZmcvRm5BZ01CQUFHalV6QlJNQjBHQTFVZApEZ1FXQkJUYlFUdmlUTW1xNXlNK2ZJRVI4VjdTZk1pK3B6QWZCZ05WSFNNRUdEQVdnQlRiUVR2aVRNbXE1eU0rCmZJRVI4VjdTZk1pK3B6QVBCZ05WSFJNQkFmOEVCVEFEQVFIL01BMEdDU3FHU0liM0RRRUJDd1VBQTRJQkFRREYKTllyRnpBa2RIVkhjUkd5SUNsTi9IVGswaldOcTVSdTB1RUpDQ21Dbm9ZY1pRSTlDQlcwTkl3dGpZUkpTKzR1UwordWh4VWpSYTA5YXdOWDhvYmU0dDZjK25HRnhZMGZqamk0cGZnbU1kMWNJeGdsM3E3Nlp0ZkllRGR6alRLRXN1CjRFUTVadnEwMnJvTEZ0ZjEvL3dRVG0xNkNKdFpGWnhNZ1phYnNxc2JRc3M2dWdMUGtTTmdBWjI1L2VhcWhnQ20KTjFUV2FxL0xJMVBLSkxPK085NFlMa2FsNVpyOTJCOXk4Q0VKVUVuSTA1R1N1MmJUOFM2a0ZBMEpadEszTW9SbwpqRWZWV1lQVHR5TFR4amNvRndCcDlHaXZYSDdSdHBxMDlmSmFhU1pNekxmNGlyNHpBdXprbExBNWZvampPNXlKCllnYlVaQUU2aS81N1NFWjR3VmxTCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K" SHARP_PROOF_LAYOUT="small" +GPS_VERIFIER_CONTRACT_ADDRESS="0x07ec0D28e50322Eb0C159B9090ecF3aeA8346DFe" -##### ON CHAIN CONFIG ##### +##### DA ##### DA_LAYER="ethereum" +DA_RPC_URL="https://eth-sepolia.public.blastapi.io" + +##### SETTLEMENT ##### + SETTLEMENT_LAYER="ethereum" + +# Ethereum + SETTLEMENT_RPC_URL="https://eth-sepolia.public.blastapi.io" -MADARA_RPC_URL=http://localhost:9944 -GPS_VERIFIER_CONTRACT_ADDRESS="0x07ec0D28e50322Eb0C159B9090ecF3aeA8346DFe" ETHEREUM_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" L1_CORE_CONTRACT_ADDRESS="0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057" +STARKNET_OPERATOR_ADDRESS="0x5b98B836969A60FEC50Fa925905Dd1D382a7db43" -##### SNOS ##### -## This is needed right now because Madara doesn't support getProof -RPC_FOR_SNOS="" - +# Starknet -##### STARKNET SETTLEMENT ##### +STARKNET_RPC_URL="https://starknet-sepolia.public.blastapi.io" STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 STARKNET_ACCOUNT_ADDRESS=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 +STARKNET_CAIRO_CORE_CONTRACT_ADDRESS="" +STARKNET_FINALITY_RETRY_WAIT_IN_SECS="" +MADARA_BINARY_PATH="/path/to/madara" + + +##### SNOS ##### +## This is needed right now because Madara doesn't support getProof +RPC_FOR_SNOS="" +MAX_BLOCK_TO_PROCESS= +MIN_BLOCK_TO_PROCESS= ## Instrumentation OTEL_SERVICE_NAME="madara_orchestrator" OTEL_COLLECTOR_ENDPOINT="" -##### Tests ##### +##### ON CHAIN CONFIG ##### -STARKNET_OPERATOR_ADDRESS="0x5b98B836969A60FEC50Fa925905Dd1D382a7db43" +MADARA_RPC_URL=http://localhost:9944 + +##### Tests ##### +# Can be removed, we already have AWS_SNS_ARN AWS_SNS_ARN_NAME="madara-orchestrator-arn" -MADARA_BINARY_PATH="/path/to/madara" -# pick up by AWS sdk -AWS_ENDPOINT_URL="http://localhost.localstack.cloud:4566" diff --git a/Cargo.lock b/Cargo.lock index ecd06598..8d68fc54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6946,6 +6946,7 @@ dependencies = [ "c-kzg", "cairo-vm 1.0.1 (git+https://github.com/Moonsong-Labs/cairo-vm?branch=notlesh%2Fsegment-arena-relocation-fix)", "chrono", + "clap", "color-eyre", "da-client-interface", "dotenvy", diff --git a/crates/da-clients/ethereum/src/config.rs b/crates/da-clients/ethereum/src/config.rs index f5fa9d86..07885728 100644 --- a/crates/da-clients/ethereum/src/config.rs +++ b/crates/da-clients/ethereum/src/config.rs @@ -16,7 +16,7 @@ pub struct EthereumDaConfig { impl EthereumDaConfig { pub fn new_with_settings(settings: &impl Settings) -> color_eyre::Result { - Ok(Self { rpc_url: settings.get_settings_or_panic("SETTLEMENT_RPC_URL") }) + Ok(Self { rpc_url: settings.get_settings_or_panic("DA_RPC_URL") }) } pub async fn build_client(&self) -> EthereumDaClient { diff --git a/crates/orchestrator/Cargo.toml b/crates/orchestrator/Cargo.toml index c2c258e0..940f3f8d 100644 --- a/crates/orchestrator/Cargo.toml +++ b/crates/orchestrator/Cargo.toml @@ -27,6 +27,7 @@ axum = { workspace = true, features = ["macros"] } axum-macros = { workspace = true } bincode = { workspace = true } bytes.workspace = true +clap = { version = "4.4", features = ["derive", "env"] } c-kzg = { workspace = true } cairo-vm = { workspace = true } chrono = { workspace = true } diff --git a/crates/orchestrator/src/cli/alert/aws_sns.rs b/crates/orchestrator/src/cli/alert/aws_sns.rs new file mode 100644 index 00000000..351d0004 --- /dev/null +++ b/crates/orchestrator/src/cli/alert/aws_sns.rs @@ -0,0 +1,13 @@ +use clap::Args; + +/// Parameters used to config AWS SNS. +#[derive(Debug, Clone, Args)] +pub struct AWSSNSParams { + /// The name of the S3 bucket. + #[arg(env = "SNS_NAME", long, default_value = "madara-orchestrator-arn")] + pub sns_arn: String, +} + +impl AWSSNSParams { + // TODO: Implement the logic to get the SNS ARN from aws config +} \ No newline at end of file diff --git a/crates/orchestrator/src/cli/alert/mod.rs b/crates/orchestrator/src/cli/alert/mod.rs new file mode 100644 index 00000000..bfe56638 --- /dev/null +++ b/crates/orchestrator/src/cli/alert/mod.rs @@ -0,0 +1 @@ +pub mod aws_sns; \ No newline at end of file diff --git a/crates/orchestrator/src/cli/aws_config.rs b/crates/orchestrator/src/cli/aws_config.rs new file mode 100644 index 00000000..0866fea5 --- /dev/null +++ b/crates/orchestrator/src/cli/aws_config.rs @@ -0,0 +1,25 @@ +use clap::Args; + +/// Parameters used to config AWS. +#[derive(Debug, Clone, Args)] +pub struct AWSConfigParams { + /// The access key ID. + #[arg(env = "AWS_ACCESS_KEY_ID", long)] + pub access_key_id: String, + + /// The secret access key. + #[arg(env = "AWS_SECRET_ACCESS_KEY", long)] + pub secret_access_key: String, + + /// The region. + #[arg(env = "AWS_REGION", long)] + pub region: String, + + /// The endpoint URL. + #[arg(env = "AWS_ENDPOINT_URL", long, default_value = "http://localhost.localstack.cloud:4566")] + pub endpoint_url: String, + + /// The default region. + #[arg(env = "AWS_DEFAULT_REGION", long, default_value = "localhost")] + pub default_region: String, +} diff --git a/crates/orchestrator/src/cli/da/ethereum.rs b/crates/orchestrator/src/cli/da/ethereum.rs new file mode 100644 index 00000000..28dca95a --- /dev/null +++ b/crates/orchestrator/src/cli/da/ethereum.rs @@ -0,0 +1,9 @@ +use clap::Args; + +/// Parameters used to config Ethereum. +#[derive(Debug, Clone, Args)] +pub struct EthereumParams { + /// The RPC URL of the Ethereum node. + #[arg(env = "DA_RPC_URL", long)] + pub rpc_url: String, +} diff --git a/crates/orchestrator/src/cli/da/mod.rs b/crates/orchestrator/src/cli/da/mod.rs new file mode 100644 index 00000000..84eb5551 --- /dev/null +++ b/crates/orchestrator/src/cli/da/mod.rs @@ -0,0 +1 @@ +pub mod ethereum; \ No newline at end of file diff --git a/crates/orchestrator/src/cli/database/mod.rs b/crates/orchestrator/src/cli/database/mod.rs new file mode 100644 index 00000000..7db7304d --- /dev/null +++ b/crates/orchestrator/src/cli/database/mod.rs @@ -0,0 +1 @@ +pub mod mongodb; \ No newline at end of file diff --git a/crates/orchestrator/src/cli/database/mongodb.rs b/crates/orchestrator/src/cli/database/mongodb.rs new file mode 100644 index 00000000..83f40fa2 --- /dev/null +++ b/crates/orchestrator/src/cli/database/mongodb.rs @@ -0,0 +1,13 @@ +use clap::Args; + +/// Parameters used to config MongoDB. +#[derive(Debug, Clone, Args)] +pub struct MongoDBParams { + /// The connection string to the MongoDB server. + #[arg(env = "MONGODB_CONNECTION_STRING", long)] + pub connection_string: String, + + /// The name of the database. + #[arg(env = "DATABASE_NAME", long)] + pub database_name: String, +} diff --git a/crates/orchestrator/src/cli/instrumentation.rs b/crates/orchestrator/src/cli/instrumentation.rs new file mode 100644 index 00000000..58e1e0d3 --- /dev/null +++ b/crates/orchestrator/src/cli/instrumentation.rs @@ -0,0 +1,13 @@ +use clap::Args; + +/// Parameters used to config instrumentation. +#[derive(Debug, Clone, Args)] +pub struct InstrumentationParams { + /// The name of the instrumentation service. + #[arg(env = "OTEL_SERVICE_NAME", long)] + pub service_name: String, + + /// The endpoint of the collector. + #[arg(env = "OTEL_COLLECTOR_ENDPOINT", long)] + pub collector_endpoint: String, +} diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs new file mode 100644 index 00000000..76a69596 --- /dev/null +++ b/crates/orchestrator/src/cli/mod.rs @@ -0,0 +1,107 @@ +use clap::ArgGroup; +use url::Url; + +pub mod aws_config; +pub mod database; +pub mod instrumentation; +pub mod server; +pub mod storage; +pub mod queue; +pub mod alert; +pub mod prover; +pub mod da; +pub mod settlement; +pub mod snos; + +#[derive(Clone, Debug, clap::Parser)] +#[clap( + group( + ArgGroup::new("storage") + .args(&["aws_s3"]) + .required(true) + .multiple(false) + ), + + group( + ArgGroup::new("queue") + .args(&["aws_sqs"]) + .required(true) + .multiple(false) + ), + + group( + ArgGroup::new("alert") + .args(&["aws_sns"]) + .required(true) + .multiple(false) + ), + + group( + ArgGroup::new("prover") + .args(&["sharp"]) + .required(true) + .multiple(false) + ), + + group( + ArgGroup::new("settlement_layer") + .args(&["ethereum", "starknet"]) + .required(true) + .multiple(false) + ), + + group( + ArgGroup::new("da_layer") + .args(&["ethereum"]) + .required(true) + .multiple(false) + ), +)] + +pub struct RunCmd { + #[clap(flatten)] + pub server: server::ServerParams, + + #[clap(flatten)] + pub aws_config: aws_config::AWSConfigParams, + + // part of storage + #[clap(flatten)] + pub aws_s3: storage::aws_s3::AWSS3Params, + + // part of queue + #[clap(flatten)] + pub aws_sqs: queue::aws_sqs::AWSSQSParams, + + // part of alert + #[clap(flatten)] + pub aws_sns: alert::aws_sns::AWSSNSParams, + + + // part of database + #[clap(flatten)] + pub mongodb: database::mongodb::MongoDBParams, + + // part of prover + #[clap(flatten)] + pub sharp: prover::sharp::SharpParams, + + // part of da_layer + #[clap(flatten)] + pub ethereum_da: da::ethereum::EthereumParams, + + + #[clap(flatten)] + pub starknet_settlement: settlement::starknet::StarknetSettlementParams, + + #[clap(flatten)] + pub ethereum_settlement: settlement::ethereum::EthereumSettlementParams, + + #[clap(flatten)] + pub snos: snos::SNOSParams, + + pub madara_rpc_url: Url, + + #[clap(flatten)] + pub instrumentation: instrumentation::InstrumentationParams, +} diff --git a/crates/orchestrator/src/cli/prover/mod.rs b/crates/orchestrator/src/cli/prover/mod.rs new file mode 100644 index 00000000..f8ceadda --- /dev/null +++ b/crates/orchestrator/src/cli/prover/mod.rs @@ -0,0 +1 @@ +pub mod sharp; \ No newline at end of file diff --git a/crates/orchestrator/src/cli/prover/sharp.rs b/crates/orchestrator/src/cli/prover/sharp.rs new file mode 100644 index 00000000..3d317ee6 --- /dev/null +++ b/crates/orchestrator/src/cli/prover/sharp.rs @@ -0,0 +1,34 @@ +use clap::Args; + +/// Parameters used to config Sharp. +#[derive(Debug, Clone, Args)] +pub struct SharpParams { + + /// The customer id for Sharp. + #[arg(env = "SHARP_CUSTOMER_ID", long)] + pub sharp_customer_id: String, + + /// The URL of the Sharp server. + #[arg(env = "SHARP_URL", long)] + pub sharp_url: String, + + /// The user certificate for Sharp. + #[arg(env = "SHARP_USER_CRT", long)] + pub sharp_user_crt: String, + + /// The user key for Sharp. + #[arg(env = "SHARP_USER_KEY", long)] + pub sharp_user_key: String, + + /// The server certificate for Sharp. + #[arg(env = "SHARP_SERVER_CRT", long)] + pub sharp_server_crt: String, + + /// The proof layout for Sharp. + #[arg(env = "SHARP_PROOF_LAYOUT", long, default_value = "small")] + pub sharp_proof_layout: String, + + /// The GPS verifier contract address. + #[arg(env = "GPS_VERIFIER_CONTRACT_ADDRESS", long)] + pub gps_verifier_contract_address: String, +} diff --git a/crates/orchestrator/src/cli/queue/aws_sqs.rs b/crates/orchestrator/src/cli/queue/aws_sqs.rs new file mode 100644 index 00000000..c561fd01 --- /dev/null +++ b/crates/orchestrator/src/cli/queue/aws_sqs.rs @@ -0,0 +1,33 @@ +use clap::Args; + +/// Parameters used to config AWS SQS. +#[derive(Debug, Clone, Args)] +pub struct AWSSQSParams { + /// The name of the S3 bucket. + #[arg(env = "SQS_PREFIX", long)] + pub sqs_prefix: String, + + /// The QUEUE url + #[arg(env = "SQS_QUEUE_URL", long)] + pub queue_url: String, +} + + +impl AWSSQSParams { + // TODO: Implement the logic to get the queue url + // SQS_SNOS_JOB_PROCESSING_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_snos_job_processing_queue" + // SQS_SNOS_JOB_VERIFICATION_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_snos_job_verification_queue" + + // SQS_PROVING_JOB_PROCESSING_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_proving_job_processing_queue" + // SQS_PROVING_JOB_VERIFICATION_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_proving_job_verification_queue" + + // SQS_DATA_SUBMISSION_JOB_PROCESSING_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_data_submission_job_processing_queue" + // SQS_DATA_SUBMISSION_JOB_VERIFICATION_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_data_submission_job_verification_queue" + + // SQS_UPDATE_STATE_JOB_PROCESSING_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_update_state_job_processing_queue" + // SQS_UPDATE_STATE_JOB_VERIFICATION_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_update_state_job_verification_queue" + + // SQS_JOB_HANDLE_FAILURE_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_job_handle_failure_queue" + // SQS_WORKER_TRIGGER_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_worker_trigger_queue" + +} \ No newline at end of file diff --git a/crates/orchestrator/src/cli/queue/mod.rs b/crates/orchestrator/src/cli/queue/mod.rs new file mode 100644 index 00000000..82317418 --- /dev/null +++ b/crates/orchestrator/src/cli/queue/mod.rs @@ -0,0 +1 @@ +pub mod aws_sqs; \ No newline at end of file diff --git a/crates/orchestrator/src/cli/server.rs b/crates/orchestrator/src/cli/server.rs new file mode 100644 index 00000000..0cca091a --- /dev/null +++ b/crates/orchestrator/src/cli/server.rs @@ -0,0 +1,14 @@ +use clap::Args; + +/// Parameters used to config the server. +#[derive(Debug, Clone, Args)] +pub struct ServerParams { + /// The host to listen on. + #[arg(env = "HOST", long, default_value = "127.0.0.1")] + pub host: String, + + /// The port to listen on. + #[arg(env = "PORT", long, default_value = "3000")] + pub port: u16, +} + \ No newline at end of file diff --git a/crates/orchestrator/src/cli/settlement/ethereum.rs b/crates/orchestrator/src/cli/settlement/ethereum.rs new file mode 100644 index 00000000..f59917d8 --- /dev/null +++ b/crates/orchestrator/src/cli/settlement/ethereum.rs @@ -0,0 +1,27 @@ +use clap::Args; + + +// SETTLEMENT_RPC_URL="https://eth-sepolia.public.blastapi.io" +// ETHEREUM_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" +// L1_CORE_CONTRACT_ADDRESS="0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057" +// STARKNET_OPERATOR_ADDRESS="0x5b98B836969A60FEC50Fa925905Dd1D382a7db43" + + +#[derive(Debug, Clone, Args)] +pub struct EthereumSettlementParams { + /// The URL of the Ethereum RPC node. + #[arg(env = "ETHEREUM_SETTLEMENT_RPC_URL", long)] + pub ethereum_rpc_url: String, + + /// The private key of the Ethereum account. + #[arg(env = "ETHEREUM_PRIVATE_KEY", long)] + pub ethereum_private_key: String, + + /// The address of the L1 core contract. + #[arg(env = "L1_CORE_CONTRACT_ADDRESS", long)] + pub l1_core_contract_address: String, + + /// The address of the Starknet operator. + #[arg(env = "STARKNET_OPERATOR_ADDRESS", long)] + pub starknet_operator_address: String, +} diff --git a/crates/orchestrator/src/cli/settlement/mod.rs b/crates/orchestrator/src/cli/settlement/mod.rs new file mode 100644 index 00000000..5afbc73e --- /dev/null +++ b/crates/orchestrator/src/cli/settlement/mod.rs @@ -0,0 +1,2 @@ +pub mod ethereum; +pub mod starknet; diff --git a/crates/orchestrator/src/cli/settlement/starknet.rs b/crates/orchestrator/src/cli/settlement/starknet.rs new file mode 100644 index 00000000..69d6b79a --- /dev/null +++ b/crates/orchestrator/src/cli/settlement/starknet.rs @@ -0,0 +1,38 @@ +use clap::Args; + + +// STARKNET_RPC_URL="https://starknet-sepolia.public.blastapi.io" +// STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 +// STARKNET_ACCOUNT_ADDRESS=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 +// STARKNET_CAIRO_CORE_CONTRACT_ADDRESS="" +// STARKNET_FINALITY_RETRY_WAIT_IN_SECS="" +// MADARA_BINARY_PATH="/path/to/madara" + + +#[derive(Debug, Clone, Args)] +pub struct StarknetSettlementParams { + /// The URL of the Ethereum RPC node. + #[arg(env = "STARKNET_RPC_URL", long)] + pub starknet_rpc_url: String, + + /// The private key of the Ethereum account. + #[arg(env = "STARKNET_PRIVATE_KEY", long)] + pub starknet_private_key: String, + + /// The address of the Starknet account. + #[arg(env = "STARKNET_ACCOUNT_ADDRESS", long)] + pub starknet_account_address: String, + + /// The address of the Cairo core contract. + #[arg(env = "STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", long)] + pub starknet_cairo_core_contract_address: String, + + /// The number of seconds to wait for finality. + #[arg(env = "STARKNET_FINALITY_RETRY_WAIT_IN_SECS", long)] + pub starknet_finality_retry_wait_in_secs: String, + + /// The path to the Madara binary. + #[arg(env = "MADARA_BINARY_PATH", long)] + pub madara_binary_path: String, + +} diff --git a/crates/orchestrator/src/cli/snos.rs b/crates/orchestrator/src/cli/snos.rs new file mode 100644 index 00000000..65129a59 --- /dev/null +++ b/crates/orchestrator/src/cli/snos.rs @@ -0,0 +1,16 @@ +use clap::Args; + +#[derive(Debug, Clone, Args)] +pub struct SNOSParams { + /// The RPC URL for SNOS. + #[arg(env = "RPC_FOR_SNOS", long)] + pub rpc_for_snos: String, + + /// The maximum block to process. + #[arg(env = "MAX_BLOCK_TO_PROCESS", long)] + pub max_block_to_process: String, + + /// The minimum block to process. + #[arg(env = "MIN_BLOCK_TO_PROCESS", long)] + pub min_block_to_process: String, +} diff --git a/crates/orchestrator/src/cli/storage/aws_s3.rs b/crates/orchestrator/src/cli/storage/aws_s3.rs new file mode 100644 index 00000000..3dff2aec --- /dev/null +++ b/crates/orchestrator/src/cli/storage/aws_s3.rs @@ -0,0 +1,9 @@ +use clap::Args; + +/// Parameters used to config AWS S3. +#[derive(Debug, Clone, Args)] +pub struct AWSS3Params { + /// The name of the S3 bucket. + #[arg(env = "AWS_S3_BUCKET_NAME", long)] + pub bucket_name: String, +} diff --git a/crates/orchestrator/src/cli/storage/mod.rs b/crates/orchestrator/src/cli/storage/mod.rs new file mode 100644 index 00000000..22b86beb --- /dev/null +++ b/crates/orchestrator/src/cli/storage/mod.rs @@ -0,0 +1,2 @@ + +pub mod aws_s3; diff --git a/crates/orchestrator/src/lib.rs b/crates/orchestrator/src/lib.rs index b580f273..fcf135b3 100644 --- a/crates/orchestrator/src/lib.rs +++ b/crates/orchestrator/src/lib.rs @@ -26,3 +26,6 @@ pub mod telemetry; pub mod tests; /// Contains workers which act like cron jobs pub mod workers; + +// Contains CLI arguments +pub mod cli; diff --git a/crates/orchestrator/src/main.rs b/crates/orchestrator/src/main.rs index dc05bc4e..3d6d2433 100644 --- a/crates/orchestrator/src/main.rs +++ b/crates/orchestrator/src/main.rs @@ -3,6 +3,7 @@ use orchestrator::config::init_config; use orchestrator::queue::init_consumers; use orchestrator::routes::setup_server; use orchestrator::telemetry::{setup_analytics, shutdown_analytics}; +use orchestrator::cli::RunCmd; /// Start the server #[tokio::main] From d963ab2e1a91555fd1806b450d44ff8e1c98c726 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 6 Nov 2024 09:34:41 +0530 Subject: [PATCH 02/63] update: run_cmd for settlement client --- Cargo.lock | 2 + crates/orchestrator/src/cli/mod.rs | 107 ------------ crates/orchestrator/src/cli/settlement/mod.rs | 2 - crates/orchestrator/src/config.rs | 46 +++-- crates/orchestrator/src/lib.rs | 5 +- crates/orchestrator/src/main.rs | 8 +- crates/orchestrator/src/tests/config.rs | 14 +- crates/settlement-clients/ethereum/src/lib.rs | 27 +-- crates/settlement-clients/starknet/src/lib.rs | 16 +- .../starknet/src/tests/test.rs | 151 +++++++++-------- crates/utils/Cargo.toml | 2 + .../src/cli/alert/aws_sns.rs | 0 .../src/cli/alert/mod.rs | 0 .../src/cli/aws_config.rs | 0 .../src/cli/da/ethereum.rs | 0 .../{orchestrator => utils}/src/cli/da/mod.rs | 0 .../src/cli/database/mod.rs | 0 .../src/cli/database/mongodb.rs | 0 .../src/cli/instrumentation.rs | 0 crates/utils/src/cli/mod.rs | 158 ++++++++++++++++++ .../src/cli/prover/mod.rs | 0 .../src/cli/prover/sharp.rs | 0 .../src/cli/queue/aws_sqs.rs | 0 .../src/cli/queue/mod.rs | 0 .../{orchestrator => utils}/src/cli/server.rs | 0 .../src/cli/settlement/ethereum.rs | 4 +- crates/utils/src/cli/settlement/mod.rs | 9 + .../src/cli/settlement/starknet.rs | 5 +- .../{orchestrator => utils}/src/cli/snos.rs | 0 .../src/cli/storage/aws_s3.rs | 0 .../src/cli/storage/mod.rs | 0 crates/utils/src/lib.rs | 1 + 32 files changed, 328 insertions(+), 229 deletions(-) delete mode 100644 crates/orchestrator/src/cli/mod.rs delete mode 100644 crates/orchestrator/src/cli/settlement/mod.rs rename crates/{orchestrator => utils}/src/cli/alert/aws_sns.rs (100%) rename crates/{orchestrator => utils}/src/cli/alert/mod.rs (100%) rename crates/{orchestrator => utils}/src/cli/aws_config.rs (100%) rename crates/{orchestrator => utils}/src/cli/da/ethereum.rs (100%) rename crates/{orchestrator => utils}/src/cli/da/mod.rs (100%) rename crates/{orchestrator => utils}/src/cli/database/mod.rs (100%) rename crates/{orchestrator => utils}/src/cli/database/mongodb.rs (100%) rename crates/{orchestrator => utils}/src/cli/instrumentation.rs (100%) create mode 100644 crates/utils/src/cli/mod.rs rename crates/{orchestrator => utils}/src/cli/prover/mod.rs (100%) rename crates/{orchestrator => utils}/src/cli/prover/sharp.rs (100%) rename crates/{orchestrator => utils}/src/cli/queue/aws_sqs.rs (100%) rename crates/{orchestrator => utils}/src/cli/queue/mod.rs (100%) rename crates/{orchestrator => utils}/src/cli/server.rs (100%) rename crates/{orchestrator => utils}/src/cli/settlement/ethereum.rs (95%) create mode 100644 crates/utils/src/cli/settlement/mod.rs rename crates/{orchestrator => utils}/src/cli/settlement/starknet.rs (92%) rename crates/{orchestrator => utils}/src/cli/snos.rs (100%) rename crates/{orchestrator => utils}/src/cli/storage/aws_s3.rs (100%) rename crates/{orchestrator => utils}/src/cli/storage/mod.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 8d68fc54..a03e4d8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10870,6 +10870,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" name = "utils" version = "0.1.0" dependencies = [ + "clap", "color-eyre", "opentelemetry", "opentelemetry-appender-tracing", @@ -10883,6 +10884,7 @@ dependencies = [ "tracing-core", "tracing-opentelemetry", "tracing-subscriber", + "url", ] [[package]] diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs deleted file mode 100644 index 76a69596..00000000 --- a/crates/orchestrator/src/cli/mod.rs +++ /dev/null @@ -1,107 +0,0 @@ -use clap::ArgGroup; -use url::Url; - -pub mod aws_config; -pub mod database; -pub mod instrumentation; -pub mod server; -pub mod storage; -pub mod queue; -pub mod alert; -pub mod prover; -pub mod da; -pub mod settlement; -pub mod snos; - -#[derive(Clone, Debug, clap::Parser)] -#[clap( - group( - ArgGroup::new("storage") - .args(&["aws_s3"]) - .required(true) - .multiple(false) - ), - - group( - ArgGroup::new("queue") - .args(&["aws_sqs"]) - .required(true) - .multiple(false) - ), - - group( - ArgGroup::new("alert") - .args(&["aws_sns"]) - .required(true) - .multiple(false) - ), - - group( - ArgGroup::new("prover") - .args(&["sharp"]) - .required(true) - .multiple(false) - ), - - group( - ArgGroup::new("settlement_layer") - .args(&["ethereum", "starknet"]) - .required(true) - .multiple(false) - ), - - group( - ArgGroup::new("da_layer") - .args(&["ethereum"]) - .required(true) - .multiple(false) - ), -)] - -pub struct RunCmd { - #[clap(flatten)] - pub server: server::ServerParams, - - #[clap(flatten)] - pub aws_config: aws_config::AWSConfigParams, - - // part of storage - #[clap(flatten)] - pub aws_s3: storage::aws_s3::AWSS3Params, - - // part of queue - #[clap(flatten)] - pub aws_sqs: queue::aws_sqs::AWSSQSParams, - - // part of alert - #[clap(flatten)] - pub aws_sns: alert::aws_sns::AWSSNSParams, - - - // part of database - #[clap(flatten)] - pub mongodb: database::mongodb::MongoDBParams, - - // part of prover - #[clap(flatten)] - pub sharp: prover::sharp::SharpParams, - - // part of da_layer - #[clap(flatten)] - pub ethereum_da: da::ethereum::EthereumParams, - - - #[clap(flatten)] - pub starknet_settlement: settlement::starknet::StarknetSettlementParams, - - #[clap(flatten)] - pub ethereum_settlement: settlement::ethereum::EthereumSettlementParams, - - #[clap(flatten)] - pub snos: snos::SNOSParams, - - pub madara_rpc_url: Url, - - #[clap(flatten)] - pub instrumentation: instrumentation::InstrumentationParams, -} diff --git a/crates/orchestrator/src/cli/settlement/mod.rs b/crates/orchestrator/src/cli/settlement/mod.rs deleted file mode 100644 index 5afbc73e..00000000 --- a/crates/orchestrator/src/cli/settlement/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod ethereum; -pub mod starknet; diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 927bf243..a762afa2 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -9,6 +9,7 @@ use alloy::providers::RootProvider; use aws_config::meta::region::RegionProviderChain; use aws_config::{Region, SdkConfig}; use aws_credential_types::Credentials; +use color_eyre::eyre::eyre; use da_client_interface::DaClient; use dotenvy::dotenv; use ethereum_da_client::config::EthereumDaConfig; @@ -19,6 +20,8 @@ use sharp_service::SharpProverService; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Url}; use starknet_settlement_client::StarknetSettlementClient; +use utils::cli::settlement::SettlementParams; +use utils::cli::RunCmd; use utils::env_utils::get_env_var_or_panic; use utils::settings::env::EnvSettingsProvider; use utils::settings::Settings; @@ -90,7 +93,7 @@ pub async fn get_aws_config(settings_provider: &impl Settings) -> SdkConfig { } /// Initializes the app config -pub async fn init_config() -> color_eyre::Result> { +pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { dotenv().ok(); let settings_provider = EnvSettingsProvider {}; @@ -104,7 +107,10 @@ pub async fn init_config() -> color_eyre::Result> { // init database let database = build_database_client(&settings_provider).await; let da_client = build_da_client(&settings_provider).await; - let settlement_client = build_settlement_client(&settings_provider).await?; + + let settlement_params = run_cmd.clone().validate_settlement_params().map_err(|e| eyre!("Failed to validate settlement params: {e}"))?; + let settlement_client = build_settlement_client(&settlement_params).await?; + let prover_client = build_prover_service(&settings_provider); let storage_client = build_storage_client(&settings_provider, provider_config.clone()).await; let alerts_client = build_alert_client(&settings_provider, provider_config.clone()).await; @@ -231,27 +237,43 @@ pub fn build_prover_service(settings_provider: &impl Settings) -> Box color_eyre::Result> { - match get_env_var_or_panic("SETTLEMENT_LAYER").as_str() { - "ethereum" => { + match settlement_params { + SettlementParams::Ethereum(ethereum_settlement_params) => { #[cfg(not(feature = "testing"))] { - Ok(Box::new(EthereumSettlementClient::new_with_settings(settings_provider))) + Ok(Box::new(EthereumSettlementClient::new_with_settings(ðereum_settlement_params))) } #[cfg(feature = "testing")] { Ok(Box::new(EthereumSettlementClient::with_test_settings( - RootProvider::new_http(get_env_var_or_panic("SETTLEMENT_RPC_URL").as_str().parse()?), - Address::from_str(&get_env_var_or_panic("L1_CORE_CONTRACT_ADDRESS"))?, - Url::from_str(get_env_var_or_panic("SETTLEMENT_RPC_URL").as_str())?, - Some(Address::from_str(get_env_var_or_panic("STARKNET_OPERATOR_ADDRESS").as_str())?), + ðereum_settlement_params ))) } } - "starknet" => Ok(Box::new(StarknetSettlementClient::new_with_settings(settings_provider).await)), - _ => panic!("Unsupported Settlement layer"), + SettlementParams::Starknet(starknet_settlement_params) => Ok(Box::new(StarknetSettlementClient::new_with_settings(&starknet_settlement_params).await)), } + + // match settlement_params { + // "ethereum" => { + // #[cfg(not(feature = "testing"))] + // { + // Ok(Box::new(EthereumSettlementClient::new_with_settings(settings_provider))) + // } + // #[cfg(feature = "testing")] + // { + // Ok(Box::new(EthereumSettlementClient::with_test_settings( + // RootProvider::new_http(get_env_var_or_panic("SETTLEMENT_RPC_URL").as_str().parse()?), + // Address::from_str(&get_env_var_or_panic("L1_CORE_CONTRACT_ADDRESS"))?, + // Url::from_str(get_env_var_or_panic("SETTLEMENT_RPC_URL").as_str())?, + // Some(Address::from_str(get_env_var_or_panic("STARKNET_OPERATOR_ADDRESS").as_str())?), + // ))) + // } + // } + // "starknet" => Ok(Box::new(StarknetSettlementClient::new_with_settings(settings_provider).await)), + // _ => panic!("Unsupported Settlement layer"), + // } } pub async fn build_storage_client( diff --git a/crates/orchestrator/src/lib.rs b/crates/orchestrator/src/lib.rs index fcf135b3..aef82a08 100644 --- a/crates/orchestrator/src/lib.rs +++ b/crates/orchestrator/src/lib.rs @@ -25,7 +25,4 @@ pub mod telemetry; #[cfg(test)] pub mod tests; /// Contains workers which act like cron jobs -pub mod workers; - -// Contains CLI arguments -pub mod cli; +pub mod workers; \ No newline at end of file diff --git a/crates/orchestrator/src/main.rs b/crates/orchestrator/src/main.rs index 3d6d2433..bbf3d98d 100644 --- a/crates/orchestrator/src/main.rs +++ b/crates/orchestrator/src/main.rs @@ -1,9 +1,10 @@ +use clap::Parser as _; use dotenvy::dotenv; use orchestrator::config::init_config; use orchestrator::queue::init_consumers; use orchestrator::routes::setup_server; use orchestrator::telemetry::{setup_analytics, shutdown_analytics}; -use orchestrator::cli::RunCmd; +use utils::cli::RunCmd; /// Start the server #[tokio::main] @@ -12,6 +13,9 @@ use orchestrator::cli::RunCmd; #[allow(clippy::needless_return)] async fn main() { dotenv().ok(); + + let mut run_cmd: RunCmd = RunCmd::parse(); + // Analytics Setup let meter_provider = setup_analytics(); tracing::info!(service = "orchestrator", "Starting orchestrator service"); @@ -19,7 +23,7 @@ async fn main() { color_eyre::install().expect("Unable to install color_eyre"); // initial config setup - let config = init_config().await.expect("Config instantiation failed"); + let config = init_config(&run_cmd).await.expect("Config instantiation failed"); tracing::debug!(service = "orchestrator", "Configuration initialized"); // initialize the server diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 1737614b..6c0ef4e4 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -2,6 +2,8 @@ use std::net::SocketAddr; use std::sync::Arc; use axum::Router; +use clap::Parser; +use color_eyre::eyre::eyre; use da_client_interface::{DaClient, MockDaClient}; use httpmock::MockServer; use prover_client_interface::{MockProverClient, ProverClient}; @@ -9,6 +11,7 @@ use settlement_client_interface::{MockSettlementClient, SettlementClient}; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::JsonRpcClient; use url::Url; +use utils::cli::RunCmd; use utils::settings::env::EnvSettingsProvider; use utils::settings::Settings; @@ -179,7 +182,7 @@ impl TestConfigBuilder { } pub async fn build(self) -> TestConfigBuilderReturns { - dotenvy::from_filename("../.env.test").expect("Failed to load the .env.test file"); + let mut run_cmd: RunCmd = RunCmd::parse(); let settings_provider = EnvSettingsProvider {}; let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(&settings_provider).await))); @@ -204,8 +207,10 @@ impl TestConfigBuilder { let alerts = implement_client::init_alerts(alerts_type, &settings_provider, provider_config.clone()).await; let da_client = implement_client::init_da_client(da_client_type, &settings_provider).await; + let settlement_params = run_cmd.clone().validate_settlement_params().unwrap(); let settlement_client = - implement_client::init_settlement_client(settlement_client_type, &settings_provider).await; + implement_client::init_settlement_client(settlement_client_type, &settlement_params + ).await; let prover_client = implement_client::init_prover_client(prover_client_type, &settings_provider).await; @@ -277,6 +282,7 @@ pub mod implement_client { use settlement_client_interface::{MockSettlementClient, SettlementClient}; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Url}; + use utils::cli::settlement::SettlementParams; use utils::env_utils::get_env_var_or_panic; use utils::settings::env::EnvSettingsProvider; use utils::settings::Settings; @@ -324,12 +330,12 @@ pub mod implement_client { pub(crate) async fn init_settlement_client( service: ConfigType, - settings_provider: &impl Settings, + settlement_cfg : &SettlementParams ) -> Box { match service { ConfigType::Mock(client) => client.into(), ConfigType::Actual => { - build_settlement_client(settings_provider).await.expect("Failed to initialise settlement_client") + build_settlement_client(settlement_cfg).await.expect("Failed to initialise settlement_client") } ConfigType::Dummy => Box::new(MockSettlementClient::new()), } diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index f7c4cf5c..9b503c7a 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -25,6 +25,7 @@ use conversion::{get_input_data_for_eip_4844, prepare_sidecar}; use settlement_client_interface::{SettlementClient, SettlementVerificationStatus}; #[cfg(feature = "testing")] use url::Url; +use utils::cli::settlement::ethereum::EthereumSettlementParams; use utils::env_utils::get_env_var_or_panic; use crate::clients::interfaces::validity_interface::StarknetValidityContractTrait; @@ -74,23 +75,25 @@ pub struct EthereumSettlementClient { } impl EthereumSettlementClient { - pub fn new_with_settings(settings: &impl Settings) -> Self { - let settlement_cfg = EthereumSettlementConfig::new_with_settings(settings); - let private_key = get_env_var_or_panic(ENV_PRIVATE_KEY); + pub fn new_with_settings(settlement_cfg: &EthereumSettlementParams) -> Self { + // let settlement_cfg = EthereumSettlementConfig::new_with_settings(settings);3 + // TODO: can pass the actual struct here no ned for reference + let private_key = settlement_cfg.ethereum_private_key.clone(); let signer: PrivateKeySigner = private_key.parse().expect("Failed to parse private key"); let wallet_address = signer.address(); let wallet = EthereumWallet::from(signer); // provider without wallet - let provider = Arc::new(ProviderBuilder::new().on_http(settlement_cfg.rpc_url.clone())); + let provider = Arc::new(ProviderBuilder::new().on_http(settlement_cfg.ethereum_rpc_url.clone())); // provider with wallet let filler_provider = Arc::new( - ProviderBuilder::new().with_recommended_fillers().wallet(wallet.clone()).on_http(settlement_cfg.rpc_url), + ProviderBuilder::new().with_recommended_fillers().wallet(wallet.clone()).on_http(settlement_cfg.ethereum_rpc_url.clone()), ); + let core_contract_client = StarknetValidityContractClient::new( - Address::from_str(&settlement_cfg.core_contract_address) + Address::from_str(&settlement_cfg.l1_core_contract_address) .expect("Failed to convert the validity contract address.") .0 .into(), @@ -102,18 +105,18 @@ impl EthereumSettlementClient { #[cfg(feature = "testing")] pub fn with_test_settings( - provider: RootProvider>, - core_contract_address: Address, - rpc_url: Url, - impersonate_account: Option
, + settlement_cfg: &EthereumSettlementParams, ) -> Self { - let private_key = get_env_var_or_panic(ENV_PRIVATE_KEY); + let root_provider = RootProvider::new_http(settlement_cfg.ethereum_rpc_url.clone().as_str().parse()?); + let core_contract_address = Address::from_str(&settlement_cfg.l1_core_contract_address.clone())?; + let settlement_rpc_url = Url::from_str(&settlement_cfg.ethereum_rpc_url.clone())?; + let private_key = &settlement_cfg.ethereum_private_key.clone(); let signer: PrivateKeySigner = private_key.parse().expect("Failed to parse private key"); let wallet_address = signer.address(); let wallet = EthereumWallet::from(signer); let fill_provider = - Arc::new(ProviderBuilder::new().with_recommended_fillers().wallet(wallet.clone()).on_http(rpc_url)); + Arc::new(ProviderBuilder::new().with_recommended_fillers().wallet(wallet.clone()).on_http(settlement_rpc_url)); let core_contract_client = StarknetValidityContractClient::new(core_contract_address, fill_provider); diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index c3bae338..5b0fb4fe 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -22,6 +22,7 @@ use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Provider}; use starknet::signers::{LocalWallet, SigningKey}; use tokio::time::{sleep, Duration}; +use utils::cli::settlement::starknet::StarknetSettlementParams; use utils::settings::Settings; use crate::config::StarknetSettlementConfig; @@ -41,25 +42,24 @@ pub const ENV_PRIVATE_KEY: &str = "STARKNET_PRIVATE_KEY"; const MAX_RETRIES_VERIFY_TX_FINALITY: usize = 10; -// Assumed the contract called for settlement l ooks like: +// Assumed the contract called for settlement looks like: // https://github.com/keep-starknet-strange/piltover impl StarknetSettlementClient { - pub async fn new_with_settings(settings: &impl Settings) -> Self { - let settlement_cfg = StarknetSettlementConfig::new_with_settings(settings); + pub async fn new_with_settings(settlement_cfg: &StarknetSettlementParams) -> Self { let provider: Arc> = - Arc::new(JsonRpcClient::new(HttpTransport::new(settlement_cfg.rpc_url.clone()))); + Arc::new(JsonRpcClient::new(HttpTransport::new(settlement_cfg.starknet_rpc_url.clone()))); - let public_key = settings.get_settings_or_panic(ENV_ACCOUNT_ADDRESS); + let public_key = settlement_cfg.starknet_account_address.clone(); let signer_address = Felt::from_hex(&public_key).expect("invalid signer address"); // TODO: Very insecure way of building the signer. Needs to be adjusted. - let private_key = settings.get_settings_or_panic(ENV_PRIVATE_KEY); + let private_key = settlement_cfg.starknet_private_key.clone(); let signer = Felt::from_hex(&private_key).expect("Invalid private key"); let signer = LocalWallet::from(SigningKey::from_secret_scalar(signer)); let core_contract_address = - Felt::from_hex(&settlement_cfg.core_contract_address).expect("Invalid core contract address"); + Felt::from_hex(&settlement_cfg.starknet_cairo_core_contract_address).expect("Invalid core contract address"); let account: Arc>, LocalWallet>> = Arc::new(SingleOwnerAccount::new( @@ -77,7 +77,7 @@ impl StarknetSettlementClient { account, core_contract_address, starknet_core_contract_client, - tx_finality_retry_delay_in_seconds: settlement_cfg.tx_finality_retry_delay_in_seconds, + tx_finality_retry_delay_in_seconds: settlement_cfg.starknet_finality_retry_wait_in_secs, } } } diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index f5eedad2..eea5535b 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -99,80 +99,83 @@ async fn setup(#[future] spin_up_madara: MadaraCmd) -> (LocalWalletSignerMiddlew (Arc::new(account), madara_process) } -#[rstest] -#[tokio::test] -async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) { - let (account, _madara_process) = setup.await; - - let project_root = Path::new(env!("CARGO_MANIFEST_DIR")).ancestors().nth(3).unwrap(); - let contract_path = project_root.join("crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev"); - let sierra_class: SierraClass = serde_json::from_reader( - std::fs::File::open(contract_path.join("mock_contracts_Piltover.contract_class.json")) - .expect("Could not open sierra class file"), - ) - .expect("Failed to parse SierraClass"); - - let compiled_class: CompiledClass = serde_json::from_reader( - std::fs::File::open(contract_path.join("mock_contracts_Piltover.compiled_contract_class.json")) - .expect("Could not open compiled class file"), - ) - .expect("Failed to parse CompiledClass"); - - let flattened_class = sierra_class.clone().flatten().unwrap(); - let compiled_class_hash = compiled_class.class_hash().unwrap(); - - let DeclareTransactionResult { transaction_hash: declare_tx_hash, class_hash: _ } = - account.declare_v2(Arc::new(flattened_class.clone()), compiled_class_hash).send().await.unwrap(); - tracing::debug!("declare tx hash {:?}", declare_tx_hash); - - let is_success = wait_for_tx(&account, declare_tx_hash, Duration::from_secs(2)).await; - assert!(is_success, "Declare trasactiion failed"); - - let contract_factory = ContractFactory::new(flattened_class.class_hash(), account.clone()); - let deploy_v1 = contract_factory.deploy_v1(vec![], felt!("1122"), false); - let deployed_address = deploy_v1.deployed_address(); - - env::set_var("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", deployed_address.to_hex_string()); - let InvokeTransactionResult { transaction_hash: deploy_tx_hash } = - deploy_v1.send().await.expect("Unable to deploy contract"); - - let is_success = wait_for_tx(&account, deploy_tx_hash, Duration::from_secs(2)).await; - assert!(is_success, "Deploy trasaction failed"); - - let env_settings = EnvSettingsProvider {}; - let settlement_client = StarknetSettlementClient::new_with_settings(&env_settings).await; - let onchain_data_hash = [1; 32]; - let mut program_output = Vec::with_capacity(32); - program_output.fill(onchain_data_hash); - let update_state_tx_hash = settlement_client - .update_state_calldata(program_output, onchain_data_hash, [1; 32]) - .await - .expect("Sending Update state"); - - tracing::debug!("update state tx hash {:?}", update_state_tx_hash); - - let is_success = wait_for_tx( - &account, - Felt::from_hex(&update_state_tx_hash).expect("Incorrect transaction hash"), - Duration::from_secs(2), - ) - .await; - assert!(is_success, "Update state transaction failed/reverted"); - - let call_result = account - .provider() - .call( - FunctionCall { - contract_address: deployed_address, - entry_point_selector: selector!("get_is_updated"), - calldata: vec![Felt::from_bytes_be_slice(&onchain_data_hash)], - }, - BlockId::Tag(BlockTag::Latest), - ) - .await - .expect("failed to call the contract"); - assert!(call_result[0] == true.into(), "Should be updated"); -} +// TODO: Why is this code not going through the TestConfigBuilder? +// #[rstest] +// #[tokio::test] +// async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) { +// let (account, _madara_process) = setup.await; + +// let project_root = Path::new(env!("CARGO_MANIFEST_DIR")).ancestors().nth(3).unwrap(); +// let contract_path = project_root.join("crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev"); +// let sierra_class: SierraClass = serde_json::from_reader( +// std::fs::File::open(contract_path.join("mock_contracts_Piltover.contract_class.json")) +// .expect("Could not open sierra class file"), +// ) +// .expect("Failed to parse SierraClass"); + +// let compiled_class: CompiledClass = serde_json::from_reader( +// std::fs::File::open(contract_path.join("mock_contracts_Piltover.compiled_contract_class.json")) +// .expect("Could not open compiled class file"), +// ) +// .expect("Failed to parse CompiledClass"); + +// let flattened_class = sierra_class.clone().flatten().unwrap(); +// let compiled_class_hash = compiled_class.class_hash().unwrap(); + +// let DeclareTransactionResult { transaction_hash: declare_tx_hash, class_hash: _ } = +// account.declare_v2(Arc::new(flattened_class.clone()), compiled_class_hash).send().await.unwrap(); +// tracing::debug!("declare tx hash {:?}", declare_tx_hash); + +// let is_success = wait_for_tx(&account, declare_tx_hash, Duration::from_secs(2)).await; +// assert!(is_success, "Declare trasactiion failed"); + +// let contract_factory = ContractFactory::new(flattened_class.class_hash(), account.clone()); +// let deploy_v1 = contract_factory.deploy_v1(vec![], felt!("1122"), false); +// let deployed_address = deploy_v1.deployed_address(); + +// env::set_var("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", deployed_address.to_hex_string()); +// let InvokeTransactionResult { transaction_hash: deploy_tx_hash } = +// deploy_v1.send().await.expect("Unable to deploy contract"); + +// let is_success = wait_for_tx(&account, deploy_tx_hash, Duration::from_secs(2)).await; +// assert!(is_success, "Deploy trasaction failed"); + +// let env_settings = EnvSettingsProvider {}; +// let settlement_params = run_cmd.clone().validate_settlement_params().unwrap(); + +// let settlement_client = StarknetSettlementClient::new_with_settings(&settlement_params).await; +// let onchain_data_hash = [1; 32]; +// let mut program_output = Vec::with_capacity(32); +// program_output.fill(onchain_data_hash); +// let update_state_tx_hash = settlement_client +// .update_state_calldata(program_output, onchain_data_hash, [1; 32]) +// .await +// .expect("Sending Update state"); + +// tracing::debug!("update state tx hash {:?}", update_state_tx_hash); + +// let is_success = wait_for_tx( +// &account, +// Felt::from_hex(&update_state_tx_hash).expect("Incorrect transaction hash"), +// Duration::from_secs(2), +// ) +// .await; +// assert!(is_success, "Update state transaction failed/reverted"); + +// let call_result = account +// .provider() +// .call( +// FunctionCall { +// contract_address: deployed_address, +// entry_point_selector: selector!("get_is_updated"), +// calldata: vec![Felt::from_bytes_be_slice(&onchain_data_hash)], +// }, +// BlockId::Tag(BlockTag::Latest), +// ) +// .await +// .expect("failed to call the contract"); +// assert!(call_result[0] == true.into(), "Should be updated"); +// } #[rstest] #[tokio::test] diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml index 59a5f9c5..80205f64 100644 --- a/crates/utils/Cargo.toml +++ b/crates/utils/Cargo.toml @@ -9,6 +9,8 @@ edition.workspace = true color-eyre = { workspace = true } serde.workspace = true thiserror.workspace = true +clap = { version = "4.4", features = ["derive", "env"] } +url = { workspace = true } #Instrumentation opentelemetry = { workspace = true, features = ["metrics", "logs"] } diff --git a/crates/orchestrator/src/cli/alert/aws_sns.rs b/crates/utils/src/cli/alert/aws_sns.rs similarity index 100% rename from crates/orchestrator/src/cli/alert/aws_sns.rs rename to crates/utils/src/cli/alert/aws_sns.rs diff --git a/crates/orchestrator/src/cli/alert/mod.rs b/crates/utils/src/cli/alert/mod.rs similarity index 100% rename from crates/orchestrator/src/cli/alert/mod.rs rename to crates/utils/src/cli/alert/mod.rs diff --git a/crates/orchestrator/src/cli/aws_config.rs b/crates/utils/src/cli/aws_config.rs similarity index 100% rename from crates/orchestrator/src/cli/aws_config.rs rename to crates/utils/src/cli/aws_config.rs diff --git a/crates/orchestrator/src/cli/da/ethereum.rs b/crates/utils/src/cli/da/ethereum.rs similarity index 100% rename from crates/orchestrator/src/cli/da/ethereum.rs rename to crates/utils/src/cli/da/ethereum.rs diff --git a/crates/orchestrator/src/cli/da/mod.rs b/crates/utils/src/cli/da/mod.rs similarity index 100% rename from crates/orchestrator/src/cli/da/mod.rs rename to crates/utils/src/cli/da/mod.rs diff --git a/crates/orchestrator/src/cli/database/mod.rs b/crates/utils/src/cli/database/mod.rs similarity index 100% rename from crates/orchestrator/src/cli/database/mod.rs rename to crates/utils/src/cli/database/mod.rs diff --git a/crates/orchestrator/src/cli/database/mongodb.rs b/crates/utils/src/cli/database/mongodb.rs similarity index 100% rename from crates/orchestrator/src/cli/database/mongodb.rs rename to crates/utils/src/cli/database/mongodb.rs diff --git a/crates/orchestrator/src/cli/instrumentation.rs b/crates/utils/src/cli/instrumentation.rs similarity index 100% rename from crates/orchestrator/src/cli/instrumentation.rs rename to crates/utils/src/cli/instrumentation.rs diff --git a/crates/utils/src/cli/mod.rs b/crates/utils/src/cli/mod.rs new file mode 100644 index 00000000..680d96c4 --- /dev/null +++ b/crates/utils/src/cli/mod.rs @@ -0,0 +1,158 @@ +use clap::ArgGroup; +use settlement::SettlementParams; + +pub mod aws_config; +pub mod database; +pub mod instrumentation; +pub mod server; +pub mod storage; +pub mod queue; +pub mod alert; +pub mod prover; +pub mod da; +pub mod settlement; +pub mod snos; + +#[derive(Clone, Debug, clap::Parser)] +#[clap( + + // Mutual Exclusion Solved + group( + ArgGroup::new("settlement_layer") + .args(&["ethereum", "starknet"]) + .required(true) + .multiple(false) + ), + + // Solving + + // group( + // ArgGroup::new("storage") + // .args(&["aws_s3"]) + // .required(true) + // .multiple(false) + // ), + + // group( + // ArgGroup::new("queue") + // .args(&["aws_sqs"]) + // .required(true) + // .multiple(false) + // ), + + // group( + // ArgGroup::new("alert") + // .args(&["aws_sns"]) + // .required(true) + // .multiple(false) + // ), + + // group( + // ArgGroup::new("prover") + // .args(&["sharp"]) + // .required(true) + // .multiple(false) + // ), + + + + // group( + // ArgGroup::new("da_layer") + // .args(&["ethereum"]) + // .required(true) + // .multiple(false) + // ), +)] + +pub struct RunCmd { + + #[clap(long, group = "settlement_layer")] + pub ethereum: bool, + + #[clap(long, group = "settlement_layer")] + pub starknet: bool, + + #[clap(flatten)] + ethereum_settlement_params: Option, + + #[clap(flatten)] + starknet_settlement_params: Option, + + // #[clap(flatten)] + // pub server: server::ServerParams, + + // #[clap(flatten)] + // pub aws_config: aws_config::AWSConfigParams, + + // // part of storage + // #[clap(flatten)] + // pub aws_s3: storage::aws_s3::AWSS3Params, + + // // part of queue + // #[clap(flatten)] + // pub aws_sqs: queue::aws_sqs::AWSSQSParams, + + // // part of alert + // #[clap(flatten)] + // pub aws_sns: alert::aws_sns::AWSSNSParams, + + + // // part of database + // #[clap(flatten)] + // pub mongodb: database::mongodb::MongoDBParams, + + // // part of prover + // #[clap(flatten)] + // pub sharp: prover::sharp::SharpParams, + + // // part of da_layer + // #[clap(flatten)] + // pub ethereum_da: da::ethereum::EthereumParams, + + + // #[clap(flatten)] + // pub starknet_settlement: settlement::starknet::StarknetSettlementParams, + + // #[clap(flatten)] + // pub ethereum_settlement: settlement::ethereum::EthereumSettlementParams, + + // #[clap(flatten)] + // pub snos: snos::SNOSParams, + + // pub madara_rpc_url: Url, + + // #[clap(flatten)] + // pub instrumentation: instrumentation::InstrumentationParams, +} + +impl RunCmd { + pub fn validate_settlement_params(self) -> Result { + match (self.ethereum, self.starknet) { + (true, false) => { + // Ensure Starknet params are not provided + if self.starknet_settlement_params.is_some() { + return Err("Starknet parameters cannot be specified when Ethereum settlement is selected".to_string()); + } + + // Get Ethereum params or error if none provided + self.ethereum_settlement_params + .map(SettlementParams::Ethereum) + .ok_or_else(|| "Ethereum parameters must be provided when Ethereum settlement is selected".to_string()) + } + (false, true) => { + // Ensure Ethereum params are not provided + if self.ethereum_settlement_params.is_some() { + return Err("Ethereum parameters cannot be specified when Starknet settlement is selected".to_string()); + } + + // Get Starknet params or error if none provided + self.starknet_settlement_params + .map(SettlementParams::Starknet) + .ok_or_else(|| "Starknet parameters must be provided when Starknet settlement is selected".to_string()) + } + (true, true) | (false, false) => { + Err("Exactly one settlement layer must be selected".to_string()) + } + } + } +} \ No newline at end of file diff --git a/crates/orchestrator/src/cli/prover/mod.rs b/crates/utils/src/cli/prover/mod.rs similarity index 100% rename from crates/orchestrator/src/cli/prover/mod.rs rename to crates/utils/src/cli/prover/mod.rs diff --git a/crates/orchestrator/src/cli/prover/sharp.rs b/crates/utils/src/cli/prover/sharp.rs similarity index 100% rename from crates/orchestrator/src/cli/prover/sharp.rs rename to crates/utils/src/cli/prover/sharp.rs diff --git a/crates/orchestrator/src/cli/queue/aws_sqs.rs b/crates/utils/src/cli/queue/aws_sqs.rs similarity index 100% rename from crates/orchestrator/src/cli/queue/aws_sqs.rs rename to crates/utils/src/cli/queue/aws_sqs.rs diff --git a/crates/orchestrator/src/cli/queue/mod.rs b/crates/utils/src/cli/queue/mod.rs similarity index 100% rename from crates/orchestrator/src/cli/queue/mod.rs rename to crates/utils/src/cli/queue/mod.rs diff --git a/crates/orchestrator/src/cli/server.rs b/crates/utils/src/cli/server.rs similarity index 100% rename from crates/orchestrator/src/cli/server.rs rename to crates/utils/src/cli/server.rs diff --git a/crates/orchestrator/src/cli/settlement/ethereum.rs b/crates/utils/src/cli/settlement/ethereum.rs similarity index 95% rename from crates/orchestrator/src/cli/settlement/ethereum.rs rename to crates/utils/src/cli/settlement/ethereum.rs index f59917d8..882cdba6 100644 --- a/crates/orchestrator/src/cli/settlement/ethereum.rs +++ b/crates/utils/src/cli/settlement/ethereum.rs @@ -1,5 +1,5 @@ use clap::Args; - +use url::Url; // SETTLEMENT_RPC_URL="https://eth-sepolia.public.blastapi.io" // ETHEREUM_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" @@ -11,7 +11,7 @@ use clap::Args; pub struct EthereumSettlementParams { /// The URL of the Ethereum RPC node. #[arg(env = "ETHEREUM_SETTLEMENT_RPC_URL", long)] - pub ethereum_rpc_url: String, + pub ethereum_rpc_url: Url, /// The private key of the Ethereum account. #[arg(env = "ETHEREUM_PRIVATE_KEY", long)] diff --git a/crates/utils/src/cli/settlement/mod.rs b/crates/utils/src/cli/settlement/mod.rs new file mode 100644 index 00000000..50d39c06 --- /dev/null +++ b/crates/utils/src/cli/settlement/mod.rs @@ -0,0 +1,9 @@ +pub mod ethereum; +pub mod starknet; + + +#[derive(Clone, Debug)] +pub enum SettlementParams { + Ethereum(ethereum::EthereumSettlementParams), + Starknet(starknet::StarknetSettlementParams), +} \ No newline at end of file diff --git a/crates/orchestrator/src/cli/settlement/starknet.rs b/crates/utils/src/cli/settlement/starknet.rs similarity index 92% rename from crates/orchestrator/src/cli/settlement/starknet.rs rename to crates/utils/src/cli/settlement/starknet.rs index 69d6b79a..41261baa 100644 --- a/crates/orchestrator/src/cli/settlement/starknet.rs +++ b/crates/utils/src/cli/settlement/starknet.rs @@ -1,4 +1,5 @@ use clap::Args; +use url::Url; // STARKNET_RPC_URL="https://starknet-sepolia.public.blastapi.io" @@ -13,7 +14,7 @@ use clap::Args; pub struct StarknetSettlementParams { /// The URL of the Ethereum RPC node. #[arg(env = "STARKNET_RPC_URL", long)] - pub starknet_rpc_url: String, + pub starknet_rpc_url: Url, /// The private key of the Ethereum account. #[arg(env = "STARKNET_PRIVATE_KEY", long)] @@ -29,7 +30,7 @@ pub struct StarknetSettlementParams { /// The number of seconds to wait for finality. #[arg(env = "STARKNET_FINALITY_RETRY_WAIT_IN_SECS", long)] - pub starknet_finality_retry_wait_in_secs: String, + pub starknet_finality_retry_wait_in_secs: u64, /// The path to the Madara binary. #[arg(env = "MADARA_BINARY_PATH", long)] diff --git a/crates/orchestrator/src/cli/snos.rs b/crates/utils/src/cli/snos.rs similarity index 100% rename from crates/orchestrator/src/cli/snos.rs rename to crates/utils/src/cli/snos.rs diff --git a/crates/orchestrator/src/cli/storage/aws_s3.rs b/crates/utils/src/cli/storage/aws_s3.rs similarity index 100% rename from crates/orchestrator/src/cli/storage/aws_s3.rs rename to crates/utils/src/cli/storage/aws_s3.rs diff --git a/crates/orchestrator/src/cli/storage/mod.rs b/crates/utils/src/cli/storage/mod.rs similarity index 100% rename from crates/orchestrator/src/cli/storage/mod.rs rename to crates/utils/src/cli/storage/mod.rs diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs index e374f6c5..68a63379 100644 --- a/crates/utils/src/lib.rs +++ b/crates/utils/src/lib.rs @@ -2,6 +2,7 @@ pub mod collections; pub mod env_utils; pub mod metrics; pub mod settings; +pub mod cli; /// Evaluate `$x:expr` and if not true return `Err($y:expr)`. /// From 9cb3702eaf1ac5ec4ae2df746c0065eedadbb5a0 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 6 Nov 2024 10:16:52 +0530 Subject: [PATCH 03/63] update: working instrumentation run_cmd --- crates/orchestrator/src/main.rs | 8 +- crates/orchestrator/src/telemetry.rs | 99 +++++++++++++------------ crates/utils/src/cli/instrumentation.rs | 12 ++- crates/utils/src/cli/mod.rs | 12 +-- 4 files changed, 70 insertions(+), 61 deletions(-) diff --git a/crates/orchestrator/src/main.rs b/crates/orchestrator/src/main.rs index bbf3d98d..e29337cf 100644 --- a/crates/orchestrator/src/main.rs +++ b/crates/orchestrator/src/main.rs @@ -13,11 +13,11 @@ use utils::cli::RunCmd; #[allow(clippy::needless_return)] async fn main() { dotenv().ok(); - - let mut run_cmd: RunCmd = RunCmd::parse(); + // TODO: could this be an ARC ? + let run_cmd: RunCmd = RunCmd::parse(); // Analytics Setup - let meter_provider = setup_analytics(); + let meter_provider = setup_analytics(&run_cmd.instrumentation); tracing::info!(service = "orchestrator", "Starting orchestrator service"); color_eyre::install().expect("Unable to install color_eyre"); @@ -43,6 +43,6 @@ async fn main() { tokio::signal::ctrl_c().await.expect("Failed to listen for ctrl+c"); // Analytics Shutdown - shutdown_analytics(meter_provider); + shutdown_analytics(meter_provider, &run_cmd.instrumentation); tracing::info!(service = "orchestrator", "Orchestrator service shutting down"); } diff --git a/crates/orchestrator/src/telemetry.rs b/crates/orchestrator/src/telemetry.rs index f1be094b..ca916222 100644 --- a/crates/orchestrator/src/telemetry.rs +++ b/crates/orchestrator/src/telemetry.rs @@ -1,4 +1,3 @@ -use std::str::FromStr; use std::time::Duration; use opentelemetry::trace::TracerProvider; @@ -15,18 +14,17 @@ use tracing_opentelemetry::OpenTelemetryLayer; use tracing_subscriber::layer::SubscriberExt as _; use tracing_subscriber::util::SubscriberInitExt as _; use tracing_subscriber::EnvFilter; -use utils::env_utils::{get_env_var_optional, get_env_var_or_default}; +use url::Url; +use utils::cli::instrumentation::InstrumentationParams; pub struct OTELConfig { - endpoint: String, + endpoint: Url, service_name: String, } -pub fn setup_analytics() -> Option { - let otel_config = get_otel_config(); - - let log_level = get_env_var_or_default("RUST_LOG", "INFO"); - let level = Level::from_str(&log_level).unwrap_or(Level::INFO); +pub fn setup_analytics(instrumentation: &InstrumentationParams) -> Option { + let otel_config = get_otel_config(instrumentation); + let level = instrumentation.log_level; let tracing_subscriber = tracing_subscriber::registry() .with(tracing_subscriber::filter::LevelFilter::from_level(level)) @@ -53,21 +51,21 @@ pub fn setup_analytics() -> Option { } } -fn get_otel_config() -> Option { - let otel_endpoint = get_env_var_optional("OTEL_COLLECTOR_ENDPOINT").expect("Failed to get OTEL_COLLECTOR_ENDPOINT"); - let otel_service_name = get_env_var_optional("OTEL_SERVICE_NAME").expect("Failed to get OTEL_SERVICE_NAME"); +fn get_otel_config(instrumentation: &InstrumentationParams) -> Option { + let otel_endpoint = instrumentation.otel_collector_endpoint.clone(); + let otel_service_name = instrumentation.otel_service_name.clone(); - match (otel_endpoint, otel_service_name) { - (Some(endpoint), Some(service_name)) => Some(OTELConfig { endpoint, service_name }), + match otel_endpoint { + Some(endpoint) => Some(OTELConfig { endpoint, service_name: otel_service_name }), _ => { - tracing::warn!("OTEL_COLLECTOR_ENDPOINT or OTEL_SERVICE_NAME is not set"); + tracing::warn!("OTEL_COLLECTOR_ENDPOINT is not set"); None } } } -pub fn shutdown_analytics(meter_provider: Option) { - let otel_config = get_otel_config(); +pub fn shutdown_analytics(meter_provider: Option, instrumentation: &InstrumentationParams) { + let otel_config = get_otel_config(instrumentation); // guard clause if otel is disabled if otel_config.is_none() { @@ -144,12 +142,15 @@ fn init_logs(otel_config: &OTELConfig) -> Result, + + /// The log level. + #[arg(env = "RUST_LOG", long, default_value = "INFO")] + pub log_level: Level, } diff --git a/crates/utils/src/cli/mod.rs b/crates/utils/src/cli/mod.rs index 680d96c4..46e85e05 100644 --- a/crates/utils/src/cli/mod.rs +++ b/crates/utils/src/cli/mod.rs @@ -19,7 +19,7 @@ pub mod snos; // Mutual Exclusion Solved group( ArgGroup::new("settlement_layer") - .args(&["ethereum", "starknet"]) + .args(&["settle_on_ethereum", "settle_on_starknet"]) .required(true) .multiple(false) ), @@ -67,10 +67,10 @@ pub mod snos; pub struct RunCmd { #[clap(long, group = "settlement_layer")] - pub ethereum: bool, + pub settle_on_ethereum: bool, #[clap(long, group = "settlement_layer")] - pub starknet: bool, + pub settle_on_starknet: bool, #[clap(flatten)] ethereum_settlement_params: Option, @@ -121,13 +121,13 @@ pub struct RunCmd { // pub madara_rpc_url: Url, - // #[clap(flatten)] - // pub instrumentation: instrumentation::InstrumentationParams, + #[clap(flatten)] + pub instrumentation: instrumentation::InstrumentationParams, } impl RunCmd { pub fn validate_settlement_params(self) -> Result { - match (self.ethereum, self.starknet) { + match (self.settle_on_ethereum, self.settle_on_starknet) { (true, false) => { // Ensure Starknet params are not provided if self.starknet_settlement_params.is_some() { From 9be43e01e68c1fcce8c25916972755cb65371d4a Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 6 Nov 2024 11:19:15 +0530 Subject: [PATCH 04/63] update: run_cmd for storage --- crates/orchestrator/src/config.rs | 12 ++++--- .../src/data_storage/aws_s3/mod.rs | 10 +++--- crates/orchestrator/src/tests/common/mod.rs | 6 ++-- crates/orchestrator/src/tests/config.rs | 17 +++++---- .../src/tests/data_storage/mod.rs | 2 -- crates/settlement-clients/ethereum/src/lib.rs | 2 +- crates/utils/src/cli/mod.rs | 35 +++++++++++++------ crates/utils/src/cli/storage/aws_s3.rs | 2 +- crates/utils/src/cli/storage/mod.rs | 5 +++ 9 files changed, 57 insertions(+), 34 deletions(-) diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index a762afa2..6dccc908 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -21,6 +21,7 @@ use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Url}; use starknet_settlement_client::StarknetSettlementClient; use utils::cli::settlement::SettlementParams; +use utils::cli::storage::StorageParams; use utils::cli::RunCmd; use utils::env_utils::get_env_var_or_panic; use utils::settings::env::EnvSettingsProvider; @@ -112,7 +113,9 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { let settlement_client = build_settlement_client(&settlement_params).await?; let prover_client = build_prover_service(&settings_provider); - let storage_client = build_storage_client(&settings_provider, provider_config.clone()).await; + + let data_storage_params = run_cmd.clone().validate_storage_params().map_err(|e| eyre!("Failed to validate storage params: {e}"))?; + let storage_client = build_storage_client(&data_storage_params, provider_config.clone()).await; let alerts_client = build_alert_client(&settings_provider, provider_config.clone()).await; // init the queue @@ -277,12 +280,11 @@ pub async fn build_settlement_client( } pub async fn build_storage_client( - settings_provider: &impl Settings, + data_storage_params: &StorageParams, provider_config: Arc, ) -> Box { - match get_env_var_or_panic("DATA_STORAGE").as_str() { - "s3" => Box::new(AWSS3::new_with_settings(settings_provider, provider_config).await), - _ => panic!("Unsupported Storage Client"), + match data_storage_params { + StorageParams::AWSS3(aws_s3_params) => Box::new(AWSS3::new_with_settings(aws_s3_params, provider_config).await), } } diff --git a/crates/orchestrator/src/data_storage/aws_s3/mod.rs b/crates/orchestrator/src/data_storage/aws_s3/mod.rs index f57d46ae..5d9d7101 100644 --- a/crates/orchestrator/src/data_storage/aws_s3/mod.rs +++ b/crates/orchestrator/src/data_storage/aws_s3/mod.rs @@ -5,11 +5,10 @@ use aws_sdk_s3::primitives::ByteStream; use aws_sdk_s3::Client; use bytes::Bytes; use color_eyre::Result; -use utils::settings::Settings; +use utils::cli::storage::aws_s3::AWSS3Params; use crate::config::ProviderConfig; -use crate::data_storage::aws_s3::config::AWSS3Config; -use crate::data_storage::{DataStorage, DataStorageConfig}; +use crate::data_storage::DataStorage; pub const S3_SETTINGS_NAME: &str = "s3"; @@ -27,15 +26,14 @@ pub struct AWSS3 { /// - initializing a new AWS S3 client impl AWSS3 { /// To init the struct with main settings - pub async fn new_with_settings(settings: &impl Settings, provider_config: Arc) -> Self { - let s3_config = AWSS3Config::new_with_settings(settings); + pub async fn new_with_settings(s3_config: &AWSS3Params, provider_config: Arc) -> Self { let aws_config = provider_config.get_aws_client_or_panic(); // Building AWS S3 config let mut s3_config_builder = aws_sdk_s3::config::Builder::from(aws_config); // this is necessary for it to work with localstack in test cases s3_config_builder.set_force_path_style(Some(true)); let client = Client::from_conf(s3_config_builder.build()); - Self { client, bucket: s3_config.bucket_name } + Self { client, bucket: s3_config.bucket_name.clone() } } } diff --git a/crates/orchestrator/src/tests/common/mod.rs b/crates/orchestrator/src/tests/common/mod.rs index 336abf46..141348f9 100644 --- a/crates/orchestrator/src/tests/common/mod.rs +++ b/crates/orchestrator/src/tests/common/mod.rs @@ -3,6 +3,8 @@ pub mod constants; use std::collections::HashMap; use std::sync::Arc; +use utils::cli::storage::aws_s3::AWSS3Params; +use utils::cli::storage::StorageParams; use ::uuid::Uuid; use aws_config::SdkConfig; use aws_sdk_sns::error::SdkError; @@ -112,6 +114,6 @@ pub struct MessagePayloadType { pub(crate) id: Uuid, } -pub async fn get_storage_client(provider_config: Arc) -> Box { - Box::new(AWSS3::new_with_settings(&EnvSettingsProvider {}, provider_config).await) +pub async fn get_storage_client(storage_cfg: &AWSS3Params, provider_config: Arc) -> Box { + Box::new(AWSS3::new_with_settings(storage_cfg, provider_config).await) } diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 6c0ef4e4..2f1e5852 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -182,6 +182,7 @@ impl TestConfigBuilder { } pub async fn build(self) -> TestConfigBuilderReturns { + dotenvy::from_filename("../.env.test").expect("Failed to load the .env.test file"); let mut run_cmd: RunCmd = RunCmd::parse(); let settings_provider = EnvSettingsProvider {}; @@ -218,7 +219,8 @@ impl TestConfigBuilder { Url::parse(&settings_provider.get_settings_or_panic("RPC_FOR_SNOS")).expect("Failed to parse URL"); // External Dependencies - let storage = implement_client::init_storage_client(storage_type, provider_config.clone()).await; + let data_storage_params = run_cmd.clone().validate_storage_params().map_err(|e| eyre!("Failed to validate storage params: {e}")).unwrap(); + let storage = implement_client::init_storage_client(storage_type, &data_storage_params, provider_config.clone()).await; let database = implement_client::init_database(database_type, settings_provider).await; let queue = implement_client::init_queue_client(queue_type).await; // Deleting and Creating the queues in sqs. @@ -283,6 +285,7 @@ pub mod implement_client { use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Url}; use utils::cli::settlement::SettlementParams; + use utils::cli::storage::StorageParams; use utils::env_utils::get_env_var_or_panic; use utils::settings::env::EnvSettingsProvider; use utils::settings::Settings; @@ -366,19 +369,19 @@ pub mod implement_client { pub(crate) async fn init_storage_client( service: ConfigType, + storage_cfg : &StorageParams, provider_config: Arc, ) -> Box { match service { ConfigType::Mock(client) => client.into(), ConfigType::Actual => { - let storage = get_storage_client(provider_config).await; - match get_env_var_or_panic("DATA_STORAGE").as_str() { - "s3" => { - storage.as_ref().build_test_bucket(&get_env_var_or_panic("AWS_S3_BUCKET_NAME")).await.unwrap() + match storage_cfg { + StorageParams::AWSS3(aws_s3_params) => { + let storage = get_storage_client(aws_s3_params, provider_config).await; + storage.as_ref().build_test_bucket(&aws_s3_params.bucket_name).await.unwrap(); + storage } - _ => panic!("Unsupported Storage Client"), } - storage } ConfigType::Dummy => Box::new(MockDataStorage::new()), } diff --git a/crates/orchestrator/src/tests/data_storage/mod.rs b/crates/orchestrator/src/tests/data_storage/mod.rs index 968e1c61..cd7d12fd 100644 --- a/crates/orchestrator/src/tests/data_storage/mod.rs +++ b/crates/orchestrator/src/tests/data_storage/mod.rs @@ -13,8 +13,6 @@ use crate::tests::config::{ConfigType, TestConfigBuilder}; async fn test_put_and_get_data_s3() -> color_eyre::Result<()> { let services = TestConfigBuilder::new().configure_storage_client(ConfigType::Actual).build().await; - dotenvy::from_filename("../.env.test")?; - let s3_client = services.config.storage(); let mock_data = json!( diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index 9b503c7a..710805a0 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -109,7 +109,7 @@ impl EthereumSettlementClient { ) -> Self { let root_provider = RootProvider::new_http(settlement_cfg.ethereum_rpc_url.clone().as_str().parse()?); let core_contract_address = Address::from_str(&settlement_cfg.l1_core_contract_address.clone())?; - let settlement_rpc_url = Url::from_str(&settlement_cfg.ethereum_rpc_url.clone())?; + let settlement_rpc_url = &settlement_cfg.ethereum_rpc_url.clone()?; let private_key = &settlement_cfg.ethereum_private_key.clone(); let signer: PrivateKeySigner = private_key.parse().expect("Failed to parse private key"); let wallet_address = signer.address(); diff --git a/crates/utils/src/cli/mod.rs b/crates/utils/src/cli/mod.rs index 46e85e05..e1665d2a 100644 --- a/crates/utils/src/cli/mod.rs +++ b/crates/utils/src/cli/mod.rs @@ -1,5 +1,6 @@ use clap::ArgGroup; use settlement::SettlementParams; +use storage::StorageParams; pub mod aws_config; pub mod database; @@ -24,14 +25,12 @@ pub mod snos; .multiple(false) ), - // Solving - - // group( - // ArgGroup::new("storage") - // .args(&["aws_s3"]) - // .required(true) - // .multiple(false) - // ), + group( + ArgGroup::new("storage") + .args(&["aws_s3"]) + .required(true) + .multiple(false) + ), // group( // ArgGroup::new("queue") @@ -66,6 +65,7 @@ pub mod snos; pub struct RunCmd { + // Settlement Layer #[clap(long, group = "settlement_layer")] pub settle_on_ethereum: bool, @@ -78,6 +78,13 @@ pub struct RunCmd { #[clap(flatten)] starknet_settlement_params: Option, + // Storage + #[clap(long, group = "storage")] + pub aws_s3: bool, + + #[clap(flatten)] + pub aws_s3_params: storage::aws_s3::AWSS3Params, + // #[clap(flatten)] // pub server: server::ServerParams, @@ -85,8 +92,7 @@ pub struct RunCmd { // pub aws_config: aws_config::AWSConfigParams, // // part of storage - // #[clap(flatten)] - // pub aws_s3: storage::aws_s3::AWSS3Params, + // // part of queue // #[clap(flatten)] @@ -155,4 +161,13 @@ impl RunCmd { } } } + + pub fn validate_storage_params(self) -> Result { + if self.aws_s3 { + Ok(StorageParams::AWSS3(self.aws_s3_params)) + } else { + Err("Only AWS S3 is supported as of now".to_string()) + } + } + } \ No newline at end of file diff --git a/crates/utils/src/cli/storage/aws_s3.rs b/crates/utils/src/cli/storage/aws_s3.rs index 3dff2aec..0ffb7bfa 100644 --- a/crates/utils/src/cli/storage/aws_s3.rs +++ b/crates/utils/src/cli/storage/aws_s3.rs @@ -4,6 +4,6 @@ use clap::Args; #[derive(Debug, Clone, Args)] pub struct AWSS3Params { /// The name of the S3 bucket. - #[arg(env = "AWS_S3_BUCKET_NAME", long)] + #[arg(env = "AWS_S3_BUCKET_NAME", long, default_value = "madara-orchestrator-bucket")] pub bucket_name: String, } diff --git a/crates/utils/src/cli/storage/mod.rs b/crates/utils/src/cli/storage/mod.rs index 22b86beb..edd568a4 100644 --- a/crates/utils/src/cli/storage/mod.rs +++ b/crates/utils/src/cli/storage/mod.rs @@ -1,2 +1,7 @@ pub mod aws_s3; + +#[derive(Clone, Debug)] +pub enum StorageParams { + AWSS3(aws_s3::AWSS3Params), +} \ No newline at end of file From a7431412babf785993e133749e707e4f9ce27880 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 6 Nov 2024 12:31:27 +0530 Subject: [PATCH 05/63] update: run_cmd for server, aws config --- Cargo.lock | 1 + crates/orchestrator/src/config.rs | 28 ++++-- crates/orchestrator/src/main.rs | 2 +- crates/orchestrator/src/queue/job_queue.rs | 102 +++++++-------------- crates/orchestrator/src/queue/mod.rs | 6 +- crates/orchestrator/src/queue/sqs/mod.rs | 45 ++------- crates/orchestrator/src/routes/mod.rs | 11 +-- crates/utils/Cargo.toml | 2 +- crates/utils/src/cli/mod.rs | 39 +++++--- crates/utils/src/cli/queue/aws_sqs.rs | 74 ++++++++++++--- crates/utils/src/cli/queue/mod.rs | 8 +- 11 files changed, 163 insertions(+), 155 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a03e4d8c..da8c26ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10879,6 +10879,7 @@ dependencies = [ "opentelemetry-stdout", "opentelemetry_sdk", "serde", + "serde_json", "thiserror", "tracing", "tracing-core", diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 6dccc908..771e746b 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -20,6 +20,8 @@ use sharp_service::SharpProverService; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Url}; use starknet_settlement_client::StarknetSettlementClient; +use utils::cli::aws_config::AWSConfigParams; +use utils::cli::queue::QueueParams; use utils::cli::settlement::SettlementParams; use utils::cli::storage::StorageParams; use utils::cli::RunCmd; @@ -82,12 +84,12 @@ impl ProviderConfig { } /// To build a `SdkConfig` for AWS provider. -pub async fn get_aws_config(settings_provider: &impl Settings) -> SdkConfig { - let region = settings_provider.get_settings_or_panic("AWS_REGION"); +pub async fn get_aws_config(aws_config: &AWSConfigParams) -> SdkConfig { + let region = aws_config.region.clone(); let region_provider = RegionProviderChain::first_try(Region::new(region)).or_default_provider(); let credentials = Credentials::from_keys( - settings_provider.get_settings_or_panic("AWS_ACCESS_KEY_ID"), - settings_provider.get_settings_or_panic("AWS_SECRET_ACCESS_KEY"), + aws_config.access_key_id.clone(), + aws_config.secret_access_key.clone(), None, ); aws_config::from_env().credentials_provider(credentials).region(region_provider).load().await @@ -98,7 +100,9 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { dotenv().ok(); let settings_provider = EnvSettingsProvider {}; - let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(&settings_provider).await))); + + let aws_config = &run_cmd.aws_config; + let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(aws_config).await))); // init starknet client let rpc_url = Url::parse(&settings_provider.get_settings_or_panic("MADARA_RPC_URL")).expect("Failed to parse URL"); @@ -109,20 +113,25 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { let database = build_database_client(&settings_provider).await; let da_client = build_da_client(&settings_provider).await; + // init settlement let settlement_params = run_cmd.clone().validate_settlement_params().map_err(|e| eyre!("Failed to validate settlement params: {e}"))?; let settlement_client = build_settlement_client(&settlement_params).await?; let prover_client = build_prover_service(&settings_provider); + // init storage let data_storage_params = run_cmd.clone().validate_storage_params().map_err(|e| eyre!("Failed to validate storage params: {e}"))?; let storage_client = build_storage_client(&data_storage_params, provider_config.clone()).await; + let alerts_client = build_alert_client(&settings_provider, provider_config.clone()).await; // init the queue // TODO: we use omniqueue for now which doesn't support loading AWS config // from `SdkConfig`. We can later move to using `aws_sdk_sqs`. This would require // us stop using the generic omniqueue abstractions for message ack/nack - let queue = build_queue_client(); + // init queue + let queue_params = run_cmd.clone().validate_queue_params().map_err(|e| eyre!("Failed to validate queue params: {e}"))?; + let queue = build_queue_client(&queue_params); Ok(Arc::new(Config::new( rpc_url, @@ -298,10 +307,9 @@ pub async fn build_alert_client( } } -pub fn build_queue_client() -> Box { - match get_env_var_or_panic("QUEUE_PROVIDER").as_str() { - "sqs" => Box::new(SqsQueue {}), - _ => panic!("Unsupported Queue Client"), +pub fn build_queue_client(queue_params: &QueueParams) -> Box { + match queue_params { + QueueParams::AWSSQS(aws_sqs_params) => Box::new(SqsQueue { params: aws_sqs_params.clone() }), } } diff --git a/crates/orchestrator/src/main.rs b/crates/orchestrator/src/main.rs index e29337cf..c317ceed 100644 --- a/crates/orchestrator/src/main.rs +++ b/crates/orchestrator/src/main.rs @@ -27,7 +27,7 @@ async fn main() { tracing::debug!(service = "orchestrator", "Configuration initialized"); // initialize the server - let _ = setup_server(config.clone()).await; + let _ = setup_server(config.clone(), run_cmd.server).await; tracing::debug!(service = "orchestrator", "Application router initialized"); diff --git a/crates/orchestrator/src/queue/job_queue.rs b/crates/orchestrator/src/queue/job_queue.rs index 616c3b62..5ac800dc 100644 --- a/crates/orchestrator/src/queue/job_queue.rs +++ b/crates/orchestrator/src/queue/job_queue.rs @@ -9,6 +9,7 @@ use omniqueue::{Delivery, QueueError}; use serde::{Deserialize, Deserializer, Serialize}; use thiserror::Error; use tokio::time::sleep; +use utils::cli::queue::aws_sqs::QueueType; use uuid::Uuid; use crate::config::Config; @@ -21,28 +22,6 @@ use crate::workers::snos::SnosWorker; use crate::workers::update_state::UpdateStateWorker; use crate::workers::Worker; -pub const SNOS_JOB_PROCESSING_QUEUE: &str = "madara_orchestrator_snos_job_processing_queue"; -pub const SNOS_JOB_VERIFICATION_QUEUE: &str = "madara_orchestrator_snos_job_verification_queue"; - -pub const PROVING_JOB_PROCESSING_QUEUE: &str = "madara_orchestrator_proving_job_processing_queue"; -pub const PROVING_JOB_VERIFICATION_QUEUE: &str = "madara_orchestrator_proving_job_verification_queue"; - -pub const PROOF_REGISTRATION_JOB_PROCESSING_QUEUE: &str = "madara_orchestrator_proof_registration_job_processing_queue"; -pub const PROOF_REGISTRATION_JOB_VERIFICATION_QUEUE: &str = - "madara_orchestrator_proof_registration_job_verification_queue"; - -pub const DATA_SUBMISSION_JOB_PROCESSING_QUEUE: &str = "madara_orchestrator_data_submission_job_processing_queue"; -pub const DATA_SUBMISSION_JOB_VERIFICATION_QUEUE: &str = "madara_orchestrator_data_submission_job_verification_queue"; - -pub const UPDATE_STATE_JOB_PROCESSING_QUEUE: &str = "madara_orchestrator_update_state_job_processing_queue"; -pub const UPDATE_STATE_JOB_VERIFICATION_QUEUE: &str = "madara_orchestrator_update_state_job_verification_queue"; - -// Below is the Dead Letter Queue for the above queues. -pub const JOB_HANDLE_FAILURE_QUEUE: &str = "madara_orchestrator_job_handle_failure_queue"; - -// Queues for SNOS worker trigger listening -pub const WORKER_TRIGGER_QUEUE: &str = "madara_orchestrator_worker_trigger_queue"; - #[derive(Error, Debug, PartialEq)] pub enum ConsumptionError { #[error("Failed to consume message from queue, error {error_msg:?}")] @@ -118,30 +97,28 @@ enum DeliveryReturnType { } pub trait QueueNameForJobType { - fn process_queue_name(&self) -> String; - fn verify_queue_name(&self) -> String; + fn process_queue_name(&self) -> QueueType; + fn verify_queue_name(&self) -> QueueType; } impl QueueNameForJobType for JobType { - fn process_queue_name(&self) -> String { + fn process_queue_name(&self) -> QueueType { match self { - JobType::SnosRun => SNOS_JOB_PROCESSING_QUEUE, - JobType::ProofCreation => PROVING_JOB_PROCESSING_QUEUE, - JobType::ProofRegistration => PROOF_REGISTRATION_JOB_PROCESSING_QUEUE, - JobType::DataSubmission => DATA_SUBMISSION_JOB_PROCESSING_QUEUE, - JobType::StateTransition => UPDATE_STATE_JOB_PROCESSING_QUEUE, + JobType::SnosRun => QueueType::SnosJobProcessing, + JobType::ProofCreation => QueueType::ProvingJobProcessing, + JobType::ProofRegistration => QueueType::ProofRegistrationJobProcessing, + JobType::DataSubmission => QueueType::DataSubmissionJobProcessing, + JobType::StateTransition => QueueType::UpdateStateJobProcessing, } - .to_string() } - fn verify_queue_name(&self) -> String { + fn verify_queue_name(&self) -> QueueType { match self { - JobType::SnosRun => SNOS_JOB_VERIFICATION_QUEUE, - JobType::ProofCreation => PROVING_JOB_VERIFICATION_QUEUE, - JobType::ProofRegistration => PROOF_REGISTRATION_JOB_VERIFICATION_QUEUE, - JobType::DataSubmission => DATA_SUBMISSION_JOB_VERIFICATION_QUEUE, - JobType::StateTransition => UPDATE_STATE_JOB_VERIFICATION_QUEUE, + JobType::SnosRun => QueueType::SnosJobVerification, + JobType::ProofCreation => QueueType::ProvingJobVerification, + JobType::ProofRegistration => QueueType::ProofRegistrationJobVerification, + JobType::DataSubmission => QueueType::DataSubmissionJobVerification, + JobType::StateTransition => QueueType::UpdateStateJobVerification, } - .to_string() } } @@ -161,7 +138,7 @@ pub async fn add_job_to_verification_queue( } pub async fn consume_job_from_queue( - queue: String, + queue: QueueType, handler: F, config: Arc, ) -> Result<(), ConsumptionError> @@ -172,7 +149,7 @@ where { tracing::trace!(queue = %queue, "Attempting to consume job from queue"); - let delivery = get_delivery_from_queue(&queue, config.clone()).await?; + let delivery = get_delivery_from_queue(queue.clone(), config.clone()).await?; let message = match delivery { DeliveryReturnType::Message(message) => { @@ -206,7 +183,7 @@ where /// Function to consume the message from the worker trigger queues and spawn the worker /// for respective message received. pub async fn consume_worker_trigger_messages_from_queue( - queue: String, + queue: QueueType, handler: F, config: Arc, ) -> Result<(), ConsumptionError> @@ -216,7 +193,7 @@ where Fut: Future> + Send, { tracing::debug!("Consuming from queue {:?}", queue); - let delivery = get_delivery_from_queue(&queue, config.clone()).await?; + let delivery = get_delivery_from_queue(queue.clone(), config.clone()).await?; let message = match delivery { DeliveryReturnType::Message(message) => message, @@ -346,8 +323,8 @@ fn get_worker_handler_from_worker_trigger_type(worker_trigger_type: WorkerTrigge } /// To get the delivery from the message queue using the queue name -async fn get_delivery_from_queue(queue: &str, config: Arc) -> Result { - match config.queue().consume_message_from_queue(queue.to_string()).await { +async fn get_delivery_from_queue(queue: QueueType, config: Arc) -> Result { + match config.queue().consume_message_from_queue(queue).await { Ok(d) => Ok(DeliveryReturnType::Message(d)), Err(QueueError::NoData) => Ok(DeliveryReturnType::NoMessage), Err(e) => Err(ConsumptionError::FailedToConsumeFromQueue { error_msg: e.to_string() }), @@ -370,36 +347,21 @@ macro_rules! spawn_consumer { } pub async fn init_consumers(config: Arc) -> Result<(), JobError> { - spawn_consumer!(SNOS_JOB_PROCESSING_QUEUE.to_string(), process_job, consume_job_from_queue, config.clone()); - spawn_consumer!(SNOS_JOB_VERIFICATION_QUEUE.to_string(), verify_job, consume_job_from_queue, config.clone()); + spawn_consumer!(QueueType::SnosJobProcessing, process_job, consume_job_from_queue, config.clone()); + spawn_consumer!(QueueType::SnosJobVerification, verify_job, consume_job_from_queue, config.clone()); - spawn_consumer!(PROVING_JOB_PROCESSING_QUEUE.to_string(), process_job, consume_job_from_queue, config.clone()); - spawn_consumer!(PROVING_JOB_VERIFICATION_QUEUE.to_string(), verify_job, consume_job_from_queue, config.clone()); + spawn_consumer!(QueueType::ProvingJobProcessing, process_job, consume_job_from_queue, config.clone()); + spawn_consumer!(QueueType::ProvingJobVerification, verify_job, consume_job_from_queue, config.clone()); - spawn_consumer!( - DATA_SUBMISSION_JOB_PROCESSING_QUEUE.to_string(), - process_job, - consume_job_from_queue, - config.clone() - ); - spawn_consumer!( - DATA_SUBMISSION_JOB_VERIFICATION_QUEUE.to_string(), - verify_job, - consume_job_from_queue, - config.clone() - ); + spawn_consumer!(QueueType::DataSubmissionJobProcessing, process_job, consume_job_from_queue, config.clone()); + spawn_consumer!(QueueType::DataSubmissionJobVerification, verify_job, consume_job_from_queue, config.clone()); - spawn_consumer!(UPDATE_STATE_JOB_PROCESSING_QUEUE.to_string(), process_job, consume_job_from_queue, config.clone()); - spawn_consumer!( - UPDATE_STATE_JOB_VERIFICATION_QUEUE.to_string(), - verify_job, - consume_job_from_queue, - config.clone() - ); + spawn_consumer!(QueueType::UpdateStateJobProcessing, process_job, consume_job_from_queue, config.clone()); + spawn_consumer!(QueueType::UpdateStateJobVerification, verify_job, consume_job_from_queue, config.clone()); - spawn_consumer!(JOB_HANDLE_FAILURE_QUEUE.to_string(), handle_job_failure, consume_job_from_queue, config.clone()); + spawn_consumer!(QueueType::JobHandleFailure, handle_job_failure, consume_job_from_queue, config.clone()); - spawn_consumer!(WORKER_TRIGGER_QUEUE.to_string(), spawn_worker, consume_worker_trigger_messages_from_queue, config); + spawn_consumer!(QueueType::WorkerTrigger, spawn_worker, consume_worker_trigger_messages_from_queue, config); Ok(()) } @@ -411,7 +373,7 @@ async fn spawn_worker(worker: Box, config: Arc) -> color_eyr } Ok(()) } -async fn add_job_to_queue(id: Uuid, queue: String, delay: Option, config: Arc) -> EyreResult<()> { +async fn add_job_to_queue(id: Uuid, queue: QueueType, delay: Option, config: Arc) -> EyreResult<()> { let message = JobQueueMessage { id }; config.queue().send_message_to_queue(queue.clone(), serde_json::to_string(&message)?, delay).await?; tracing::info!( diff --git a/crates/orchestrator/src/queue/mod.rs b/crates/orchestrator/src/queue/mod.rs index a5f513d5..10c72021 100644 --- a/crates/orchestrator/src/queue/mod.rs +++ b/crates/orchestrator/src/queue/mod.rs @@ -11,7 +11,7 @@ use omniqueue::{Delivery, QueueError}; use crate::config::Config; use crate::jobs::JobError; - +use utils::cli::queue::aws_sqs::QueueType; /// Queue Provider Trait /// /// The QueueProvider trait is used to define the methods that a queue @@ -20,8 +20,8 @@ use crate::jobs::JobError; #[automock] #[async_trait] pub trait QueueProvider: Send + Sync { - async fn send_message_to_queue(&self, queue: String, payload: String, delay: Option) -> EyreResult<()>; - async fn consume_message_from_queue(&self, queue: String) -> std::result::Result; + async fn send_message_to_queue(&self, queue: QueueType, payload: String, delay: Option) -> EyreResult<()>; + async fn consume_message_from_queue(&self, queue: QueueType) -> std::result::Result; } pub async fn init_consumers(config: Arc) -> Result<(), JobError> { diff --git a/crates/orchestrator/src/queue/sqs/mod.rs b/crates/orchestrator/src/queue/sqs/mod.rs index dc20d21d..562a45b5 100644 --- a/crates/orchestrator/src/queue/sqs/mod.rs +++ b/crates/orchestrator/src/queue/sqs/mod.rs @@ -1,44 +1,20 @@ -use std::collections::HashMap; use std::time::Duration; use async_trait::async_trait; use color_eyre::Result; -use lazy_static::lazy_static; use omniqueue::backends::{SqsBackend, SqsConfig, SqsConsumer, SqsProducer}; use omniqueue::{Delivery, QueueError}; -use utils::env_utils::get_env_var_or_panic; +use utils::cli::queue::aws_sqs::{AWSSQSParams, QueueType}; -use crate::queue::job_queue::{ - DATA_SUBMISSION_JOB_PROCESSING_QUEUE, DATA_SUBMISSION_JOB_VERIFICATION_QUEUE, JOB_HANDLE_FAILURE_QUEUE, - PROOF_REGISTRATION_JOB_PROCESSING_QUEUE, PROOF_REGISTRATION_JOB_VERIFICATION_QUEUE, PROVING_JOB_PROCESSING_QUEUE, - PROVING_JOB_VERIFICATION_QUEUE, SNOS_JOB_PROCESSING_QUEUE, SNOS_JOB_VERIFICATION_QUEUE, - UPDATE_STATE_JOB_PROCESSING_QUEUE, UPDATE_STATE_JOB_VERIFICATION_QUEUE, WORKER_TRIGGER_QUEUE, -}; use crate::queue::QueueProvider; -pub struct SqsQueue; - -lazy_static! { - /// Maps Queue Name to Env var of queue URL. - pub static ref QUEUE_NAME_TO_ENV_VAR_MAPPING: HashMap<&'static str, &'static str> = HashMap::from([ - (DATA_SUBMISSION_JOB_PROCESSING_QUEUE, "SQS_DATA_SUBMISSION_JOB_PROCESSING_QUEUE_URL"), - (DATA_SUBMISSION_JOB_VERIFICATION_QUEUE, "SQS_DATA_SUBMISSION_JOB_VERIFICATION_QUEUE_URL"), - (PROOF_REGISTRATION_JOB_PROCESSING_QUEUE, "SQS_PROOF_REGISTRATION_JOB_PROCESSING_QUEUE_URL"), - (PROOF_REGISTRATION_JOB_VERIFICATION_QUEUE, "SQS_PROOF_REGISTRATION_JOB_VERIFICATION_QUEUE_URL"), - (PROVING_JOB_PROCESSING_QUEUE, "SQS_PROVING_JOB_PROCESSING_QUEUE_URL"), - (PROVING_JOB_VERIFICATION_QUEUE, "SQS_PROVING_JOB_VERIFICATION_QUEUE_URL"), - (SNOS_JOB_PROCESSING_QUEUE, "SQS_SNOS_JOB_PROCESSING_QUEUE_URL"), - (SNOS_JOB_VERIFICATION_QUEUE, "SQS_SNOS_JOB_VERIFICATION_QUEUE_URL"), - (UPDATE_STATE_JOB_PROCESSING_QUEUE, "SQS_UPDATE_STATE_JOB_PROCESSING_QUEUE_URL"), - (UPDATE_STATE_JOB_VERIFICATION_QUEUE, "SQS_UPDATE_STATE_JOB_VERIFICATION_QUEUE_URL"), - (JOB_HANDLE_FAILURE_QUEUE, "SQS_JOB_HANDLE_FAILURE_QUEUE_URL"), - (WORKER_TRIGGER_QUEUE, "SQS_WORKER_TRIGGER_QUEUE_URL"), - ]); +pub struct SqsQueue{ + pub params: AWSSQSParams, } #[async_trait] impl QueueProvider for SqsQueue { - async fn send_message_to_queue(&self, queue: String, payload: String, delay: Option) -> Result<()> { - let queue_url = get_queue_url(queue); + async fn send_message_to_queue(&self, queue: QueueType, payload: String, delay: Option) -> Result<()> { + let queue_url = self.params.get_queue_url(queue); let producer = get_producer(queue_url).await?; match delay { @@ -49,20 +25,13 @@ impl QueueProvider for SqsQueue { Ok(()) } - async fn consume_message_from_queue(&self, queue: String) -> std::result::Result { - let queue_url = get_queue_url(queue); + async fn consume_message_from_queue(&self, queue: QueueType) -> std::result::Result { + let queue_url = self.params.get_queue_url(queue); let mut consumer = get_consumer(queue_url).await?; consumer.receive().await } } -/// To fetch the queue URL from the environment variables -fn get_queue_url(queue_name: String) -> String { - get_env_var_or_panic( - QUEUE_NAME_TO_ENV_VAR_MAPPING.get(queue_name.as_str()).expect("Not able to get the queue env var name."), - ) -} - // TODO: store the producer and consumer in memory to avoid creating a new one every time async fn get_producer(queue: String) -> Result { let (producer, _) = diff --git a/crates/orchestrator/src/routes/mod.rs b/crates/orchestrator/src/routes/mod.rs index 21c4d9bd..756105ab 100644 --- a/crates/orchestrator/src/routes/mod.rs +++ b/crates/orchestrator/src/routes/mod.rs @@ -7,6 +7,7 @@ use axum::response::{IntoResponse, Response}; use axum::{Json, Router}; use job_routes::job_router; use serde::Serialize; +use utils::cli::server::ServerParams; use utils::env_utils::get_env_var_or_default; use crate::config::Config; @@ -49,8 +50,8 @@ where } } -pub async fn setup_server(config: Arc) -> SocketAddr { - let (api_server_url, listener) = get_server_url().await; +pub async fn setup_server(config: Arc, server_params: ServerParams) -> SocketAddr { + let (api_server_url, listener) = get_server_url(server_params).await; let job_routes = job_router(config.clone()); let app_routes = app_router(); @@ -63,10 +64,8 @@ pub async fn setup_server(config: Arc) -> SocketAddr { api_server_url } -pub async fn get_server_url() -> (SocketAddr, tokio::net::TcpListener) { - let host = get_env_var_or_default("HOST", "127.0.0.1"); - let port = get_env_var_or_default("PORT", "3000").parse::().expect("PORT must be a u16"); - let address = format!("{}:{}", host, port); +pub async fn get_server_url(server_params: ServerParams) -> (SocketAddr, tokio::net::TcpListener) { + let address = format!("{}:{}", server_params.host, server_params.port); let listener = tokio::net::TcpListener::bind(address.clone()).await.expect("Failed to get listener"); let api_server_url = listener.local_addr().expect("Unable to bind address to listener."); diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml index 80205f64..6319af5d 100644 --- a/crates/utils/Cargo.toml +++ b/crates/utils/Cargo.toml @@ -11,7 +11,7 @@ serde.workspace = true thiserror.workspace = true clap = { version = "4.4", features = ["derive", "env"] } url = { workspace = true } - +serde_json = { workspace = true } #Instrumentation opentelemetry = { workspace = true, features = ["metrics", "logs"] } opentelemetry-appender-tracing = { workspace = true, default-features = false } diff --git a/crates/utils/src/cli/mod.rs b/crates/utils/src/cli/mod.rs index e1665d2a..ef0588c1 100644 --- a/crates/utils/src/cli/mod.rs +++ b/crates/utils/src/cli/mod.rs @@ -1,4 +1,5 @@ use clap::ArgGroup; +use queue::QueueParams; use settlement::SettlementParams; use storage::StorageParams; @@ -32,12 +33,12 @@ pub mod snos; .multiple(false) ), - // group( - // ArgGroup::new("queue") - // .args(&["aws_sqs"]) - // .required(true) - // .multiple(false) - // ), + group( + ArgGroup::new("queue") + .args(&["aws_sqs"]) + .required(true) + .multiple(false) + ), // group( // ArgGroup::new("alert") @@ -65,6 +66,9 @@ pub mod snos; pub struct RunCmd { + #[clap(flatten)] + pub aws_config: aws_config::AWSConfigParams, + // Settlement Layer #[clap(long, group = "settlement_layer")] pub settle_on_ethereum: bool, @@ -85,15 +89,20 @@ pub struct RunCmd { #[clap(flatten)] pub aws_s3_params: storage::aws_s3::AWSS3Params, - // #[clap(flatten)] - // pub server: server::ServerParams, + // Queue + #[clap(long, group = "queue")] + pub aws_sqs: bool, - // #[clap(flatten)] - // pub aws_config: aws_config::AWSConfigParams, + #[clap(flatten)] + pub aws_sqs_params: queue::aws_sqs::AWSSQSParams, + + // Server + #[clap(flatten)] + pub server: server::ServerParams, + // // part of storage - // // part of queue // #[clap(flatten)] // pub aws_sqs: queue::aws_sqs::AWSSQSParams, @@ -170,4 +179,12 @@ impl RunCmd { } } + pub fn validate_queue_params(self) -> Result { + if self.aws_sqs { + Ok(QueueParams::AWSSQS(self.aws_sqs_params)) + } else { + Err("Only AWS SQS is supported as of now".to_string()) + } + } + } \ No newline at end of file diff --git a/crates/utils/src/cli/queue/aws_sqs.rs b/crates/utils/src/cli/queue/aws_sqs.rs index c561fd01..65491948 100644 --- a/crates/utils/src/cli/queue/aws_sqs.rs +++ b/crates/utils/src/cli/queue/aws_sqs.rs @@ -1,4 +1,7 @@ +use std::fmt; + use clap::Args; +use serde::Serialize; /// Parameters used to config AWS SQS. #[derive(Debug, Clone, Args)] @@ -7,27 +10,70 @@ pub struct AWSSQSParams { #[arg(env = "SQS_PREFIX", long)] pub sqs_prefix: String, + #[arg(env = "SQS_SUFFIX", long, default_value = "queue")] + pub sqs_suffix: String, + /// The QUEUE url - #[arg(env = "SQS_QUEUE_URL", long)] - pub queue_url: String, + #[arg(env = "SQS_BASE_QUEUE_URL", long)] + pub queue_base_url: String, } -impl AWSSQSParams { - // TODO: Implement the logic to get the queue url - // SQS_SNOS_JOB_PROCESSING_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_snos_job_processing_queue" - // SQS_SNOS_JOB_VERIFICATION_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_snos_job_verification_queue" +#[derive(Debug, Clone, Serialize)] +pub enum QueueType { + + #[serde(rename = "snos_job_processing")] + SnosJobProcessing, + + #[serde(rename = "snos_job_verification")] + SnosJobVerification, + + #[serde(rename = "proving_job_processing")] + ProvingJobProcessing, + + #[serde(rename = "proving_job_verification")] + ProvingJobVerification, + + #[serde(rename = "proof_registration_job_processing")] + ProofRegistrationJobProcessing, + + #[serde(rename = "proof_registration_job_verification")] + ProofRegistrationJobVerification, - // SQS_PROVING_JOB_PROCESSING_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_proving_job_processing_queue" - // SQS_PROVING_JOB_VERIFICATION_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_proving_job_verification_queue" + #[serde(rename = "data_submission_job_processing")] + DataSubmissionJobProcessing, - // SQS_DATA_SUBMISSION_JOB_PROCESSING_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_data_submission_job_processing_queue" - // SQS_DATA_SUBMISSION_JOB_VERIFICATION_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_data_submission_job_verification_queue" + #[serde(rename = "data_submission_job_verification")] + DataSubmissionJobVerification, - // SQS_UPDATE_STATE_JOB_PROCESSING_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_update_state_job_processing_queue" - // SQS_UPDATE_STATE_JOB_VERIFICATION_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_update_state_job_verification_queue" + #[serde(rename = "update_state_job_processing")] + UpdateStateJobProcessing, - // SQS_JOB_HANDLE_FAILURE_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_job_handle_failure_queue" - // SQS_WORKER_TRIGGER_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_worker_trigger_queue" + #[serde(rename = "update_state_job_verification")] + UpdateStateJobVerification, + + #[serde(rename = "job_handle_failure")] + JobHandleFailure, + + #[serde(rename = "worker_trigger")] + WorkerTrigger, +} + + +impl fmt::Display for QueueType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + _ => write!(f, "{}", serde_json::to_string(self).unwrap()), + } + } +} + + +impl AWSSQSParams { + + pub fn get_queue_url(&self, queue_type: QueueType) -> String { + let queue_name = serde_json::to_string(&queue_type).unwrap(); + format!("{}/{}/{}_{}", self.queue_base_url, self.sqs_prefix, queue_name, self.sqs_suffix) + } } \ No newline at end of file diff --git a/crates/utils/src/cli/queue/mod.rs b/crates/utils/src/cli/queue/mod.rs index 82317418..a59318bb 100644 --- a/crates/utils/src/cli/queue/mod.rs +++ b/crates/utils/src/cli/queue/mod.rs @@ -1 +1,7 @@ -pub mod aws_sqs; \ No newline at end of file +pub mod aws_sqs; + + +#[derive(Clone, Debug)] +pub enum QueueParams { + AWSSQS(aws_sqs::AWSSQSParams), +} \ No newline at end of file From 1aafaa51a958732d72f9bc8423b48d2544394108 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 6 Nov 2024 12:59:47 +0530 Subject: [PATCH 06/63] update: run_cmd for da and alert --- Cargo.lock | 2 +- crates/da-clients/ethereum/src/lib.rs | 2 +- crates/orchestrator/Cargo.toml | 11 ++- crates/orchestrator/src/alerts/aws_sns/mod.rs | 12 +-- crates/orchestrator/src/config.rs | 50 +++++++---- .../orchestrator/src/database/mongodb/mod.rs | 12 ++- crates/utils/src/cli/alert/mod.rs | 7 +- crates/utils/src/cli/da/ethereum.rs | 3 +- crates/utils/src/cli/da/mod.rs | 7 +- crates/utils/src/cli/database/mod.rs | 7 +- crates/utils/src/cli/database/mongodb.rs | 4 +- crates/utils/src/cli/mod.rs | 88 ++++++++++++------- 12 files changed, 131 insertions(+), 74 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index da8c26ef..bbbcdd0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6930,7 +6930,7 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" name = "orchestrator" version = "0.1.0" dependencies = [ - "alloy 0.2.1", + "alloy 0.1.0", "assert_matches", "async-std", "async-trait", diff --git a/crates/da-clients/ethereum/src/lib.rs b/crates/da-clients/ethereum/src/lib.rs index 5bf7ab63..e8c92d70 100644 --- a/crates/da-clients/ethereum/src/lib.rs +++ b/crates/da-clients/ethereum/src/lib.rs @@ -23,7 +23,7 @@ pub const DA_SETTINGS_NAME: &str = "ethereum"; pub mod config; pub struct EthereumDaClient { #[allow(dead_code)] - provider: RootProvider>, + pub provider: RootProvider>, } #[automock] diff --git a/crates/orchestrator/Cargo.toml b/crates/orchestrator/Cargo.toml index 940f3f8d..48961546 100644 --- a/crates/orchestrator/Cargo.toml +++ b/crates/orchestrator/Cargo.toml @@ -12,7 +12,16 @@ name = "orchestrator" path = "src/main.rs" [dependencies] -alloy = { workspace = true } +alloy = { git = "https://github.com/alloy-rs/alloy", rev = "68952c0", features = [ + "consensus", + "providers", + "rpc-client", + "transport-http", + "network", + "eips", + "signers", + "signer-wallet", +] } assert_matches = "1.5.0" async-std = "1.12.0" async-trait = { workspace = true } diff --git a/crates/orchestrator/src/alerts/aws_sns/mod.rs b/crates/orchestrator/src/alerts/aws_sns/mod.rs index c78845ba..3a0e5710 100644 --- a/crates/orchestrator/src/alerts/aws_sns/mod.rs +++ b/crates/orchestrator/src/alerts/aws_sns/mod.rs @@ -4,25 +4,19 @@ use std::sync::Arc; use async_trait::async_trait; use aws_sdk_sns::Client; -use utils::settings::Settings; - -use crate::alerts::aws_sns::config::AWSSNSConfig; +use utils::cli::alert::aws_sns::AWSSNSParams; use crate::alerts::Alerts; use crate::config::ProviderConfig; -pub const AWS_SNS_SETTINGS_NAME: &str = "sns"; - pub struct AWSSNS { client: Client, topic_arn: String, } impl AWSSNS { - pub async fn new_with_settings(settings: &impl Settings, provider_config: Arc) -> Self { - let sns_config = - AWSSNSConfig::new_with_settings(settings).expect("Not able to get Aws sns config from provided settings"); + pub async fn new_with_settings(aws_sns_params: &AWSSNSParams, provider_config: Arc) -> Self { let config = provider_config.get_aws_client_or_panic(); - Self { client: Client::new(config), topic_arn: sns_config.sns_arn } + Self { client: Client::new(config), topic_arn: aws_sns_params.sns_arn.clone() } } } diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 771e746b..4bdea7c1 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -13,6 +13,7 @@ use color_eyre::eyre::eyre; use da_client_interface::DaClient; 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; @@ -20,7 +21,11 @@ use sharp_service::SharpProverService; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Url}; use starknet_settlement_client::StarknetSettlementClient; +use utils::cli::alert::aws_sns::AWSSNSParams; +use utils::cli::alert::AlertParams; use utils::cli::aws_config::AWSConfigParams; +use utils::cli::da::DaParams; +use utils::cli::database::DatabaseParams; use utils::cli::queue::QueueParams; use utils::cli::settlement::SettlementParams; use utils::cli::storage::StorageParams; @@ -110,8 +115,12 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { let provider = JsonRpcClient::new(HttpTransport::new(rpc_url.clone())); // init database - let database = build_database_client(&settings_provider).await; - let da_client = build_da_client(&settings_provider).await; + let database_params = run_cmd.clone().validate_database_params().map_err(|e| eyre!("Failed to validate database params: {e}"))?; + let database = build_database_client(&database_params).await; + + // init DA client + let da_params = run_cmd.clone().validate_da_params().map_err(|e| eyre!("Failed to validate DA params: {e}"))?; + let da_client = build_da_client(&da_params).await; // init settlement let settlement_params = run_cmd.clone().validate_settlement_params().map_err(|e| eyre!("Failed to validate settlement params: {e}"))?; @@ -123,7 +132,9 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { let data_storage_params = run_cmd.clone().validate_storage_params().map_err(|e| eyre!("Failed to validate storage params: {e}"))?; let storage_client = build_storage_client(&data_storage_params, provider_config.clone()).await; - let alerts_client = build_alert_client(&settings_provider, provider_config.clone()).await; + // init alerts + let alert_params = run_cmd.clone().validate_alert_params().map_err(|e| eyre!("Failed to validate alert params: {e}"))?; + let alerts_client = build_alert_client(&alert_params, provider_config.clone()).await; // init the queue // TODO: we use omniqueue for now which doesn't support loading AWS config @@ -227,15 +238,20 @@ impl Config { } } +use std::str::FromStr; + +use alloy::network::Ethereum; +use alloy::providers::ProviderBuilder; +use alloy::rpc::client::RpcClient; + /// Builds the DA client based on the environment variable DA_LAYER -pub async fn build_da_client(settings_provider: &impl Settings) -> Box { - match get_env_var_or_panic("DA_LAYER").as_str() { - "ethereum" => { - let config = EthereumDaConfig::new_with_settings(settings_provider) - .expect("Not able to build config from the given settings provider."); - Box::new(config.build_client().await) +pub async fn build_da_client(da_params: &DaParams) -> Box { + match da_params { + DaParams::Ethereum(ethereum_da_params) => { + let client = RpcClient::new_http(Url::from_str(ethereum_da_params.rpc_url.as_str()).expect("Failed to parse SETTLEMENT_RPC_URL")); + let provider = ProviderBuilder::<_, Ethereum>::new().on_client(client); + Box::new(EthereumDaClient { provider }) } - _ => panic!("Unsupported DA layer"), } } @@ -298,12 +314,11 @@ pub async fn build_storage_client( } pub async fn build_alert_client( - settings_provider: &impl Settings, + alert_params: &AlertParams, provider_config: Arc, ) -> Box { - match get_env_var_or_panic("ALERTS").as_str() { - "sns" => Box::new(AWSSNS::new_with_settings(settings_provider, provider_config).await), - _ => panic!("Unsupported Alert Client"), + match alert_params { + AlertParams::AWSSNS(aws_sns_params) => Box::new(AWSSNS::new_with_settings(aws_sns_params, provider_config).await), } } @@ -313,9 +328,8 @@ pub fn build_queue_client(queue_params: &QueueParams) -> Box Box { - match get_env_var_or_panic("DATABASE").as_str() { - "mongodb" => Box::new(MongoDb::new_with_settings(settings_provider).await), - _ => panic!("Unsupported Database Client"), +pub async fn build_database_client(database_params: &DatabaseParams) -> Box { + match database_params { + DatabaseParams::MongoDB(mongodb_params) => Box::new(MongoDb::new_with_settings(mongodb_params).await), } } diff --git a/crates/orchestrator/src/database/mongodb/mod.rs b/crates/orchestrator/src/database/mongodb/mod.rs index f2989db3..fd313263 100644 --- a/crates/orchestrator/src/database/mongodb/mod.rs +++ b/crates/orchestrator/src/database/mongodb/mod.rs @@ -1,4 +1,3 @@ -use ::utils::settings::Settings; use async_std::stream::StreamExt; use async_trait::async_trait; use chrono::{SubsecRound, Utc}; @@ -11,11 +10,11 @@ use mongodb::options::{ UpdateOptions, }; use mongodb::{bson, Client, Collection}; +use ::utils::cli::database::mongodb::MongoDBParams; use utils::ToDocument; use uuid::Uuid; -use crate::database::mongodb::config::MongoDbConfig; -use crate::database::{Database, DatabaseConfig}; +use crate::database::Database; use crate::jobs::types::{JobItem, JobItemUpdates, JobStatus, JobType}; use crate::jobs::JobError; @@ -28,10 +27,9 @@ pub struct MongoDb { } impl MongoDb { - pub async fn new_with_settings(settings: &impl Settings) -> Self { - let mongo_db_settings = MongoDbConfig::new_with_settings(settings); + pub async fn new_with_settings(mongodb_params: &MongoDBParams) -> Self { let mut client_options = - ClientOptions::parse(mongo_db_settings.url).await.expect("Failed to parse MongoDB Url"); + ClientOptions::parse(mongodb_params.connection_url.clone()).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 let server_api = ServerApi::builder().version(ServerApiVersion::V1).build(); @@ -46,7 +44,7 @@ impl MongoDb { .expect("Failed to ping MongoDB deployment"); tracing::debug!("Pinged your deployment. You successfully connected to MongoDB!"); - Self { client, database_name: mongo_db_settings.database_name } + Self { client, database_name: mongodb_params.database_name.clone() } } /// Mongodb client uses Arc internally, reducing the cost of clone. diff --git a/crates/utils/src/cli/alert/mod.rs b/crates/utils/src/cli/alert/mod.rs index bfe56638..d7cb1801 100644 --- a/crates/utils/src/cli/alert/mod.rs +++ b/crates/utils/src/cli/alert/mod.rs @@ -1 +1,6 @@ -pub mod aws_sns; \ No newline at end of file +pub mod aws_sns; + +#[derive(Clone, Debug)] +pub enum AlertParams { + AWSSNS(aws_sns::AWSSNSParams), +} \ No newline at end of file diff --git a/crates/utils/src/cli/da/ethereum.rs b/crates/utils/src/cli/da/ethereum.rs index 28dca95a..e0e8a911 100644 --- a/crates/utils/src/cli/da/ethereum.rs +++ b/crates/utils/src/cli/da/ethereum.rs @@ -1,9 +1,10 @@ use clap::Args; +use url::Url; /// Parameters used to config Ethereum. #[derive(Debug, Clone, Args)] pub struct EthereumParams { /// The RPC URL of the Ethereum node. #[arg(env = "DA_RPC_URL", long)] - pub rpc_url: String, + pub rpc_url: Url, } diff --git a/crates/utils/src/cli/da/mod.rs b/crates/utils/src/cli/da/mod.rs index 84eb5551..6cc1f9eb 100644 --- a/crates/utils/src/cli/da/mod.rs +++ b/crates/utils/src/cli/da/mod.rs @@ -1 +1,6 @@ -pub mod ethereum; \ No newline at end of file +pub mod ethereum; + +#[derive(Debug, Clone)] +pub enum DaParams { + Ethereum(ethereum::EthereumParams), +} diff --git a/crates/utils/src/cli/database/mod.rs b/crates/utils/src/cli/database/mod.rs index 7db7304d..50f47442 100644 --- a/crates/utils/src/cli/database/mod.rs +++ b/crates/utils/src/cli/database/mod.rs @@ -1 +1,6 @@ -pub mod mongodb; \ No newline at end of file +pub mod mongodb; + +#[derive(Debug, Clone)] +pub enum DatabaseParams { + MongoDB(mongodb::MongoDBParams), +} \ No newline at end of file diff --git a/crates/utils/src/cli/database/mongodb.rs b/crates/utils/src/cli/database/mongodb.rs index 83f40fa2..d77c94a5 100644 --- a/crates/utils/src/cli/database/mongodb.rs +++ b/crates/utils/src/cli/database/mongodb.rs @@ -4,8 +4,8 @@ use clap::Args; #[derive(Debug, Clone, Args)] pub struct MongoDBParams { /// The connection string to the MongoDB server. - #[arg(env = "MONGODB_CONNECTION_STRING", long)] - pub connection_string: String, + #[arg(env = "MONGODB_CONNECTION_URL", long)] + pub connection_url: String, /// The name of the database. #[arg(env = "DATABASE_NAME", long)] diff --git a/crates/utils/src/cli/mod.rs b/crates/utils/src/cli/mod.rs index ef0588c1..2516da18 100644 --- a/crates/utils/src/cli/mod.rs +++ b/crates/utils/src/cli/mod.rs @@ -1,4 +1,7 @@ +use alert::AlertParams; use clap::ArgGroup; +use da::DaParams; +use database::DatabaseParams; use queue::QueueParams; use settlement::SettlementParams; use storage::StorageParams; @@ -40,12 +43,12 @@ pub mod snos; .multiple(false) ), - // group( - // ArgGroup::new("alert") - // .args(&["aws_sns"]) - // .required(true) - // .multiple(false) - // ), + group( + ArgGroup::new("alert") + .args(&["aws_sns"]) + .required(true) + .multiple(false) + ), // group( // ArgGroup::new("prover") @@ -56,16 +59,17 @@ pub mod snos; - // group( - // ArgGroup::new("da_layer") - // .args(&["ethereum"]) - // .required(true) - // .multiple(false) - // ), + group( + ArgGroup::new("da_layer") + .args(&["da_on_ethereum"]) + .required(true) + .multiple(false) + ), )] pub struct RunCmd { + // AWS Config #[clap(flatten)] pub aws_config: aws_config::AWSConfigParams, @@ -100,22 +104,27 @@ pub struct RunCmd { #[clap(flatten)] pub server: server::ServerParams, - - // // part of storage - - // // part of queue - // #[clap(flatten)] - // pub aws_sqs: queue::aws_sqs::AWSSQSParams, + // Alert + #[clap(long, group = "alert")] + pub aws_sns: bool, - // // part of alert - // #[clap(flatten)] - // pub aws_sns: alert::aws_sns::AWSSNSParams, + #[clap(flatten)] + pub aws_sns_params: alert::aws_sns::AWSSNSParams, + // Database + #[clap(long, group = "database")] + pub mongodb: bool, - // // part of database - // #[clap(flatten)] - // pub mongodb: database::mongodb::MongoDBParams, + #[clap(flatten)] + pub mongodb_params: database::mongodb::MongoDBParams, + // Data Availability Layer + #[clap(long, group = "da_layer")] + pub da_on_ethereum: bool, + + #[clap(flatten)] + pub ethereum_da_params: da::ethereum::EthereumParams, + // // part of prover // #[clap(flatten)] // pub sharp: prover::sharp::SharpParams, @@ -124,13 +133,6 @@ pub struct RunCmd { // #[clap(flatten)] // pub ethereum_da: da::ethereum::EthereumParams, - - // #[clap(flatten)] - // pub starknet_settlement: settlement::starknet::StarknetSettlementParams, - - // #[clap(flatten)] - // pub ethereum_settlement: settlement::ethereum::EthereumSettlementParams, - // #[clap(flatten)] // pub snos: snos::SNOSParams, @@ -187,4 +189,28 @@ impl RunCmd { } } + pub fn validate_alert_params(self) -> Result { + if self.aws_sns { + Ok(AlertParams::AWSSNS(self.aws_sns_params)) + } else { + Err("Only AWS SNS is supported as of now".to_string()) + } + } + + pub fn validate_database_params(self) -> Result { + if self.mongodb { + Ok(DatabaseParams::MongoDB(self.mongodb_params)) + } else { + Err("Only MongoDB is supported as of now".to_string()) + } + } + + pub fn validate_da_params(self) -> Result { + if self.da_on_ethereum { + Ok(DaParams::Ethereum(self.ethereum_da_params)) + } else { + Err("Only Ethereum is supported as of now".to_string()) + } + } + } \ No newline at end of file From bc44afdec64a6f3822298cff0698495cf0765537 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 6 Nov 2024 13:46:01 +0530 Subject: [PATCH 07/63] update: run_cmd for sharp and snos --- crates/orchestrator/src/config.rs | 41 ++++++++++++++----- crates/orchestrator/src/jobs/snos_job/mod.rs | 2 +- crates/orchestrator/src/workers/snos.rs | 13 ++---- .../gps-fact-checker/src/lib.rs | 10 +++-- .../sharp-service/src/client.rs | 13 +++--- .../prover-services/sharp-service/src/lib.rs | 9 ++-- crates/utils/src/cli/mod.rs | 38 +++++++++-------- crates/utils/src/cli/prover/mod.rs | 9 +++- crates/utils/src/cli/prover/sharp.rs | 7 +++- crates/utils/src/cli/snos.rs | 9 ++-- 10 files changed, 92 insertions(+), 59 deletions(-) diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 4bdea7c1..3986396b 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -26,6 +26,7 @@ use utils::cli::alert::AlertParams; use utils::cli::aws_config::AWSConfigParams; use utils::cli::da::DaParams; use utils::cli::database::DatabaseParams; +use utils::cli::prover::ProverParams; use utils::cli::queue::QueueParams; use utils::cli::settlement::SettlementParams; use utils::cli::storage::StorageParams; @@ -51,7 +52,7 @@ pub struct Config { /// The RPC url to be used when running SNOS /// When Madara supports getProof, we can re use /// starknet_rpc_url for SNOS as well - snos_url: Url, + snos_config: SnosConfig, /// The starknet client to get data from the node starknet_client: Arc>, /// The DA client to interact with the DA layer @@ -70,6 +71,14 @@ pub struct Config { alerts: Box, } + +#[derive(Debug, Clone)] +pub struct SnosConfig { + pub rpc_url : Url, + pub max_block_to_process : u64, + pub min_block_to_process : u64, +} + /// `ProviderConfig` is an enum used to represent the global config built /// using the settings provider. More providers can be added eg : GCP, AZURE etc. /// @@ -111,7 +120,15 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { // init starknet client let rpc_url = Url::parse(&settings_provider.get_settings_or_panic("MADARA_RPC_URL")).expect("Failed to parse URL"); - let snos_url = Url::parse(&settings_provider.get_settings_or_panic("RPC_FOR_SNOS")).expect("Failed to parse URL"); + + + // init snos url + let snos_config = SnosConfig { + rpc_url : run_cmd.snos.rpc_for_snos, + max_block_to_process : run_cmd.snos.max_block_to_process, + min_block_to_process : run_cmd.snos.min_block_to_process, + }; + let provider = JsonRpcClient::new(HttpTransport::new(rpc_url.clone())); // init database @@ -126,7 +143,9 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { let settlement_params = run_cmd.clone().validate_settlement_params().map_err(|e| eyre!("Failed to validate settlement params: {e}"))?; let settlement_client = build_settlement_client(&settlement_params).await?; - let prover_client = build_prover_service(&settings_provider); + // init prover + let prover_params = run_cmd.clone().validate_prover_params().map_err(|e| eyre!("Failed to validate prover params: {e}"))?; + let prover_client = build_prover_service(&prover_params); // init storage let data_storage_params = run_cmd.clone().validate_storage_params().map_err(|e| eyre!("Failed to validate storage params: {e}"))?; @@ -146,7 +165,7 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { Ok(Arc::new(Config::new( rpc_url, - snos_url, + snos_config, Arc::new(provider), da_client, prover_client, @@ -163,7 +182,7 @@ impl Config { #[allow(clippy::too_many_arguments)] pub fn new( starknet_rpc_url: Url, - snos_url: Url, + snos_config: SnosConfig, starknet_client: Arc>, da_client: Box, prover_client: Box, @@ -175,7 +194,7 @@ impl Config { ) -> Self { Self { starknet_rpc_url, - snos_url, + snos_config, starknet_client, da_client, prover_client, @@ -193,8 +212,8 @@ impl Config { } /// Returns the snos rpc url - pub fn snos_url(&self) -> &Url { - &self.snos_url + pub fn snos_config(&self) -> &SnosConfig { + &self.snos_config } /// Returns the starknet client @@ -256,9 +275,9 @@ pub async fn build_da_client(da_params: &DaParams) -> Box Box { - match get_env_var_or_panic("PROVER_SERVICE").as_str() { - "sharp" => Box::new(SharpProverService::new_with_settings(settings_provider)), +pub fn build_prover_service(prover_params: &ProverParams) -> Box { + match prover_params { + ProverParams::Sharp(sharp_params) => Box::new(SharpProverService::new_with_settings(sharp_params)), _ => panic!("Unsupported prover service"), } } diff --git a/crates/orchestrator/src/jobs/snos_job/mod.rs b/crates/orchestrator/src/jobs/snos_job/mod.rs index f257a211..2573b16b 100644 --- a/crates/orchestrator/src/jobs/snos_job/mod.rs +++ b/crates/orchestrator/src/jobs/snos_job/mod.rs @@ -103,7 +103,7 @@ impl Job for SnosJob { let block_number = self.get_block_number_from_metadata(job)?; tracing::debug!(job_id = %job.internal_id, block_number = %block_number, "Retrieved block number from metadata"); - let snos_url = config.snos_url().to_string(); + let snos_url = config.snos_config().rpc_url.to_string(); let snos_url = snos_url.trim_end_matches('/'); tracing::debug!(job_id = %job.internal_id, "Calling prove_block function"); let (cairo_pie, snos_output) = diff --git a/crates/orchestrator/src/workers/snos.rs b/crates/orchestrator/src/workers/snos.rs index ccff21ed..5ba1fd09 100644 --- a/crates/orchestrator/src/workers/snos.rs +++ b/crates/orchestrator/src/workers/snos.rs @@ -23,8 +23,8 @@ impl Worker for SnosWorker { let provider = config.starknet_client(); let block_number_provider = &provider.block_number().await?; - let latest_block_number = - get_env_var_or_default_block_number("MAX_BLOCK_TO_PROCESS", &block_number_provider.to_string())?; + let snos_config = config.snos_config(); + let latest_block_number = snos_config.max_block_to_process; tracing::debug!(latest_block_number = %latest_block_number, "Fetched latest block number from starknet"); let latest_job_in_db = config.database().get_latest_job_by_type(JobType::SnosRun).await?; @@ -35,7 +35,7 @@ impl Worker for SnosWorker { }; // To be used when testing in specific block range - let block_start = get_env_var_or_default_block_number("MIN_BLOCK_TO_PROCESS", &latest_job_id)?; + let block_start = snos_config.min_block_to_process; for block_num in block_start..latest_block_number + 1 { match create_job(JobType::SnosRun, block_num.to_string(), HashMap::new(), config.clone()).await { @@ -50,10 +50,3 @@ impl Worker for SnosWorker { } } -fn get_env_var_or_default_block_number(env_var_name: &str, default_block_number: &str) -> color_eyre::Result { - if get_env_var_or_default(env_var_name, default_block_number) == *"" { - Ok(default_block_number.to_string().parse::()?) - } else { - Ok(get_env_var_or_default(env_var_name, default_block_number).parse::()?) - } -} diff --git a/crates/prover-services/gps-fact-checker/src/lib.rs b/crates/prover-services/gps-fact-checker/src/lib.rs index 87f0252b..77e96d68 100644 --- a/crates/prover-services/gps-fact-checker/src/lib.rs +++ b/crates/prover-services/gps-fact-checker/src/lib.rs @@ -1,8 +1,10 @@ +use std::str::FromStr as _; + use alloy::primitives::{Address, B256}; use alloy::providers::{ProviderBuilder, RootProvider}; use alloy::sol; use alloy::transports::http::{Client, Http}; -use url::Url; +use utils::cli::prover::sharp::SharpParams; sol!( #[allow(missing_docs)] @@ -25,9 +27,9 @@ type TransportT = Http; type ProviderT = RootProvider; impl FactChecker { - pub fn new(rpc_node_url: Url, verifier_address: Address) -> Self { - let provider = ProviderBuilder::new().on_http(rpc_node_url); - let fact_registry = FactRegistry::new(verifier_address, provider); + pub fn new(sharp_params: &SharpParams) -> Self { + let provider = ProviderBuilder::new().on_http(sharp_params.sharp_rpc_node_url.clone()); + let fact_registry = FactRegistry::new(Address::from_str(sharp_params.gps_verifier_contract_address.as_str()).unwrap() , provider); Self { fact_registry } } diff --git a/crates/prover-services/sharp-service/src/client.rs b/crates/prover-services/sharp-service/src/client.rs index c652e23d..17b94feb 100644 --- a/crates/prover-services/sharp-service/src/client.rs +++ b/crates/prover-services/sharp-service/src/client.rs @@ -4,6 +4,7 @@ use base64::engine::general_purpose; use base64::Engine; use reqwest::{Certificate, ClientBuilder, Identity}; use url::Url; +use utils::cli::prover::sharp::SharpParams; use utils::env_utils::get_env_var_or_panic; use utils::settings::Settings; use uuid::Uuid; @@ -28,23 +29,23 @@ impl SharpClient { /// and then copy it and paste it into .env file : /// /// `cat | base64` - pub fn new_with_settings(url: Url, settings: &impl Settings) -> Self { + pub fn new_with_settings(url: Url, sharp_params: &SharpParams) -> Self { // Getting the cert files from the .env and then decoding it from base64 - + let cert = general_purpose::STANDARD - .decode(settings.get_settings_or_panic("SHARP_USER_CRT")) + .decode(sharp_params.sharp_user_crt.clone()) .expect("Failed to decode certificate"); let key = general_purpose::STANDARD - .decode(settings.get_settings_or_panic("SHARP_USER_KEY")) + .decode(sharp_params.sharp_user_key.clone()) .expect("Failed to decode sharp user key"); let server_cert = general_purpose::STANDARD - .decode(settings.get_settings_or_panic("SHARP_SERVER_CRT")) + .decode(sharp_params.sharp_server_crt.clone()) .expect("Failed to decode sharp server certificate"); // Adding Customer ID to the url let mut url_mut = url.clone(); - let customer_id = settings.get_settings_or_panic("SHARP_CUSTOMER_ID"); + let customer_id = sharp_params.sharp_customer_id.clone(); url_mut.query_pairs_mut().append_pair("customer_id", customer_id.as_str()); Self { diff --git a/crates/prover-services/sharp-service/src/lib.rs b/crates/prover-services/sharp-service/src/lib.rs index 6cdb8cbb..a1967c78 100644 --- a/crates/prover-services/sharp-service/src/lib.rs +++ b/crates/prover-services/sharp-service/src/lib.rs @@ -10,6 +10,7 @@ use async_trait::async_trait; use gps_fact_checker::FactChecker; use prover_client_interface::{ProverClient, ProverClientError, Task, TaskStatus}; use starknet_os::sharp::CairoJobStatus; +use utils::cli::prover::sharp::SharpParams; use utils::settings::Settings; use uuid::Uuid; @@ -134,11 +135,9 @@ impl SharpProverService { Self { sharp_client, fact_checker } } - pub fn new_with_settings(settings: &impl Settings) -> Self { - let sharp_config = SharpConfig::new_with_settings(settings) - .expect("Not able to create SharpProverService from given settings."); - let sharp_client = SharpClient::new_with_settings(sharp_config.service_url, settings); - let fact_checker = FactChecker::new(sharp_config.rpc_node_url, sharp_config.verifier_address); + pub fn new_with_settings(sharp_params: &SharpParams) -> Self { + let sharp_client = SharpClient::new_with_settings(sharp_params.sharp_url.clone(), sharp_params); + let fact_checker = FactChecker::new(sharp_params); Self::new(sharp_client, fact_checker) } diff --git a/crates/utils/src/cli/mod.rs b/crates/utils/src/cli/mod.rs index 2516da18..afe1aa52 100644 --- a/crates/utils/src/cli/mod.rs +++ b/crates/utils/src/cli/mod.rs @@ -2,6 +2,7 @@ use alert::AlertParams; use clap::ArgGroup; use da::DaParams; use database::DatabaseParams; +use prover::ProverParams; use queue::QueueParams; use settlement::SettlementParams; use storage::StorageParams; @@ -50,14 +51,12 @@ pub mod snos; .multiple(false) ), - // group( - // ArgGroup::new("prover") - // .args(&["sharp"]) - // .required(true) - // .multiple(false) - // ), - - + group( + ArgGroup::new("prover") + .args(&["sharp"]) + .required(true) + .multiple(false) + ), group( ArgGroup::new("da_layer") @@ -125,16 +124,15 @@ pub struct RunCmd { #[clap(flatten)] pub ethereum_da_params: da::ethereum::EthereumParams, - // // part of prover - // #[clap(flatten)] - // pub sharp: prover::sharp::SharpParams, + // Prover + #[clap(long, group = "prover")] + pub sharp: bool, - // // part of da_layer - // #[clap(flatten)] - // pub ethereum_da: da::ethereum::EthereumParams, + #[clap(flatten)] + pub sharp_params: prover::sharp::SharpParams, - // #[clap(flatten)] - // pub snos: snos::SNOSParams, + #[clap(flatten)] + pub snos: snos::SNOSParams, // pub madara_rpc_url: Url, @@ -213,4 +211,12 @@ impl RunCmd { } } + pub fn validate_prover_params(self) -> Result { + if self.sharp { + Ok(ProverParams::Sharp(self.sharp_params)) + } else { + Err("Only Sharp is supported as of now".to_string()) + } + } + } \ No newline at end of file diff --git a/crates/utils/src/cli/prover/mod.rs b/crates/utils/src/cli/prover/mod.rs index f8ceadda..2b66131d 100644 --- a/crates/utils/src/cli/prover/mod.rs +++ b/crates/utils/src/cli/prover/mod.rs @@ -1 +1,8 @@ -pub mod sharp; \ No newline at end of file +use sharp::SharpParams; + +pub mod sharp; + +#[derive(Debug, Clone)] +pub enum ProverParams { + Sharp(SharpParams), +} diff --git a/crates/utils/src/cli/prover/sharp.rs b/crates/utils/src/cli/prover/sharp.rs index 3d317ee6..e2262ea8 100644 --- a/crates/utils/src/cli/prover/sharp.rs +++ b/crates/utils/src/cli/prover/sharp.rs @@ -1,4 +1,5 @@ use clap::Args; +use url::Url; /// Parameters used to config Sharp. #[derive(Debug, Clone, Args)] @@ -10,7 +11,7 @@ pub struct SharpParams { /// The URL of the Sharp server. #[arg(env = "SHARP_URL", long)] - pub sharp_url: String, + pub sharp_url: Url, /// The user certificate for Sharp. #[arg(env = "SHARP_USER_CRT", long)] @@ -20,6 +21,10 @@ pub struct SharpParams { #[arg(env = "SHARP_USER_KEY", long)] pub sharp_user_key: String, + /// The RPC node URL for Sharp. + #[arg(env = "SHARP_RPC_NODE_URL", long)] + pub sharp_rpc_node_url: Url, + /// The server certificate for Sharp. #[arg(env = "SHARP_SERVER_CRT", long)] pub sharp_server_crt: String, diff --git a/crates/utils/src/cli/snos.rs b/crates/utils/src/cli/snos.rs index 65129a59..aca2110a 100644 --- a/crates/utils/src/cli/snos.rs +++ b/crates/utils/src/cli/snos.rs @@ -1,16 +1,17 @@ use clap::Args; +use url::Url; #[derive(Debug, Clone, Args)] pub struct SNOSParams { /// The RPC URL for SNOS. - #[arg(env = "RPC_FOR_SNOS", long)] - pub rpc_for_snos: String, + #[arg(env = "RPC_FOR_SNOS", long, required = true)] + pub rpc_for_snos: Url, /// The maximum block to process. #[arg(env = "MAX_BLOCK_TO_PROCESS", long)] - pub max_block_to_process: String, + pub max_block_to_process: u64, /// The minimum block to process. #[arg(env = "MIN_BLOCK_TO_PROCESS", long)] - pub min_block_to_process: String, + pub min_block_to_process: u64, } From 2c1d5cb4b7f1ac5ef14ad9a493ff8708ac29f42a Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 6 Nov 2024 13:51:15 +0530 Subject: [PATCH 08/63] update: run_cmd for madara rpc url --- crates/orchestrator/src/config.rs | 3 +-- crates/utils/src/cli/mod.rs | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 3986396b..33131896 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -119,8 +119,7 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(aws_config).await))); // init starknet client - let rpc_url = Url::parse(&settings_provider.get_settings_or_panic("MADARA_RPC_URL")).expect("Failed to parse URL"); - + let rpc_url = run_cmd.madara_rpc_url; // init snos url let snos_config = SnosConfig { diff --git a/crates/utils/src/cli/mod.rs b/crates/utils/src/cli/mod.rs index afe1aa52..e148e466 100644 --- a/crates/utils/src/cli/mod.rs +++ b/crates/utils/src/cli/mod.rs @@ -6,6 +6,7 @@ use prover::ProverParams; use queue::QueueParams; use settlement::SettlementParams; use storage::StorageParams; +use url::Url; pub mod aws_config; pub mod database; @@ -134,7 +135,8 @@ pub struct RunCmd { #[clap(flatten)] pub snos: snos::SNOSParams, - // pub madara_rpc_url: Url, + #[arg(env = "MADARA_RPC_URL", long, required = true)] + pub madara_rpc_url: Url, #[clap(flatten)] pub instrumentation: instrumentation::InstrumentationParams, From 00b2e3179846f537be39ae6aa1eab2647531a519 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 6 Nov 2024 15:57:54 +0530 Subject: [PATCH 09/63] update: run_cmd adaptation for: testcases --- crates/orchestrator/src/config.rs | 24 ++--- crates/orchestrator/src/main.rs | 2 +- crates/orchestrator/src/routes/mod.rs | 6 +- crates/orchestrator/src/tests/common/mod.rs | 76 ++++++++-------- crates/orchestrator/src/tests/config.rs | 83 ++++++++++------- .../orchestrator/src/tests/jobs/da_job/mod.rs | 2 - crates/orchestrator/src/tests/jobs/mod.rs | 12 +-- .../src/tests/workers/proving/mod.rs | 7 +- .../src/tests/workers/snos/mod.rs | 5 +- .../prover-services/sharp-service/src/lib.rs | 11 +-- .../sharp-service/tests/lib.rs | 90 +++++++++---------- crates/utils/src/cli/queue/aws_sqs.rs | 41 +++++---- e2e-tests/src/localstack.rs | 8 +- 13 files changed, 196 insertions(+), 171 deletions(-) diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 33131896..5b703e83 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -12,7 +12,6 @@ use aws_credential_types::Credentials; use color_eyre::eyre::eyre; use da_client_interface::DaClient; use dotenvy::dotenv; -use ethereum_da_client::config::EthereumDaConfig; use ethereum_da_client::EthereumDaClient; use ethereum_settlement_client::EthereumSettlementClient; use prover_client_interface::ProverClient; @@ -21,19 +20,16 @@ use sharp_service::SharpProverService; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Url}; use starknet_settlement_client::StarknetSettlementClient; -use utils::cli::alert::aws_sns::AWSSNSParams; use utils::cli::alert::AlertParams; use utils::cli::aws_config::AWSConfigParams; use utils::cli::da::DaParams; use utils::cli::database::DatabaseParams; use utils::cli::prover::ProverParams; use utils::cli::queue::QueueParams; +use utils::cli::server::ServerParams; use utils::cli::settlement::SettlementParams; use utils::cli::storage::StorageParams; use utils::cli::RunCmd; -use utils::env_utils::get_env_var_or_panic; -use utils::settings::env::EnvSettingsProvider; -use utils::settings::Settings; use crate::alerts::aws_sns::AWSSNS; use crate::alerts::Alerts; @@ -49,6 +45,8 @@ use crate::queue::QueueProvider; pub struct Config { /// The RPC url used by the [starknet_client] starknet_rpc_url: Url, + + server_config: ServerParams, /// The RPC url to be used when running SNOS /// When Madara supports getProof, we can re use /// starknet_rpc_url for SNOS as well @@ -113,21 +111,20 @@ pub async fn get_aws_config(aws_config: &AWSConfigParams) -> SdkConfig { pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { dotenv().ok(); - let settings_provider = EnvSettingsProvider {}; - let aws_config = &run_cmd.aws_config; let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(aws_config).await))); // init starknet client - let rpc_url = run_cmd.madara_rpc_url; + let rpc_url = run_cmd.madara_rpc_url.clone(); // init snos url let snos_config = SnosConfig { - rpc_url : run_cmd.snos.rpc_for_snos, + rpc_url : run_cmd.snos.rpc_for_snos.clone(), max_block_to_process : run_cmd.snos.max_block_to_process, min_block_to_process : run_cmd.snos.min_block_to_process, }; + let server_config = run_cmd.server.clone(); let provider = JsonRpcClient::new(HttpTransport::new(rpc_url.clone())); // init database @@ -164,6 +161,7 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { Ok(Arc::new(Config::new( rpc_url, + server_config, snos_config, Arc::new(provider), da_client, @@ -181,6 +179,7 @@ impl Config { #[allow(clippy::too_many_arguments)] pub fn new( starknet_rpc_url: Url, + server_config: ServerParams, snos_config: SnosConfig, starknet_client: Arc>, da_client: Box, @@ -193,6 +192,7 @@ impl Config { ) -> Self { Self { starknet_rpc_url, + server_config, snos_config, starknet_client, da_client, @@ -210,6 +210,11 @@ impl Config { &self.starknet_rpc_url } + /// Returns the server config + pub fn server_config(&self) -> &ServerParams { + &self.server_config + } + /// Returns the snos rpc url pub fn snos_config(&self) -> &SnosConfig { &self.snos_config @@ -277,7 +282,6 @@ pub async fn build_da_client(da_params: &DaParams) -> Box Box { match prover_params { ProverParams::Sharp(sharp_params) => Box::new(SharpProverService::new_with_settings(sharp_params)), - _ => panic!("Unsupported prover service"), } } diff --git a/crates/orchestrator/src/main.rs b/crates/orchestrator/src/main.rs index c317ceed..e29337cf 100644 --- a/crates/orchestrator/src/main.rs +++ b/crates/orchestrator/src/main.rs @@ -27,7 +27,7 @@ async fn main() { tracing::debug!(service = "orchestrator", "Configuration initialized"); // initialize the server - let _ = setup_server(config.clone(), run_cmd.server).await; + let _ = setup_server(config.clone()).await; tracing::debug!(service = "orchestrator", "Application router initialized"); diff --git a/crates/orchestrator/src/routes/mod.rs b/crates/orchestrator/src/routes/mod.rs index 756105ab..10539978 100644 --- a/crates/orchestrator/src/routes/mod.rs +++ b/crates/orchestrator/src/routes/mod.rs @@ -50,8 +50,8 @@ where } } -pub async fn setup_server(config: Arc, server_params: ServerParams) -> SocketAddr { - let (api_server_url, listener) = get_server_url(server_params).await; +pub async fn setup_server(config: Arc) -> SocketAddr { + let (api_server_url, listener) = get_server_url(config.server_config()).await; let job_routes = job_router(config.clone()); let app_routes = app_router(); @@ -64,7 +64,7 @@ pub async fn setup_server(config: Arc, server_params: ServerParams) -> S api_server_url } -pub async fn get_server_url(server_params: ServerParams) -> (SocketAddr, tokio::net::TcpListener) { +pub async fn get_server_url(server_params: &ServerParams) -> (SocketAddr, tokio::net::TcpListener) { let address = format!("{}:{}", server_params.host, server_params.port); let listener = tokio::net::TcpListener::bind(address.clone()).await.expect("Failed to get listener"); let api_server_url = listener.local_addr().expect("Unable to bind address to listener."); diff --git a/crates/orchestrator/src/tests/common/mod.rs b/crates/orchestrator/src/tests/common/mod.rs index 141348f9..72d7d10d 100644 --- a/crates/orchestrator/src/tests/common/mod.rs +++ b/crates/orchestrator/src/tests/common/mod.rs @@ -3,8 +3,10 @@ pub mod constants; use std::collections::HashMap; use std::sync::Arc; +use utils::cli::database::DatabaseParams; +use utils::cli::queue::aws_sqs::QueueType; +use utils::cli::queue::QueueParams; use utils::cli::storage::aws_s3::AWSS3Params; -use utils::cli::storage::StorageParams; use ::uuid::Uuid; use aws_config::SdkConfig; use aws_sdk_sns::error::SdkError; @@ -14,7 +16,6 @@ use mongodb::Client; use rstest::*; use serde::Deserialize; use utils::env_utils::get_env_var_or_panic; -use utils::settings::env::EnvSettingsProvider; use crate::config::ProviderConfig; use crate::data_storage::aws_s3::AWSS3; @@ -23,12 +24,7 @@ use crate::database::mongodb::MongoDb; use crate::jobs::types::JobStatus::Created; use crate::jobs::types::JobType::DataSubmission; use crate::jobs::types::{ExternalId, JobItem}; -use crate::queue::job_queue::{ - DATA_SUBMISSION_JOB_PROCESSING_QUEUE, DATA_SUBMISSION_JOB_VERIFICATION_QUEUE, - PROOF_REGISTRATION_JOB_PROCESSING_QUEUE, PROOF_REGISTRATION_JOB_VERIFICATION_QUEUE, PROVING_JOB_PROCESSING_QUEUE, - PROVING_JOB_VERIFICATION_QUEUE, SNOS_JOB_PROCESSING_QUEUE, SNOS_JOB_VERIFICATION_QUEUE, - UPDATE_STATE_JOB_PROCESSING_QUEUE, UPDATE_STATE_JOB_VERIFICATION_QUEUE, -}; + #[fixture] pub fn default_job_item() -> JobItem { @@ -63,43 +59,47 @@ pub async fn get_sns_client(aws_config: &SdkConfig) -> aws_sdk_sns::client::Clie aws_sdk_sns::Client::new(aws_config) } -pub async fn drop_database() -> color_eyre::Result<()> { - let db_client: Client = MongoDb::new_with_settings(&EnvSettingsProvider {}).await.client(); - // dropping all the collection. - // use .collection::("") - // if only particular collection is to be dropped - db_client.database("orchestrator").drop(None).await?; +pub async fn drop_database( + database_params: &DatabaseParams, +) -> color_eyre::Result<()> { + match database_params { + DatabaseParams::MongoDB(mongodb_params) => { + let db_client: Client = MongoDb::new_with_settings(&mongodb_params).await.client(); + // dropping all the collection. + // use .collection::("") + // if only particular collection is to be dropped + db_client.database(&mongodb_params.database_name).drop(None).await?; + } + } Ok(()) } // SQS structs & functions -pub async fn create_sqs_queues(provider_config: Arc) -> color_eyre::Result<()> { - let sqs_client = get_sqs_client(provider_config).await; - - // Dropping sqs queues - let list_queues_output = sqs_client.list_queues().send().await?; - let queue_urls = list_queues_output.queue_urls(); - tracing::debug!("Found {} queues", queue_urls.len()); - for queue_url in queue_urls { - match sqs_client.delete_queue().queue_url(queue_url).send().await { - Ok(_) => tracing::debug!("Successfully deleted queue: {}", queue_url), - Err(e) => tracing::error!("Error deleting queue {}: {:?}", queue_url, e), - } - } +pub async fn create_queues(provider_config: Arc, queue_params: &QueueParams) -> color_eyre::Result<()> { - // Creating SQS queues - sqs_client.create_queue().queue_name(DATA_SUBMISSION_JOB_PROCESSING_QUEUE).send().await?; - sqs_client.create_queue().queue_name(DATA_SUBMISSION_JOB_VERIFICATION_QUEUE).send().await?; - sqs_client.create_queue().queue_name(SNOS_JOB_PROCESSING_QUEUE).send().await?; - sqs_client.create_queue().queue_name(SNOS_JOB_VERIFICATION_QUEUE).send().await?; - sqs_client.create_queue().queue_name(PROVING_JOB_PROCESSING_QUEUE).send().await?; - sqs_client.create_queue().queue_name(PROVING_JOB_VERIFICATION_QUEUE).send().await?; - sqs_client.create_queue().queue_name(PROOF_REGISTRATION_JOB_PROCESSING_QUEUE).send().await?; - sqs_client.create_queue().queue_name(PROOF_REGISTRATION_JOB_VERIFICATION_QUEUE).send().await?; - sqs_client.create_queue().queue_name(UPDATE_STATE_JOB_PROCESSING_QUEUE).send().await?; - sqs_client.create_queue().queue_name(UPDATE_STATE_JOB_VERIFICATION_QUEUE).send().await?; + match queue_params { + QueueParams::AWSSQS(aws_sqs_params) => { + let sqs_client = get_sqs_client(provider_config).await; + + // Dropping sqs queues + let list_queues_output = sqs_client.list_queues().send().await?; + let queue_urls = list_queues_output.queue_urls(); + tracing::debug!("Found {} queues", queue_urls.len()); + for queue_url in queue_urls { + match sqs_client.delete_queue().queue_url(queue_url).send().await { + Ok(_) => tracing::debug!("Successfully deleted queue: {}", queue_url), + Err(e) => tracing::error!("Error deleting queue {}: {:?}", queue_url, e), + } + } + + for queue_type in QueueType::iter() { + let queue_name = aws_sqs_params.get_queue_name(queue_type); + sqs_client.create_queue().queue_name(queue_name).send().await?; + } + } + } Ok(()) } diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 2f1e5852..8340103c 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -12,16 +12,14 @@ use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::JsonRpcClient; use url::Url; use utils::cli::RunCmd; -use utils::settings::env::EnvSettingsProvider; -use utils::settings::Settings; use crate::alerts::Alerts; -use crate::config::{get_aws_config, Config, ProviderConfig}; +use crate::config::{get_aws_config, Config, ProviderConfig, SnosConfig}; use crate::data_storage::{DataStorage, MockDataStorage}; use crate::database::{Database, MockDatabase}; use crate::queue::{MockQueueProvider, QueueProvider}; use crate::routes::{get_server_url, setup_server}; -use crate::tests::common::{create_sns_arn, create_sqs_queues, drop_database}; +use crate::tests::common::{create_queues, create_sns_arn, drop_database}; // Inspiration : https://rust-unofficial.github.io/patterns/patterns/creational/builder.html // TestConfigBuilder allows to heavily customise the global configs based on the test's requirement. @@ -183,11 +181,20 @@ impl TestConfigBuilder { pub async fn build(self) -> TestConfigBuilderReturns { dotenvy::from_filename("../.env.test").expect("Failed to load the .env.test file"); - let mut run_cmd: RunCmd = RunCmd::parse(); + let run_cmd: RunCmd = RunCmd::parse(); - let settings_provider = EnvSettingsProvider {}; - let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(&settings_provider).await))); + let run_cmd_clone = run_cmd.clone(); + let aws_config = &run_cmd_clone.aws_config; + let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(aws_config).await))); + let server_config = run_cmd_clone.server; + + let snos_config = SnosConfig { + rpc_url : run_cmd_clone.snos.rpc_for_snos.clone(), + max_block_to_process : run_cmd_clone.snos.max_block_to_process, + min_block_to_process : run_cmd_clone.snos.min_block_to_process, + }; + use std::sync::Arc; let TestConfigBuilder { @@ -205,34 +212,44 @@ impl TestConfigBuilder { let (starknet_rpc_url, starknet_client, starknet_server) = implement_client::init_starknet_client(starknet_rpc_url_type, starknet_client_type).await; - let alerts = implement_client::init_alerts(alerts_type, &settings_provider, provider_config.clone()).await; - let da_client = implement_client::init_da_client(da_client_type, &settings_provider).await; + + // init alerts + let alert_params = run_cmd.clone().validate_alert_params().map_err(|e| eyre!("Failed to validate alert params: {e}")).unwrap(); + let alerts = implement_client::init_alerts(alerts_type, &alert_params, provider_config.clone()).await; + + let da_params = run_cmd.clone().validate_da_params().unwrap(); + let da_client = implement_client::init_da_client(da_client_type, &da_params).await; let settlement_params = run_cmd.clone().validate_settlement_params().unwrap(); let settlement_client = implement_client::init_settlement_client(settlement_client_type, &settlement_params ).await; - let prover_client = implement_client::init_prover_client(prover_client_type, &settings_provider).await; - - let snos_url = - Url::parse(&settings_provider.get_settings_or_panic("RPC_FOR_SNOS")).expect("Failed to parse URL"); + let prover_params = run_cmd.clone().validate_prover_params().map_err(|e| eyre!("Failed to validate prover params: {e}")).unwrap(); + let prover_client = implement_client::init_prover_client(prover_client_type, &prover_params).await ; + // External Dependencies let data_storage_params = run_cmd.clone().validate_storage_params().map_err(|e| eyre!("Failed to validate storage params: {e}")).unwrap(); let storage = implement_client::init_storage_client(storage_type, &data_storage_params, provider_config.clone()).await; - let database = implement_client::init_database(database_type, settings_provider).await; - let queue = implement_client::init_queue_client(queue_type).await; + + let database_params = run_cmd.clone().validate_database_params().map_err(|e| eyre!("Failed to validate database params: {e}")).unwrap(); + let database = implement_client::init_database(database_type, &database_params).await; + + let queue_params = run_cmd.clone().validate_queue_params().map_err(|e| eyre!("Failed to validate queue params: {e}")).unwrap(); + let queue = implement_client::init_queue_client(queue_type, queue_params.clone()).await; // Deleting and Creating the queues in sqs. - create_sqs_queues(provider_config.clone()).await.expect("Not able to delete and create the queues."); + + create_queues(provider_config.clone(), &queue_params).await.expect("Not able to delete and create the queues."); // Deleting the database - drop_database().await.expect("Unable to drop the database."); + drop_database(&database_params).await.expect("Unable to drop the database."); // Creating the SNS ARN create_sns_arn(provider_config.clone()).await.expect("Unable to create the sns arn"); let config = Arc::new(Config::new( starknet_rpc_url, - snos_url, + server_config, + snos_config, starknet_client, da_client, prover_client, @@ -258,7 +275,7 @@ async fn implement_api_server(api_server_type: ConfigType, config: Arc) match api_server_type { ConfigType::Mock(client) => { if let MockType::Server(router) = client { - let (api_server_url, listener) = get_server_url().await; + let (api_server_url, listener) = get_server_url(config.server_config()).await; let app = Router::new().merge(router); tokio::spawn(async move { @@ -284,11 +301,13 @@ pub mod implement_client { use settlement_client_interface::{MockSettlementClient, SettlementClient}; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Url}; + use utils::cli::alert::AlertParams; + use utils::cli::da::DaParams; + use utils::cli::database::DatabaseParams; + use utils::cli::prover::ProverParams; + use utils::cli::queue::QueueParams; use utils::cli::settlement::SettlementParams; use utils::cli::storage::StorageParams; - use utils::env_utils::get_env_var_or_panic; - use utils::settings::env::EnvSettingsProvider; - use utils::settings::Settings; use super::{ConfigType, MockType}; use crate::alerts::{Alerts, MockAlerts}; @@ -323,10 +342,10 @@ pub mod implement_client { implement_mock_client_conversion!(SettlementClient, SettlementClient); implement_mock_client_conversion!(DaClient, DaClient); - pub(crate) async fn init_da_client(service: ConfigType, settings_provider: &impl Settings) -> Box { + pub(crate) async fn init_da_client(service: ConfigType, da_params: &DaParams) -> Box { match service { ConfigType::Mock(client) => client.into(), - ConfigType::Actual => build_da_client(settings_provider).await, + ConfigType::Actual => build_da_client(da_params).await, ConfigType::Dummy => Box::new(MockDaClient::new()), } } @@ -346,23 +365,23 @@ pub mod implement_client { pub(crate) async fn init_prover_client( service: ConfigType, - settings_provider: &impl Settings, + prover_params: &ProverParams, ) -> Box { match service { ConfigType::Mock(client) => client.into(), - ConfigType::Actual => build_prover_service(settings_provider), + ConfigType::Actual => build_prover_service(prover_params), ConfigType::Dummy => Box::new(MockProverClient::new()), } } pub(crate) async fn init_alerts( service: ConfigType, - settings_provider: &impl Settings, + alert_params: &AlertParams, provider_config: Arc, ) -> Box { match service { ConfigType::Mock(client) => client.into(), - ConfigType::Actual => build_alert_client(settings_provider, provider_config).await, + ConfigType::Actual => build_alert_client(alert_params, provider_config).await, ConfigType::Dummy => Box::new(MockAlerts::new()), } } @@ -387,21 +406,21 @@ pub mod implement_client { } } - pub(crate) async fn init_queue_client(service: ConfigType) -> Box { + pub(crate) async fn init_queue_client(service: ConfigType, queue_params: QueueParams) -> Box { match service { ConfigType::Mock(client) => client.into(), - ConfigType::Actual => build_queue_client(), + ConfigType::Actual => build_queue_client(&queue_params), ConfigType::Dummy => Box::new(MockQueueProvider::new()), } } pub(crate) async fn init_database( service: ConfigType, - settings_provider: EnvSettingsProvider, + database_params: &DatabaseParams, ) -> Box { match service { ConfigType::Mock(client) => client.into(), - ConfigType::Actual => build_database_client(&settings_provider).await, + ConfigType::Actual => build_database_client(&database_params).await, ConfigType::Dummy => Box::new(MockDatabase::new()), } } diff --git a/crates/orchestrator/src/tests/jobs/da_job/mod.rs b/crates/orchestrator/src/tests/jobs/da_job/mod.rs index 871318e7..57fe6bbf 100644 --- a/crates/orchestrator/src/tests/jobs/da_job/mod.rs +++ b/crates/orchestrator/src/tests/jobs/da_job/mod.rs @@ -14,7 +14,6 @@ use crate::jobs::da_job::test::{get_nonce_attached, read_state_update_from_file} use crate::jobs::da_job::{DaError, DaJob}; use crate::jobs::types::{ExternalId, JobItem, JobStatus, JobType}; use crate::jobs::{Job, JobError}; -use crate::tests::common::drop_database; use crate::tests::config::{ConfigType, TestConfigBuilder}; /// Tests the DA Job's handling of a blob length exceeding the supported size. @@ -234,5 +233,4 @@ async fn test_da_job_process_job_success( ); state_update_mock.assert(); - let _ = drop_database().await; } diff --git a/crates/orchestrator/src/tests/jobs/mod.rs b/crates/orchestrator/src/tests/jobs/mod.rs index a04b1ce8..2f30cd5b 100644 --- a/crates/orchestrator/src/tests/jobs/mod.rs +++ b/crates/orchestrator/src/tests/jobs/mod.rs @@ -7,6 +7,7 @@ use mongodb::bson::doc; use omniqueue::QueueError; use rstest::rstest; use tokio::time::sleep; +use utils::cli::queue::aws_sqs::QueueType; use uuid::Uuid; use super::database::build_job_item; @@ -18,9 +19,8 @@ use crate::jobs::types::{ExternalId, JobItem, JobStatus, JobType, JobVerificatio use crate::jobs::{ create_job, handle_job_failure, increment_key_in_metadata, process_job, verify_job, Job, JobError, MockJob, }; -use crate::queue::job_queue::{ - QueueNameForJobType, DATA_SUBMISSION_JOB_PROCESSING_QUEUE, DATA_SUBMISSION_JOB_VERIFICATION_QUEUE, -}; + +use crate::queue::job_queue::QueueNameForJobType; use crate::tests::common::MessagePayloadType; use crate::tests::config::{ConfigType, TestConfigBuilder}; @@ -385,14 +385,14 @@ async fn verify_job_with_verified_status_works() { let consumed_messages_verification_queue = services .config .queue() - .consume_message_from_queue(DATA_SUBMISSION_JOB_VERIFICATION_QUEUE.to_string()) + .consume_message_from_queue(QueueType::DataSubmissionJobVerification) .await .unwrap_err(); assert_matches!(consumed_messages_verification_queue, QueueError::NoData); let consumed_messages_processing_queue = services .config .queue() - .consume_message_from_queue(DATA_SUBMISSION_JOB_PROCESSING_QUEUE.to_string()) + .consume_message_from_queue(QueueType::DataSubmissionJobProcessing) .await .unwrap_err(); assert_matches!(consumed_messages_processing_queue, QueueError::NoData); @@ -439,7 +439,7 @@ async fn verify_job_with_rejected_status_adds_to_queue_works() { let consumed_messages = services .config .queue() - .consume_message_from_queue(DATA_SUBMISSION_JOB_PROCESSING_QUEUE.to_string()) + .consume_message_from_queue(QueueType::DataSubmissionJobProcessing) .await .unwrap(); let consumed_message_payload: MessagePayloadType = consumed_messages.payload_serde_json().unwrap().unwrap(); diff --git a/crates/orchestrator/src/tests/workers/proving/mod.rs b/crates/orchestrator/src/tests/workers/proving/mod.rs index 24a602b9..e479d710 100644 --- a/crates/orchestrator/src/tests/workers/proving/mod.rs +++ b/crates/orchestrator/src/tests/workers/proving/mod.rs @@ -15,7 +15,6 @@ use crate::database::MockDatabase; use crate::jobs::job_handler_factory::mock_factory; use crate::jobs::types::{JobItem, JobStatus, JobType}; use crate::jobs::{Job, MockJob}; -use crate::queue::job_queue::PROVING_JOB_PROCESSING_QUEUE; use crate::queue::MockQueueProvider; use crate::tests::config::TestConfigBuilder; use crate::tests::workers::utils::{db_checks_proving_worker, get_job_by_mock_id_vector}; @@ -26,6 +25,8 @@ use crate::workers::proving::ProvingWorker; #[case(false)] #[tokio::test] async fn test_proving_worker(#[case] incomplete_runs: bool) -> Result<(), Box> { + use utils::cli::queue::aws_sqs::QueueType; + let server = MockServer::start(); let da_client = MockDaClient::new(); let mut db = MockDatabase::new(); @@ -62,7 +63,7 @@ async fn test_proving_worker(#[case] incomplete_runs: bool) -> Result<(), Box Result<(), Box Result<(), Box> { + use utils::cli::queue::aws_sqs::QueueType; + let server = MockServer::start(); let da_client = MockDaClient::new(); let mut db = MockDatabase::new(); @@ -92,7 +93,7 @@ async fn test_snos_worker(#[case] db_val: bool) -> Result<(), Box> { queue .expect_send_message_to_queue() .returning(|_, _, _| Ok(())) - .withf(|queue, _payload, _delay| queue == SNOS_JOB_PROCESSING_QUEUE); + .withf(|queue, _payload, _delay| *queue == QueueType::SnosJobProcessing); // mock block number (madara) : 5 let rpc_response_block_number = block; diff --git a/crates/prover-services/sharp-service/src/lib.rs b/crates/prover-services/sharp-service/src/lib.rs index a1967c78..bfc84819 100644 --- a/crates/prover-services/sharp-service/src/lib.rs +++ b/crates/prover-services/sharp-service/src/lib.rs @@ -11,11 +11,9 @@ use gps_fact_checker::FactChecker; use prover_client_interface::{ProverClient, ProverClientError, Task, TaskStatus}; use starknet_os::sharp::CairoJobStatus; use utils::cli::prover::sharp::SharpParams; -use utils::settings::Settings; use uuid::Uuid; use crate::client::SharpClient; -use crate::config::SharpConfig; pub const SHARP_SETTINGS_NAME: &str = "sharp"; @@ -141,14 +139,13 @@ impl SharpProverService { Self::new(sharp_client, fact_checker) } - pub fn with_test_settings(settings: &impl Settings, port: u16) -> Self { - let sharp_config = SharpConfig::new_with_settings(settings) - .expect("Not able to create SharpProverService from given settings."); + pub fn with_test_settings(port: u16, sharp_params: &SharpParams) -> Self { + let sharp_client = SharpClient::new_with_settings( format!("http://127.0.0.1:{}", port).parse().expect("Failed to create sharp client with the given params"), - settings, + sharp_params, ); - let fact_checker = FactChecker::new(sharp_config.rpc_node_url, sharp_config.verifier_address); + let fact_checker = FactChecker::new(sharp_params); Self::new(sharp_client, fact_checker) } } diff --git a/crates/prover-services/sharp-service/tests/lib.rs b/crates/prover-services/sharp-service/tests/lib.rs index cfc4eb6d..82588d1e 100644 --- a/crates/prover-services/sharp-service/tests/lib.rs +++ b/crates/prover-services/sharp-service/tests/lib.rs @@ -5,66 +5,66 @@ use rstest::rstest; use serde_json::json; use sharp_service::SharpProverService; use starknet_os::sharp::CairoJobStatus; -use utils::env_utils::get_env_var_or_panic; +use utils::{cli::RunCmd, env_utils::get_env_var_or_panic}; use utils::settings::env::EnvSettingsProvider; use crate::constants::{CAIRO_PIE_PATH, TEST_FACT}; mod constants; -#[rstest] -#[tokio::test] -async fn prover_client_submit_task_works() { - dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); +// #[rstest] +// #[tokio::test] +// async fn prover_client_submit_task_works() { +// dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); - let server = MockServer::start(); - let sharp_service = SharpProverService::with_test_settings(&EnvSettingsProvider {}, server.port()); - let cairo_pie_path = env!("CARGO_MANIFEST_DIR").to_string() + CAIRO_PIE_PATH; - let cairo_pie = CairoPie::read_zip_file(cairo_pie_path.as_ref()).unwrap(); +// let server = MockServer::start(); +// let sharp_service = SharpProverService::with_test_settings(&EnvSettingsProvider {}, server.port()); +// let cairo_pie_path = env!("CARGO_MANIFEST_DIR").to_string() + CAIRO_PIE_PATH; +// let cairo_pie = CairoPie::read_zip_file(cairo_pie_path.as_ref()).unwrap(); - let sharp_response = json!( - { - "code" : "JOB_RECEIVED_SUCCESSFULLY" - } - ); - let customer_id = get_env_var_or_panic("SHARP_CUSTOMER_ID"); - let sharp_add_job_call = server.mock(|when, then| { - when.path_contains("/add_job").query_param("customer_id", customer_id.as_str()); - then.status(200).body(serde_json::to_vec(&sharp_response).unwrap()); - }); +// let sharp_response = json!( +// { +// "code" : "JOB_RECEIVED_SUCCESSFULLY" +// } +// ); +// let customer_id = get_env_var_or_panic("SHARP_CUSTOMER_ID"); +// let sharp_add_job_call = server.mock(|when, then| { +// when.path_contains("/add_job").query_param("customer_id", customer_id.as_str()); +// then.status(200).body(serde_json::to_vec(&sharp_response).unwrap()); +// }); - assert!(sharp_service.submit_task(Task::CairoPie(cairo_pie)).await.is_ok()); +// assert!(sharp_service.submit_task(Task::CairoPie(cairo_pie)).await.is_ok()); - sharp_add_job_call.assert(); -} +// sharp_add_job_call.assert(); +// } -#[rstest] -#[case(CairoJobStatus::FAILED)] -#[case(CairoJobStatus::INVALID)] -#[case(CairoJobStatus::UNKNOWN)] -#[case(CairoJobStatus::IN_PROGRESS)] -#[case(CairoJobStatus::NOT_CREATED)] -#[case(CairoJobStatus::PROCESSED)] -#[ignore] -#[case(CairoJobStatus::ONCHAIN)] -#[tokio::test] -async fn prover_client_get_task_status_works(#[case] cairo_job_status: CairoJobStatus) { - dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); +// #[rstest] +// #[case(CairoJobStatus::FAILED)] +// #[case(CairoJobStatus::INVALID)] +// #[case(CairoJobStatus::UNKNOWN)] +// #[case(CairoJobStatus::IN_PROGRESS)] +// #[case(CairoJobStatus::NOT_CREATED)] +// #[case(CairoJobStatus::PROCESSED)] +// #[ignore] +// #[case(CairoJobStatus::ONCHAIN)] +// #[tokio::test] +// async fn prover_client_get_task_status_works(#[case] cairo_job_status: CairoJobStatus) { +// dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); - let server = MockServer::start(); - let sharp_service = SharpProverService::with_test_settings(&EnvSettingsProvider {}, server.port()); - let customer_id = get_env_var_or_panic("SHARP_CUSTOMER_ID"); +// let server = MockServer::start(); +// let sharp_service = SharpProverService::with_test_settings(&EnvSettingsProvider {}, server.port()); +// let customer_id = get_env_var_or_panic("SHARP_CUSTOMER_ID"); - let sharp_add_job_call = server.mock(|when, then| { - when.path_contains("/get_status").query_param("customer_id", customer_id.as_str()); - then.status(200).body(serde_json::to_vec(&get_task_status_sharp_response(&cairo_job_status)).unwrap()); - }); +// let sharp_add_job_call = server.mock(|when, then| { +// when.path_contains("/get_status").query_param("customer_id", customer_id.as_str()); +// then.status(200).body(serde_json::to_vec(&get_task_status_sharp_response(&cairo_job_status)).unwrap()); +// }); - let task_status = sharp_service.get_task_status("c31381bf-4739-4667-b5b8-b08af1c6b1c7", TEST_FACT).await.unwrap(); - assert_eq!(task_status, get_task_status_expectation(&cairo_job_status), "Cairo Job Status assertion failed"); +// let task_status = sharp_service.get_task_status("c31381bf-4739-4667-b5b8-b08af1c6b1c7", TEST_FACT).await.unwrap(); +// assert_eq!(task_status, get_task_status_expectation(&cairo_job_status), "Cairo Job Status assertion failed"); - sharp_add_job_call.assert(); -} +// sharp_add_job_call.assert(); +// } fn get_task_status_expectation(cairo_job_status: &CairoJobStatus) -> TaskStatus { match cairo_job_status { diff --git a/crates/utils/src/cli/queue/aws_sqs.rs b/crates/utils/src/cli/queue/aws_sqs.rs index 65491948..7b6f2d81 100644 --- a/crates/utils/src/cli/queue/aws_sqs.rs +++ b/crates/utils/src/cli/queue/aws_sqs.rs @@ -18,47 +18,53 @@ pub struct AWSSQSParams { pub queue_base_url: String, } - -#[derive(Debug, Clone, Serialize)] +#[derive(Debug, Clone, Serialize, PartialEq, Eq)] pub enum QueueType { - #[serde(rename = "snos_job_processing")] SnosJobProcessing, - #[serde(rename = "snos_job_verification")] SnosJobVerification, - #[serde(rename = "proving_job_processing")] ProvingJobProcessing, - #[serde(rename = "proving_job_verification")] ProvingJobVerification, - #[serde(rename = "proof_registration_job_processing")] ProofRegistrationJobProcessing, - #[serde(rename = "proof_registration_job_verification")] ProofRegistrationJobVerification, - #[serde(rename = "data_submission_job_processing")] DataSubmissionJobProcessing, - #[serde(rename = "data_submission_job_verification")] DataSubmissionJobVerification, - #[serde(rename = "update_state_job_processing")] UpdateStateJobProcessing, - #[serde(rename = "update_state_job_verification")] UpdateStateJobVerification, - #[serde(rename = "job_handle_failure")] JobHandleFailure, - #[serde(rename = "worker_trigger")] WorkerTrigger, } +impl QueueType { + pub fn iter() -> impl Iterator { + [ + QueueType::SnosJobProcessing, + QueueType::SnosJobVerification, + QueueType::ProvingJobProcessing, + QueueType::ProvingJobVerification, + QueueType::ProofRegistrationJobProcessing, + QueueType::ProofRegistrationJobVerification, + QueueType::DataSubmissionJobProcessing, + QueueType::DataSubmissionJobVerification, + QueueType::UpdateStateJobProcessing, + QueueType::UpdateStateJobVerification, + QueueType::JobHandleFailure, + QueueType::WorkerTrigger, + ].iter().cloned() + } +} + impl fmt::Display for QueueType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -72,8 +78,13 @@ impl fmt::Display for QueueType { impl AWSSQSParams { pub fn get_queue_url(&self, queue_type: QueueType) -> String { + format!("{}/{}", self.queue_base_url, self.get_queue_name(queue_type)) + } + + pub fn get_queue_name(&self, queue_type: QueueType) -> String { + // TODO: check if serde_json is the best way to convert the enum to string let queue_name = serde_json::to_string(&queue_type).unwrap(); - format!("{}/{}/{}_{}", self.queue_base_url, self.sqs_prefix, queue_name, self.sqs_suffix) + format!("{}_{}_{}", self.sqs_prefix, queue_name, self.sqs_suffix) } } \ No newline at end of file diff --git a/e2e-tests/src/localstack.rs b/e2e-tests/src/localstack.rs index c93d6418..0471f060 100644 --- a/e2e-tests/src/localstack.rs +++ b/e2e-tests/src/localstack.rs @@ -11,13 +11,7 @@ use aws_sdk_sqs::types::QueueAttributeName::VisibilityTimeout; use orchestrator::config::ProviderConfig; use orchestrator::data_storage::aws_s3::AWSS3; use orchestrator::data_storage::DataStorage; -use orchestrator::queue::job_queue::{ - JobQueueMessage, WorkerTriggerMessage, WorkerTriggerType, DATA_SUBMISSION_JOB_PROCESSING_QUEUE, - DATA_SUBMISSION_JOB_VERIFICATION_QUEUE, JOB_HANDLE_FAILURE_QUEUE, PROOF_REGISTRATION_JOB_PROCESSING_QUEUE, - PROOF_REGISTRATION_JOB_VERIFICATION_QUEUE, PROVING_JOB_PROCESSING_QUEUE, PROVING_JOB_VERIFICATION_QUEUE, - SNOS_JOB_PROCESSING_QUEUE, SNOS_JOB_VERIFICATION_QUEUE, UPDATE_STATE_JOB_PROCESSING_QUEUE, - UPDATE_STATE_JOB_VERIFICATION_QUEUE, WORKER_TRIGGER_QUEUE, -}; + use utils::env_utils::get_env_var_or_panic; use utils::settings::env::EnvSettingsProvider; From 8685ce213a409d7f1462891158ecb6813a0929d7 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 6 Nov 2024 16:40:43 +0530 Subject: [PATCH 10/63] update: rework e2e --- Cargo.lock | 1 + Cargo.toml | 1 + crates/orchestrator/Cargo.toml | 2 +- e2e-tests/Cargo.toml | 1 + e2e-tests/src/localstack.rs | 36 ++++++++++++---------------------- e2e-tests/src/mongodb.rs | 9 ++++----- e2e-tests/tests.rs | 28 +++++++++++++++++--------- 7 files changed, 39 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bbbcdd0f..511e9b26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4264,6 +4264,7 @@ dependencies = [ "aws-sdk-sqs", "bytes", "chrono", + "clap", "color-eyre", "dotenvy", "ethereum-settlement-client", diff --git a/Cargo.toml b/Cargo.toml index d09b920a..9f44c13b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,6 +74,7 @@ lazy_static = "1.4.0" stark_evm_adapter = "0.1.1" hex = "0.4" itertools = "0.13.0" +clap = { version = "4.4", features = ["derive", "env"] } mockall = "0.13.0" testcontainers = "0.18.0" once_cell = "1.8" diff --git a/crates/orchestrator/Cargo.toml b/crates/orchestrator/Cargo.toml index 48961546..65c4c940 100644 --- a/crates/orchestrator/Cargo.toml +++ b/crates/orchestrator/Cargo.toml @@ -36,7 +36,7 @@ axum = { workspace = true, features = ["macros"] } axum-macros = { workspace = true } bincode = { workspace = true } bytes.workspace = true -clap = { version = "4.4", features = ["derive", "env"] } +clap.workspace = true c-kzg = { workspace = true } cairo-vm = { workspace = true } chrono = { workspace = true } diff --git a/e2e-tests/Cargo.toml b/e2e-tests/Cargo.toml index f7396b77..34ac6249 100644 --- a/e2e-tests/Cargo.toml +++ b/e2e-tests/Cargo.toml @@ -13,6 +13,7 @@ aws-sdk-s3.workspace = true aws-sdk-sqs.workspace = true bytes.workspace = true chrono = { workspace = true } +clap.workspace = true color-eyre.workspace = true dotenvy.workspace = true ethereum-settlement-client.workspace = true diff --git a/e2e-tests/src/localstack.rs b/e2e-tests/src/localstack.rs index 0471f060..3eb82845 100644 --- a/e2e-tests/src/localstack.rs +++ b/e2e-tests/src/localstack.rs @@ -12,8 +12,10 @@ use orchestrator::config::ProviderConfig; use orchestrator::data_storage::aws_s3::AWSS3; use orchestrator::data_storage::DataStorage; -use utils::env_utils::get_env_var_or_panic; -use utils::settings::env::EnvSettingsProvider; +use orchestrator::queue::job_queue::{JobQueueMessage, WorkerTriggerMessage, WorkerTriggerType}; +use utils::cli::aws_config::AWSConfigParams; +use utils::cli::queue::aws_sqs::{AWSSQSParams, QueueType}; +use utils::cli::storage::aws_s3::AWSS3Params; /// LocalStack struct pub struct LocalStack { @@ -23,8 +25,8 @@ pub struct LocalStack { } impl LocalStack { - pub async fn new() -> Self { - let region_provider = Region::new(get_env_var_or_panic("AWS_REGION")); + pub async fn new(aws_config: AWSConfigParams, s3_config: &AWSS3Params) -> Self { + let region_provider = Region::new(aws_config.region); let creds = EnvironmentVariableCredentialsProvider::new().provide_credentials().await.unwrap(); let config = from_env().region(region_provider).credentials_provider(creds).load().await; @@ -32,7 +34,7 @@ impl LocalStack { Self { sqs_client: aws_sdk_sqs::Client::new(&config), - s3_client: Box::new(AWSS3::new_with_settings(&EnvSettingsProvider {}, provider_config).await), + s3_client: Box::new(AWSS3::new_with_settings(s3_config, provider_config).await), event_bridge_client: aws_sdk_eventbridge::Client::new(&config), } } @@ -43,7 +45,7 @@ impl LocalStack { } /// To set up SQS on localstack instance - pub async fn setup_sqs(&self) -> color_eyre::Result<()> { + pub async fn setup_sqs(&self, sqs_config: &AWSSQSParams) -> color_eyre::Result<()> { let list_queues_output = self.sqs_client.list_queues().send().await?; let queue_urls = list_queues_output.queue_urls(); println!("Found {} queues", queue_urls.len()); @@ -58,22 +60,8 @@ impl LocalStack { let mut queue_attributes = HashMap::new(); queue_attributes.insert(VisibilityTimeout, "10000".into()); - let queue_names = vec![ - DATA_SUBMISSION_JOB_PROCESSING_QUEUE, - DATA_SUBMISSION_JOB_VERIFICATION_QUEUE, - PROOF_REGISTRATION_JOB_PROCESSING_QUEUE, - PROOF_REGISTRATION_JOB_VERIFICATION_QUEUE, - PROVING_JOB_PROCESSING_QUEUE, - PROVING_JOB_VERIFICATION_QUEUE, - SNOS_JOB_PROCESSING_QUEUE, - SNOS_JOB_VERIFICATION_QUEUE, - UPDATE_STATE_JOB_PROCESSING_QUEUE, - UPDATE_STATE_JOB_VERIFICATION_QUEUE, - JOB_HANDLE_FAILURE_QUEUE, - WORKER_TRIGGER_QUEUE, - ]; - - for queue_name in queue_names { + for queue_type in QueueType::iter() { + let queue_name = sqs_config.get_queue_name(queue_type); self.sqs_client .create_queue() .queue_name(queue_name) @@ -88,7 +76,7 @@ impl LocalStack { } /// Event Bridge setup - pub async fn setup_event_bridge(&self, worker_trigger_type: WorkerTriggerType) -> color_eyre::Result<()> { + pub async fn setup_event_bridge(&self, worker_trigger_type: WorkerTriggerType, sqs_config: &AWSSQSParams) -> color_eyre::Result<()> { let rule_name = "worker_trigger_scheduled"; self.event_bridge_client @@ -98,7 +86,7 @@ impl LocalStack { .state(RuleState::Enabled) .send() .await?; - let queue_url = self.sqs_client.get_queue_url().queue_name(WORKER_TRIGGER_QUEUE).send().await?; + let queue_url = self.sqs_client.get_queue_url().queue_name(sqs_config.get_queue_name(QueueType::WorkerTrigger)).send().await?; let queue_attributes = self .sqs_client diff --git a/e2e-tests/src/mongodb.rs b/e2e-tests/src/mongodb.rs index ba653653..3bafb0b6 100644 --- a/e2e-tests/src/mongodb.rs +++ b/e2e-tests/src/mongodb.rs @@ -1,19 +1,18 @@ use std::str::FromStr; use url::Url; -use utils::env_utils::get_env_var_or_panic; - +use utils::cli::database::mongodb::MongoDBParams; #[allow(dead_code)] pub struct MongoDbServer { endpoint: Url, } impl MongoDbServer { - pub async fn run() -> Self { - Self { endpoint: Url::from_str(&get_env_var_or_panic("MONGODB_CONNECTION_STRING")).unwrap() } + pub fn run(mongodb_params: MongoDBParams) -> Self { + Self { endpoint: Url::from_str(&mongodb_params.connection_url).unwrap() } } pub fn endpoint(&self) -> Url { - Url::from_str(&get_env_var_or_panic("MONGODB_CONNECTION_STRING")).unwrap() + self.endpoint.clone() } } diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index 252ac151..79cf2f32 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::fs::File; use std::io::Read; use std::time::{Duration, Instant}; +use clap::Parser as _; use chrono::{SubsecRound, Utc}; use e2e_tests::anvil::AnvilSetup; @@ -20,6 +21,7 @@ use rstest::rstest; use serde::{Deserialize, Serialize}; use serde_json::json; use starknet::core::types::{Felt, MaybePendingStateUpdate}; +use utils::cli::RunCmd; use utils::env_utils::get_env_var_or_panic; use uuid::Uuid; @@ -46,8 +48,10 @@ struct Setup { impl Setup { /// Initialise a new setup - pub async fn new(l2_block_number: String) -> Self { - let mongo_db_instance = MongoDbServer::run().await; + pub async fn new(l2_block_number: String, run_cmd: RunCmd) -> Self { + + let mongodb_params = run_cmd.mongodb_params; + let mongo_db_instance = MongoDbServer::run(mongodb_params); println!("✅ Mongo DB setup completed"); let starknet_client = StarknetClient::new(); @@ -61,13 +65,16 @@ impl Setup { println!("✅ Anvil setup completed"); // Setting up LocalStack - let localstack_instance = LocalStack::new().await; - localstack_instance.setup_sqs().await.unwrap(); + let aws_config = run_cmd.aws_config; + let s3_config = run_cmd.aws_s3_params; + let sqs_config = run_cmd.aws_sqs_params; + let localstack_instance = LocalStack::new(aws_config, &s3_config).await; + localstack_instance.setup_sqs(&sqs_config).await.unwrap(); localstack_instance.delete_event_bridge_rule("worker_trigger_scheduled").await.unwrap(); - localstack_instance.setup_event_bridge(WorkerTriggerType::Snos).await.unwrap(); - localstack_instance.setup_event_bridge(WorkerTriggerType::Proving).await.unwrap(); - localstack_instance.setup_event_bridge(WorkerTriggerType::DataSubmission).await.unwrap(); - localstack_instance.setup_event_bridge(WorkerTriggerType::UpdateState).await.unwrap(); + localstack_instance.setup_event_bridge(WorkerTriggerType::Snos, &sqs_config).await.unwrap(); + localstack_instance.setup_event_bridge(WorkerTriggerType::Proving, &sqs_config).await.unwrap(); + localstack_instance.setup_event_bridge(WorkerTriggerType::DataSubmission, &sqs_config).await.unwrap(); + localstack_instance.setup_event_bridge(WorkerTriggerType::UpdateState, &sqs_config).await.unwrap(); println!("✅ Localstack instance setup completed"); @@ -125,11 +132,14 @@ impl Setup { #[case("66645".to_string())] #[tokio::test] async fn test_orchestrator_workflow(#[case] l2_block_number: String) { + // Fetching the env vars from the test env file as these will be used in // setting up of the test and during orchestrator run too. dotenvy::from_filename(".env.test").expect("Failed to load the .env file"); - let mut setup_config = Setup::new(l2_block_number.clone()).await; + let run_cmd = RunCmd::parse(); + + let mut setup_config = Setup::new(l2_block_number.clone(), run_cmd).await; // Setup S3 setup_s3(setup_config.localstack().s3_client()).await.unwrap(); From 153bc93f328c87ddb8e1690cd08e9447a300b840 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 6 Nov 2024 16:43:47 +0530 Subject: [PATCH 11/63] update: lint cleanu --- crates/orchestrator/src/alerts/aws_sns/mod.rs | 1 + crates/orchestrator/src/config.rs | 72 ++++++++++-------- .../orchestrator/src/database/mongodb/mod.rs | 2 +- crates/orchestrator/src/lib.rs | 2 +- crates/orchestrator/src/queue/job_queue.rs | 5 +- crates/orchestrator/src/queue/mod.rs | 5 +- crates/orchestrator/src/queue/sqs/mod.rs | 2 +- crates/orchestrator/src/routes/mod.rs | 1 - crates/orchestrator/src/telemetry.rs | 6 -- crates/orchestrator/src/tests/common/mod.rs | 22 +++--- crates/orchestrator/src/tests/config.rs | 73 ++++++++++--------- crates/orchestrator/src/tests/jobs/mod.rs | 25 ++----- crates/orchestrator/src/workers/snos.rs | 2 - .../gps-fact-checker/src/lib.rs | 5 +- .../sharp-service/src/client.rs | 3 +- .../prover-services/sharp-service/src/lib.rs | 1 - .../sharp-service/tests/lib.rs | 27 +++---- crates/settlement-clients/ethereum/src/lib.rs | 18 ++--- crates/settlement-clients/starknet/src/lib.rs | 6 +- .../starknet/src/tests/test.rs | 29 +++----- crates/utils/src/cli/alert/aws_sns.rs | 2 +- crates/utils/src/cli/alert/mod.rs | 2 +- crates/utils/src/cli/database/mod.rs | 2 +- crates/utils/src/cli/mod.rs | 53 ++++++-------- crates/utils/src/cli/prover/sharp.rs | 49 ++++++------- crates/utils/src/cli/queue/aws_sqs.rs | 14 ++-- crates/utils/src/cli/queue/mod.rs | 3 +- crates/utils/src/cli/server.rs | 1 - crates/utils/src/cli/settlement/ethereum.rs | 1 - crates/utils/src/cli/settlement/mod.rs | 3 +- crates/utils/src/cli/settlement/starknet.rs | 5 +- crates/utils/src/cli/storage/mod.rs | 3 +- crates/utils/src/lib.rs | 2 +- e2e-tests/src/localstack.rs | 14 +++- e2e-tests/tests.rs | 4 +- 35 files changed, 216 insertions(+), 249 deletions(-) diff --git a/crates/orchestrator/src/alerts/aws_sns/mod.rs b/crates/orchestrator/src/alerts/aws_sns/mod.rs index 3a0e5710..7fe899cc 100644 --- a/crates/orchestrator/src/alerts/aws_sns/mod.rs +++ b/crates/orchestrator/src/alerts/aws_sns/mod.rs @@ -5,6 +5,7 @@ use std::sync::Arc; use async_trait::async_trait; use aws_sdk_sns::Client; use utils::cli::alert::aws_sns::AWSSNSParams; + use crate::alerts::Alerts; use crate::config::ProviderConfig; diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 5b703e83..161921fa 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -69,12 +69,11 @@ pub struct Config { alerts: Box, } - #[derive(Debug, Clone)] pub struct SnosConfig { - pub rpc_url : Url, - pub max_block_to_process : u64, - pub min_block_to_process : u64, + pub rpc_url: Url, + pub max_block_to_process: u64, + pub min_block_to_process: u64, } /// `ProviderConfig` is an enum used to represent the global config built @@ -99,11 +98,8 @@ impl ProviderConfig { pub async fn get_aws_config(aws_config: &AWSConfigParams) -> SdkConfig { let region = aws_config.region.clone(); let region_provider = RegionProviderChain::first_try(Region::new(region)).or_default_provider(); - let credentials = Credentials::from_keys( - aws_config.access_key_id.clone(), - aws_config.secret_access_key.clone(), - None, - ); + let credentials = + Credentials::from_keys(aws_config.access_key_id.clone(), aws_config.secret_access_key.clone(), None); aws_config::from_env().credentials_provider(credentials).region(region_provider).load().await } @@ -119,16 +115,17 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { // init snos url let snos_config = SnosConfig { - rpc_url : run_cmd.snos.rpc_for_snos.clone(), - max_block_to_process : run_cmd.snos.max_block_to_process, - min_block_to_process : run_cmd.snos.min_block_to_process, + rpc_url: run_cmd.snos.rpc_for_snos.clone(), + max_block_to_process: run_cmd.snos.max_block_to_process, + min_block_to_process: run_cmd.snos.min_block_to_process, }; - + let server_config = run_cmd.server.clone(); let provider = JsonRpcClient::new(HttpTransport::new(rpc_url.clone())); // init database - let database_params = run_cmd.clone().validate_database_params().map_err(|e| eyre!("Failed to validate database params: {e}"))?; + let database_params = + run_cmd.clone().validate_database_params().map_err(|e| eyre!("Failed to validate database params: {e}"))?; let database = build_database_client(&database_params).await; // init DA client @@ -136,19 +133,23 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { let da_client = build_da_client(&da_params).await; // init settlement - let settlement_params = run_cmd.clone().validate_settlement_params().map_err(|e| eyre!("Failed to validate settlement params: {e}"))?; + let settlement_params = + run_cmd.clone().validate_settlement_params().map_err(|e| eyre!("Failed to validate settlement params: {e}"))?; let settlement_client = build_settlement_client(&settlement_params).await?; // init prover - let prover_params = run_cmd.clone().validate_prover_params().map_err(|e| eyre!("Failed to validate prover params: {e}"))?; + let prover_params = + run_cmd.clone().validate_prover_params().map_err(|e| eyre!("Failed to validate prover params: {e}"))?; let prover_client = build_prover_service(&prover_params); // init storage - let data_storage_params = run_cmd.clone().validate_storage_params().map_err(|e| eyre!("Failed to validate storage params: {e}"))?; + let data_storage_params = + run_cmd.clone().validate_storage_params().map_err(|e| eyre!("Failed to validate storage params: {e}"))?; let storage_client = build_storage_client(&data_storage_params, provider_config.clone()).await; - + // init alerts - let alert_params = run_cmd.clone().validate_alert_params().map_err(|e| eyre!("Failed to validate alert params: {e}"))?; + let alert_params = + run_cmd.clone().validate_alert_params().map_err(|e| eyre!("Failed to validate alert params: {e}"))?; let alerts_client = build_alert_client(&alert_params, provider_config.clone()).await; // init the queue @@ -156,7 +157,8 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { // from `SdkConfig`. We can later move to using `aws_sdk_sqs`. This would require // us stop using the generic omniqueue abstractions for message ack/nack // init queue - let queue_params = run_cmd.clone().validate_queue_params().map_err(|e| eyre!("Failed to validate queue params: {e}"))?; + let queue_params = + run_cmd.clone().validate_queue_params().map_err(|e| eyre!("Failed to validate queue params: {e}"))?; let queue = build_queue_client(&queue_params); Ok(Arc::new(Config::new( @@ -271,7 +273,9 @@ use alloy::rpc::client::RpcClient; pub async fn build_da_client(da_params: &DaParams) -> Box { match da_params { DaParams::Ethereum(ethereum_da_params) => { - let client = RpcClient::new_http(Url::from_str(ethereum_da_params.rpc_url.as_str()).expect("Failed to parse SETTLEMENT_RPC_URL")); + let client = RpcClient::new_http( + Url::from_str(ethereum_da_params.rpc_url.as_str()).expect("Failed to parse SETTLEMENT_RPC_URL"), + ); let provider = ProviderBuilder::<_, Ethereum>::new().on_client(client); Box::new(EthereumDaClient { provider }) } @@ -293,16 +297,16 @@ pub async fn build_settlement_client( SettlementParams::Ethereum(ethereum_settlement_params) => { #[cfg(not(feature = "testing"))] { - Ok(Box::new(EthereumSettlementClient::new_with_settings(ðereum_settlement_params))) + Ok(Box::new(EthereumSettlementClient::new_with_settings(ethereum_settlement_params))) } #[cfg(feature = "testing")] { - Ok(Box::new(EthereumSettlementClient::with_test_settings( - ðereum_settlement_params - ))) + Ok(Box::new(EthereumSettlementClient::with_test_settings(ðereum_settlement_params))) } } - SettlementParams::Starknet(starknet_settlement_params) => Ok(Box::new(StarknetSettlementClient::new_with_settings(&starknet_settlement_params).await)), + SettlementParams::Starknet(starknet_settlement_params) => { + Ok(Box::new(StarknetSettlementClient::new_with_settings(starknet_settlement_params).await)) + } } // match settlement_params { @@ -314,16 +318,18 @@ pub async fn build_settlement_client( // #[cfg(feature = "testing")] // { // Ok(Box::new(EthereumSettlementClient::with_test_settings( - // RootProvider::new_http(get_env_var_or_panic("SETTLEMENT_RPC_URL").as_str().parse()?), + // + // RootProvider::new_http(get_env_var_or_panic("SETTLEMENT_RPC_URL").as_str().parse()?), // Address::from_str(&get_env_var_or_panic("L1_CORE_CONTRACT_ADDRESS"))?, // Url::from_str(get_env_var_or_panic("SETTLEMENT_RPC_URL").as_str())?, - // Some(Address::from_str(get_env_var_or_panic("STARKNET_OPERATOR_ADDRESS").as_str())?), + // + // Some(Address::from_str(get_env_var_or_panic("STARKNET_OPERATOR_ADDRESS").as_str())?), // ))) // } // } - // "starknet" => Ok(Box::new(StarknetSettlementClient::new_with_settings(settings_provider).await)), - // _ => panic!("Unsupported Settlement layer"), - // } + // "starknet" => + // Ok(Box::new(StarknetSettlementClient::new_with_settings(settings_provider).await)), _ + // => panic!("Unsupported Settlement layer"), } } pub async fn build_storage_client( @@ -340,7 +346,9 @@ pub async fn build_alert_client( provider_config: Arc, ) -> Box { match alert_params { - AlertParams::AWSSNS(aws_sns_params) => Box::new(AWSSNS::new_with_settings(aws_sns_params, provider_config).await), + AlertParams::AWSSNS(aws_sns_params) => { + Box::new(AWSSNS::new_with_settings(aws_sns_params, provider_config).await) + } } } diff --git a/crates/orchestrator/src/database/mongodb/mod.rs b/crates/orchestrator/src/database/mongodb/mod.rs index fd313263..5043c67a 100644 --- a/crates/orchestrator/src/database/mongodb/mod.rs +++ b/crates/orchestrator/src/database/mongodb/mod.rs @@ -1,3 +1,4 @@ +use ::utils::cli::database::mongodb::MongoDBParams; use async_std::stream::StreamExt; use async_trait::async_trait; use chrono::{SubsecRound, Utc}; @@ -10,7 +11,6 @@ use mongodb::options::{ UpdateOptions, }; use mongodb::{bson, Client, Collection}; -use ::utils::cli::database::mongodb::MongoDBParams; use utils::ToDocument; use uuid::Uuid; diff --git a/crates/orchestrator/src/lib.rs b/crates/orchestrator/src/lib.rs index aef82a08..b580f273 100644 --- a/crates/orchestrator/src/lib.rs +++ b/crates/orchestrator/src/lib.rs @@ -25,4 +25,4 @@ pub mod telemetry; #[cfg(test)] pub mod tests; /// Contains workers which act like cron jobs -pub mod workers; \ No newline at end of file +pub mod workers; diff --git a/crates/orchestrator/src/queue/job_queue.rs b/crates/orchestrator/src/queue/job_queue.rs index 5ac800dc..d39d3449 100644 --- a/crates/orchestrator/src/queue/job_queue.rs +++ b/crates/orchestrator/src/queue/job_queue.rs @@ -323,7 +323,10 @@ fn get_worker_handler_from_worker_trigger_type(worker_trigger_type: WorkerTrigge } /// To get the delivery from the message queue using the queue name -async fn get_delivery_from_queue(queue: QueueType, config: Arc) -> Result { +async fn get_delivery_from_queue( + queue: QueueType, + config: Arc, +) -> Result { match config.queue().consume_message_from_queue(queue).await { Ok(d) => Ok(DeliveryReturnType::Message(d)), Err(QueueError::NoData) => Ok(DeliveryReturnType::NoMessage), diff --git a/crates/orchestrator/src/queue/mod.rs b/crates/orchestrator/src/queue/mod.rs index 10c72021..9309a3f5 100644 --- a/crates/orchestrator/src/queue/mod.rs +++ b/crates/orchestrator/src/queue/mod.rs @@ -8,10 +8,10 @@ use async_trait::async_trait; use color_eyre::Result as EyreResult; use mockall::automock; use omniqueue::{Delivery, QueueError}; +use utils::cli::queue::aws_sqs::QueueType; use crate::config::Config; use crate::jobs::JobError; -use utils::cli::queue::aws_sqs::QueueType; /// Queue Provider Trait /// /// The QueueProvider trait is used to define the methods that a queue @@ -20,7 +20,8 @@ use utils::cli::queue::aws_sqs::QueueType; #[automock] #[async_trait] pub trait QueueProvider: Send + Sync { - async fn send_message_to_queue(&self, queue: QueueType, payload: String, delay: Option) -> EyreResult<()>; + async fn send_message_to_queue(&self, queue: QueueType, payload: String, delay: Option) + -> EyreResult<()>; async fn consume_message_from_queue(&self, queue: QueueType) -> std::result::Result; } diff --git a/crates/orchestrator/src/queue/sqs/mod.rs b/crates/orchestrator/src/queue/sqs/mod.rs index 562a45b5..77c15ae7 100644 --- a/crates/orchestrator/src/queue/sqs/mod.rs +++ b/crates/orchestrator/src/queue/sqs/mod.rs @@ -7,7 +7,7 @@ use omniqueue::{Delivery, QueueError}; use utils::cli::queue::aws_sqs::{AWSSQSParams, QueueType}; use crate::queue::QueueProvider; -pub struct SqsQueue{ +pub struct SqsQueue { pub params: AWSSQSParams, } diff --git a/crates/orchestrator/src/routes/mod.rs b/crates/orchestrator/src/routes/mod.rs index 10539978..f6f2afcf 100644 --- a/crates/orchestrator/src/routes/mod.rs +++ b/crates/orchestrator/src/routes/mod.rs @@ -8,7 +8,6 @@ use axum::{Json, Router}; use job_routes::job_router; use serde::Serialize; use utils::cli::server::ServerParams; -use utils::env_utils::get_env_var_or_default; use crate::config::Config; diff --git a/crates/orchestrator/src/telemetry.rs b/crates/orchestrator/src/telemetry.rs index ca916222..cea79b65 100644 --- a/crates/orchestrator/src/telemetry.rs +++ b/crates/orchestrator/src/telemetry.rs @@ -9,7 +9,6 @@ use opentelemetry_sdk::metrics::reader::{DefaultAggregationSelector, DefaultTemp use opentelemetry_sdk::metrics::{PeriodicReader, SdkMeterProvider}; use opentelemetry_sdk::trace::{BatchConfigBuilder, Config, Tracer}; use opentelemetry_sdk::{runtime, Resource}; -use tracing::Level; use tracing_opentelemetry::OpenTelemetryLayer; use tracing_subscriber::layer::SubscriberExt as _; use tracing_subscriber::util::SubscriberInitExt as _; @@ -143,14 +142,9 @@ mod tests { use std::env; use clap::Parser as _; - use once_cell::sync::Lazy; use utils::cli::RunCmd; - use utils::metrics::lib::Metrics; - use utils::register_metric; use super::*; - use crate::metrics::OrchestratorMetrics; - #[tokio::test] #[allow(clippy::needless_return)] diff --git a/crates/orchestrator/src/tests/common/mod.rs b/crates/orchestrator/src/tests/common/mod.rs index 72d7d10d..acc1f4f3 100644 --- a/crates/orchestrator/src/tests/common/mod.rs +++ b/crates/orchestrator/src/tests/common/mod.rs @@ -3,10 +3,6 @@ pub mod constants; use std::collections::HashMap; use std::sync::Arc; -use utils::cli::database::DatabaseParams; -use utils::cli::queue::aws_sqs::QueueType; -use utils::cli::queue::QueueParams; -use utils::cli::storage::aws_s3::AWSS3Params; use ::uuid::Uuid; use aws_config::SdkConfig; use aws_sdk_sns::error::SdkError; @@ -15,6 +11,10 @@ use chrono::{SubsecRound, Utc}; use mongodb::Client; use rstest::*; use serde::Deserialize; +use utils::cli::database::DatabaseParams; +use utils::cli::queue::aws_sqs::QueueType; +use utils::cli::queue::QueueParams; +use utils::cli::storage::aws_s3::AWSS3Params; use utils::env_utils::get_env_var_or_panic; use crate::config::ProviderConfig; @@ -25,7 +25,6 @@ use crate::jobs::types::JobStatus::Created; use crate::jobs::types::JobType::DataSubmission; use crate::jobs::types::{ExternalId, JobItem}; - #[fixture] pub fn default_job_item() -> JobItem { JobItem { @@ -59,12 +58,10 @@ pub async fn get_sns_client(aws_config: &SdkConfig) -> aws_sdk_sns::client::Clie aws_sdk_sns::Client::new(aws_config) } -pub async fn drop_database( - database_params: &DatabaseParams, -) -> color_eyre::Result<()> { +pub async fn drop_database(database_params: &DatabaseParams) -> color_eyre::Result<()> { match database_params { DatabaseParams::MongoDB(mongodb_params) => { - let db_client: Client = MongoDb::new_with_settings(&mongodb_params).await.client(); + let db_client: Client = MongoDb::new_with_settings(mongodb_params).await.client(); // dropping all the collection. // use .collection::("") // if only particular collection is to be dropped @@ -77,10 +74,8 @@ pub async fn drop_database( // SQS structs & functions pub async fn create_queues(provider_config: Arc, queue_params: &QueueParams) -> color_eyre::Result<()> { - match queue_params { QueueParams::AWSSQS(aws_sqs_params) => { - let sqs_client = get_sqs_client(provider_config).await; // Dropping sqs queues @@ -114,6 +109,9 @@ pub struct MessagePayloadType { pub(crate) id: Uuid, } -pub async fn get_storage_client(storage_cfg: &AWSS3Params, provider_config: Arc) -> Box { +pub async fn get_storage_client( + storage_cfg: &AWSS3Params, + provider_config: Arc, +) -> Box { Box::new(AWSS3::new_with_settings(storage_cfg, provider_config).await) } diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 8340103c..1f03618d 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -190,11 +190,11 @@ impl TestConfigBuilder { let server_config = run_cmd_clone.server; let snos_config = SnosConfig { - rpc_url : run_cmd_clone.snos.rpc_for_snos.clone(), - max_block_to_process : run_cmd_clone.snos.max_block_to_process, - min_block_to_process : run_cmd_clone.snos.min_block_to_process, + rpc_url: run_cmd_clone.snos.rpc_for_snos.clone(), + max_block_to_process: run_cmd_clone.snos.max_block_to_process, + min_block_to_process: run_cmd_clone.snos.min_block_to_process, }; - + use std::sync::Arc; let TestConfigBuilder { @@ -214,7 +214,8 @@ impl TestConfigBuilder { implement_client::init_starknet_client(starknet_rpc_url_type, starknet_client_type).await; // init alerts - let alert_params = run_cmd.clone().validate_alert_params().map_err(|e| eyre!("Failed to validate alert params: {e}")).unwrap(); + let alert_params = + run_cmd.clone().validate_alert_params().map_err(|e| eyre!("Failed to validate alert params: {e}")).unwrap(); let alerts = implement_client::init_alerts(alerts_type, &alert_params, provider_config.clone()).await; let da_params = run_cmd.clone().validate_da_params().unwrap(); @@ -222,21 +223,33 @@ impl TestConfigBuilder { let settlement_params = run_cmd.clone().validate_settlement_params().unwrap(); let settlement_client = - implement_client::init_settlement_client(settlement_client_type, &settlement_params - ).await; + implement_client::init_settlement_client(settlement_client_type, &settlement_params).await; - let prover_params = run_cmd.clone().validate_prover_params().map_err(|e| eyre!("Failed to validate prover params: {e}")).unwrap(); - let prover_client = implement_client::init_prover_client(prover_client_type, &prover_params).await ; + let prover_params = run_cmd + .clone() + .validate_prover_params() + .map_err(|e| eyre!("Failed to validate prover params: {e}")) + .unwrap(); + let prover_client = implement_client::init_prover_client(prover_client_type, &prover_params).await; - // External Dependencies - let data_storage_params = run_cmd.clone().validate_storage_params().map_err(|e| eyre!("Failed to validate storage params: {e}")).unwrap(); - let storage = implement_client::init_storage_client(storage_type, &data_storage_params, provider_config.clone()).await; - - let database_params = run_cmd.clone().validate_database_params().map_err(|e| eyre!("Failed to validate database params: {e}")).unwrap(); + let data_storage_params = run_cmd + .clone() + .validate_storage_params() + .map_err(|e| eyre!("Failed to validate storage params: {e}")) + .unwrap(); + let storage = + implement_client::init_storage_client(storage_type, &data_storage_params, provider_config.clone()).await; + + let database_params = run_cmd + .clone() + .validate_database_params() + .map_err(|e| eyre!("Failed to validate database params: {e}")) + .unwrap(); let database = implement_client::init_database(database_type, &database_params).await; - let queue_params = run_cmd.clone().validate_queue_params().map_err(|e| eyre!("Failed to validate queue params: {e}")).unwrap(); + let queue_params = + run_cmd.clone().validate_queue_params().map_err(|e| eyre!("Failed to validate queue params: {e}")).unwrap(); let queue = implement_client::init_queue_client(queue_type, queue_params.clone()).await; // Deleting and Creating the queues in sqs. @@ -352,7 +365,7 @@ pub mod implement_client { pub(crate) async fn init_settlement_client( service: ConfigType, - settlement_cfg : &SettlementParams + settlement_cfg: &SettlementParams, ) -> Box { match service { ConfigType::Mock(client) => client.into(), @@ -363,10 +376,7 @@ pub mod implement_client { } } - pub(crate) async fn init_prover_client( - service: ConfigType, - prover_params: &ProverParams, - ) -> Box { + pub(crate) async fn init_prover_client(service: ConfigType, prover_params: &ProverParams) -> Box { match service { ConfigType::Mock(client) => client.into(), ConfigType::Actual => build_prover_service(prover_params), @@ -388,20 +398,18 @@ pub mod implement_client { pub(crate) async fn init_storage_client( service: ConfigType, - storage_cfg : &StorageParams, + storage_cfg: &StorageParams, provider_config: Arc, ) -> Box { match service { ConfigType::Mock(client) => client.into(), - ConfigType::Actual => { - match storage_cfg { - StorageParams::AWSS3(aws_s3_params) => { - let storage = get_storage_client(aws_s3_params, provider_config).await; - storage.as_ref().build_test_bucket(&aws_s3_params.bucket_name).await.unwrap(); - storage - } + ConfigType::Actual => match storage_cfg { + StorageParams::AWSS3(aws_s3_params) => { + let storage = get_storage_client(aws_s3_params, provider_config).await; + storage.as_ref().build_test_bucket(&aws_s3_params.bucket_name).await.unwrap(); + storage } - } + }, ConfigType::Dummy => Box::new(MockDataStorage::new()), } } @@ -414,13 +422,10 @@ pub mod implement_client { } } - pub(crate) async fn init_database( - service: ConfigType, - database_params: &DatabaseParams, - ) -> Box { + pub(crate) async fn init_database(service: ConfigType, database_params: &DatabaseParams) -> Box { match service { ConfigType::Mock(client) => client.into(), - ConfigType::Actual => build_database_client(&database_params).await, + ConfigType::Actual => build_database_client(database_params).await, ConfigType::Dummy => Box::new(MockDatabase::new()), } } diff --git a/crates/orchestrator/src/tests/jobs/mod.rs b/crates/orchestrator/src/tests/jobs/mod.rs index 2f30cd5b..0a73c185 100644 --- a/crates/orchestrator/src/tests/jobs/mod.rs +++ b/crates/orchestrator/src/tests/jobs/mod.rs @@ -19,7 +19,6 @@ use crate::jobs::types::{ExternalId, JobItem, JobStatus, JobType, JobVerificatio use crate::jobs::{ create_job, handle_job_failure, increment_key_in_metadata, process_job, verify_job, Job, JobError, MockJob, }; - use crate::queue::job_queue::QueueNameForJobType; use crate::tests::common::MessagePayloadType; use crate::tests::config::{ConfigType, TestConfigBuilder}; @@ -382,19 +381,11 @@ async fn verify_job_with_verified_status_works() { sleep(Duration::from_secs(5)).await; // Queue checks. - let consumed_messages_verification_queue = services - .config - .queue() - .consume_message_from_queue(QueueType::DataSubmissionJobVerification) - .await - .unwrap_err(); + let consumed_messages_verification_queue = + services.config.queue().consume_message_from_queue(QueueType::DataSubmissionJobVerification).await.unwrap_err(); assert_matches!(consumed_messages_verification_queue, QueueError::NoData); - let consumed_messages_processing_queue = services - .config - .queue() - .consume_message_from_queue(QueueType::DataSubmissionJobProcessing) - .await - .unwrap_err(); + let consumed_messages_processing_queue = + services.config.queue().consume_message_from_queue(QueueType::DataSubmissionJobProcessing).await.unwrap_err(); assert_matches!(consumed_messages_processing_queue, QueueError::NoData); } @@ -436,12 +427,8 @@ async fn verify_job_with_rejected_status_adds_to_queue_works() { sleep(Duration::from_secs(5)).await; // Queue checks. - let consumed_messages = services - .config - .queue() - .consume_message_from_queue(QueueType::DataSubmissionJobProcessing) - .await - .unwrap(); + let consumed_messages = + services.config.queue().consume_message_from_queue(QueueType::DataSubmissionJobProcessing).await.unwrap(); let consumed_message_payload: MessagePayloadType = consumed_messages.payload_serde_json().unwrap().unwrap(); assert_eq!(consumed_message_payload.id, job_item.id); } diff --git a/crates/orchestrator/src/workers/snos.rs b/crates/orchestrator/src/workers/snos.rs index 5ba1fd09..9ecda249 100644 --- a/crates/orchestrator/src/workers/snos.rs +++ b/crates/orchestrator/src/workers/snos.rs @@ -3,7 +3,6 @@ use std::sync::Arc; use async_trait::async_trait; use starknet::providers::Provider; -use utils::env_utils::get_env_var_or_default; use crate::config::Config; use crate::jobs::create_job; @@ -49,4 +48,3 @@ impl Worker for SnosWorker { Ok(()) } } - diff --git a/crates/prover-services/gps-fact-checker/src/lib.rs b/crates/prover-services/gps-fact-checker/src/lib.rs index 77e96d68..185ed198 100644 --- a/crates/prover-services/gps-fact-checker/src/lib.rs +++ b/crates/prover-services/gps-fact-checker/src/lib.rs @@ -29,7 +29,10 @@ type ProviderT = RootProvider; impl FactChecker { pub fn new(sharp_params: &SharpParams) -> Self { let provider = ProviderBuilder::new().on_http(sharp_params.sharp_rpc_node_url.clone()); - let fact_registry = FactRegistry::new(Address::from_str(sharp_params.gps_verifier_contract_address.as_str()).unwrap() , provider); + let fact_registry = FactRegistry::new( + Address::from_str(sharp_params.gps_verifier_contract_address.as_str()).unwrap(), + provider, + ); Self { fact_registry } } diff --git a/crates/prover-services/sharp-service/src/client.rs b/crates/prover-services/sharp-service/src/client.rs index 17b94feb..bbc1649c 100644 --- a/crates/prover-services/sharp-service/src/client.rs +++ b/crates/prover-services/sharp-service/src/client.rs @@ -6,7 +6,6 @@ use reqwest::{Certificate, ClientBuilder, Identity}; use url::Url; use utils::cli::prover::sharp::SharpParams; use utils::env_utils::get_env_var_or_panic; -use utils::settings::Settings; use uuid::Uuid; use crate::error::SharpError; @@ -31,7 +30,7 @@ impl SharpClient { /// `cat | base64` pub fn new_with_settings(url: Url, sharp_params: &SharpParams) -> Self { // Getting the cert files from the .env and then decoding it from base64 - + let cert = general_purpose::STANDARD .decode(sharp_params.sharp_user_crt.clone()) .expect("Failed to decode certificate"); diff --git a/crates/prover-services/sharp-service/src/lib.rs b/crates/prover-services/sharp-service/src/lib.rs index bfc84819..6ea92c32 100644 --- a/crates/prover-services/sharp-service/src/lib.rs +++ b/crates/prover-services/sharp-service/src/lib.rs @@ -140,7 +140,6 @@ impl SharpProverService { } pub fn with_test_settings(port: u16, sharp_params: &SharpParams) -> Self { - let sharp_client = SharpClient::new_with_settings( format!("http://127.0.0.1:{}", port).parse().expect("Failed to create sharp client with the given params"), sharp_params, diff --git a/crates/prover-services/sharp-service/tests/lib.rs b/crates/prover-services/sharp-service/tests/lib.rs index 82588d1e..168ab6cf 100644 --- a/crates/prover-services/sharp-service/tests/lib.rs +++ b/crates/prover-services/sharp-service/tests/lib.rs @@ -1,14 +1,8 @@ -use cairo_vm::vm::runners::cairo_pie::CairoPie; -use httpmock::MockServer; -use prover_client_interface::{ProverClient, Task, TaskStatus}; -use rstest::rstest; +use prover_client_interface::TaskStatus; use serde_json::json; -use sharp_service::SharpProverService; use starknet_os::sharp::CairoJobStatus; -use utils::{cli::RunCmd, env_utils::get_env_var_or_panic}; -use utils::settings::env::EnvSettingsProvider; -use crate::constants::{CAIRO_PIE_PATH, TEST_FACT}; +use crate::constants::TEST_FACT; mod constants; @@ -18,8 +12,8 @@ mod constants; // dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); // let server = MockServer::start(); -// let sharp_service = SharpProverService::with_test_settings(&EnvSettingsProvider {}, server.port()); -// let cairo_pie_path = env!("CARGO_MANIFEST_DIR").to_string() + CAIRO_PIE_PATH; +// let sharp_service = SharpProverService::with_test_settings(&EnvSettingsProvider {}, +// server.port()); let cairo_pie_path = env!("CARGO_MANIFEST_DIR").to_string() + CAIRO_PIE_PATH; // let cairo_pie = CairoPie::read_zip_file(cairo_pie_path.as_ref()).unwrap(); // let sharp_response = json!( @@ -52,16 +46,17 @@ mod constants; // dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); // let server = MockServer::start(); -// let sharp_service = SharpProverService::with_test_settings(&EnvSettingsProvider {}, server.port()); -// let customer_id = get_env_var_or_panic("SHARP_CUSTOMER_ID"); +// let sharp_service = SharpProverService::with_test_settings(&EnvSettingsProvider {}, +// server.port()); let customer_id = get_env_var_or_panic("SHARP_CUSTOMER_ID"); // let sharp_add_job_call = server.mock(|when, then| { // when.path_contains("/get_status").query_param("customer_id", customer_id.as_str()); -// then.status(200).body(serde_json::to_vec(&get_task_status_sharp_response(&cairo_job_status)).unwrap()); -// }); +// then.status(200).body(serde_json::to_vec(&get_task_status_sharp_response(& +// cairo_job_status)).unwrap()); }); -// let task_status = sharp_service.get_task_status("c31381bf-4739-4667-b5b8-b08af1c6b1c7", TEST_FACT).await.unwrap(); -// assert_eq!(task_status, get_task_status_expectation(&cairo_job_status), "Cairo Job Status assertion failed"); +// let task_status = sharp_service.get_task_status("c31381bf-4739-4667-b5b8-b08af1c6b1c7", +// TEST_FACT).await.unwrap(); assert_eq!(task_status, +// get_task_status_expectation(&cairo_job_status), "Cairo Job Status assertion failed"); // sharp_add_job_call.assert(); // } diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index 710805a0..29b7ae44 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -26,11 +26,9 @@ use settlement_client_interface::{SettlementClient, SettlementVerificationStatus #[cfg(feature = "testing")] use url::Url; use utils::cli::settlement::ethereum::EthereumSettlementParams; -use utils::env_utils::get_env_var_or_panic; use crate::clients::interfaces::validity_interface::StarknetValidityContractTrait; use crate::clients::StarknetValidityContractClient; -use crate::config::EthereumSettlementConfig; use crate::conversion::{slice_u8_to_u256, vec_u8_32_to_vec_u256}; pub mod clients; pub mod config; @@ -43,7 +41,6 @@ use lazy_static::lazy_static; use mockall::automock; use reqwest::Client; use tokio::time::sleep; -use utils::settings::Settings; use crate::types::{bytes_be_to_u128, convert_stark_bigint_to_u256}; @@ -88,10 +85,12 @@ impl EthereumSettlementClient { // provider with wallet let filler_provider = Arc::new( - ProviderBuilder::new().with_recommended_fillers().wallet(wallet.clone()).on_http(settlement_cfg.ethereum_rpc_url.clone()), + ProviderBuilder::new() + .with_recommended_fillers() + .wallet(wallet.clone()) + .on_http(settlement_cfg.ethereum_rpc_url.clone()), ); - let core_contract_client = StarknetValidityContractClient::new( Address::from_str(&settlement_cfg.l1_core_contract_address) .expect("Failed to convert the validity contract address.") @@ -104,9 +103,7 @@ impl EthereumSettlementClient { } #[cfg(feature = "testing")] - pub fn with_test_settings( - settlement_cfg: &EthereumSettlementParams, - ) -> Self { + pub fn with_test_settings(settlement_cfg: &EthereumSettlementParams) -> Self { let root_provider = RootProvider::new_http(settlement_cfg.ethereum_rpc_url.clone().as_str().parse()?); let core_contract_address = Address::from_str(&settlement_cfg.l1_core_contract_address.clone())?; let settlement_rpc_url = &settlement_cfg.ethereum_rpc_url.clone()?; @@ -115,8 +112,9 @@ impl EthereumSettlementClient { let wallet_address = signer.address(); let wallet = EthereumWallet::from(signer); - let fill_provider = - Arc::new(ProviderBuilder::new().with_recommended_fillers().wallet(wallet.clone()).on_http(settlement_rpc_url)); + let fill_provider = Arc::new( + ProviderBuilder::new().with_recommended_fillers().wallet(wallet.clone()).on_http(settlement_rpc_url), + ); let core_contract_client = StarknetValidityContractClient::new(core_contract_address, fill_provider); diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 5b0fb4fe..33fee884 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -23,9 +23,7 @@ use starknet::providers::{JsonRpcClient, Provider}; use starknet::signers::{LocalWallet, SigningKey}; use tokio::time::{sleep, Duration}; use utils::cli::settlement::starknet::StarknetSettlementParams; -use utils::settings::Settings; -use crate::config::StarknetSettlementConfig; use crate::conversion::{slice_slice_u8_to_vec_field, slice_u8_to_field, u64_from_felt}; pub type LocalWalletSignerMiddleware = Arc>, LocalWallet>>; @@ -58,8 +56,8 @@ impl StarknetSettlementClient { let signer = Felt::from_hex(&private_key).expect("Invalid private key"); let signer = LocalWallet::from(SigningKey::from_secret_scalar(signer)); - let core_contract_address = - Felt::from_hex(&settlement_cfg.starknet_cairo_core_contract_address).expect("Invalid core contract address"); + let core_contract_address = Felt::from_hex(&settlement_cfg.starknet_cairo_core_contract_address) + .expect("Invalid core contract address"); let account: Arc>, LocalWallet>> = Arc::new(SingleOwnerAccount::new( diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index eea5535b..0d96528f 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -1,5 +1,4 @@ use std::env; -use std::path::Path; use std::sync::Arc; use std::time::Duration; @@ -7,13 +6,7 @@ use color_eyre::eyre::eyre; use rstest::{fixture, rstest}; use settlement_client_interface::SettlementClient; use starknet::accounts::{Account, ConnectedAccount, ExecutionEncoding, SingleOwnerAccount}; -use starknet::contract::ContractFactory; -use starknet::core::types::contract::{CompiledClass, SierraClass}; -use starknet::core::types::{ - BlockId, BlockTag, DeclareTransactionResult, Felt, FunctionCall, InvokeTransactionResult, StarknetError, - TransactionExecutionStatus, TransactionStatus, -}; -use starknet::macros::{felt, selector}; +use starknet::core::types::{BlockId, BlockTag, Felt, StarknetError, TransactionExecutionStatus, TransactionStatus}; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Provider, ProviderError, Url}; use starknet::signers::{LocalWallet, SigningKey}; @@ -21,7 +14,7 @@ use utils::settings::env::EnvSettingsProvider; use utils::settings::Settings; use super::setup::{wait_for_cond, MadaraCmd, MadaraCmdBuilder}; -use crate::{LocalWalletSignerMiddleware, StarknetSettlementClient}; +use crate::LocalWalletSignerMiddleware; #[fixture] pub async fn spin_up_madara() -> MadaraCmd { @@ -106,7 +99,8 @@ async fn setup(#[future] spin_up_madara: MadaraCmd) -> (LocalWalletSignerMiddlew // let (account, _madara_process) = setup.await; // let project_root = Path::new(env!("CARGO_MANIFEST_DIR")).ancestors().nth(3).unwrap(); -// let contract_path = project_root.join("crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev"); +// let contract_path = +// project_root.join("crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev"); // let sierra_class: SierraClass = serde_json::from_reader( // std::fs::File::open(contract_path.join("mock_contracts_Piltover.contract_class.json")) // .expect("Could not open sierra class file"), @@ -114,8 +108,8 @@ async fn setup(#[future] spin_up_madara: MadaraCmd) -> (LocalWalletSignerMiddlew // .expect("Failed to parse SierraClass"); // let compiled_class: CompiledClass = serde_json::from_reader( -// std::fs::File::open(contract_path.join("mock_contracts_Piltover.compiled_contract_class.json")) -// .expect("Could not open compiled class file"), +// std::fs::File::open(contract_path.join("mock_contracts_Piltover.compiled_contract_class. +// json")) .expect("Could not open compiled class file"), // ) // .expect("Failed to parse CompiledClass"); @@ -123,8 +117,9 @@ async fn setup(#[future] spin_up_madara: MadaraCmd) -> (LocalWalletSignerMiddlew // let compiled_class_hash = compiled_class.class_hash().unwrap(); // let DeclareTransactionResult { transaction_hash: declare_tx_hash, class_hash: _ } = -// account.declare_v2(Arc::new(flattened_class.clone()), compiled_class_hash).send().await.unwrap(); -// tracing::debug!("declare tx hash {:?}", declare_tx_hash); +// account.declare_v2(Arc::new(flattened_class.clone()), +// compiled_class_hash).send().await.unwrap(); tracing::debug!("declare tx hash {:?}", +// declare_tx_hash); // let is_success = wait_for_tx(&account, declare_tx_hash, Duration::from_secs(2)).await; // assert!(is_success, "Declare trasactiion failed"); @@ -143,9 +138,9 @@ async fn setup(#[future] spin_up_madara: MadaraCmd) -> (LocalWalletSignerMiddlew // let env_settings = EnvSettingsProvider {}; // let settlement_params = run_cmd.clone().validate_settlement_params().unwrap(); -// let settlement_client = StarknetSettlementClient::new_with_settings(&settlement_params).await; -// let onchain_data_hash = [1; 32]; -// let mut program_output = Vec::with_capacity(32); +// let settlement_client = +// StarknetSettlementClient::new_with_settings(&settlement_params).await; let onchain_data_hash +// = [1; 32]; let mut program_output = Vec::with_capacity(32); // program_output.fill(onchain_data_hash); // let update_state_tx_hash = settlement_client // .update_state_calldata(program_output, onchain_data_hash, [1; 32]) diff --git a/crates/utils/src/cli/alert/aws_sns.rs b/crates/utils/src/cli/alert/aws_sns.rs index 351d0004..ba10bb5c 100644 --- a/crates/utils/src/cli/alert/aws_sns.rs +++ b/crates/utils/src/cli/alert/aws_sns.rs @@ -10,4 +10,4 @@ pub struct AWSSNSParams { impl AWSSNSParams { // TODO: Implement the logic to get the SNS ARN from aws config -} \ No newline at end of file +} diff --git a/crates/utils/src/cli/alert/mod.rs b/crates/utils/src/cli/alert/mod.rs index d7cb1801..5a7b4b97 100644 --- a/crates/utils/src/cli/alert/mod.rs +++ b/crates/utils/src/cli/alert/mod.rs @@ -3,4 +3,4 @@ pub mod aws_sns; #[derive(Clone, Debug)] pub enum AlertParams { AWSSNS(aws_sns::AWSSNSParams), -} \ No newline at end of file +} diff --git a/crates/utils/src/cli/database/mod.rs b/crates/utils/src/cli/database/mod.rs index 50f47442..1d55f094 100644 --- a/crates/utils/src/cli/database/mod.rs +++ b/crates/utils/src/cli/database/mod.rs @@ -3,4 +3,4 @@ pub mod mongodb; #[derive(Debug, Clone)] pub enum DatabaseParams { MongoDB(mongodb::MongoDBParams), -} \ No newline at end of file +} diff --git a/crates/utils/src/cli/mod.rs b/crates/utils/src/cli/mod.rs index e148e466..357ce7d6 100644 --- a/crates/utils/src/cli/mod.rs +++ b/crates/utils/src/cli/mod.rs @@ -8,57 +8,50 @@ use settlement::SettlementParams; use storage::StorageParams; use url::Url; +pub mod alert; pub mod aws_config; +pub mod da; pub mod database; pub mod instrumentation; -pub mod server; -pub mod storage; -pub mod queue; -pub mod alert; pub mod prover; -pub mod da; +pub mod queue; +pub mod server; pub mod settlement; pub mod snos; +pub mod storage; #[derive(Clone, Debug, clap::Parser)] #[clap( - - // Mutual Exclusion Solved group( ArgGroup::new("settlement_layer") .args(&["settle_on_ethereum", "settle_on_starknet"]) .required(true) .multiple(false) ), - group( ArgGroup::new("storage") .args(&["aws_s3"]) .required(true) .multiple(false) ), - group( ArgGroup::new("queue") .args(&["aws_sqs"]) .required(true) .multiple(false) ), - group( ArgGroup::new("alert") .args(&["aws_sns"]) .required(true) .multiple(false) ), - group( ArgGroup::new("prover") .args(&["sharp"]) .required(true) .multiple(false) ), - group( ArgGroup::new("da_layer") .args(&["da_on_ethereum"]) @@ -68,7 +61,6 @@ pub mod snos; )] pub struct RunCmd { - // AWS Config #[clap(flatten)] pub aws_config: aws_config::AWSConfigParams, @@ -89,7 +81,7 @@ pub struct RunCmd { // Storage #[clap(long, group = "storage")] pub aws_s3: bool, - + #[clap(flatten)] pub aws_s3_params: storage::aws_s3::AWSS3Params, @@ -124,7 +116,7 @@ pub struct RunCmd { #[clap(flatten)] pub ethereum_da_params: da::ethereum::EthereumParams, - + // Prover #[clap(long, group = "prover")] pub sharp: bool, @@ -148,28 +140,30 @@ impl RunCmd { (true, false) => { // Ensure Starknet params are not provided if self.starknet_settlement_params.is_some() { - return Err("Starknet parameters cannot be specified when Ethereum settlement is selected".to_string()); + return Err( + "Starknet parameters cannot be specified when Ethereum settlement is selected".to_string() + ); } - + // Get Ethereum params or error if none provided - self.ethereum_settlement_params - .map(SettlementParams::Ethereum) - .ok_or_else(|| "Ethereum parameters must be provided when Ethereum settlement is selected".to_string()) + self.ethereum_settlement_params.map(SettlementParams::Ethereum).ok_or_else(|| { + "Ethereum parameters must be provided when Ethereum settlement is selected".to_string() + }) } (false, true) => { // Ensure Ethereum params are not provided if self.ethereum_settlement_params.is_some() { - return Err("Ethereum parameters cannot be specified when Starknet settlement is selected".to_string()); + return Err( + "Ethereum parameters cannot be specified when Starknet settlement is selected".to_string() + ); } - + // Get Starknet params or error if none provided - self.starknet_settlement_params - .map(SettlementParams::Starknet) - .ok_or_else(|| "Starknet parameters must be provided when Starknet settlement is selected".to_string()) - } - (true, true) | (false, false) => { - Err("Exactly one settlement layer must be selected".to_string()) + self.starknet_settlement_params.map(SettlementParams::Starknet).ok_or_else(|| { + "Starknet parameters must be provided when Starknet settlement is selected".to_string() + }) } + (true, true) | (false, false) => Err("Exactly one settlement layer must be selected".to_string()), } } @@ -220,5 +214,4 @@ impl RunCmd { Err("Only Sharp is supported as of now".to_string()) } } - -} \ No newline at end of file +} diff --git a/crates/utils/src/cli/prover/sharp.rs b/crates/utils/src/cli/prover/sharp.rs index e2262ea8..3185293f 100644 --- a/crates/utils/src/cli/prover/sharp.rs +++ b/crates/utils/src/cli/prover/sharp.rs @@ -4,36 +4,35 @@ use url::Url; /// Parameters used to config Sharp. #[derive(Debug, Clone, Args)] pub struct SharpParams { + /// The customer id for Sharp. + #[arg(env = "SHARP_CUSTOMER_ID", long)] + pub sharp_customer_id: String, - /// The customer id for Sharp. - #[arg(env = "SHARP_CUSTOMER_ID", long)] - pub sharp_customer_id: String, + /// The URL of the Sharp server. + #[arg(env = "SHARP_URL", long)] + pub sharp_url: Url, - /// The URL of the Sharp server. - #[arg(env = "SHARP_URL", long)] - pub sharp_url: Url, + /// The user certificate for Sharp. + #[arg(env = "SHARP_USER_CRT", long)] + pub sharp_user_crt: String, - /// The user certificate for Sharp. - #[arg(env = "SHARP_USER_CRT", long)] - pub sharp_user_crt: String, + /// The user key for Sharp. + #[arg(env = "SHARP_USER_KEY", long)] + pub sharp_user_key: String, - /// The user key for Sharp. - #[arg(env = "SHARP_USER_KEY", long)] - pub sharp_user_key: String, + /// The RPC node URL for Sharp. + #[arg(env = "SHARP_RPC_NODE_URL", long)] + pub sharp_rpc_node_url: Url, - /// The RPC node URL for Sharp. - #[arg(env = "SHARP_RPC_NODE_URL", long)] - pub sharp_rpc_node_url: Url, + /// The server certificate for Sharp. + #[arg(env = "SHARP_SERVER_CRT", long)] + pub sharp_server_crt: String, - /// The server certificate for Sharp. - #[arg(env = "SHARP_SERVER_CRT", long)] - pub sharp_server_crt: String, + /// The proof layout for Sharp. + #[arg(env = "SHARP_PROOF_LAYOUT", long, default_value = "small")] + pub sharp_proof_layout: String, - /// The proof layout for Sharp. - #[arg(env = "SHARP_PROOF_LAYOUT", long, default_value = "small")] - pub sharp_proof_layout: String, - - /// The GPS verifier contract address. - #[arg(env = "GPS_VERIFIER_CONTRACT_ADDRESS", long)] - pub gps_verifier_contract_address: String, + /// The GPS verifier contract address. + #[arg(env = "GPS_VERIFIER_CONTRACT_ADDRESS", long)] + pub gps_verifier_contract_address: String, } diff --git a/crates/utils/src/cli/queue/aws_sqs.rs b/crates/utils/src/cli/queue/aws_sqs.rs index 7b6f2d81..635cf059 100644 --- a/crates/utils/src/cli/queue/aws_sqs.rs +++ b/crates/utils/src/cli/queue/aws_sqs.rs @@ -61,22 +61,19 @@ impl QueueType { QueueType::UpdateStateJobVerification, QueueType::JobHandleFailure, QueueType::WorkerTrigger, - ].iter().cloned() + ] + .iter() + .cloned() } } - impl fmt::Display for QueueType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - _ => write!(f, "{}", serde_json::to_string(self).unwrap()), - } + write!(f, "{}", serde_json::to_string(self).unwrap()) } } - impl AWSSQSParams { - pub fn get_queue_url(&self, queue_type: QueueType) -> String { format!("{}/{}", self.queue_base_url, self.get_queue_name(queue_type)) } @@ -86,5 +83,4 @@ impl AWSSQSParams { let queue_name = serde_json::to_string(&queue_type).unwrap(); format!("{}_{}_{}", self.sqs_prefix, queue_name, self.sqs_suffix) } - -} \ No newline at end of file +} diff --git a/crates/utils/src/cli/queue/mod.rs b/crates/utils/src/cli/queue/mod.rs index a59318bb..9794d078 100644 --- a/crates/utils/src/cli/queue/mod.rs +++ b/crates/utils/src/cli/queue/mod.rs @@ -1,7 +1,6 @@ pub mod aws_sqs; - #[derive(Clone, Debug)] pub enum QueueParams { AWSSQS(aws_sqs::AWSSQSParams), -} \ No newline at end of file +} diff --git a/crates/utils/src/cli/server.rs b/crates/utils/src/cli/server.rs index 0cca091a..815c4dc5 100644 --- a/crates/utils/src/cli/server.rs +++ b/crates/utils/src/cli/server.rs @@ -11,4 +11,3 @@ pub struct ServerParams { #[arg(env = "PORT", long, default_value = "3000")] pub port: u16, } - \ No newline at end of file diff --git a/crates/utils/src/cli/settlement/ethereum.rs b/crates/utils/src/cli/settlement/ethereum.rs index 882cdba6..ec4e7f27 100644 --- a/crates/utils/src/cli/settlement/ethereum.rs +++ b/crates/utils/src/cli/settlement/ethereum.rs @@ -6,7 +6,6 @@ use url::Url; // L1_CORE_CONTRACT_ADDRESS="0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057" // STARKNET_OPERATOR_ADDRESS="0x5b98B836969A60FEC50Fa925905Dd1D382a7db43" - #[derive(Debug, Clone, Args)] pub struct EthereumSettlementParams { /// The URL of the Ethereum RPC node. diff --git a/crates/utils/src/cli/settlement/mod.rs b/crates/utils/src/cli/settlement/mod.rs index 50d39c06..9149c0f4 100644 --- a/crates/utils/src/cli/settlement/mod.rs +++ b/crates/utils/src/cli/settlement/mod.rs @@ -1,9 +1,8 @@ pub mod ethereum; pub mod starknet; - #[derive(Clone, Debug)] pub enum SettlementParams { Ethereum(ethereum::EthereumSettlementParams), Starknet(starknet::StarknetSettlementParams), -} \ No newline at end of file +} diff --git a/crates/utils/src/cli/settlement/starknet.rs b/crates/utils/src/cli/settlement/starknet.rs index 41261baa..53c12c3f 100644 --- a/crates/utils/src/cli/settlement/starknet.rs +++ b/crates/utils/src/cli/settlement/starknet.rs @@ -1,7 +1,6 @@ use clap::Args; use url::Url; - // STARKNET_RPC_URL="https://starknet-sepolia.public.blastapi.io" // STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 // STARKNET_ACCOUNT_ADDRESS=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 @@ -9,13 +8,12 @@ use url::Url; // STARKNET_FINALITY_RETRY_WAIT_IN_SECS="" // MADARA_BINARY_PATH="/path/to/madara" - #[derive(Debug, Clone, Args)] pub struct StarknetSettlementParams { /// The URL of the Ethereum RPC node. #[arg(env = "STARKNET_RPC_URL", long)] pub starknet_rpc_url: Url, - + /// The private key of the Ethereum account. #[arg(env = "STARKNET_PRIVATE_KEY", long)] pub starknet_private_key: String, @@ -35,5 +33,4 @@ pub struct StarknetSettlementParams { /// The path to the Madara binary. #[arg(env = "MADARA_BINARY_PATH", long)] pub madara_binary_path: String, - } diff --git a/crates/utils/src/cli/storage/mod.rs b/crates/utils/src/cli/storage/mod.rs index edd568a4..289aa036 100644 --- a/crates/utils/src/cli/storage/mod.rs +++ b/crates/utils/src/cli/storage/mod.rs @@ -1,7 +1,6 @@ - pub mod aws_s3; #[derive(Clone, Debug)] pub enum StorageParams { AWSS3(aws_s3::AWSS3Params), -} \ No newline at end of file +} diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs index 68a63379..f52d6000 100644 --- a/crates/utils/src/lib.rs +++ b/crates/utils/src/lib.rs @@ -1,8 +1,8 @@ +pub mod cli; pub mod collections; pub mod env_utils; pub mod metrics; pub mod settings; -pub mod cli; /// Evaluate `$x:expr` and if not true return `Err($y:expr)`. /// diff --git a/e2e-tests/src/localstack.rs b/e2e-tests/src/localstack.rs index 3eb82845..123b7c20 100644 --- a/e2e-tests/src/localstack.rs +++ b/e2e-tests/src/localstack.rs @@ -11,7 +11,6 @@ use aws_sdk_sqs::types::QueueAttributeName::VisibilityTimeout; use orchestrator::config::ProviderConfig; use orchestrator::data_storage::aws_s3::AWSS3; use orchestrator::data_storage::DataStorage; - use orchestrator::queue::job_queue::{JobQueueMessage, WorkerTriggerMessage, WorkerTriggerType}; use utils::cli::aws_config::AWSConfigParams; use utils::cli::queue::aws_sqs::{AWSSQSParams, QueueType}; @@ -76,7 +75,11 @@ impl LocalStack { } /// Event Bridge setup - pub async fn setup_event_bridge(&self, worker_trigger_type: WorkerTriggerType, sqs_config: &AWSSQSParams) -> color_eyre::Result<()> { + pub async fn setup_event_bridge( + &self, + worker_trigger_type: WorkerTriggerType, + sqs_config: &AWSSQSParams, + ) -> color_eyre::Result<()> { let rule_name = "worker_trigger_scheduled"; self.event_bridge_client @@ -86,7 +89,12 @@ impl LocalStack { .state(RuleState::Enabled) .send() .await?; - let queue_url = self.sqs_client.get_queue_url().queue_name(sqs_config.get_queue_name(QueueType::WorkerTrigger)).send().await?; + let queue_url = self + .sqs_client + .get_queue_url() + .queue_name(sqs_config.get_queue_name(QueueType::WorkerTrigger)) + .send() + .await?; let queue_attributes = self .sqs_client diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index 79cf2f32..4ee63f95 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -2,9 +2,9 @@ use std::collections::HashMap; use std::fs::File; use std::io::Read; use std::time::{Duration, Instant}; -use clap::Parser as _; use chrono::{SubsecRound, Utc}; +use clap::Parser as _; use e2e_tests::anvil::AnvilSetup; use e2e_tests::localstack::LocalStack; use e2e_tests::mock_server::MockResponseBodyType; @@ -49,7 +49,6 @@ struct Setup { impl Setup { /// Initialise a new setup pub async fn new(l2_block_number: String, run_cmd: RunCmd) -> Self { - let mongodb_params = run_cmd.mongodb_params; let mongo_db_instance = MongoDbServer::run(mongodb_params); println!("✅ Mongo DB setup completed"); @@ -132,7 +131,6 @@ impl Setup { #[case("66645".to_string())] #[tokio::test] async fn test_orchestrator_workflow(#[case] l2_block_number: String) { - // Fetching the env vars from the test env file as these will be used in // setting up of the test and during orchestrator run too. dotenvy::from_filename(".env.test").expect("Failed to load the .env file"); From 715c9b66f7eb367520731064a68c94c0b762b546 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 6 Nov 2024 21:21:02 +0530 Subject: [PATCH 12/63] update: working mutual exclusion --- crates/orchestrator/src/config.rs | 14 ++-- crates/orchestrator/src/main.rs | 3 + crates/orchestrator/src/tests/config.rs | 43 +++------- crates/utils/src/cli/mod.rs | 90 ++++++++++----------- crates/utils/src/cli/settlement/ethereum.rs | 31 ++++--- crates/utils/src/cli/settlement/starknet.rs | 39 ++++++--- 6 files changed, 114 insertions(+), 106 deletions(-) diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 161921fa..3c9206f3 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -125,31 +125,31 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { // init database let database_params = - run_cmd.clone().validate_database_params().map_err(|e| eyre!("Failed to validate database params: {e}"))?; + run_cmd.validate_database_params().map_err(|e| eyre!("Failed to validate database params: {e}"))?; let database = build_database_client(&database_params).await; // init DA client - let da_params = run_cmd.clone().validate_da_params().map_err(|e| eyre!("Failed to validate DA params: {e}"))?; + let da_params = run_cmd.validate_da_params().map_err(|e| eyre!("Failed to validate DA params: {e}"))?; let da_client = build_da_client(&da_params).await; // init settlement let settlement_params = - run_cmd.clone().validate_settlement_params().map_err(|e| eyre!("Failed to validate settlement params: {e}"))?; + run_cmd.validate_settlement_params().map_err(|e| eyre!("Failed to validate settlement params: {e}"))?; let settlement_client = build_settlement_client(&settlement_params).await?; // init prover let prover_params = - run_cmd.clone().validate_prover_params().map_err(|e| eyre!("Failed to validate prover params: {e}"))?; + run_cmd.validate_prover_params().map_err(|e| eyre!("Failed to validate prover params: {e}"))?; let prover_client = build_prover_service(&prover_params); // init storage let data_storage_params = - run_cmd.clone().validate_storage_params().map_err(|e| eyre!("Failed to validate storage params: {e}"))?; + run_cmd.validate_storage_params().map_err(|e| eyre!("Failed to validate storage params: {e}"))?; let storage_client = build_storage_client(&data_storage_params, provider_config.clone()).await; // init alerts let alert_params = - run_cmd.clone().validate_alert_params().map_err(|e| eyre!("Failed to validate alert params: {e}"))?; + run_cmd.validate_alert_params().map_err(|e| eyre!("Failed to validate alert params: {e}"))?; let alerts_client = build_alert_client(&alert_params, provider_config.clone()).await; // init the queue @@ -158,7 +158,7 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { // us stop using the generic omniqueue abstractions for message ack/nack // init queue let queue_params = - run_cmd.clone().validate_queue_params().map_err(|e| eyre!("Failed to validate queue params: {e}"))?; + run_cmd.validate_queue_params().map_err(|e| eyre!("Failed to validate queue params: {e}"))?; let queue = build_queue_client(&queue_params); Ok(Arc::new(Config::new( diff --git a/crates/orchestrator/src/main.rs b/crates/orchestrator/src/main.rs index e29337cf..9157b227 100644 --- a/crates/orchestrator/src/main.rs +++ b/crates/orchestrator/src/main.rs @@ -15,6 +15,9 @@ async fn main() { dotenv().ok(); // TODO: could this be an ARC ? let run_cmd: RunCmd = RunCmd::parse(); + + // print the run cmd + println!("{:?}", run_cmd); // Analytics Setup let meter_provider = setup_analytics(&run_cmd.instrumentation); diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 1f03618d..2b65c088 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -181,22 +181,18 @@ impl TestConfigBuilder { pub async fn build(self) -> TestConfigBuilderReturns { dotenvy::from_filename("../.env.test").expect("Failed to load the .env.test file"); - let run_cmd: RunCmd = RunCmd::parse(); + let run_cmd = RunCmd::parse(); - let run_cmd_clone = run_cmd.clone(); - - let aws_config = &run_cmd_clone.aws_config; + let aws_config = &run_cmd.aws_config; let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(aws_config).await))); - let server_config = run_cmd_clone.server; + let server_config = run_cmd.server.clone(); let snos_config = SnosConfig { - rpc_url: run_cmd_clone.snos.rpc_for_snos.clone(), - max_block_to_process: run_cmd_clone.snos.max_block_to_process, - min_block_to_process: run_cmd_clone.snos.min_block_to_process, + rpc_url: run_cmd.snos.rpc_for_snos.clone(), + max_block_to_process: run_cmd.snos.max_block_to_process, + min_block_to_process: run_cmd.snos.min_block_to_process, }; - use std::sync::Arc; - let TestConfigBuilder { starknet_rpc_url_type, starknet_client_type, @@ -215,41 +211,28 @@ impl TestConfigBuilder { // init alerts let alert_params = - run_cmd.clone().validate_alert_params().map_err(|e| eyre!("Failed to validate alert params: {e}")).unwrap(); + run_cmd.validate_alert_params().map_err(|e| eyre!("Failed to validate alert params: {e}")).unwrap(); let alerts = implement_client::init_alerts(alerts_type, &alert_params, provider_config.clone()).await; - let da_params = run_cmd.clone().validate_da_params().unwrap(); + let da_params = run_cmd.validate_da_params().unwrap(); let da_client = implement_client::init_da_client(da_client_type, &da_params).await; - let settlement_params = run_cmd.clone().validate_settlement_params().unwrap(); + let settlement_params = run_cmd.validate_settlement_params().unwrap(); let settlement_client = implement_client::init_settlement_client(settlement_client_type, &settlement_params).await; - let prover_params = run_cmd - .clone() - .validate_prover_params() - .map_err(|e| eyre!("Failed to validate prover params: {e}")) - .unwrap(); + let prover_params = run_cmd.validate_prover_params().unwrap(); let prover_client = implement_client::init_prover_client(prover_client_type, &prover_params).await; // External Dependencies - let data_storage_params = run_cmd - .clone() - .validate_storage_params() - .map_err(|e| eyre!("Failed to validate storage params: {e}")) - .unwrap(); + let data_storage_params = run_cmd.validate_storage_params().unwrap(); let storage = implement_client::init_storage_client(storage_type, &data_storage_params, provider_config.clone()).await; - let database_params = run_cmd - .clone() - .validate_database_params() - .map_err(|e| eyre!("Failed to validate database params: {e}")) - .unwrap(); + let database_params = run_cmd.validate_database_params().unwrap(); let database = implement_client::init_database(database_type, &database_params).await; - let queue_params = - run_cmd.clone().validate_queue_params().map_err(|e| eyre!("Failed to validate queue params: {e}")).unwrap(); + let queue_params = run_cmd.validate_queue_params().unwrap(); let queue = implement_client::init_queue_client(queue_type, queue_params.clone()).await; // Deleting and Creating the queues in sqs. diff --git a/crates/utils/src/cli/mod.rs b/crates/utils/src/cli/mod.rs index 357ce7d6..8f6b8822 100644 --- a/crates/utils/src/cli/mod.rs +++ b/crates/utils/src/cli/mod.rs @@ -1,10 +1,10 @@ use alert::AlertParams; -use clap::ArgGroup; +use clap::{command, ArgGroup, Parser}; use da::DaParams; use database::DatabaseParams; use prover::ProverParams; use queue::QueueParams; -use settlement::SettlementParams; +use settlement::{ethereum::EthereumSettlementParams, starknet::StarknetSettlementParams, SettlementParams}; use storage::StorageParams; use url::Url; @@ -20,7 +20,9 @@ pub mod settlement; pub mod snos; pub mod storage; -#[derive(Clone, Debug, clap::Parser)] + +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] #[clap( group( ArgGroup::new("settlement_layer") @@ -59,24 +61,17 @@ pub mod storage; .multiple(false) ), )] - pub struct RunCmd { // AWS Config #[clap(flatten)] pub aws_config: aws_config::AWSConfigParams, // Settlement Layer - #[clap(long, group = "settlement_layer")] - pub settle_on_ethereum: bool, - - #[clap(long, group = "settlement_layer")] - pub settle_on_starknet: bool, + #[command(flatten)] + ethereum_args: settlement::ethereum::EthereumSettlementArgs, - #[clap(flatten)] - ethereum_settlement_params: Option, - - #[clap(flatten)] - starknet_settlement_params: Option, + #[command(flatten)] + starknet_args: settlement::starknet::StarknetSettlementArgs, // Storage #[clap(long, group = "storage")] @@ -135,81 +130,84 @@ pub struct RunCmd { } impl RunCmd { - pub fn validate_settlement_params(self) -> Result { - match (self.settle_on_ethereum, self.settle_on_starknet) { + pub fn validate_settlement_params(&self) -> Result { + match (self.ethereum_args.settle_on_ethereum, self.starknet_args.settle_on_starknet) { (true, false) => { - // Ensure Starknet params are not provided - if self.starknet_settlement_params.is_some() { - return Err( - "Starknet parameters cannot be specified when Ethereum settlement is selected".to_string() - ); - } + // TODO: Ensure Starknet params are not provided // Get Ethereum params or error if none provided - self.ethereum_settlement_params.map(SettlementParams::Ethereum).ok_or_else(|| { - "Ethereum parameters must be provided when Ethereum settlement is selected".to_string() - }) + // Either all the values are provided or panic + let ethereum_params = EthereumSettlementParams { + ethereum_rpc_url: self.ethereum_args.ethereum_rpc_url.clone().unwrap(), + ethereum_private_key: self.ethereum_args.ethereum_private_key.clone().unwrap(), + l1_core_contract_address: self.ethereum_args.l1_core_contract_address.clone().unwrap(), + starknet_operator_address: self.ethereum_args.starknet_operator_address.clone().unwrap(), + }; + Ok(SettlementParams::Ethereum(ethereum_params)) } (false, true) => { - // Ensure Ethereum params are not provided - if self.ethereum_settlement_params.is_some() { - return Err( - "Ethereum parameters cannot be specified when Starknet settlement is selected".to_string() - ); - } + // TODO: Ensure Ethereum params are not provided // Get Starknet params or error if none provided - self.starknet_settlement_params.map(SettlementParams::Starknet).ok_or_else(|| { - "Starknet parameters must be provided when Starknet settlement is selected".to_string() - }) + // Either all the values are provided or panic + let starknet_params = StarknetSettlementParams { + starknet_rpc_url: self.starknet_args.starknet_rpc_url.clone().unwrap(), + starknet_private_key: self.starknet_args.starknet_private_key.clone().unwrap(), + starknet_account_address: self.starknet_args.starknet_account_address.clone().unwrap(), + starknet_cairo_core_contract_address: self.starknet_args.starknet_cairo_core_contract_address.clone().unwrap(), + starknet_finality_retry_wait_in_secs: self.starknet_args.starknet_finality_retry_wait_in_secs.clone().unwrap(), + madara_binary_path: self.starknet_args.madara_binary_path.clone().unwrap(), + }; + Ok(SettlementParams::Starknet(starknet_params)) + } (true, true) | (false, false) => Err("Exactly one settlement layer must be selected".to_string()), } } - pub fn validate_storage_params(self) -> Result { + pub fn validate_storage_params(&self) -> Result { if self.aws_s3 { - Ok(StorageParams::AWSS3(self.aws_s3_params)) + Ok(StorageParams::AWSS3(self.aws_s3_params.clone())) } else { Err("Only AWS S3 is supported as of now".to_string()) } } - pub fn validate_queue_params(self) -> Result { + pub fn validate_queue_params(&self) -> Result { if self.aws_sqs { - Ok(QueueParams::AWSSQS(self.aws_sqs_params)) + Ok(QueueParams::AWSSQS(self.aws_sqs_params.clone())) } else { Err("Only AWS SQS is supported as of now".to_string()) } } - pub fn validate_alert_params(self) -> Result { + pub fn validate_alert_params(&self) -> Result { if self.aws_sns { - Ok(AlertParams::AWSSNS(self.aws_sns_params)) + Ok(AlertParams::AWSSNS(self.aws_sns_params.clone())) } else { Err("Only AWS SNS is supported as of now".to_string()) } } - pub fn validate_database_params(self) -> Result { + pub fn validate_database_params(&self) -> Result { if self.mongodb { - Ok(DatabaseParams::MongoDB(self.mongodb_params)) + Ok(DatabaseParams::MongoDB(self.mongodb_params.clone())) } else { Err("Only MongoDB is supported as of now".to_string()) } } - pub fn validate_da_params(self) -> Result { + pub fn validate_da_params(&self) -> Result { if self.da_on_ethereum { - Ok(DaParams::Ethereum(self.ethereum_da_params)) + Ok(DaParams::Ethereum(self.ethereum_da_params.clone())) } else { Err("Only Ethereum is supported as of now".to_string()) } } - pub fn validate_prover_params(self) -> Result { + pub fn validate_prover_params(&self) -> Result { if self.sharp { - Ok(ProverParams::Sharp(self.sharp_params)) + Ok(ProverParams::Sharp(self.sharp_params.clone())) } else { Err("Only Sharp is supported as of now".to_string()) } diff --git a/crates/utils/src/cli/settlement/ethereum.rs b/crates/utils/src/cli/settlement/ethereum.rs index ec4e7f27..db2372a6 100644 --- a/crates/utils/src/cli/settlement/ethereum.rs +++ b/crates/utils/src/cli/settlement/ethereum.rs @@ -1,26 +1,37 @@ use clap::Args; use url::Url; -// SETTLEMENT_RPC_URL="https://eth-sepolia.public.blastapi.io" -// ETHEREUM_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" -// L1_CORE_CONTRACT_ADDRESS="0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057" -// STARKNET_OPERATOR_ADDRESS="0x5b98B836969A60FEC50Fa925905Dd1D382a7db43" - #[derive(Debug, Clone, Args)] -pub struct EthereumSettlementParams { +#[group(requires_all = ["ethereum_rpc_url", "ethereum_private_key", "l1_core_contract_address", "starknet_operator_address"])] +pub struct EthereumSettlementArgs { + /// Use the Ethereum settlement layer. + #[arg(long)] + pub settle_on_ethereum: bool, + /// The URL of the Ethereum RPC node. #[arg(env = "ETHEREUM_SETTLEMENT_RPC_URL", long)] - pub ethereum_rpc_url: Url, + pub ethereum_rpc_url: Option, /// The private key of the Ethereum account. #[arg(env = "ETHEREUM_PRIVATE_KEY", long)] - pub ethereum_private_key: String, + pub ethereum_private_key: Option, /// The address of the L1 core contract. #[arg(env = "L1_CORE_CONTRACT_ADDRESS", long)] - pub l1_core_contract_address: String, + pub l1_core_contract_address: Option, /// The address of the Starknet operator. #[arg(env = "STARKNET_OPERATOR_ADDRESS", long)] - pub starknet_operator_address: String, + pub starknet_operator_address: Option, +} + +#[derive(Clone, Debug)] +pub struct EthereumSettlementParams { + pub ethereum_rpc_url: Url, + + pub ethereum_private_key: String, + + pub l1_core_contract_address: String, + + pub starknet_operator_address: String } diff --git a/crates/utils/src/cli/settlement/starknet.rs b/crates/utils/src/cli/settlement/starknet.rs index 53c12c3f..15ba89cb 100644 --- a/crates/utils/src/cli/settlement/starknet.rs +++ b/crates/utils/src/cli/settlement/starknet.rs @@ -1,36 +1,49 @@ use clap::Args; use url::Url; -// STARKNET_RPC_URL="https://starknet-sepolia.public.blastapi.io" -// STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 -// STARKNET_ACCOUNT_ADDRESS=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 -// STARKNET_CAIRO_CORE_CONTRACT_ADDRESS="" -// STARKNET_FINALITY_RETRY_WAIT_IN_SECS="" -// MADARA_BINARY_PATH="/path/to/madara" - #[derive(Debug, Clone, Args)] -pub struct StarknetSettlementParams { +#[group(requires_all = ["starknet_rpc_url", "starknet_private_key", "starknet_account_address", "starknet_cairo_core_contract_address", "starknet_finality_retry_wait_in_secs", "madara_binary_path"])] +pub struct StarknetSettlementArgs { + /// Use the Starknet settlement layer. + #[arg(long)] + pub settle_on_starknet: bool, + /// The URL of the Ethereum RPC node. #[arg(env = "STARKNET_RPC_URL", long)] - pub starknet_rpc_url: Url, + pub starknet_rpc_url: Option, /// The private key of the Ethereum account. #[arg(env = "STARKNET_PRIVATE_KEY", long)] - pub starknet_private_key: String, + pub starknet_private_key: Option, /// The address of the Starknet account. #[arg(env = "STARKNET_ACCOUNT_ADDRESS", long)] - pub starknet_account_address: String, + pub starknet_account_address: Option, /// The address of the Cairo core contract. #[arg(env = "STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", long)] - pub starknet_cairo_core_contract_address: String, + pub starknet_cairo_core_contract_address: Option, /// The number of seconds to wait for finality. #[arg(env = "STARKNET_FINALITY_RETRY_WAIT_IN_SECS", long)] - pub starknet_finality_retry_wait_in_secs: u64, + pub starknet_finality_retry_wait_in_secs: Option, /// The path to the Madara binary. #[arg(env = "MADARA_BINARY_PATH", long)] + pub madara_binary_path: Option, +} + +#[derive(Clone, Debug)] +pub struct StarknetSettlementParams { + pub starknet_rpc_url: Url, + + pub starknet_private_key: String, + + pub starknet_account_address: String, + + pub starknet_cairo_core_contract_address: String, + + pub starknet_finality_retry_wait_in_secs: u64, + pub madara_binary_path: String, } From fa1efc451f91f53f82b9a369daf32ca534d06b12 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 6 Nov 2024 22:36:02 +0530 Subject: [PATCH 13/63] update: fixed telemetry tests --- CHANGELOG.md | 1 + crates/orchestrator/src/config.rs | 9 +- crates/orchestrator/src/main.rs | 2 +- crates/orchestrator/src/telemetry.rs | 91 ++++++++++++--------- crates/utils/src/cli/mod.rs | 21 +++-- crates/utils/src/cli/settlement/ethereum.rs | 2 +- madara | 2 +- madara-bootstrapper | 2 +- pathfinder | 2 +- 9 files changed, 74 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ed57bb6..55866493 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## Added +- Added cli args support for all the services - upgrade ETH L1 bridge for withdrawals to work - added makefile and submodules - Endpoints for triggering processing and verification jobs diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 3c9206f3..9aec077c 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -138,8 +138,7 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { let settlement_client = build_settlement_client(&settlement_params).await?; // init prover - let prover_params = - run_cmd.validate_prover_params().map_err(|e| eyre!("Failed to validate prover params: {e}"))?; + let prover_params = run_cmd.validate_prover_params().map_err(|e| eyre!("Failed to validate prover params: {e}"))?; let prover_client = build_prover_service(&prover_params); // init storage @@ -148,8 +147,7 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { let storage_client = build_storage_client(&data_storage_params, provider_config.clone()).await; // init alerts - let alert_params = - run_cmd.validate_alert_params().map_err(|e| eyre!("Failed to validate alert params: {e}"))?; + let alert_params = run_cmd.validate_alert_params().map_err(|e| eyre!("Failed to validate alert params: {e}"))?; let alerts_client = build_alert_client(&alert_params, provider_config.clone()).await; // init the queue @@ -157,8 +155,7 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { // from `SdkConfig`. We can later move to using `aws_sdk_sqs`. This would require // us stop using the generic omniqueue abstractions for message ack/nack // init queue - let queue_params = - run_cmd.validate_queue_params().map_err(|e| eyre!("Failed to validate queue params: {e}"))?; + let queue_params = run_cmd.validate_queue_params().map_err(|e| eyre!("Failed to validate queue params: {e}"))?; let queue = build_queue_client(&queue_params); Ok(Arc::new(Config::new( diff --git a/crates/orchestrator/src/main.rs b/crates/orchestrator/src/main.rs index 9157b227..9a754246 100644 --- a/crates/orchestrator/src/main.rs +++ b/crates/orchestrator/src/main.rs @@ -15,7 +15,7 @@ async fn main() { dotenv().ok(); // TODO: could this be an ARC ? let run_cmd: RunCmd = RunCmd::parse(); - + // print the run cmd println!("{:?}", run_cmd); diff --git a/crates/orchestrator/src/telemetry.rs b/crates/orchestrator/src/telemetry.rs index cea79b65..2c1371f3 100644 --- a/crates/orchestrator/src/telemetry.rs +++ b/crates/orchestrator/src/telemetry.rs @@ -139,23 +139,25 @@ fn init_logs(otel_config: &OTELConfig) -> Result Err("Exactly one settlement layer must be selected".to_string()), } diff --git a/crates/utils/src/cli/settlement/ethereum.rs b/crates/utils/src/cli/settlement/ethereum.rs index db2372a6..534c06fe 100644 --- a/crates/utils/src/cli/settlement/ethereum.rs +++ b/crates/utils/src/cli/settlement/ethereum.rs @@ -33,5 +33,5 @@ pub struct EthereumSettlementParams { pub l1_core_contract_address: String, - pub starknet_operator_address: String + pub starknet_operator_address: String, } diff --git a/madara b/madara index d188aa91..93d57632 160000 --- a/madara +++ b/madara @@ -1 +1 @@ -Subproject commit d188aa91efa78bcc54f92aa1035295fd50e068d2 +Subproject commit 93d57632e7a56707d74ab63eb0ca8558df9f0d8e diff --git a/madara-bootstrapper b/madara-bootstrapper index f717bf17..b0b64750 160000 --- a/madara-bootstrapper +++ b/madara-bootstrapper @@ -1 +1 @@ -Subproject commit f717bf179581da53d68fee03b50ef78e0628ee20 +Subproject commit b0b647500c2ae3e3b0d99e345fa652989bca4726 diff --git a/pathfinder b/pathfinder index 29f93d0d..138140e5 160000 --- a/pathfinder +++ b/pathfinder @@ -1 +1 @@ -Subproject commit 29f93d0d6ad8758fdcf5ae3a8bd2faad2a3bc92b +Subproject commit 138140e5fd967ede92806fd62de47c2e6b65712a From 1cbf00ce7e033e960def8a638f83cc2a02aa2ea7 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Thu, 7 Nov 2024 08:13:03 +0530 Subject: [PATCH 14/63] update: tests cleanup --- crates/orchestrator/src/config.rs | 6 +- crates/orchestrator/src/workers/snos.rs | 22 ++- .../sharp-service/tests/lib.rs | 141 ++++++++------ .../starknet/src/tests/test.rs | 183 ++++++++++-------- crates/utils/src/cli/snos.rs | 4 +- 5 files changed, 209 insertions(+), 147 deletions(-) diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 9aec077c..53115479 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -50,7 +50,7 @@ pub struct Config { /// The RPC url to be used when running SNOS /// When Madara supports getProof, we can re use /// starknet_rpc_url for SNOS as well - snos_config: SnosConfig, + pub snos_config: SnosConfig, /// The starknet client to get data from the node starknet_client: Arc>, /// The DA client to interact with the DA layer @@ -72,8 +72,8 @@ pub struct Config { #[derive(Debug, Clone)] pub struct SnosConfig { pub rpc_url: Url, - pub max_block_to_process: u64, - pub min_block_to_process: u64, + pub max_block_to_process: Option, + pub min_block_to_process: Option, } /// `ProviderConfig` is an enum used to represent the global config built diff --git a/crates/orchestrator/src/workers/snos.rs b/crates/orchestrator/src/workers/snos.rs index 9ecda249..a38a5acd 100644 --- a/crates/orchestrator/src/workers/snos.rs +++ b/crates/orchestrator/src/workers/snos.rs @@ -20,21 +20,31 @@ impl Worker for SnosWorker { tracing::trace!(log_type = "starting", category = "SnosWorker", "SnosWorker started."); let provider = config.starknet_client(); - let block_number_provider = &provider.block_number().await?; + let block_number_provider = provider.block_number().await?; + + let latest_block_number = if let Some(max_block_to_process) = config.snos_config.max_block_to_process { + max_block_to_process + } else { + block_number_provider + }; - let snos_config = config.snos_config(); - let latest_block_number = snos_config.max_block_to_process; tracing::debug!(latest_block_number = %latest_block_number, "Fetched latest block number from starknet"); let latest_job_in_db = config.database().get_latest_job_by_type(JobType::SnosRun).await?; - let latest_job_id = match latest_job_in_db { + let latest_job_id: u64 = match latest_job_in_db { Some(job) => job.internal_id, None => "0".to_string(), - }; + } + .parse::() + .unwrap(); // To be used when testing in specific block range - let block_start = snos_config.min_block_to_process; + let block_start = if let Some(min_block_to_process) = config.snos_config.min_block_to_process { + min_block_to_process + } else { + latest_job_id + }; for block_num in block_start..latest_block_number + 1 { match create_job(JobType::SnosRun, block_num.to_string(), HashMap::new(), config.clone()).await { diff --git a/crates/prover-services/sharp-service/tests/lib.rs b/crates/prover-services/sharp-service/tests/lib.rs index 168ab6cf..3207fb6e 100644 --- a/crates/prover-services/sharp-service/tests/lib.rs +++ b/crates/prover-services/sharp-service/tests/lib.rs @@ -1,65 +1,96 @@ -use prover_client_interface::TaskStatus; +use cairo_vm::vm::runners::cairo_pie::CairoPie; +use constants::CAIRO_PIE_PATH; +use httpmock::MockServer; +// ProverClient +use prover_client_interface::ProverClient; +use prover_client_interface::{Task, TaskStatus}; +use rstest::rstest; use serde_json::json; +use sharp_service::SharpProverService; use starknet_os::sharp::CairoJobStatus; +use url::Url; +use utils::cli::prover::sharp::SharpParams; +use utils::env_utils::get_env_var_or_panic; use crate::constants::TEST_FACT; mod constants; -// #[rstest] -// #[tokio::test] -// async fn prover_client_submit_task_works() { -// dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); - -// let server = MockServer::start(); -// let sharp_service = SharpProverService::with_test_settings(&EnvSettingsProvider {}, -// server.port()); let cairo_pie_path = env!("CARGO_MANIFEST_DIR").to_string() + CAIRO_PIE_PATH; -// let cairo_pie = CairoPie::read_zip_file(cairo_pie_path.as_ref()).unwrap(); - -// let sharp_response = json!( -// { -// "code" : "JOB_RECEIVED_SUCCESSFULLY" -// } -// ); -// let customer_id = get_env_var_or_panic("SHARP_CUSTOMER_ID"); -// let sharp_add_job_call = server.mock(|when, then| { -// when.path_contains("/add_job").query_param("customer_id", customer_id.as_str()); -// then.status(200).body(serde_json::to_vec(&sharp_response).unwrap()); -// }); - -// assert!(sharp_service.submit_task(Task::CairoPie(cairo_pie)).await.is_ok()); - -// sharp_add_job_call.assert(); -// } - -// #[rstest] -// #[case(CairoJobStatus::FAILED)] -// #[case(CairoJobStatus::INVALID)] -// #[case(CairoJobStatus::UNKNOWN)] -// #[case(CairoJobStatus::IN_PROGRESS)] -// #[case(CairoJobStatus::NOT_CREATED)] -// #[case(CairoJobStatus::PROCESSED)] -// #[ignore] -// #[case(CairoJobStatus::ONCHAIN)] -// #[tokio::test] -// async fn prover_client_get_task_status_works(#[case] cairo_job_status: CairoJobStatus) { -// dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); - -// let server = MockServer::start(); -// let sharp_service = SharpProverService::with_test_settings(&EnvSettingsProvider {}, -// server.port()); let customer_id = get_env_var_or_panic("SHARP_CUSTOMER_ID"); - -// let sharp_add_job_call = server.mock(|when, then| { -// when.path_contains("/get_status").query_param("customer_id", customer_id.as_str()); -// then.status(200).body(serde_json::to_vec(&get_task_status_sharp_response(& -// cairo_job_status)).unwrap()); }); - -// let task_status = sharp_service.get_task_status("c31381bf-4739-4667-b5b8-b08af1c6b1c7", -// TEST_FACT).await.unwrap(); assert_eq!(task_status, -// get_task_status_expectation(&cairo_job_status), "Cairo Job Status assertion failed"); - -// sharp_add_job_call.assert(); -// } +#[rstest] +#[tokio::test] +async fn prover_client_submit_task_works() { + dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); + + let sharp_params = SharpParams { + sharp_customer_id: get_env_var_or_panic("SHARP_CUSTOMER_ID"), + sharp_url: Url::parse(&get_env_var_or_panic("SHARP_URL")).unwrap(), + sharp_user_crt: get_env_var_or_panic("SHARP_USER_CRT"), + sharp_user_key: get_env_var_or_panic("SHARP_USER_KEY"), + sharp_rpc_node_url: Url::parse(&get_env_var_or_panic("SHARP_RPC_NODE_URL")).unwrap(), + sharp_server_crt: get_env_var_or_panic("SHARP_SERVER_CRT"), + sharp_proof_layout: get_env_var_or_panic("SHARP_PROOF_LAYOUT"), + gps_verifier_contract_address: get_env_var_or_panic("GPS_VERIFIER_CONTRACT_ADDRESS"), + }; + + let server = MockServer::start(); + let sharp_service = SharpProverService::with_test_settings(server.port(), &sharp_params); + let cairo_pie_path = env!("CARGO_MANIFEST_DIR").to_string() + CAIRO_PIE_PATH; + let cairo_pie = CairoPie::read_zip_file(cairo_pie_path.as_ref()).unwrap(); + + let sharp_response = json!( + { + "code" : "JOB_RECEIVED_SUCCESSFULLY" + } + ); + let customer_id = get_env_var_or_panic("SHARP_CUSTOMER_ID"); + let sharp_add_job_call = server.mock(|when, then| { + when.path_contains("/add_job").query_param("customer_id", customer_id.as_str()); + then.status(200).body(serde_json::to_vec(&sharp_response).unwrap()); + }); + + assert!(sharp_service.submit_task(Task::CairoPie(cairo_pie)).await.is_ok()); + + sharp_add_job_call.assert(); +} + +#[rstest] +#[case(CairoJobStatus::FAILED)] +#[case(CairoJobStatus::INVALID)] +#[case(CairoJobStatus::UNKNOWN)] +#[case(CairoJobStatus::IN_PROGRESS)] +#[case(CairoJobStatus::NOT_CREATED)] +#[case(CairoJobStatus::PROCESSED)] +#[ignore] +#[case(CairoJobStatus::ONCHAIN)] +#[tokio::test] +async fn prover_client_get_task_status_works(#[case] cairo_job_status: CairoJobStatus) { + dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); + + let sharp_params = SharpParams { + sharp_customer_id: get_env_var_or_panic("SHARP_CUSTOMER_ID"), + sharp_url: Url::parse(&get_env_var_or_panic("SHARP_URL")).unwrap(), + sharp_user_crt: get_env_var_or_panic("SHARP_USER_CRT"), + sharp_user_key: get_env_var_or_panic("SHARP_USER_KEY"), + sharp_rpc_node_url: Url::parse(&get_env_var_or_panic("SHARP_RPC_NODE_URL")).unwrap(), + sharp_server_crt: get_env_var_or_panic("SHARP_SERVER_CRT"), + sharp_proof_layout: get_env_var_or_panic("SHARP_PROOF_LAYOUT"), + gps_verifier_contract_address: get_env_var_or_panic("GPS_VERIFIER_CONTRACT_ADDRESS"), + }; + + let server = MockServer::start(); + let sharp_service = SharpProverService::with_test_settings(server.port(), &sharp_params); + let customer_id = get_env_var_or_panic("SHARP_CUSTOMER_ID"); + + let sharp_add_job_call = server.mock(|when, then| { + when.path_contains("/get_status").query_param("customer_id", customer_id.as_str()); + then.status(200).body(serde_json::to_vec(&get_task_status_sharp_response(&cairo_job_status)).unwrap()); + }); + + let task_status = sharp_service.get_task_status("c31381bf-4739-4667-b5b8-b08af1c6b1c7", TEST_FACT).await.unwrap(); + assert_eq!(task_status, get_task_status_expectation(&cairo_job_status), "Cairo Job Status assertion failed"); + + sharp_add_job_call.assert(); +} fn get_task_status_expectation(cairo_job_status: &CairoJobStatus) -> TaskStatus { match cairo_job_status { diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 0d96528f..be29c94a 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -1,4 +1,5 @@ use std::env; +use std::path::Path; use std::sync::Arc; use std::time::Duration; @@ -6,15 +7,22 @@ use color_eyre::eyre::eyre; use rstest::{fixture, rstest}; use settlement_client_interface::SettlementClient; use starknet::accounts::{Account, ConnectedAccount, ExecutionEncoding, SingleOwnerAccount}; -use starknet::core::types::{BlockId, BlockTag, Felt, StarknetError, TransactionExecutionStatus, TransactionStatus}; +use starknet::contract::ContractFactory; +use starknet::core::types::contract::{CompiledClass, SierraClass}; +use starknet::core::types::{ + BlockId, BlockTag, DeclareTransactionResult, Felt, FunctionCall, InvokeTransactionResult, StarknetError, + TransactionExecutionStatus, TransactionStatus, +}; +use starknet::macros::{felt, selector}; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Provider, ProviderError, Url}; use starknet::signers::{LocalWallet, SigningKey}; +use utils::cli::settlement::starknet::StarknetSettlementParams; use utils::settings::env::EnvSettingsProvider; use utils::settings::Settings; use super::setup::{wait_for_cond, MadaraCmd, MadaraCmdBuilder}; -use crate::LocalWalletSignerMiddleware; +use crate::{LocalWalletSignerMiddleware, StarknetSettlementClient}; #[fixture] pub async fn spin_up_madara() -> MadaraCmd { @@ -92,85 +100,98 @@ async fn setup(#[future] spin_up_madara: MadaraCmd) -> (LocalWalletSignerMiddlew (Arc::new(account), madara_process) } -// TODO: Why is this code not going through the TestConfigBuilder? -// #[rstest] -// #[tokio::test] -// async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) { -// let (account, _madara_process) = setup.await; - -// let project_root = Path::new(env!("CARGO_MANIFEST_DIR")).ancestors().nth(3).unwrap(); -// let contract_path = -// project_root.join("crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev"); -// let sierra_class: SierraClass = serde_json::from_reader( -// std::fs::File::open(contract_path.join("mock_contracts_Piltover.contract_class.json")) -// .expect("Could not open sierra class file"), -// ) -// .expect("Failed to parse SierraClass"); - -// let compiled_class: CompiledClass = serde_json::from_reader( -// std::fs::File::open(contract_path.join("mock_contracts_Piltover.compiled_contract_class. -// json")) .expect("Could not open compiled class file"), -// ) -// .expect("Failed to parse CompiledClass"); - -// let flattened_class = sierra_class.clone().flatten().unwrap(); -// let compiled_class_hash = compiled_class.class_hash().unwrap(); - -// let DeclareTransactionResult { transaction_hash: declare_tx_hash, class_hash: _ } = -// account.declare_v2(Arc::new(flattened_class.clone()), -// compiled_class_hash).send().await.unwrap(); tracing::debug!("declare tx hash {:?}", -// declare_tx_hash); - -// let is_success = wait_for_tx(&account, declare_tx_hash, Duration::from_secs(2)).await; -// assert!(is_success, "Declare trasactiion failed"); - -// let contract_factory = ContractFactory::new(flattened_class.class_hash(), account.clone()); -// let deploy_v1 = contract_factory.deploy_v1(vec![], felt!("1122"), false); -// let deployed_address = deploy_v1.deployed_address(); - -// env::set_var("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", deployed_address.to_hex_string()); -// let InvokeTransactionResult { transaction_hash: deploy_tx_hash } = -// deploy_v1.send().await.expect("Unable to deploy contract"); - -// let is_success = wait_for_tx(&account, deploy_tx_hash, Duration::from_secs(2)).await; -// assert!(is_success, "Deploy trasaction failed"); - -// let env_settings = EnvSettingsProvider {}; -// let settlement_params = run_cmd.clone().validate_settlement_params().unwrap(); - -// let settlement_client = -// StarknetSettlementClient::new_with_settings(&settlement_params).await; let onchain_data_hash -// = [1; 32]; let mut program_output = Vec::with_capacity(32); -// program_output.fill(onchain_data_hash); -// let update_state_tx_hash = settlement_client -// .update_state_calldata(program_output, onchain_data_hash, [1; 32]) -// .await -// .expect("Sending Update state"); - -// tracing::debug!("update state tx hash {:?}", update_state_tx_hash); - -// let is_success = wait_for_tx( -// &account, -// Felt::from_hex(&update_state_tx_hash).expect("Incorrect transaction hash"), -// Duration::from_secs(2), -// ) -// .await; -// assert!(is_success, "Update state transaction failed/reverted"); - -// let call_result = account -// .provider() -// .call( -// FunctionCall { -// contract_address: deployed_address, -// entry_point_selector: selector!("get_is_updated"), -// calldata: vec![Felt::from_bytes_be_slice(&onchain_data_hash)], -// }, -// BlockId::Tag(BlockTag::Latest), -// ) -// .await -// .expect("failed to call the contract"); -// assert!(call_result[0] == true.into(), "Should be updated"); -// } +#[rstest] +#[tokio::test] +async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) { + dotenvy::from_filename_override(".env.test").expect("Failed to load the .env file"); + + let env_settings = EnvSettingsProvider::default(); + let starknet_settlement_params = StarknetSettlementParams { + starknet_rpc_url: Url::parse(&env_settings.get_settings_or_panic("STARKNET_RPC_URL")).unwrap(), + starknet_private_key: env_settings.get_settings_or_panic("STARKNET_PRIVATE_KEY"), + starknet_account_address: env_settings.get_settings_or_panic("STARKNET_ACCOUNT_ADDRESS"), + starknet_cairo_core_contract_address: env_settings + .get_settings_or_panic("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS"), + starknet_finality_retry_wait_in_secs: env_settings + .get_settings_or_panic("STARKNET_FINALITY_RETRY_WAIT_IN_SECS") + .parse::() + .unwrap(), + madara_binary_path: env_settings.get_settings_or_panic("MADARA_BINARY_PATH"), + }; + + let (account, _madara_process) = setup.await; + + let project_root = Path::new(env!("CARGO_MANIFEST_DIR")).ancestors().nth(3).unwrap(); + let contract_path = project_root.join("crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev"); + let sierra_class: SierraClass = serde_json::from_reader( + std::fs::File::open(contract_path.join("mock_contracts_Piltover.contract_class.json")) + .expect("Could not open sierra class file"), + ) + .expect("Failed to parse SierraClass"); + + let compiled_class: CompiledClass = serde_json::from_reader( + std::fs::File::open(contract_path.join( + "mock_contracts_Piltover.compiled_contract_class. +json", + )) + .expect("Could not open compiled class file"), + ) + .expect("Failed to parse CompiledClass"); + + let flattened_class = sierra_class.clone().flatten().unwrap(); + let compiled_class_hash = compiled_class.class_hash().unwrap(); + + let DeclareTransactionResult { transaction_hash: declare_tx_hash, class_hash: _ } = + account.declare_v2(Arc::new(flattened_class.clone()), compiled_class_hash).send().await.unwrap(); + tracing::debug!("declare tx hash {:?}", declare_tx_hash); + + let is_success = wait_for_tx(&account, declare_tx_hash, Duration::from_secs(2)).await; + assert!(is_success, "Declare trasactiion failed"); + + let contract_factory = ContractFactory::new(flattened_class.class_hash(), account.clone()); + let deploy_v1 = contract_factory.deploy_v1(vec![], felt!("1122"), false); + let deployed_address = deploy_v1.deployed_address(); + + env::set_var("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", deployed_address.to_hex_string()); + let InvokeTransactionResult { transaction_hash: deploy_tx_hash } = + deploy_v1.send().await.expect("Unable to deploy contract"); + + let is_success = wait_for_tx(&account, deploy_tx_hash, Duration::from_secs(2)).await; + assert!(is_success, "Deploy trasaction failed"); + + let settlement_client = StarknetSettlementClient::new_with_settings(&starknet_settlement_params).await; + let onchain_data_hash = [1; 32]; + let mut program_output = Vec::with_capacity(32); + program_output.fill(onchain_data_hash); + let update_state_tx_hash = settlement_client + .update_state_calldata(program_output, onchain_data_hash, [1; 32]) + .await + .expect("Sending Update state"); + + tracing::debug!("update state tx hash {:?}", update_state_tx_hash); + + let is_success = wait_for_tx( + &account, + Felt::from_hex(&update_state_tx_hash).expect("Incorrect transaction hash"), + Duration::from_secs(2), + ) + .await; + assert!(is_success, "Update state transaction failed/reverted"); + + let call_result = account + .provider() + .call( + FunctionCall { + contract_address: deployed_address, + entry_point_selector: selector!("get_is_updated"), + calldata: vec![Felt::from_bytes_be_slice(&onchain_data_hash)], + }, + BlockId::Tag(BlockTag::Latest), + ) + .await + .expect("failed to call the contract"); + assert!(call_result[0] == true.into(), "Should be updated"); +} #[rstest] #[tokio::test] diff --git a/crates/utils/src/cli/snos.rs b/crates/utils/src/cli/snos.rs index aca2110a..2417e78a 100644 --- a/crates/utils/src/cli/snos.rs +++ b/crates/utils/src/cli/snos.rs @@ -9,9 +9,9 @@ pub struct SNOSParams { /// The maximum block to process. #[arg(env = "MAX_BLOCK_TO_PROCESS", long)] - pub max_block_to_process: u64, + pub max_block_to_process: Option, /// The minimum block to process. #[arg(env = "MIN_BLOCK_TO_PROCESS", long)] - pub min_block_to_process: u64, + pub min_block_to_process: Option, } From 0c2b489c2e47f74670d3fd8c6112cda7602bac29 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Thu, 7 Nov 2024 08:44:47 +0530 Subject: [PATCH 15/63] update: coverage build fix --- crates/orchestrator/src/config.rs | 2 - crates/settlement-clients/ethereum/src/lib.rs | 14 ++--- .../ethereum/src/tests/mod.rs | 52 ++++++++++++------- 3 files changed, 42 insertions(+), 26 deletions(-) diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 53115479..767fda7f 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -1,5 +1,3 @@ -#[cfg(feature = "testing")] -use std::str::FromStr; use std::sync::Arc; #[cfg(feature = "testing")] diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index 29b7ae44..31fde978 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -104,10 +104,12 @@ impl EthereumSettlementClient { #[cfg(feature = "testing")] pub fn with_test_settings(settlement_cfg: &EthereumSettlementParams) -> Self { - let root_provider = RootProvider::new_http(settlement_cfg.ethereum_rpc_url.clone().as_str().parse()?); - let core_contract_address = Address::from_str(&settlement_cfg.l1_core_contract_address.clone())?; - let settlement_rpc_url = &settlement_cfg.ethereum_rpc_url.clone()?; - let private_key = &settlement_cfg.ethereum_private_key.clone(); + let root_provider = RootProvider::new_http(settlement_cfg.ethereum_rpc_url.clone().as_str().parse().unwrap()); + let core_contract_address = Address::from_str(&settlement_cfg.l1_core_contract_address.clone()).unwrap(); + let operator_address = Address::from_str(&settlement_cfg.starknet_operator_address.clone()).unwrap(); + + let settlement_rpc_url = settlement_cfg.ethereum_rpc_url.clone(); + let private_key = settlement_cfg.ethereum_private_key.clone(); let signer: PrivateKeySigner = private_key.parse().expect("Failed to parse private key"); let wallet_address = signer.address(); let wallet = EthereumWallet::from(signer); @@ -119,11 +121,11 @@ impl EthereumSettlementClient { let core_contract_client = StarknetValidityContractClient::new(core_contract_address, fill_provider); EthereumSettlementClient { - provider: Arc::new(provider), + provider: Arc::new(root_provider), core_contract_client, wallet, wallet_address, - impersonate_account, + impersonate_account: Some(operator_address), } } diff --git a/crates/settlement-clients/ethereum/src/tests/mod.rs b/crates/settlement-clients/ethereum/src/tests/mod.rs index a61bdcb4..338a3b30 100644 --- a/crates/settlement-clients/ethereum/src/tests/mod.rs +++ b/crates/settlement-clients/ethereum/src/tests/mod.rs @@ -134,6 +134,9 @@ mod settlement_client_tests { use rstest::rstest; use settlement_client_interface::{SettlementClient, SettlementVerificationStatus}; use tokio::time::sleep; + use url::Url; + use utils::cli::settlement::ethereum::EthereumSettlementParams; + use utils::env_utils::get_env_var_or_panic; use super::{BLOCK_TIME, ENV_FILE_PATH}; use crate::conversion::to_padded_hex; @@ -153,16 +156,20 @@ mod settlement_client_tests { /// And hence to test the signature and transaction via a dummy contract that has same function /// selector as `updateStateKzgDa`. and anvil is for testing on fork Eth. async fn update_state_blob_with_dummy_contract_works() { + dotenvy::from_filename(&*ENV_FILE_PATH).expect("Could not load .env.test file."); + + let ethereum_settlement_params = EthereumSettlementParams { + ethereum_rpc_url: Url::from_str(get_env_var_or_panic("SETTLEMENT_RPC_URL").as_str()).unwrap(), + ethereum_private_key: get_env_var_or_panic("ETHEREUM_PRIVATE_KEY"), + l1_core_contract_address: get_env_var_or_panic("L1_CORE_CONTRACT_ADDRESS"), + starknet_operator_address: get_env_var_or_panic("STARKNET_OPERATOR_ADDRESS"), + }; + let setup = EthereumTestBuilder::new().build().await; // Deploying a dummy contract let contract = DummyCoreContract::deploy(&setup.provider).await.expect("Unable to deploy address"); - let ethereum_settlement_client = EthereumSettlementClient::with_test_settings( - setup.provider.clone(), - *contract.address(), - setup.rpc_url, - None, - ); + let ethereum_settlement_client = EthereumSettlementClient::with_test_settings(ðereum_settlement_params); // Getting latest nonce after deployment let nonce = ethereum_settlement_client.get_nonce().await.expect("Unable to fetch nonce"); @@ -213,17 +220,21 @@ mod settlement_client_tests { /// contract Here signature checks are bypassed and anvil is for testing on fork Eth. async fn update_state_blob_with_impersonation_works(#[case] fork_block_no: u64) { dotenvy::from_filename(&*ENV_FILE_PATH).expect("Could not load .env.test file."); + + let ethereum_settlement_params = EthereumSettlementParams { + ethereum_rpc_url: Url::from_str(get_env_var_or_panic("SETTLEMENT_RPC_URL").as_str()).unwrap(), + ethereum_private_key: get_env_var_or_panic("ETHEREUM_PRIVATE_KEY"), + l1_core_contract_address: get_env_var_or_panic("L1_CORE_CONTRACT_ADDRESS"), + starknet_operator_address: get_env_var_or_panic("STARKNET_OPERATOR_ADDRESS"), + }; + let setup = EthereumTestBuilder::new() .with_fork_block(fork_block_no) .with_impersonator(*STARKNET_OPERATOR_ADDRESS) .build() .await; - let ethereum_settlement_client = EthereumSettlementClient::with_test_settings( - setup.provider.clone(), - *STARKNET_CORE_CONTRACT_ADDRESS, - setup.rpc_url, - Some(*STARKNET_OPERATOR_ADDRESS), - ); + + let ethereum_settlement_client = EthereumSettlementClient::with_test_settings(ðereum_settlement_params); // let nonce = ethereum_settlement_client.get_nonce().await.expect("Unable to fetch nonce"); @@ -274,13 +285,18 @@ mod settlement_client_tests { #[tokio::test] #[case::typical(6806847)] async fn get_last_settled_block_typical_works(#[case] fork_block_no: u64) { + dotenvy::from_filename(&*ENV_FILE_PATH).expect("Could not load .env.test file."); + + let ethereum_settlement_params = EthereumSettlementParams { + ethereum_rpc_url: Url::from_str(get_env_var_or_panic("SETTLEMENT_RPC_URL").as_str()).unwrap(), + ethereum_private_key: get_env_var_or_panic("ETHEREUM_PRIVATE_KEY"), + l1_core_contract_address: get_env_var_or_panic("L1_CORE_CONTRACT_ADDRESS"), + starknet_operator_address: get_env_var_or_panic("STARKNET_OPERATOR_ADDRESS"), + }; + let setup = EthereumTestBuilder::new().with_fork_block(fork_block_no).build().await; - let ethereum_settlement_client = EthereumSettlementClient::with_test_settings( - setup.provider.clone(), - *STARKNET_CORE_CONTRACT_ADDRESS, - setup.rpc_url, - None, - ); + let ethereum_settlement_client = EthereumSettlementClient::with_test_settings(ðereum_settlement_params); + assert_eq!( ethereum_settlement_client.get_last_settled_block().await.expect("Could not get last settled block."), 218378 From 4a8de787a5d6e210aefe8ceac1c781d1e015c419 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Thu, 7 Nov 2024 08:52:15 +0530 Subject: [PATCH 16/63] update: lint fix --- crates/orchestrator/Cargo.toml | 2 +- .../orchestrator/src/alerts/aws_sns/config.rs | 19 ------------------- crates/orchestrator/src/alerts/aws_sns/mod.rs | 2 -- crates/utils/Cargo.toml | 4 ++-- e2e-tests/Cargo.toml | 2 +- 5 files changed, 4 insertions(+), 25 deletions(-) delete mode 100644 crates/orchestrator/src/alerts/aws_sns/config.rs diff --git a/crates/orchestrator/Cargo.toml b/crates/orchestrator/Cargo.toml index 65c4c940..d4a85e28 100644 --- a/crates/orchestrator/Cargo.toml +++ b/crates/orchestrator/Cargo.toml @@ -36,10 +36,10 @@ axum = { workspace = true, features = ["macros"] } axum-macros = { workspace = true } bincode = { workspace = true } bytes.workspace = true -clap.workspace = true c-kzg = { workspace = true } cairo-vm = { workspace = true } chrono = { workspace = true } +clap.workspace = true color-eyre = { workspace = true } da-client-interface = { workspace = true } dotenvy = { workspace = true } diff --git a/crates/orchestrator/src/alerts/aws_sns/config.rs b/crates/orchestrator/src/alerts/aws_sns/config.rs deleted file mode 100644 index 6387dd72..00000000 --- a/crates/orchestrator/src/alerts/aws_sns/config.rs +++ /dev/null @@ -1,19 +0,0 @@ -use serde::{Deserialize, Serialize}; -use utils::settings::Settings; - -#[derive(Clone, Serialize, Deserialize)] -pub struct AWSSNSConfig { - /// AWS SNS ARN - pub sns_arn: String, - /// AWS SNS region - pub sns_arn_region: String, -} - -impl AWSSNSConfig { - pub fn new_with_settings(settings: &impl Settings) -> color_eyre::Result { - Ok(Self { - sns_arn: settings.get_settings_or_panic("AWS_SNS_ARN"), - sns_arn_region: settings.get_settings_or_panic("AWS_REGION"), - }) - } -} diff --git a/crates/orchestrator/src/alerts/aws_sns/mod.rs b/crates/orchestrator/src/alerts/aws_sns/mod.rs index 7fe899cc..c4feeea7 100644 --- a/crates/orchestrator/src/alerts/aws_sns/mod.rs +++ b/crates/orchestrator/src/alerts/aws_sns/mod.rs @@ -1,5 +1,3 @@ -mod config; - use std::sync::Arc; use async_trait::async_trait; diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml index 6319af5d..537df164 100644 --- a/crates/utils/Cargo.toml +++ b/crates/utils/Cargo.toml @@ -6,12 +6,12 @@ edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = { version = "4.4", features = ["derive", "env"] } color-eyre = { workspace = true } serde.workspace = true +serde_json = { workspace = true } thiserror.workspace = true -clap = { version = "4.4", features = ["derive", "env"] } url = { workspace = true } -serde_json = { workspace = true } #Instrumentation opentelemetry = { workspace = true, features = ["metrics", "logs"] } opentelemetry-appender-tracing = { workspace = true, default-features = false } diff --git a/e2e-tests/Cargo.toml b/e2e-tests/Cargo.toml index 34ac6249..d5af0994 100644 --- a/e2e-tests/Cargo.toml +++ b/e2e-tests/Cargo.toml @@ -4,8 +4,8 @@ version = "0.1.0" edition = "2021" [dependencies] -alloy.workspace = true alloy-sol-types = "0.8.5" +alloy.workspace = true async-trait.workspace = true aws-config.workspace = true aws-sdk-eventbridge.workspace = true From 5201fad1f3f8781b56436e927f4bd277b1378d13 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Thu, 7 Nov 2024 09:02:00 +0530 Subject: [PATCH 17/63] update: lint e2e cargo fix --- e2e-tests/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e-tests/Cargo.toml b/e2e-tests/Cargo.toml index d5af0994..34ac6249 100644 --- a/e2e-tests/Cargo.toml +++ b/e2e-tests/Cargo.toml @@ -4,8 +4,8 @@ version = "0.1.0" edition = "2021" [dependencies] -alloy-sol-types = "0.8.5" alloy.workspace = true +alloy-sol-types = "0.8.5" async-trait.workspace = true aws-config.workspace = true aws-sdk-eventbridge.workspace = true From 7e7ab9b73a7e0196791be632b6ea9777621347f5 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Thu, 7 Nov 2024 09:12:49 +0530 Subject: [PATCH 18/63] lint fix --- crates/orchestrator/src/config.rs | 6 +----- crates/settlement-clients/ethereum/src/lib.rs | 2 -- crates/settlement-clients/ethereum/src/tests/mod.rs | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 767fda7f..5e6105ec 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -1,9 +1,5 @@ use std::sync::Arc; -#[cfg(feature = "testing")] -use alloy::primitives::Address; -#[cfg(feature = "testing")] -use alloy::providers::RootProvider; use aws_config::meta::region::RegionProviderChain; use aws_config::{Region, SdkConfig}; use aws_credential_types::Credentials; @@ -296,7 +292,7 @@ pub async fn build_settlement_client( } #[cfg(feature = "testing")] { - Ok(Box::new(EthereumSettlementClient::with_test_settings(ðereum_settlement_params))) + Ok(Box::new(EthereumSettlementClient::with_test_settings(ethereum_settlement_params))) } } SettlementParams::Starknet(starknet_settlement_params) => { diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index 31fde978..9370da76 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -23,8 +23,6 @@ use color_eyre::eyre::{bail, eyre, Ok}; use color_eyre::Result; use conversion::{get_input_data_for_eip_4844, prepare_sidecar}; use settlement_client_interface::{SettlementClient, SettlementVerificationStatus}; -#[cfg(feature = "testing")] -use url::Url; use utils::cli::settlement::ethereum::EthereumSettlementParams; use crate::clients::interfaces::validity_interface::StarknetValidityContractTrait; diff --git a/crates/settlement-clients/ethereum/src/tests/mod.rs b/crates/settlement-clients/ethereum/src/tests/mod.rs index 338a3b30..f5af3564 100644 --- a/crates/settlement-clients/ethereum/src/tests/mod.rs +++ b/crates/settlement-clients/ethereum/src/tests/mod.rs @@ -294,7 +294,7 @@ mod settlement_client_tests { starknet_operator_address: get_env_var_or_panic("STARKNET_OPERATOR_ADDRESS"), }; - let setup = EthereumTestBuilder::new().with_fork_block(fork_block_no).build().await; + let _setup = EthereumTestBuilder::new().with_fork_block(fork_block_no).build().await; let ethereum_settlement_client = EthereumSettlementClient::with_test_settings(ðereum_settlement_params); assert_eq!( From e4dacd97a7560f7f0fb371ede6ee5165109884fd Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Thu, 7 Nov 2024 12:07:05 +0530 Subject: [PATCH 19/63] update: reworked cli params for tests --- crates/orchestrator/src/config.rs | 8 +-- crates/orchestrator/src/main.rs | 5 +- crates/orchestrator/src/tests/config.rs | 6 +- crates/utils/src/cli/alert/aws_sns.rs | 16 +++-- crates/utils/src/cli/da/ethereum.rs | 14 +++- crates/utils/src/cli/da/mod.rs | 2 +- crates/utils/src/cli/database/mongodb.rs | 19 +++-- crates/utils/src/cli/instrumentation.rs | 12 +++- crates/utils/src/cli/mod.rs | 91 ++++++++++++++---------- crates/utils/src/cli/prover/sharp.rs | 33 ++++++--- crates/utils/src/cli/queue/aws_sqs.rs | 49 ++++++++----- crates/utils/src/cli/server.rs | 1 + crates/utils/src/cli/snos.rs | 11 ++- crates/utils/src/cli/storage/aws_s3.rs | 13 +++- e2e-tests/tests.rs | 26 ++++--- 15 files changed, 206 insertions(+), 100 deletions(-) diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 5e6105ec..d6386311 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -109,9 +109,9 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { // init snos url let snos_config = SnosConfig { - rpc_url: run_cmd.snos.rpc_for_snos.clone(), - max_block_to_process: run_cmd.snos.max_block_to_process, - min_block_to_process: run_cmd.snos.min_block_to_process, + rpc_url: run_cmd.snos_args.rpc_for_snos.clone(), + max_block_to_process: run_cmd.snos_args.max_block_to_process, + min_block_to_process: run_cmd.snos_args.min_block_to_process, }; let server_config = run_cmd.server.clone(); @@ -265,7 +265,7 @@ pub async fn build_da_client(da_params: &DaParams) -> Box { let client = RpcClient::new_http( - Url::from_str(ethereum_da_params.rpc_url.as_str()).expect("Failed to parse SETTLEMENT_RPC_URL"), + Url::from_str(ethereum_da_params.da_rpc_url.as_str()).expect("Failed to parse DA_RPC_URL"), ); let provider = ProviderBuilder::<_, Ethereum>::new().on_client(client); Box::new(EthereumDaClient { provider }) diff --git a/crates/orchestrator/src/main.rs b/crates/orchestrator/src/main.rs index 9a754246..a6bb466c 100644 --- a/crates/orchestrator/src/main.rs +++ b/crates/orchestrator/src/main.rs @@ -20,7 +20,8 @@ async fn main() { println!("{:?}", run_cmd); // Analytics Setup - let meter_provider = setup_analytics(&run_cmd.instrumentation); + let instrumentation_params = run_cmd.validate_instrumentation_params().expect("Invalid instrumentation params"); + let meter_provider = setup_analytics(&instrumentation_params); tracing::info!(service = "orchestrator", "Starting orchestrator service"); color_eyre::install().expect("Unable to install color_eyre"); @@ -46,6 +47,6 @@ async fn main() { tokio::signal::ctrl_c().await.expect("Failed to listen for ctrl+c"); // Analytics Shutdown - shutdown_analytics(meter_provider, &run_cmd.instrumentation); + shutdown_analytics(meter_provider, &instrumentation_params); tracing::info!(service = "orchestrator", "Orchestrator service shutting down"); } diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 2b65c088..c3556218 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -188,9 +188,9 @@ impl TestConfigBuilder { let server_config = run_cmd.server.clone(); let snos_config = SnosConfig { - rpc_url: run_cmd.snos.rpc_for_snos.clone(), - max_block_to_process: run_cmd.snos.max_block_to_process, - min_block_to_process: run_cmd.snos.min_block_to_process, + rpc_url: run_cmd.snos_args.rpc_for_snos.clone(), + max_block_to_process: run_cmd.snos_args.max_block_to_process, + min_block_to_process: run_cmd.snos_args.min_block_to_process, }; let TestConfigBuilder { diff --git a/crates/utils/src/cli/alert/aws_sns.rs b/crates/utils/src/cli/alert/aws_sns.rs index ba10bb5c..979a3cb4 100644 --- a/crates/utils/src/cli/alert/aws_sns.rs +++ b/crates/utils/src/cli/alert/aws_sns.rs @@ -2,12 +2,18 @@ use clap::Args; /// Parameters used to config AWS SNS. #[derive(Debug, Clone, Args)] -pub struct AWSSNSParams { +#[group(requires_all = ["sns_arn"])] +pub struct AWSSNSCliArgs { + /// Use the AWS SNS client + #[arg(long)] + pub aws_sns: bool, + /// The name of the S3 bucket. - #[arg(env = "SNS_NAME", long, default_value = "madara-orchestrator-arn")] - pub sns_arn: String, + #[arg(env = "SNS_NAME", long, default_value = Some("madara-orchestrator-arn"))] + pub sns_arn: Option, } -impl AWSSNSParams { - // TODO: Implement the logic to get the SNS ARN from aws config +#[derive(Debug, Clone)] +pub struct AWSSNSParams { + pub sns_arn: String, } diff --git a/crates/utils/src/cli/da/ethereum.rs b/crates/utils/src/cli/da/ethereum.rs index e0e8a911..0c75c757 100644 --- a/crates/utils/src/cli/da/ethereum.rs +++ b/crates/utils/src/cli/da/ethereum.rs @@ -3,8 +3,18 @@ use url::Url; /// Parameters used to config Ethereum. #[derive(Debug, Clone, Args)] -pub struct EthereumParams { +#[group(requires_all = ["da_rpc_url"])] +pub struct EthereumDACliArgs { + /// Use the Ethereum DA layer. + #[arg(long)] + pub da_on_ethereum: bool, + /// The RPC URL of the Ethereum node. #[arg(env = "DA_RPC_URL", long)] - pub rpc_url: Url, + pub da_rpc_url: Option, +} + +#[derive(Debug, Clone)] +pub struct EthereumDAParams { + pub da_rpc_url: Url, } diff --git a/crates/utils/src/cli/da/mod.rs b/crates/utils/src/cli/da/mod.rs index 6cc1f9eb..9425cd1c 100644 --- a/crates/utils/src/cli/da/mod.rs +++ b/crates/utils/src/cli/da/mod.rs @@ -2,5 +2,5 @@ pub mod ethereum; #[derive(Debug, Clone)] pub enum DaParams { - Ethereum(ethereum::EthereumParams), + Ethereum(ethereum::EthereumDAParams), } diff --git a/crates/utils/src/cli/database/mongodb.rs b/crates/utils/src/cli/database/mongodb.rs index d77c94a5..00bbb243 100644 --- a/crates/utils/src/cli/database/mongodb.rs +++ b/crates/utils/src/cli/database/mongodb.rs @@ -2,12 +2,23 @@ use clap::Args; /// Parameters used to config MongoDB. #[derive(Debug, Clone, Args)] -pub struct MongoDBParams { +#[group(requires_all = ["connection_url", "database_name"])] +pub struct MongoDBCliArgs { + /// Use the MongoDB client + #[arg(long)] + pub mongodb: bool, + /// The connection string to the MongoDB server. - #[arg(env = "MONGODB_CONNECTION_URL", long)] - pub connection_url: String, + #[arg(env = "MONGODB_CONNECTION_URL", long, default_value = Some("mongodb://localhost:27017"))] + pub connection_url: Option, /// The name of the database. - #[arg(env = "DATABASE_NAME", long)] + #[arg(env = "DATABASE_NAME", long, default_value = Some("orchestrator"))] + pub database_name: Option, +} + +#[derive(Debug, Clone)] +pub struct MongoDBParams { + pub connection_url: String, pub database_name: String, } diff --git a/crates/utils/src/cli/instrumentation.rs b/crates/utils/src/cli/instrumentation.rs index 4b61e432..bc1760b3 100644 --- a/crates/utils/src/cli/instrumentation.rs +++ b/crates/utils/src/cli/instrumentation.rs @@ -4,10 +4,11 @@ use url::Url; /// Parameters used to config instrumentation. #[derive(Debug, Clone, Args)] -pub struct InstrumentationParams { +#[group(requires_all = ["otel_service_name", "otel_collector_endpoint", "log_level"])] +pub struct InstrumentationCliArgs { /// The name of the instrumentation service. #[arg(env = "OTEL_SERVICE_NAME", long, default_value = "orchestrator")] - pub otel_service_name: String, + pub otel_service_name: Option, /// The endpoint of the collector. #[arg(env = "OTEL_COLLECTOR_ENDPOINT", long)] @@ -17,3 +18,10 @@ pub struct InstrumentationParams { #[arg(env = "RUST_LOG", long, default_value = "INFO")] pub log_level: Level, } + +#[derive(Debug, Clone)] +pub struct InstrumentationParams { + pub otel_service_name: String, + pub otel_collector_endpoint: Option, + pub log_level: Level, +} diff --git a/crates/utils/src/cli/mod.rs b/crates/utils/src/cli/mod.rs index 8dc7cbcd..232a6bc7 100644 --- a/crates/utils/src/cli/mod.rs +++ b/crates/utils/src/cli/mod.rs @@ -1,12 +1,19 @@ +use alert::aws_sns::AWSSNSParams; use alert::AlertParams; use clap::{command, ArgGroup, Parser}; +use da::ethereum::EthereumDAParams; use da::DaParams; +use database::mongodb::MongoDBParams; use database::DatabaseParams; +use instrumentation::InstrumentationParams; +use prover::sharp::SharpParams; use prover::ProverParams; +use queue::aws_sqs::AWSSQSParams; use queue::QueueParams; use settlement::ethereum::EthereumSettlementParams; use settlement::starknet::StarknetSettlementParams; use settlement::SettlementParams; +use storage::aws_s3::AWSS3Params; use storage::StorageParams; use url::Url; @@ -75,59 +82,41 @@ pub struct RunCmd { starknet_args: settlement::starknet::StarknetSettlementArgs, // Storage - #[clap(long, group = "storage")] - pub aws_s3: bool, - #[clap(flatten)] - pub aws_s3_params: storage::aws_s3::AWSS3Params, - - // Queue - #[clap(long, group = "queue")] - pub aws_sqs: bool, + pub aws_s3_args: storage::aws_s3::AWSS3CliArgs, #[clap(flatten)] - pub aws_sqs_params: queue::aws_sqs::AWSSQSParams, + pub aws_sqs_args: queue::aws_sqs::AWSSQSCliArgs, // Server #[clap(flatten)] pub server: server::ServerParams, // Alert - #[clap(long, group = "alert")] - pub aws_sns: bool, - #[clap(flatten)] - pub aws_sns_params: alert::aws_sns::AWSSNSParams, + pub aws_sns_args: alert::aws_sns::AWSSNSCliArgs, // Database - #[clap(long, group = "database")] - pub mongodb: bool, - #[clap(flatten)] - pub mongodb_params: database::mongodb::MongoDBParams, + pub mongodb_args: database::mongodb::MongoDBCliArgs, // Data Availability Layer - #[clap(long, group = "da_layer")] - pub da_on_ethereum: bool, - #[clap(flatten)] - pub ethereum_da_params: da::ethereum::EthereumParams, + pub ethereum_da_args: da::ethereum::EthereumDACliArgs, // Prover - #[clap(long, group = "prover")] - pub sharp: bool, - #[clap(flatten)] - pub sharp_params: prover::sharp::SharpParams, + pub sharp_args: prover::sharp::SharpCliArgs, + // SNOS #[clap(flatten)] - pub snos: snos::SNOSParams, + pub snos_args: snos::SNOSCliArgs, #[arg(env = "MADARA_RPC_URL", long, required = true)] pub madara_rpc_url: Url, #[clap(flatten)] - pub instrumentation: instrumentation::InstrumentationParams, + pub instrumentation_args: instrumentation::InstrumentationCliArgs, } impl RunCmd { @@ -173,50 +162,74 @@ impl RunCmd { } pub fn validate_storage_params(&self) -> Result { - if self.aws_s3 { - Ok(StorageParams::AWSS3(self.aws_s3_params.clone())) + if self.aws_s3_args.aws_s3 { + Ok(StorageParams::AWSS3(AWSS3Params { bucket_name: self.aws_s3_args.bucket_name.clone().unwrap() })) } else { Err("Only AWS S3 is supported as of now".to_string()) } } pub fn validate_queue_params(&self) -> Result { - if self.aws_sqs { - Ok(QueueParams::AWSSQS(self.aws_sqs_params.clone())) + if self.aws_sqs_args.aws_sqs { + Ok(QueueParams::AWSSQS(AWSSQSParams { + queue_base_url: self.aws_sqs_args.queue_base_url.clone().unwrap(), + sqs_prefix: self.aws_sqs_args.sqs_prefix.clone().unwrap(), + sqs_suffix: self.aws_sqs_args.sqs_suffix.clone().unwrap(), + })) } else { Err("Only AWS SQS is supported as of now".to_string()) } } pub fn validate_alert_params(&self) -> Result { - if self.aws_sns { - Ok(AlertParams::AWSSNS(self.aws_sns_params.clone())) + if self.aws_sns_args.aws_sns { + Ok(AlertParams::AWSSNS(AWSSNSParams { sns_arn: self.aws_sns_args.sns_arn.clone().unwrap() })) } else { Err("Only AWS SNS is supported as of now".to_string()) } } pub fn validate_database_params(&self) -> Result { - if self.mongodb { - Ok(DatabaseParams::MongoDB(self.mongodb_params.clone())) + if self.mongodb_args.mongodb { + Ok(DatabaseParams::MongoDB(MongoDBParams { + connection_url: self.mongodb_args.connection_url.clone().unwrap(), + database_name: self.mongodb_args.database_name.clone().unwrap(), + })) } else { Err("Only MongoDB is supported as of now".to_string()) } } pub fn validate_da_params(&self) -> Result { - if self.da_on_ethereum { - Ok(DaParams::Ethereum(self.ethereum_da_params.clone())) + if self.ethereum_da_args.da_on_ethereum { + Ok(DaParams::Ethereum(EthereumDAParams { da_rpc_url: self.ethereum_da_args.da_rpc_url.clone().unwrap() })) } else { Err("Only Ethereum is supported as of now".to_string()) } } pub fn validate_prover_params(&self) -> Result { - if self.sharp { - Ok(ProverParams::Sharp(self.sharp_params.clone())) + if self.sharp_args.sharp { + Ok(ProverParams::Sharp(SharpParams { + sharp_customer_id: self.sharp_args.sharp_customer_id.clone().unwrap(), + sharp_url: self.sharp_args.sharp_url.clone().unwrap(), + sharp_user_crt: self.sharp_args.sharp_user_crt.clone().unwrap(), + sharp_user_key: self.sharp_args.sharp_user_key.clone().unwrap(), + sharp_rpc_node_url: self.sharp_args.sharp_rpc_node_url.clone().unwrap(), + sharp_proof_layout: self.sharp_args.sharp_proof_layout.clone().unwrap(), + gps_verifier_contract_address: self.sharp_args.gps_verifier_contract_address.clone().unwrap(), + sharp_server_crt: self.sharp_args.sharp_server_crt.clone().unwrap(), + })) } else { Err("Only Sharp is supported as of now".to_string()) } } + + pub fn validate_instrumentation_params(&self) -> Result { + Ok(InstrumentationParams { + otel_service_name: self.instrumentation_args.otel_service_name.clone().unwrap(), + otel_collector_endpoint: self.instrumentation_args.otel_collector_endpoint.clone(), + log_level: self.instrumentation_args.log_level, + }) + } } diff --git a/crates/utils/src/cli/prover/sharp.rs b/crates/utils/src/cli/prover/sharp.rs index 3185293f..e848cfbf 100644 --- a/crates/utils/src/cli/prover/sharp.rs +++ b/crates/utils/src/cli/prover/sharp.rs @@ -3,36 +3,53 @@ use url::Url; /// Parameters used to config Sharp. #[derive(Debug, Clone, Args)] -pub struct SharpParams { +#[group(requires_all = ["sharp_customer_id", "sharp_url", "sharp_user_crt", "sharp_user_key", "sharp_rpc_node_url"])] +pub struct SharpCliArgs { + /// Use the Sharp prover. + #[arg(long)] + pub sharp: bool, + /// The customer id for Sharp. #[arg(env = "SHARP_CUSTOMER_ID", long)] - pub sharp_customer_id: String, + pub sharp_customer_id: Option, /// The URL of the Sharp server. #[arg(env = "SHARP_URL", long)] - pub sharp_url: Url, + pub sharp_url: Option, /// The user certificate for Sharp. #[arg(env = "SHARP_USER_CRT", long)] - pub sharp_user_crt: String, + pub sharp_user_crt: Option, /// The user key for Sharp. #[arg(env = "SHARP_USER_KEY", long)] - pub sharp_user_key: String, + pub sharp_user_key: Option, /// The RPC node URL for Sharp. #[arg(env = "SHARP_RPC_NODE_URL", long)] - pub sharp_rpc_node_url: Url, + pub sharp_rpc_node_url: Option, /// The server certificate for Sharp. #[arg(env = "SHARP_SERVER_CRT", long)] - pub sharp_server_crt: String, + pub sharp_server_crt: Option, /// The proof layout for Sharp. #[arg(env = "SHARP_PROOF_LAYOUT", long, default_value = "small")] - pub sharp_proof_layout: String, + pub sharp_proof_layout: Option, /// The GPS verifier contract address. #[arg(env = "GPS_VERIFIER_CONTRACT_ADDRESS", long)] + pub gps_verifier_contract_address: Option, +} + +#[derive(Debug, Clone)] +pub struct SharpParams { + pub sharp_customer_id: String, + pub sharp_url: Url, + pub sharp_user_crt: String, + pub sharp_user_key: String, + pub sharp_rpc_node_url: Url, + pub sharp_server_crt: String, + pub sharp_proof_layout: String, pub gps_verifier_contract_address: String, } diff --git a/crates/utils/src/cli/queue/aws_sqs.rs b/crates/utils/src/cli/queue/aws_sqs.rs index 635cf059..43cd38c4 100644 --- a/crates/utils/src/cli/queue/aws_sqs.rs +++ b/crates/utils/src/cli/queue/aws_sqs.rs @@ -5,19 +5,46 @@ use serde::Serialize; /// Parameters used to config AWS SQS. #[derive(Debug, Clone, Args)] -pub struct AWSSQSParams { +#[group(requires_all = ["sqs_prefix", "sqs_suffix", "queue_base_url"])] +pub struct AWSSQSCliArgs { + /// Use the AWS sqs client + #[arg(long)] + pub aws_sqs: bool, + /// The name of the S3 bucket. - #[arg(env = "SQS_PREFIX", long)] - pub sqs_prefix: String, + #[arg(env = "SQS_PREFIX", long, default_value = Some("madara-orchestrator"))] + pub sqs_prefix: Option, - #[arg(env = "SQS_SUFFIX", long, default_value = "queue")] - pub sqs_suffix: String, + /// The suffix of the queue. + #[arg(env = "SQS_SUFFIX", long, default_value = Some("queue"))] + pub sqs_suffix: Option, /// The QUEUE url #[arg(env = "SQS_BASE_QUEUE_URL", long)] + pub queue_base_url: Option, +} + +#[derive(Debug, Clone)] +pub struct AWSSQSParams { pub queue_base_url: String, + pub sqs_prefix: String, + pub sqs_suffix: String, +} + +impl AWSSQSParams { + pub fn get_queue_url(&self, queue_type: QueueType) -> String { + format!("{}/{}", self.queue_base_url, self.get_queue_name(queue_type)) + } + + pub fn get_queue_name(&self, queue_type: QueueType) -> String { + // TODO: check if serde_json is the best way to convert the enum to string + let queue_name = serde_json::to_string(&queue_type).unwrap(); + format!("{}_{}_{}", self.sqs_prefix, queue_name, self.sqs_suffix) + } } +// TODO: Can we move this to the queue config? + #[derive(Debug, Clone, Serialize, PartialEq, Eq)] pub enum QueueType { #[serde(rename = "snos_job_processing")] @@ -72,15 +99,3 @@ impl fmt::Display for QueueType { write!(f, "{}", serde_json::to_string(self).unwrap()) } } - -impl AWSSQSParams { - pub fn get_queue_url(&self, queue_type: QueueType) -> String { - format!("{}/{}", self.queue_base_url, self.get_queue_name(queue_type)) - } - - pub fn get_queue_name(&self, queue_type: QueueType) -> String { - // TODO: check if serde_json is the best way to convert the enum to string - let queue_name = serde_json::to_string(&queue_type).unwrap(); - format!("{}_{}_{}", self.sqs_prefix, queue_name, self.sqs_suffix) - } -} diff --git a/crates/utils/src/cli/server.rs b/crates/utils/src/cli/server.rs index 815c4dc5..76e1b3bc 100644 --- a/crates/utils/src/cli/server.rs +++ b/crates/utils/src/cli/server.rs @@ -2,6 +2,7 @@ use clap::Args; /// Parameters used to config the server. #[derive(Debug, Clone, Args)] +#[group(requires_all = ["host", "port"])] pub struct ServerParams { /// The host to listen on. #[arg(env = "HOST", long, default_value = "127.0.0.1")] diff --git a/crates/utils/src/cli/snos.rs b/crates/utils/src/cli/snos.rs index 2417e78a..26e9d7d3 100644 --- a/crates/utils/src/cli/snos.rs +++ b/crates/utils/src/cli/snos.rs @@ -2,9 +2,10 @@ use clap::Args; use url::Url; #[derive(Debug, Clone, Args)] -pub struct SNOSParams { +#[group(requires_all = ["rpc_for_snos"])] +pub struct SNOSCliArgs { /// The RPC URL for SNOS. - #[arg(env = "RPC_FOR_SNOS", long, required = true)] + #[arg(env = "RPC_FOR_SNOS", long)] pub rpc_for_snos: Url, /// The maximum block to process. @@ -15,3 +16,9 @@ pub struct SNOSParams { #[arg(env = "MIN_BLOCK_TO_PROCESS", long)] pub min_block_to_process: Option, } +#[derive(Debug, Clone)] +pub struct SNOSParams { + pub rpc_for_snos: Url, + pub max_block_to_process: Option, + pub min_block_to_process: Option, +} diff --git a/crates/utils/src/cli/storage/aws_s3.rs b/crates/utils/src/cli/storage/aws_s3.rs index 0ffb7bfa..08aa70f5 100644 --- a/crates/utils/src/cli/storage/aws_s3.rs +++ b/crates/utils/src/cli/storage/aws_s3.rs @@ -2,8 +2,17 @@ use clap::Args; /// Parameters used to config AWS S3. #[derive(Debug, Clone, Args)] -pub struct AWSS3Params { +#[group(requires_all = ["bucket_name"])] +pub struct AWSS3CliArgs { + /// Use the AWS s3 client + #[arg(long)] + pub aws_s3: bool, + /// The name of the S3 bucket. - #[arg(env = "AWS_S3_BUCKET_NAME", long, default_value = "madara-orchestrator-bucket")] + #[arg(env = "AWS_S3_BUCKET_NAME", long, default_value = Some("madara-orchestrator-bucket"))] + pub bucket_name: Option, +} +#[derive(Debug, Clone)] +pub struct AWSS3Params { pub bucket_name: String, } diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index 4ee63f95..17c31bed 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -21,6 +21,9 @@ use rstest::rstest; use serde::{Deserialize, Serialize}; use serde_json::json; use starknet::core::types::{Felt, MaybePendingStateUpdate}; +use utils::cli::database::DatabaseParams; +use utils::cli::queue::QueueParams; +use utils::cli::storage::StorageParams; use utils::cli::RunCmd; use utils::env_utils::get_env_var_or_panic; use uuid::Uuid; @@ -49,7 +52,12 @@ struct Setup { impl Setup { /// Initialise a new setup pub async fn new(l2_block_number: String, run_cmd: RunCmd) -> Self { - let mongodb_params = run_cmd.mongodb_params; + let db_params = run_cmd.validate_database_params().expect("Invalid database params"); + let storage_params = run_cmd.validate_storage_params().expect("Invalid storage params"); + let queue_params = run_cmd.validate_queue_params().expect("Invalid queue params"); + + let DatabaseParams::MongoDB(mongodb_params) = db_params; + let mongo_db_instance = MongoDbServer::run(mongodb_params); println!("✅ Mongo DB setup completed"); @@ -65,15 +73,15 @@ impl Setup { // Setting up LocalStack let aws_config = run_cmd.aws_config; - let s3_config = run_cmd.aws_s3_params; - let sqs_config = run_cmd.aws_sqs_params; - let localstack_instance = LocalStack::new(aws_config, &s3_config).await; - localstack_instance.setup_sqs(&sqs_config).await.unwrap(); + let StorageParams::AWSS3(s3_params) = storage_params; + let QueueParams::AWSSQS(sqs_params) = queue_params; + let localstack_instance = LocalStack::new(aws_config, &s3_params).await; + localstack_instance.setup_sqs(&sqs_params).await.unwrap(); localstack_instance.delete_event_bridge_rule("worker_trigger_scheduled").await.unwrap(); - localstack_instance.setup_event_bridge(WorkerTriggerType::Snos, &sqs_config).await.unwrap(); - localstack_instance.setup_event_bridge(WorkerTriggerType::Proving, &sqs_config).await.unwrap(); - localstack_instance.setup_event_bridge(WorkerTriggerType::DataSubmission, &sqs_config).await.unwrap(); - localstack_instance.setup_event_bridge(WorkerTriggerType::UpdateState, &sqs_config).await.unwrap(); + localstack_instance.setup_event_bridge(WorkerTriggerType::Snos, &sqs_params).await.unwrap(); + localstack_instance.setup_event_bridge(WorkerTriggerType::Proving, &sqs_params).await.unwrap(); + localstack_instance.setup_event_bridge(WorkerTriggerType::DataSubmission, &sqs_params).await.unwrap(); + localstack_instance.setup_event_bridge(WorkerTriggerType::UpdateState, &sqs_params).await.unwrap(); println!("✅ Localstack instance setup completed"); From 87b571c0ee84c887abe8ecf9cc88474f7dafd585 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Thu, 7 Nov 2024 13:48:36 +0530 Subject: [PATCH 20/63] update: aws args renamed --- crates/orchestrator/src/config.rs | 6 +++--- crates/orchestrator/src/tests/config.rs | 2 +- crates/utils/src/cli/aws_config.rs | 10 +++++----- crates/utils/src/cli/mod.rs | 2 +- crates/utils/src/cli/queue/aws_sqs.rs | 2 +- e2e-tests/src/localstack.rs | 2 +- e2e-tests/tests.rs | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index d6386311..30e04293 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -90,10 +90,10 @@ impl ProviderConfig { /// To build a `SdkConfig` for AWS provider. pub async fn get_aws_config(aws_config: &AWSConfigParams) -> SdkConfig { - let region = aws_config.region.clone(); + let region = aws_config.aws_region.clone(); let region_provider = RegionProviderChain::first_try(Region::new(region)).or_default_provider(); let credentials = - Credentials::from_keys(aws_config.access_key_id.clone(), aws_config.secret_access_key.clone(), None); + Credentials::from_keys(aws_config.aws_access_key_id.clone(), aws_config.aws_secret_access_key.clone(), None); aws_config::from_env().credentials_provider(credentials).region(region_provider).load().await } @@ -101,7 +101,7 @@ pub async fn get_aws_config(aws_config: &AWSConfigParams) -> SdkConfig { pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { dotenv().ok(); - let aws_config = &run_cmd.aws_config; + let aws_config = &run_cmd.aws_config_args; let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(aws_config).await))); // init starknet client diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index c3556218..8db32113 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -183,7 +183,7 @@ impl TestConfigBuilder { dotenvy::from_filename("../.env.test").expect("Failed to load the .env.test file"); let run_cmd = RunCmd::parse(); - let aws_config = &run_cmd.aws_config; + let aws_config = &run_cmd.aws_config_args; let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(aws_config).await))); let server_config = run_cmd.server.clone(); diff --git a/crates/utils/src/cli/aws_config.rs b/crates/utils/src/cli/aws_config.rs index 0866fea5..c8cb4745 100644 --- a/crates/utils/src/cli/aws_config.rs +++ b/crates/utils/src/cli/aws_config.rs @@ -5,21 +5,21 @@ use clap::Args; pub struct AWSConfigParams { /// The access key ID. #[arg(env = "AWS_ACCESS_KEY_ID", long)] - pub access_key_id: String, + pub aws_access_key_id: String, /// The secret access key. #[arg(env = "AWS_SECRET_ACCESS_KEY", long)] - pub secret_access_key: String, + pub aws_secret_access_key: String, /// The region. #[arg(env = "AWS_REGION", long)] - pub region: String, + pub aws_region: String, /// The endpoint URL. #[arg(env = "AWS_ENDPOINT_URL", long, default_value = "http://localhost.localstack.cloud:4566")] - pub endpoint_url: String, + pub aws_endpoint_url: String, /// The default region. #[arg(env = "AWS_DEFAULT_REGION", long, default_value = "localhost")] - pub default_region: String, + pub aws_default_region: String, } diff --git a/crates/utils/src/cli/mod.rs b/crates/utils/src/cli/mod.rs index 232a6bc7..b0eb5ec8 100644 --- a/crates/utils/src/cli/mod.rs +++ b/crates/utils/src/cli/mod.rs @@ -72,7 +72,7 @@ pub mod storage; pub struct RunCmd { // AWS Config #[clap(flatten)] - pub aws_config: aws_config::AWSConfigParams, + pub aws_config_args: aws_config::AWSConfigParams, // Settlement Layer #[command(flatten)] diff --git a/crates/utils/src/cli/queue/aws_sqs.rs b/crates/utils/src/cli/queue/aws_sqs.rs index 43cd38c4..0f98cd6f 100644 --- a/crates/utils/src/cli/queue/aws_sqs.rs +++ b/crates/utils/src/cli/queue/aws_sqs.rs @@ -12,7 +12,7 @@ pub struct AWSSQSCliArgs { pub aws_sqs: bool, /// The name of the S3 bucket. - #[arg(env = "SQS_PREFIX", long, default_value = Some("madara-orchestrator"))] + #[arg(env = "SQS_PREFIX", long, default_value = Some("madara_orchestrator"))] pub sqs_prefix: Option, /// The suffix of the queue. diff --git a/e2e-tests/src/localstack.rs b/e2e-tests/src/localstack.rs index 123b7c20..fef15fe3 100644 --- a/e2e-tests/src/localstack.rs +++ b/e2e-tests/src/localstack.rs @@ -25,7 +25,7 @@ pub struct LocalStack { impl LocalStack { pub async fn new(aws_config: AWSConfigParams, s3_config: &AWSS3Params) -> Self { - let region_provider = Region::new(aws_config.region); + let region_provider = Region::new(aws_config.aws_region); let creds = EnvironmentVariableCredentialsProvider::new().provide_credentials().await.unwrap(); let config = from_env().region(region_provider).credentials_provider(creds).load().await; diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index 17c31bed..8f170ab9 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -72,7 +72,7 @@ impl Setup { println!("✅ Anvil setup completed"); // Setting up LocalStack - let aws_config = run_cmd.aws_config; + let aws_config = run_cmd.aws_config_args; let StorageParams::AWSS3(s3_params) = storage_params; let QueueParams::AWSSQS(sqs_params) = queue_params; let localstack_instance = LocalStack::new(aws_config, &s3_params).await; From c92a27e1b3b8e2488fefad6f4a84d2cdec23ba04 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Thu, 7 Nov 2024 14:54:06 +0530 Subject: [PATCH 21/63] update: moved cli from utils to orchestrator --- crates/orchestrator/src/alerts/aws_sns/mod.rs | 6 +- .../src/cli/alert/aws_sns.rs | 5 - crates/orchestrator/src/cli/alert/mod.rs | 8 ++ .../src/cli/aws_config.rs | 0 .../src/cli/da/ethereum.rs | 0 .../{utils => orchestrator}/src/cli/da/mod.rs | 0 crates/orchestrator/src/cli/database/mod.rs | 8 ++ .../src/cli/database/mongodb.rs | 6 -- .../src/cli/instrumentation.rs | 7 -- crates/{utils => orchestrator}/src/cli/mod.rs | 35 +++--- .../src/cli/prover/mod.rs | 2 +- .../src/cli/prover/sharp.rs | 13 +-- crates/orchestrator/src/cli/queue/aws_sqs.rs | 22 ++++ .../src/cli/queue/mod.rs | 4 +- .../{utils => orchestrator}/src/cli/server.rs | 2 +- .../src/cli/settlement/ethereum.rs | 13 +-- crates/orchestrator/src/cli/settlement/mod.rs | 11 ++ .../src/cli/settlement/starknet.rs | 17 +-- .../{utils => orchestrator}/src/cli/snos.rs | 0 .../src/cli/storage/aws_s3.rs | 4 - crates/orchestrator/src/cli/storage/mod.rs | 8 ++ crates/orchestrator/src/config.rs | 22 ++-- .../src/data_storage/aws_s3/mod.rs | 6 +- .../orchestrator/src/database/mongodb/mod.rs | 7 +- crates/orchestrator/src/lib.rs | 3 + crates/orchestrator/src/main.rs | 2 +- crates/orchestrator/src/queue/job_queue.rs | 57 +++++++++- crates/orchestrator/src/queue/mod.rs | 14 ++- crates/orchestrator/src/queue/sqs/mod.rs | 22 +++- crates/orchestrator/src/routes/mod.rs | 7 +- crates/orchestrator/src/telemetry.rs | 9 +- crates/orchestrator/src/tests/common/mod.rs | 9 +- crates/orchestrator/src/tests/config.rs | 18 ++-- crates/orchestrator/src/tests/jobs/mod.rs | 3 +- .../src/tests/workers/proving/mod.rs | 2 +- .../src/tests/workers/snos/mod.rs | 2 +- .../gps-fact-checker/src/lib.rs | 12 +-- .../sharp-service/src/client.rs | 13 ++- .../prover-services/sharp-service/src/lib.rs | 12 ++- .../sharp-service/tests/lib.rs | 4 +- .../settlement-clients/ethereum/src/config.rs | 11 ++ crates/settlement-clients/ethereum/src/lib.rs | 2 +- .../ethereum/src/tests/mod.rs | 4 +- .../settlement-clients/starknet/src/config.rs | 15 +++ crates/settlement-clients/starknet/src/lib.rs | 2 +- .../starknet/src/tests/test.rs | 2 +- crates/utils/src/cli/alert/mod.rs | 6 -- crates/utils/src/cli/database/mod.rs | 6 -- crates/utils/src/cli/queue/aws_sqs.rs | 101 ------------------ crates/utils/src/cli/settlement/mod.rs | 8 -- crates/utils/src/cli/storage/mod.rs | 6 -- crates/utils/src/lib.rs | 1 - e2e-tests/src/localstack.rs | 9 +- e2e-tests/src/mongodb.rs | 2 +- e2e-tests/tests.rs | 8 +- 55 files changed, 302 insertions(+), 276 deletions(-) rename crates/{utils => orchestrator}/src/cli/alert/aws_sns.rs (82%) create mode 100644 crates/orchestrator/src/cli/alert/mod.rs rename crates/{utils => orchestrator}/src/cli/aws_config.rs (100%) rename crates/{utils => orchestrator}/src/cli/da/ethereum.rs (100%) rename crates/{utils => orchestrator}/src/cli/da/mod.rs (100%) create mode 100644 crates/orchestrator/src/cli/database/mod.rs rename crates/{utils => orchestrator}/src/cli/database/mongodb.rs (83%) rename crates/{utils => orchestrator}/src/cli/instrumentation.rs (79%) rename crates/{utils => orchestrator}/src/cli/mod.rs (89%) rename crates/{utils => orchestrator}/src/cli/prover/mod.rs (69%) rename crates/{utils => orchestrator}/src/cli/prover/sharp.rs (80%) create mode 100644 crates/orchestrator/src/cli/queue/aws_sqs.rs rename crates/{utils => orchestrator}/src/cli/queue/mod.rs (51%) rename crates/{utils => orchestrator}/src/cli/server.rs (92%) rename crates/{utils => orchestrator}/src/cli/settlement/ethereum.rs (76%) create mode 100644 crates/orchestrator/src/cli/settlement/mod.rs rename crates/{utils => orchestrator}/src/cli/settlement/starknet.rs (77%) rename crates/{utils => orchestrator}/src/cli/snos.rs (100%) rename crates/{utils => orchestrator}/src/cli/storage/aws_s3.rs (83%) create mode 100644 crates/orchestrator/src/cli/storage/mod.rs delete mode 100644 crates/utils/src/cli/alert/mod.rs delete mode 100644 crates/utils/src/cli/database/mod.rs delete mode 100644 crates/utils/src/cli/queue/aws_sqs.rs delete mode 100644 crates/utils/src/cli/settlement/mod.rs delete mode 100644 crates/utils/src/cli/storage/mod.rs diff --git a/crates/orchestrator/src/alerts/aws_sns/mod.rs b/crates/orchestrator/src/alerts/aws_sns/mod.rs index c4feeea7..bd989613 100644 --- a/crates/orchestrator/src/alerts/aws_sns/mod.rs +++ b/crates/orchestrator/src/alerts/aws_sns/mod.rs @@ -2,11 +2,15 @@ use std::sync::Arc; use async_trait::async_trait; use aws_sdk_sns::Client; -use utils::cli::alert::aws_sns::AWSSNSParams; use crate::alerts::Alerts; use crate::config::ProviderConfig; +#[derive(Debug, Clone)] +pub struct AWSSNSParams { + pub sns_arn: String, +} + pub struct AWSSNS { client: Client, topic_arn: String, diff --git a/crates/utils/src/cli/alert/aws_sns.rs b/crates/orchestrator/src/cli/alert/aws_sns.rs similarity index 82% rename from crates/utils/src/cli/alert/aws_sns.rs rename to crates/orchestrator/src/cli/alert/aws_sns.rs index 979a3cb4..340f7686 100644 --- a/crates/utils/src/cli/alert/aws_sns.rs +++ b/crates/orchestrator/src/cli/alert/aws_sns.rs @@ -12,8 +12,3 @@ pub struct AWSSNSCliArgs { #[arg(env = "SNS_NAME", long, default_value = Some("madara-orchestrator-arn"))] pub sns_arn: Option, } - -#[derive(Debug, Clone)] -pub struct AWSSNSParams { - pub sns_arn: String, -} diff --git a/crates/orchestrator/src/cli/alert/mod.rs b/crates/orchestrator/src/cli/alert/mod.rs new file mode 100644 index 00000000..6a1f4957 --- /dev/null +++ b/crates/orchestrator/src/cli/alert/mod.rs @@ -0,0 +1,8 @@ +use crate::alerts::aws_sns::AWSSNSParams; + +pub mod aws_sns; + +#[derive(Clone, Debug)] +pub enum AlertParams { + AWSSNS(AWSSNSParams), +} diff --git a/crates/utils/src/cli/aws_config.rs b/crates/orchestrator/src/cli/aws_config.rs similarity index 100% rename from crates/utils/src/cli/aws_config.rs rename to crates/orchestrator/src/cli/aws_config.rs diff --git a/crates/utils/src/cli/da/ethereum.rs b/crates/orchestrator/src/cli/da/ethereum.rs similarity index 100% rename from crates/utils/src/cli/da/ethereum.rs rename to crates/orchestrator/src/cli/da/ethereum.rs diff --git a/crates/utils/src/cli/da/mod.rs b/crates/orchestrator/src/cli/da/mod.rs similarity index 100% rename from crates/utils/src/cli/da/mod.rs rename to crates/orchestrator/src/cli/da/mod.rs diff --git a/crates/orchestrator/src/cli/database/mod.rs b/crates/orchestrator/src/cli/database/mod.rs new file mode 100644 index 00000000..5f80cfe6 --- /dev/null +++ b/crates/orchestrator/src/cli/database/mod.rs @@ -0,0 +1,8 @@ +use crate::database::mongodb::MongoDBParams; + +pub mod mongodb; + +#[derive(Debug, Clone)] +pub enum DatabaseParams { + MongoDB(MongoDBParams), +} diff --git a/crates/utils/src/cli/database/mongodb.rs b/crates/orchestrator/src/cli/database/mongodb.rs similarity index 83% rename from crates/utils/src/cli/database/mongodb.rs rename to crates/orchestrator/src/cli/database/mongodb.rs index 00bbb243..9a912020 100644 --- a/crates/utils/src/cli/database/mongodb.rs +++ b/crates/orchestrator/src/cli/database/mongodb.rs @@ -16,9 +16,3 @@ pub struct MongoDBCliArgs { #[arg(env = "DATABASE_NAME", long, default_value = Some("orchestrator"))] pub database_name: Option, } - -#[derive(Debug, Clone)] -pub struct MongoDBParams { - pub connection_url: String, - pub database_name: String, -} diff --git a/crates/utils/src/cli/instrumentation.rs b/crates/orchestrator/src/cli/instrumentation.rs similarity index 79% rename from crates/utils/src/cli/instrumentation.rs rename to crates/orchestrator/src/cli/instrumentation.rs index bc1760b3..b2ed1dc0 100644 --- a/crates/utils/src/cli/instrumentation.rs +++ b/crates/orchestrator/src/cli/instrumentation.rs @@ -18,10 +18,3 @@ pub struct InstrumentationCliArgs { #[arg(env = "RUST_LOG", long, default_value = "INFO")] pub log_level: Level, } - -#[derive(Debug, Clone)] -pub struct InstrumentationParams { - pub otel_service_name: String, - pub otel_collector_endpoint: Option, - pub log_level: Level, -} diff --git a/crates/utils/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs similarity index 89% rename from crates/utils/src/cli/mod.rs rename to crates/orchestrator/src/cli/mod.rs index b0eb5ec8..08f1ac2d 100644 --- a/crates/utils/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -1,22 +1,25 @@ -use alert::aws_sns::AWSSNSParams; use alert::AlertParams; -use clap::{command, ArgGroup, Parser}; +use aws_config::AWSConfigParams; +use clap::{ArgGroup, Parser}; use da::ethereum::EthereumDAParams; use da::DaParams; -use database::mongodb::MongoDBParams; use database::DatabaseParams; -use instrumentation::InstrumentationParams; -use prover::sharp::SharpParams; +use ethereum_settlement_client::config::EthereumSettlementParams; use prover::ProverParams; -use queue::aws_sqs::AWSSQSParams; use queue::QueueParams; -use settlement::ethereum::EthereumSettlementParams; -use settlement::starknet::StarknetSettlementParams; use settlement::SettlementParams; -use storage::aws_s3::AWSS3Params; +use sharp_service::client::SharpParams; +use starknet_settlement_client::config::StarknetSettlementParams; use storage::StorageParams; use url::Url; +use crate::alerts::aws_sns::AWSSNSParams; +use crate::data_storage::aws_s3::AWSS3Params; +use crate::database::mongodb::MongoDBParams; +use crate::queue::sqs::AWSSQSParams; +use crate::routes::ServerParams; +use crate::telemetry::InstrumentationParams; + pub mod alert; pub mod aws_config; pub mod da; @@ -72,14 +75,14 @@ pub mod storage; pub struct RunCmd { // AWS Config #[clap(flatten)] - pub aws_config_args: aws_config::AWSConfigParams, + pub aws_config_args: AWSConfigParams, // Settlement Layer #[command(flatten)] - ethereum_args: settlement::ethereum::EthereumSettlementArgs, + ethereum_args: settlement::ethereum::EthereumSettlementCliArgs, #[command(flatten)] - starknet_args: settlement::starknet::StarknetSettlementArgs, + starknet_args: settlement::starknet::StarknetSettlementCliArgs, // Storage #[clap(flatten)] @@ -90,7 +93,7 @@ pub struct RunCmd { // Server #[clap(flatten)] - pub server: server::ServerParams, + pub server_args: server::ServerCliArgs, // Alert #[clap(flatten)] @@ -120,7 +123,7 @@ pub struct RunCmd { } impl RunCmd { - pub fn validate_settlement_params(&self) -> Result { + pub fn validate_settlement_params(&self) -> Result { match (self.ethereum_args.settle_on_ethereum, self.starknet_args.settle_on_starknet) { (true, false) => { // TODO: Ensure Starknet params are not provided @@ -232,4 +235,8 @@ impl RunCmd { log_level: self.instrumentation_args.log_level, }) } + + pub fn validate_server_params(&self) -> Result { + Ok(ServerParams { host: self.server_args.host.clone(), port: self.server_args.port }) + } } diff --git a/crates/utils/src/cli/prover/mod.rs b/crates/orchestrator/src/cli/prover/mod.rs similarity index 69% rename from crates/utils/src/cli/prover/mod.rs rename to crates/orchestrator/src/cli/prover/mod.rs index 2b66131d..97eb4316 100644 --- a/crates/utils/src/cli/prover/mod.rs +++ b/crates/orchestrator/src/cli/prover/mod.rs @@ -1,4 +1,4 @@ -use sharp::SharpParams; +use sharp_service::client::SharpParams; pub mod sharp; diff --git a/crates/utils/src/cli/prover/sharp.rs b/crates/orchestrator/src/cli/prover/sharp.rs similarity index 80% rename from crates/utils/src/cli/prover/sharp.rs rename to crates/orchestrator/src/cli/prover/sharp.rs index e848cfbf..f98c6476 100644 --- a/crates/utils/src/cli/prover/sharp.rs +++ b/crates/orchestrator/src/cli/prover/sharp.rs @@ -37,19 +37,8 @@ pub struct SharpCliArgs { #[arg(env = "SHARP_PROOF_LAYOUT", long, default_value = "small")] pub sharp_proof_layout: Option, + // TODO: GPS is a direct dependency of Sharp, hence GPS can be kept in SharpParams /// The GPS verifier contract address. #[arg(env = "GPS_VERIFIER_CONTRACT_ADDRESS", long)] pub gps_verifier_contract_address: Option, } - -#[derive(Debug, Clone)] -pub struct SharpParams { - pub sharp_customer_id: String, - pub sharp_url: Url, - pub sharp_user_crt: String, - pub sharp_user_key: String, - pub sharp_rpc_node_url: Url, - pub sharp_server_crt: String, - pub sharp_proof_layout: String, - pub gps_verifier_contract_address: String, -} diff --git a/crates/orchestrator/src/cli/queue/aws_sqs.rs b/crates/orchestrator/src/cli/queue/aws_sqs.rs new file mode 100644 index 00000000..f6378ed3 --- /dev/null +++ b/crates/orchestrator/src/cli/queue/aws_sqs.rs @@ -0,0 +1,22 @@ +use clap::Args; + +/// Parameters used to config AWS SQS. +#[derive(Debug, Clone, Args)] +#[group(requires_all = ["sqs_prefix", "sqs_suffix", "queue_base_url"])] +pub struct AWSSQSCliArgs { + /// Use the AWS sqs client + #[arg(long)] + pub aws_sqs: bool, + + /// The name of the S3 bucket. + #[arg(env = "SQS_PREFIX", long, default_value = Some("madara_orchestrator"))] + pub sqs_prefix: Option, + + /// The suffix of the queue. + #[arg(env = "SQS_SUFFIX", long, default_value = Some("queue"))] + pub sqs_suffix: Option, + + /// The QUEUE url + #[arg(env = "SQS_BASE_QUEUE_URL", long)] + pub queue_base_url: Option, +} diff --git a/crates/utils/src/cli/queue/mod.rs b/crates/orchestrator/src/cli/queue/mod.rs similarity index 51% rename from crates/utils/src/cli/queue/mod.rs rename to crates/orchestrator/src/cli/queue/mod.rs index 9794d078..5a0cc95c 100644 --- a/crates/utils/src/cli/queue/mod.rs +++ b/crates/orchestrator/src/cli/queue/mod.rs @@ -1,6 +1,8 @@ +use crate::queue::sqs::AWSSQSParams; + pub mod aws_sqs; #[derive(Clone, Debug)] pub enum QueueParams { - AWSSQS(aws_sqs::AWSSQSParams), + AWSSQS(AWSSQSParams), } diff --git a/crates/utils/src/cli/server.rs b/crates/orchestrator/src/cli/server.rs similarity index 92% rename from crates/utils/src/cli/server.rs rename to crates/orchestrator/src/cli/server.rs index 76e1b3bc..6d4d02b3 100644 --- a/crates/utils/src/cli/server.rs +++ b/crates/orchestrator/src/cli/server.rs @@ -3,7 +3,7 @@ use clap::Args; /// Parameters used to config the server. #[derive(Debug, Clone, Args)] #[group(requires_all = ["host", "port"])] -pub struct ServerParams { +pub struct ServerCliArgs { /// The host to listen on. #[arg(env = "HOST", long, default_value = "127.0.0.1")] pub host: String, diff --git a/crates/utils/src/cli/settlement/ethereum.rs b/crates/orchestrator/src/cli/settlement/ethereum.rs similarity index 76% rename from crates/utils/src/cli/settlement/ethereum.rs rename to crates/orchestrator/src/cli/settlement/ethereum.rs index 534c06fe..532955ae 100644 --- a/crates/utils/src/cli/settlement/ethereum.rs +++ b/crates/orchestrator/src/cli/settlement/ethereum.rs @@ -3,7 +3,7 @@ use url::Url; #[derive(Debug, Clone, Args)] #[group(requires_all = ["ethereum_rpc_url", "ethereum_private_key", "l1_core_contract_address", "starknet_operator_address"])] -pub struct EthereumSettlementArgs { +pub struct EthereumSettlementCliArgs { /// Use the Ethereum settlement layer. #[arg(long)] pub settle_on_ethereum: bool, @@ -24,14 +24,3 @@ pub struct EthereumSettlementArgs { #[arg(env = "STARKNET_OPERATOR_ADDRESS", long)] pub starknet_operator_address: Option, } - -#[derive(Clone, Debug)] -pub struct EthereumSettlementParams { - pub ethereum_rpc_url: Url, - - pub ethereum_private_key: String, - - pub l1_core_contract_address: String, - - pub starknet_operator_address: String, -} diff --git a/crates/orchestrator/src/cli/settlement/mod.rs b/crates/orchestrator/src/cli/settlement/mod.rs new file mode 100644 index 00000000..8dd9f0f9 --- /dev/null +++ b/crates/orchestrator/src/cli/settlement/mod.rs @@ -0,0 +1,11 @@ +use ethereum_settlement_client::config::EthereumSettlementParams; +use starknet_settlement_client::config::StarknetSettlementParams; + +pub mod ethereum; +pub mod starknet; + +#[derive(Clone, Debug)] +pub enum SettlementParams { + Ethereum(EthereumSettlementParams), + Starknet(StarknetSettlementParams), +} diff --git a/crates/utils/src/cli/settlement/starknet.rs b/crates/orchestrator/src/cli/settlement/starknet.rs similarity index 77% rename from crates/utils/src/cli/settlement/starknet.rs rename to crates/orchestrator/src/cli/settlement/starknet.rs index 15ba89cb..23658f3c 100644 --- a/crates/utils/src/cli/settlement/starknet.rs +++ b/crates/orchestrator/src/cli/settlement/starknet.rs @@ -3,7 +3,7 @@ use url::Url; #[derive(Debug, Clone, Args)] #[group(requires_all = ["starknet_rpc_url", "starknet_private_key", "starknet_account_address", "starknet_cairo_core_contract_address", "starknet_finality_retry_wait_in_secs", "madara_binary_path"])] -pub struct StarknetSettlementArgs { +pub struct StarknetSettlementCliArgs { /// Use the Starknet settlement layer. #[arg(long)] pub settle_on_starknet: bool, @@ -32,18 +32,3 @@ pub struct StarknetSettlementArgs { #[arg(env = "MADARA_BINARY_PATH", long)] pub madara_binary_path: Option, } - -#[derive(Clone, Debug)] -pub struct StarknetSettlementParams { - pub starknet_rpc_url: Url, - - pub starknet_private_key: String, - - pub starknet_account_address: String, - - pub starknet_cairo_core_contract_address: String, - - pub starknet_finality_retry_wait_in_secs: u64, - - pub madara_binary_path: String, -} diff --git a/crates/utils/src/cli/snos.rs b/crates/orchestrator/src/cli/snos.rs similarity index 100% rename from crates/utils/src/cli/snos.rs rename to crates/orchestrator/src/cli/snos.rs diff --git a/crates/utils/src/cli/storage/aws_s3.rs b/crates/orchestrator/src/cli/storage/aws_s3.rs similarity index 83% rename from crates/utils/src/cli/storage/aws_s3.rs rename to crates/orchestrator/src/cli/storage/aws_s3.rs index 08aa70f5..871a7635 100644 --- a/crates/utils/src/cli/storage/aws_s3.rs +++ b/crates/orchestrator/src/cli/storage/aws_s3.rs @@ -12,7 +12,3 @@ pub struct AWSS3CliArgs { #[arg(env = "AWS_S3_BUCKET_NAME", long, default_value = Some("madara-orchestrator-bucket"))] pub bucket_name: Option, } -#[derive(Debug, Clone)] -pub struct AWSS3Params { - pub bucket_name: String, -} diff --git a/crates/orchestrator/src/cli/storage/mod.rs b/crates/orchestrator/src/cli/storage/mod.rs new file mode 100644 index 00000000..e014db42 --- /dev/null +++ b/crates/orchestrator/src/cli/storage/mod.rs @@ -0,0 +1,8 @@ +use crate::data_storage::aws_s3::AWSS3Params; + +pub mod aws_s3; + +#[derive(Clone, Debug)] +pub enum StorageParams { + AWSS3(AWSS3Params), +} diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 30e04293..b715f33e 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -14,25 +14,25 @@ use sharp_service::SharpProverService; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Url}; use starknet_settlement_client::StarknetSettlementClient; -use utils::cli::alert::AlertParams; -use utils::cli::aws_config::AWSConfigParams; -use utils::cli::da::DaParams; -use utils::cli::database::DatabaseParams; -use utils::cli::prover::ProverParams; -use utils::cli::queue::QueueParams; -use utils::cli::server::ServerParams; -use utils::cli::settlement::SettlementParams; -use utils::cli::storage::StorageParams; -use utils::cli::RunCmd; use crate::alerts::aws_sns::AWSSNS; use crate::alerts::Alerts; +use crate::cli::alert::AlertParams; +use crate::cli::aws_config::AWSConfigParams; +use crate::cli::da::DaParams; +use crate::cli::database::DatabaseParams; +use crate::cli::prover::ProverParams; +use crate::cli::queue::QueueParams; +use crate::cli::settlement::SettlementParams; +use crate::cli::storage::StorageParams; +use crate::cli::RunCmd; use crate::data_storage::aws_s3::AWSS3; use crate::data_storage::DataStorage; use crate::database::mongodb::MongoDb; use crate::database::Database; use crate::queue::sqs::SqsQueue; use crate::queue::QueueProvider; +use crate::routes::ServerParams; /// The app config. It can be accessed from anywhere inside the service /// by calling `config` function. @@ -114,7 +114,7 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { min_block_to_process: run_cmd.snos_args.min_block_to_process, }; - let server_config = run_cmd.server.clone(); + let server_config = run_cmd.validate_server_params().map_err(|e| eyre!("Failed to validate server params: {e}"))?; let provider = JsonRpcClient::new(HttpTransport::new(rpc_url.clone())); // init database diff --git a/crates/orchestrator/src/data_storage/aws_s3/mod.rs b/crates/orchestrator/src/data_storage/aws_s3/mod.rs index 5d9d7101..6f8d015c 100644 --- a/crates/orchestrator/src/data_storage/aws_s3/mod.rs +++ b/crates/orchestrator/src/data_storage/aws_s3/mod.rs @@ -5,7 +5,6 @@ use aws_sdk_s3::primitives::ByteStream; use aws_sdk_s3::Client; use bytes::Bytes; use color_eyre::Result; -use utils::cli::storage::aws_s3::AWSS3Params; use crate::config::ProviderConfig; use crate::data_storage::DataStorage; @@ -15,6 +14,11 @@ pub const S3_SETTINGS_NAME: &str = "s3"; /// Module for AWS S3 config structs and implementations pub mod config; +#[derive(Debug, Clone)] +pub struct AWSS3Params { + pub bucket_name: String, +} + /// AWSS3 represents AWS S3 client object containing the client and the config itself. pub struct AWSS3 { client: Client, diff --git a/crates/orchestrator/src/database/mongodb/mod.rs b/crates/orchestrator/src/database/mongodb/mod.rs index 5043c67a..f90e246f 100644 --- a/crates/orchestrator/src/database/mongodb/mod.rs +++ b/crates/orchestrator/src/database/mongodb/mod.rs @@ -1,4 +1,3 @@ -use ::utils::cli::database::mongodb::MongoDBParams; use async_std::stream::StreamExt; use async_trait::async_trait; use chrono::{SubsecRound, Utc}; @@ -21,6 +20,12 @@ use crate::jobs::JobError; pub mod config; mod utils; +#[derive(Debug, Clone)] +pub struct MongoDBParams { + pub connection_url: String, + pub database_name: String, +} + pub struct MongoDb { client: Client, database_name: String, diff --git a/crates/orchestrator/src/lib.rs b/crates/orchestrator/src/lib.rs index b580f273..a400be74 100644 --- a/crates/orchestrator/src/lib.rs +++ b/crates/orchestrator/src/lib.rs @@ -26,3 +26,6 @@ pub mod telemetry; pub mod tests; /// Contains workers which act like cron jobs pub mod workers; + +/// Contains the CLI arguments for the service +pub mod cli; diff --git a/crates/orchestrator/src/main.rs b/crates/orchestrator/src/main.rs index a6bb466c..6e1e79a6 100644 --- a/crates/orchestrator/src/main.rs +++ b/crates/orchestrator/src/main.rs @@ -1,10 +1,10 @@ use clap::Parser as _; use dotenvy::dotenv; +use orchestrator::cli::RunCmd; use orchestrator::config::init_config; use orchestrator::queue::init_consumers; use orchestrator::routes::setup_server; use orchestrator::telemetry::{setup_analytics, shutdown_analytics}; -use utils::cli::RunCmd; /// Start the server #[tokio::main] diff --git a/crates/orchestrator/src/queue/job_queue.rs b/crates/orchestrator/src/queue/job_queue.rs index d39d3449..c1219160 100644 --- a/crates/orchestrator/src/queue/job_queue.rs +++ b/crates/orchestrator/src/queue/job_queue.rs @@ -1,3 +1,4 @@ +use std::fmt; use std::future::Future; use std::str::FromStr; use std::sync::Arc; @@ -9,7 +10,6 @@ use omniqueue::{Delivery, QueueError}; use serde::{Deserialize, Deserializer, Serialize}; use thiserror::Error; use tokio::time::sleep; -use utils::cli::queue::aws_sqs::QueueType; use uuid::Uuid; use crate::config::Config; @@ -22,6 +22,61 @@ use crate::workers::snos::SnosWorker; use crate::workers::update_state::UpdateStateWorker; use crate::workers::Worker; +#[derive(Debug, Clone, Serialize, PartialEq, Eq)] +pub enum QueueType { + #[serde(rename = "snos_job_processing")] + SnosJobProcessing, + #[serde(rename = "snos_job_verification")] + SnosJobVerification, + #[serde(rename = "proving_job_processing")] + ProvingJobProcessing, + #[serde(rename = "proving_job_verification")] + ProvingJobVerification, + #[serde(rename = "proof_registration_job_processing")] + ProofRegistrationJobProcessing, + #[serde(rename = "proof_registration_job_verification")] + ProofRegistrationJobVerification, + #[serde(rename = "data_submission_job_processing")] + DataSubmissionJobProcessing, + #[serde(rename = "data_submission_job_verification")] + DataSubmissionJobVerification, + #[serde(rename = "update_state_job_processing")] + UpdateStateJobProcessing, + #[serde(rename = "update_state_job_verification")] + UpdateStateJobVerification, + #[serde(rename = "job_handle_failure")] + JobHandleFailure, + #[serde(rename = "worker_trigger")] + WorkerTrigger, +} + +impl QueueType { + pub fn iter() -> impl Iterator { + [ + QueueType::SnosJobProcessing, + QueueType::SnosJobVerification, + QueueType::ProvingJobProcessing, + QueueType::ProvingJobVerification, + QueueType::ProofRegistrationJobProcessing, + QueueType::ProofRegistrationJobVerification, + QueueType::DataSubmissionJobProcessing, + QueueType::DataSubmissionJobVerification, + QueueType::UpdateStateJobProcessing, + QueueType::UpdateStateJobVerification, + QueueType::JobHandleFailure, + QueueType::WorkerTrigger, + ] + .iter() + .cloned() + } +} + +impl fmt::Display for QueueType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", serde_json::to_string(self).unwrap()) + } +} + #[derive(Error, Debug, PartialEq)] pub enum ConsumptionError { #[error("Failed to consume message from queue, error {error_msg:?}")] diff --git a/crates/orchestrator/src/queue/mod.rs b/crates/orchestrator/src/queue/mod.rs index 9309a3f5..37849390 100644 --- a/crates/orchestrator/src/queue/mod.rs +++ b/crates/orchestrator/src/queue/mod.rs @@ -8,7 +8,6 @@ use async_trait::async_trait; use color_eyre::Result as EyreResult; use mockall::automock; use omniqueue::{Delivery, QueueError}; -use utils::cli::queue::aws_sqs::QueueType; use crate::config::Config; use crate::jobs::JobError; @@ -20,9 +19,16 @@ use crate::jobs::JobError; #[automock] #[async_trait] pub trait QueueProvider: Send + Sync { - async fn send_message_to_queue(&self, queue: QueueType, payload: String, delay: Option) - -> EyreResult<()>; - async fn consume_message_from_queue(&self, queue: QueueType) -> std::result::Result; + async fn send_message_to_queue( + &self, + queue: job_queue::QueueType, + payload: String, + delay: Option, + ) -> EyreResult<()>; + async fn consume_message_from_queue( + &self, + queue: job_queue::QueueType, + ) -> std::result::Result; } pub async fn init_consumers(config: Arc) -> Result<(), JobError> { diff --git a/crates/orchestrator/src/queue/sqs/mod.rs b/crates/orchestrator/src/queue/sqs/mod.rs index 77c15ae7..973a1bc7 100644 --- a/crates/orchestrator/src/queue/sqs/mod.rs +++ b/crates/orchestrator/src/queue/sqs/mod.rs @@ -4,9 +4,29 @@ use async_trait::async_trait; use color_eyre::Result; use omniqueue::backends::{SqsBackend, SqsConfig, SqsConsumer, SqsProducer}; use omniqueue::{Delivery, QueueError}; -use utils::cli::queue::aws_sqs::{AWSSQSParams, QueueType}; +use super::job_queue::QueueType; use crate::queue::QueueProvider; + +#[derive(Debug, Clone)] +pub struct AWSSQSParams { + pub queue_base_url: String, + pub sqs_prefix: String, + pub sqs_suffix: String, +} + +impl AWSSQSParams { + pub fn get_queue_url(&self, queue_type: QueueType) -> String { + format!("{}/{}", self.queue_base_url, self.get_queue_name(queue_type)) + } + + pub fn get_queue_name(&self, queue_type: QueueType) -> String { + // TODO: check if serde_json is the best way to convert the enum to string + let queue_name = serde_json::to_string(&queue_type).unwrap(); + format!("{}_{}_{}", self.sqs_prefix, queue_name, self.sqs_suffix) + } +} + pub struct SqsQueue { pub params: AWSSQSParams, } diff --git a/crates/orchestrator/src/routes/mod.rs b/crates/orchestrator/src/routes/mod.rs index f6f2afcf..b43b6a7e 100644 --- a/crates/orchestrator/src/routes/mod.rs +++ b/crates/orchestrator/src/routes/mod.rs @@ -7,13 +7,18 @@ use axum::response::{IntoResponse, Response}; use axum::{Json, Router}; use job_routes::job_router; use serde::Serialize; -use utils::cli::server::ServerParams; use crate::config::Config; pub mod app_routes; pub mod job_routes; +#[derive(Debug, Clone)] +pub struct ServerParams { + pub host: String, + pub port: u16, +} + #[derive(Debug, Serialize)] struct ApiResponse where diff --git a/crates/orchestrator/src/telemetry.rs b/crates/orchestrator/src/telemetry.rs index 2c1371f3..c41375c7 100644 --- a/crates/orchestrator/src/telemetry.rs +++ b/crates/orchestrator/src/telemetry.rs @@ -9,12 +9,12 @@ use opentelemetry_sdk::metrics::reader::{DefaultAggregationSelector, DefaultTemp use opentelemetry_sdk::metrics::{PeriodicReader, SdkMeterProvider}; use opentelemetry_sdk::trace::{BatchConfigBuilder, Config, Tracer}; use opentelemetry_sdk::{runtime, Resource}; +use tracing::Level; use tracing_opentelemetry::OpenTelemetryLayer; use tracing_subscriber::layer::SubscriberExt as _; use tracing_subscriber::util::SubscriberInitExt as _; use tracing_subscriber::EnvFilter; use url::Url; -use utils::cli::instrumentation::InstrumentationParams; pub struct OTELConfig { endpoint: Url, @@ -220,3 +220,10 @@ mod tests { register_metric!(ORCHESTRATOR_METRICS, OrchestratorMetrics); } } + +#[derive(Debug, Clone)] +pub struct InstrumentationParams { + pub otel_service_name: String, + pub otel_collector_endpoint: Option, + pub log_level: Level, +} diff --git a/crates/orchestrator/src/tests/common/mod.rs b/crates/orchestrator/src/tests/common/mod.rs index acc1f4f3..4d9e5a98 100644 --- a/crates/orchestrator/src/tests/common/mod.rs +++ b/crates/orchestrator/src/tests/common/mod.rs @@ -11,19 +11,18 @@ use chrono::{SubsecRound, Utc}; use mongodb::Client; use rstest::*; use serde::Deserialize; -use utils::cli::database::DatabaseParams; -use utils::cli::queue::aws_sqs::QueueType; -use utils::cli::queue::QueueParams; -use utils::cli::storage::aws_s3::AWSS3Params; use utils::env_utils::get_env_var_or_panic; +use crate::cli::database::DatabaseParams; +use crate::cli::queue::QueueParams; use crate::config::ProviderConfig; -use crate::data_storage::aws_s3::AWSS3; +use crate::data_storage::aws_s3::{AWSS3Params, AWSS3}; use crate::data_storage::DataStorage; use crate::database::mongodb::MongoDb; use crate::jobs::types::JobStatus::Created; use crate::jobs::types::JobType::DataSubmission; use crate::jobs::types::{ExternalId, JobItem}; +use crate::queue::job_queue::QueueType; #[fixture] pub fn default_job_item() -> JobItem { diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 8db32113..90916f3d 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -11,9 +11,9 @@ use settlement_client_interface::{MockSettlementClient, SettlementClient}; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::JsonRpcClient; use url::Url; -use utils::cli::RunCmd; use crate::alerts::Alerts; +use crate::cli::RunCmd; use crate::config::{get_aws_config, Config, ProviderConfig, SnosConfig}; use crate::data_storage::{DataStorage, MockDataStorage}; use crate::database::{Database, MockDatabase}; @@ -185,7 +185,7 @@ impl TestConfigBuilder { let aws_config = &run_cmd.aws_config_args; let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(aws_config).await))); - let server_config = run_cmd.server.clone(); + let server_config = run_cmd.validate_server_params().expect("Failed to validate server params"); let snos_config = SnosConfig { rpc_url: run_cmd.snos_args.rpc_for_snos.clone(), @@ -297,16 +297,16 @@ pub mod implement_client { use settlement_client_interface::{MockSettlementClient, SettlementClient}; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Url}; - use utils::cli::alert::AlertParams; - use utils::cli::da::DaParams; - use utils::cli::database::DatabaseParams; - use utils::cli::prover::ProverParams; - use utils::cli::queue::QueueParams; - use utils::cli::settlement::SettlementParams; - use utils::cli::storage::StorageParams; use super::{ConfigType, MockType}; use crate::alerts::{Alerts, MockAlerts}; + use crate::cli::alert::AlertParams; + use crate::cli::da::DaParams; + use crate::cli::database::DatabaseParams; + use crate::cli::prover::ProverParams; + use crate::cli::queue::QueueParams; + use crate::cli::settlement::SettlementParams; + use crate::cli::storage::StorageParams; use crate::config::{ build_alert_client, build_da_client, build_database_client, build_prover_service, build_queue_client, build_settlement_client, ProviderConfig, diff --git a/crates/orchestrator/src/tests/jobs/mod.rs b/crates/orchestrator/src/tests/jobs/mod.rs index 905696c7..90f09552 100644 --- a/crates/orchestrator/src/tests/jobs/mod.rs +++ b/crates/orchestrator/src/tests/jobs/mod.rs @@ -7,7 +7,6 @@ use mongodb::bson::doc; use omniqueue::QueueError; use rstest::rstest; use tokio::time::sleep; -use utils::cli::queue::aws_sqs::QueueType; use uuid::Uuid; use super::database::build_job_item; @@ -19,7 +18,7 @@ use crate::jobs::types::{ExternalId, JobItem, JobStatus, JobType, JobVerificatio use crate::jobs::{ create_job, handle_job_failure, increment_key_in_metadata, process_job, verify_job, Job, JobError, MockJob, }; -use crate::queue::job_queue::QueueNameForJobType; +use crate::queue::job_queue::{QueueNameForJobType, QueueType}; use crate::tests::common::MessagePayloadType; use crate::tests::config::{ConfigType, TestConfigBuilder}; diff --git a/crates/orchestrator/src/tests/workers/proving/mod.rs b/crates/orchestrator/src/tests/workers/proving/mod.rs index e479d710..77d0b16f 100644 --- a/crates/orchestrator/src/tests/workers/proving/mod.rs +++ b/crates/orchestrator/src/tests/workers/proving/mod.rs @@ -25,7 +25,7 @@ use crate::workers::proving::ProvingWorker; #[case(false)] #[tokio::test] async fn test_proving_worker(#[case] incomplete_runs: bool) -> Result<(), Box> { - use utils::cli::queue::aws_sqs::QueueType; + use crate::queue::job_queue::QueueType; let server = MockServer::start(); let da_client = MockDaClient::new(); diff --git a/crates/orchestrator/src/tests/workers/snos/mod.rs b/crates/orchestrator/src/tests/workers/snos/mod.rs index cb138831..621347f8 100644 --- a/crates/orchestrator/src/tests/workers/snos/mod.rs +++ b/crates/orchestrator/src/tests/workers/snos/mod.rs @@ -26,7 +26,7 @@ use crate::workers::Worker; #[case(true)] #[tokio::test] async fn test_snos_worker(#[case] db_val: bool) -> Result<(), Box> { - use utils::cli::queue::aws_sqs::QueueType; + use crate::queue::job_queue::QueueType; let server = MockServer::start(); let da_client = MockDaClient::new(); diff --git a/crates/prover-services/gps-fact-checker/src/lib.rs b/crates/prover-services/gps-fact-checker/src/lib.rs index 185ed198..5dccce21 100644 --- a/crates/prover-services/gps-fact-checker/src/lib.rs +++ b/crates/prover-services/gps-fact-checker/src/lib.rs @@ -4,7 +4,7 @@ use alloy::primitives::{Address, B256}; use alloy::providers::{ProviderBuilder, RootProvider}; use alloy::sol; use alloy::transports::http::{Client, Http}; -use utils::cli::prover::sharp::SharpParams; +use url::Url; sol!( #[allow(missing_docs)] @@ -27,12 +27,10 @@ type TransportT = Http; type ProviderT = RootProvider; impl FactChecker { - pub fn new(sharp_params: &SharpParams) -> Self { - let provider = ProviderBuilder::new().on_http(sharp_params.sharp_rpc_node_url.clone()); - let fact_registry = FactRegistry::new( - Address::from_str(sharp_params.gps_verifier_contract_address.as_str()).unwrap(), - provider, - ); + pub fn new(sharp_rpc_node_url: Url, gps_verifier_contract_address: String) -> Self { + let provider = ProviderBuilder::new().on_http(sharp_rpc_node_url.clone()); + let fact_registry = + FactRegistry::new(Address::from_str(gps_verifier_contract_address.as_str()).unwrap(), provider); Self { fact_registry } } diff --git a/crates/prover-services/sharp-service/src/client.rs b/crates/prover-services/sharp-service/src/client.rs index bbc1649c..19157505 100644 --- a/crates/prover-services/sharp-service/src/client.rs +++ b/crates/prover-services/sharp-service/src/client.rs @@ -4,7 +4,6 @@ use base64::engine::general_purpose; use base64::Engine; use reqwest::{Certificate, ClientBuilder, Identity}; use url::Url; -use utils::cli::prover::sharp::SharpParams; use utils::env_utils::get_env_var_or_panic; use uuid::Uuid; @@ -124,3 +123,15 @@ fn add_params_to_url(url: &mut Url, params: Vec<(&str, &str)>) { pairs.append_pair(key, value); } } + +#[derive(Debug, Clone)] +pub struct SharpParams { + pub sharp_customer_id: String, + pub sharp_url: Url, + pub sharp_user_crt: String, + pub sharp_user_key: String, + pub sharp_rpc_node_url: Url, + pub sharp_server_crt: String, + pub sharp_proof_layout: String, + pub gps_verifier_contract_address: String, +} diff --git a/crates/prover-services/sharp-service/src/lib.rs b/crates/prover-services/sharp-service/src/lib.rs index 6ea92c32..47576de5 100644 --- a/crates/prover-services/sharp-service/src/lib.rs +++ b/crates/prover-services/sharp-service/src/lib.rs @@ -7,10 +7,10 @@ use std::str::FromStr; use alloy::primitives::B256; use async_trait::async_trait; +use client::SharpParams; use gps_fact_checker::FactChecker; use prover_client_interface::{ProverClient, ProverClientError, Task, TaskStatus}; use starknet_os::sharp::CairoJobStatus; -use utils::cli::prover::sharp::SharpParams; use uuid::Uuid; use crate::client::SharpClient; @@ -135,7 +135,10 @@ impl SharpProverService { pub fn new_with_settings(sharp_params: &SharpParams) -> Self { let sharp_client = SharpClient::new_with_settings(sharp_params.sharp_url.clone(), sharp_params); - let fact_checker = FactChecker::new(sharp_params); + let fact_checker = FactChecker::new( + sharp_params.sharp_rpc_node_url.clone(), + sharp_params.gps_verifier_contract_address.clone(), + ); Self::new(sharp_client, fact_checker) } @@ -144,7 +147,10 @@ impl SharpProverService { format!("http://127.0.0.1:{}", port).parse().expect("Failed to create sharp client with the given params"), sharp_params, ); - let fact_checker = FactChecker::new(sharp_params); + let fact_checker = FactChecker::new( + sharp_params.sharp_rpc_node_url.clone(), + sharp_params.gps_verifier_contract_address.clone(), + ); Self::new(sharp_client, fact_checker) } } diff --git a/crates/prover-services/sharp-service/tests/lib.rs b/crates/prover-services/sharp-service/tests/lib.rs index 3207fb6e..309af91a 100644 --- a/crates/prover-services/sharp-service/tests/lib.rs +++ b/crates/prover-services/sharp-service/tests/lib.rs @@ -6,10 +6,10 @@ use prover_client_interface::ProverClient; use prover_client_interface::{Task, TaskStatus}; use rstest::rstest; use serde_json::json; +use sharp_service::client::SharpParams; use sharp_service::SharpProverService; use starknet_os::sharp::CairoJobStatus; use url::Url; -use utils::cli::prover::sharp::SharpParams; use utils::env_utils::get_env_var_or_panic; use crate::constants::TEST_FACT; @@ -64,6 +64,8 @@ async fn prover_client_submit_task_works() { #[case(CairoJobStatus::ONCHAIN)] #[tokio::test] async fn prover_client_get_task_status_works(#[case] cairo_job_status: CairoJobStatus) { + use sharp_service::client::SharpParams; + dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); let sharp_params = SharpParams { diff --git a/crates/settlement-clients/ethereum/src/config.rs b/crates/settlement-clients/ethereum/src/config.rs index cd20d356..489aaf5a 100644 --- a/crates/settlement-clients/ethereum/src/config.rs +++ b/crates/settlement-clients/ethereum/src/config.rs @@ -21,3 +21,14 @@ impl EthereumSettlementConfig { Self { rpc_url, core_contract_address } } } + +#[derive(Clone, Debug)] +pub struct EthereumSettlementParams { + pub ethereum_rpc_url: Url, + + pub ethereum_private_key: String, + + pub l1_core_contract_address: String, + + pub starknet_operator_address: String, +} diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index 9370da76..5800213e 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -21,9 +21,9 @@ use async_trait::async_trait; use c_kzg::{Blob, Bytes32, KzgCommitment, KzgProof, KzgSettings}; use color_eyre::eyre::{bail, eyre, Ok}; use color_eyre::Result; +use config::EthereumSettlementParams; use conversion::{get_input_data_for_eip_4844, prepare_sidecar}; use settlement_client_interface::{SettlementClient, SettlementVerificationStatus}; -use utils::cli::settlement::ethereum::EthereumSettlementParams; use crate::clients::interfaces::validity_interface::StarknetValidityContractTrait; use crate::clients::StarknetValidityContractClient; diff --git a/crates/settlement-clients/ethereum/src/tests/mod.rs b/crates/settlement-clients/ethereum/src/tests/mod.rs index f5af3564..80a5b301 100644 --- a/crates/settlement-clients/ethereum/src/tests/mod.rs +++ b/crates/settlement-clients/ethereum/src/tests/mod.rs @@ -8,7 +8,6 @@ use alloy::providers::ProviderBuilder; use alloy::sol; use alloy_primitives::Address; use utils::env_utils::get_env_var_or_panic; - // Using the Pipe trait to write chained operations easier #[allow(dead_code)] trait Pipe: Sized { @@ -135,7 +134,6 @@ mod settlement_client_tests { use settlement_client_interface::{SettlementClient, SettlementVerificationStatus}; use tokio::time::sleep; use url::Url; - use utils::cli::settlement::ethereum::EthereumSettlementParams; use utils::env_utils::get_env_var_or_panic; use super::{BLOCK_TIME, ENV_FILE_PATH}; @@ -145,7 +143,7 @@ mod settlement_client_tests { STARKNET_CORE_CONTRACT_ADDRESS, STARKNET_OPERATOR_ADDRESS, }; use crate::types::{bytes_be_to_u128, convert_stark_bigint_to_u256}; - use crate::{EthereumSettlementClient, Y_HIGH_POINT_OFFSET, Y_LOW_POINT_OFFSET}; + use crate::{EthereumSettlementClient, EthereumSettlementParams, Y_HIGH_POINT_OFFSET, Y_LOW_POINT_OFFSET}; #[rstest] #[tokio::test] diff --git a/crates/settlement-clients/starknet/src/config.rs b/crates/settlement-clients/starknet/src/config.rs index f7f595c9..9e93aaaf 100644 --- a/crates/settlement-clients/starknet/src/config.rs +++ b/crates/settlement-clients/starknet/src/config.rs @@ -31,3 +31,18 @@ impl StarknetSettlementConfig { StarknetSettlementConfig { rpc_url, core_contract_address, tx_finality_retry_delay_in_seconds } } } + +#[derive(Clone, Debug)] +pub struct StarknetSettlementParams { + pub starknet_rpc_url: Url, + + pub starknet_private_key: String, + + pub starknet_account_address: String, + + pub starknet_cairo_core_contract_address: String, + + pub starknet_finality_retry_wait_in_secs: u64, + + pub madara_binary_path: String, +} diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 33fee884..5072162d 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -10,6 +10,7 @@ use appchain_core_contract_client::interfaces::core_contract::CoreContract; use async_trait::async_trait; use color_eyre::eyre::eyre; use color_eyre::Result; +use config::StarknetSettlementParams; use crypto_bigint::Encoding; use lazy_static::lazy_static; use mockall::automock; @@ -22,7 +23,6 @@ use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Provider}; use starknet::signers::{LocalWallet, SigningKey}; use tokio::time::{sleep, Duration}; -use utils::cli::settlement::starknet::StarknetSettlementParams; use crate::conversion::{slice_slice_u8_to_vec_field, slice_u8_to_field, u64_from_felt}; diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index be29c94a..14cdb4fc 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -17,11 +17,11 @@ use starknet::macros::{felt, selector}; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Provider, ProviderError, Url}; use starknet::signers::{LocalWallet, SigningKey}; -use utils::cli::settlement::starknet::StarknetSettlementParams; use utils::settings::env::EnvSettingsProvider; use utils::settings::Settings; use super::setup::{wait_for_cond, MadaraCmd, MadaraCmdBuilder}; +use crate::config::StarknetSettlementParams; use crate::{LocalWalletSignerMiddleware, StarknetSettlementClient}; #[fixture] diff --git a/crates/utils/src/cli/alert/mod.rs b/crates/utils/src/cli/alert/mod.rs deleted file mode 100644 index 5a7b4b97..00000000 --- a/crates/utils/src/cli/alert/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -pub mod aws_sns; - -#[derive(Clone, Debug)] -pub enum AlertParams { - AWSSNS(aws_sns::AWSSNSParams), -} diff --git a/crates/utils/src/cli/database/mod.rs b/crates/utils/src/cli/database/mod.rs deleted file mode 100644 index 1d55f094..00000000 --- a/crates/utils/src/cli/database/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -pub mod mongodb; - -#[derive(Debug, Clone)] -pub enum DatabaseParams { - MongoDB(mongodb::MongoDBParams), -} diff --git a/crates/utils/src/cli/queue/aws_sqs.rs b/crates/utils/src/cli/queue/aws_sqs.rs deleted file mode 100644 index 0f98cd6f..00000000 --- a/crates/utils/src/cli/queue/aws_sqs.rs +++ /dev/null @@ -1,101 +0,0 @@ -use std::fmt; - -use clap::Args; -use serde::Serialize; - -/// Parameters used to config AWS SQS. -#[derive(Debug, Clone, Args)] -#[group(requires_all = ["sqs_prefix", "sqs_suffix", "queue_base_url"])] -pub struct AWSSQSCliArgs { - /// Use the AWS sqs client - #[arg(long)] - pub aws_sqs: bool, - - /// The name of the S3 bucket. - #[arg(env = "SQS_PREFIX", long, default_value = Some("madara_orchestrator"))] - pub sqs_prefix: Option, - - /// The suffix of the queue. - #[arg(env = "SQS_SUFFIX", long, default_value = Some("queue"))] - pub sqs_suffix: Option, - - /// The QUEUE url - #[arg(env = "SQS_BASE_QUEUE_URL", long)] - pub queue_base_url: Option, -} - -#[derive(Debug, Clone)] -pub struct AWSSQSParams { - pub queue_base_url: String, - pub sqs_prefix: String, - pub sqs_suffix: String, -} - -impl AWSSQSParams { - pub fn get_queue_url(&self, queue_type: QueueType) -> String { - format!("{}/{}", self.queue_base_url, self.get_queue_name(queue_type)) - } - - pub fn get_queue_name(&self, queue_type: QueueType) -> String { - // TODO: check if serde_json is the best way to convert the enum to string - let queue_name = serde_json::to_string(&queue_type).unwrap(); - format!("{}_{}_{}", self.sqs_prefix, queue_name, self.sqs_suffix) - } -} - -// TODO: Can we move this to the queue config? - -#[derive(Debug, Clone, Serialize, PartialEq, Eq)] -pub enum QueueType { - #[serde(rename = "snos_job_processing")] - SnosJobProcessing, - #[serde(rename = "snos_job_verification")] - SnosJobVerification, - #[serde(rename = "proving_job_processing")] - ProvingJobProcessing, - #[serde(rename = "proving_job_verification")] - ProvingJobVerification, - #[serde(rename = "proof_registration_job_processing")] - ProofRegistrationJobProcessing, - #[serde(rename = "proof_registration_job_verification")] - ProofRegistrationJobVerification, - #[serde(rename = "data_submission_job_processing")] - DataSubmissionJobProcessing, - #[serde(rename = "data_submission_job_verification")] - DataSubmissionJobVerification, - #[serde(rename = "update_state_job_processing")] - UpdateStateJobProcessing, - #[serde(rename = "update_state_job_verification")] - UpdateStateJobVerification, - #[serde(rename = "job_handle_failure")] - JobHandleFailure, - #[serde(rename = "worker_trigger")] - WorkerTrigger, -} - -impl QueueType { - pub fn iter() -> impl Iterator { - [ - QueueType::SnosJobProcessing, - QueueType::SnosJobVerification, - QueueType::ProvingJobProcessing, - QueueType::ProvingJobVerification, - QueueType::ProofRegistrationJobProcessing, - QueueType::ProofRegistrationJobVerification, - QueueType::DataSubmissionJobProcessing, - QueueType::DataSubmissionJobVerification, - QueueType::UpdateStateJobProcessing, - QueueType::UpdateStateJobVerification, - QueueType::JobHandleFailure, - QueueType::WorkerTrigger, - ] - .iter() - .cloned() - } -} - -impl fmt::Display for QueueType { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", serde_json::to_string(self).unwrap()) - } -} diff --git a/crates/utils/src/cli/settlement/mod.rs b/crates/utils/src/cli/settlement/mod.rs deleted file mode 100644 index 9149c0f4..00000000 --- a/crates/utils/src/cli/settlement/mod.rs +++ /dev/null @@ -1,8 +0,0 @@ -pub mod ethereum; -pub mod starknet; - -#[derive(Clone, Debug)] -pub enum SettlementParams { - Ethereum(ethereum::EthereumSettlementParams), - Starknet(starknet::StarknetSettlementParams), -} diff --git a/crates/utils/src/cli/storage/mod.rs b/crates/utils/src/cli/storage/mod.rs deleted file mode 100644 index 289aa036..00000000 --- a/crates/utils/src/cli/storage/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -pub mod aws_s3; - -#[derive(Clone, Debug)] -pub enum StorageParams { - AWSS3(aws_s3::AWSS3Params), -} diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs index f52d6000..e374f6c5 100644 --- a/crates/utils/src/lib.rs +++ b/crates/utils/src/lib.rs @@ -1,4 +1,3 @@ -pub mod cli; pub mod collections; pub mod env_utils; pub mod metrics; diff --git a/e2e-tests/src/localstack.rs b/e2e-tests/src/localstack.rs index fef15fe3..070d660c 100644 --- a/e2e-tests/src/localstack.rs +++ b/e2e-tests/src/localstack.rs @@ -8,13 +8,12 @@ use aws_sdk_eventbridge::types::{InputTransformer, RuleState, Target}; use aws_sdk_s3::config::ProvideCredentials; use aws_sdk_sqs::types::QueueAttributeName; use aws_sdk_sqs::types::QueueAttributeName::VisibilityTimeout; +use orchestrator::cli::aws_config::AWSConfigParams; use orchestrator::config::ProviderConfig; -use orchestrator::data_storage::aws_s3::AWSS3; +use orchestrator::data_storage::aws_s3::{AWSS3Params, AWSS3}; use orchestrator::data_storage::DataStorage; -use orchestrator::queue::job_queue::{JobQueueMessage, WorkerTriggerMessage, WorkerTriggerType}; -use utils::cli::aws_config::AWSConfigParams; -use utils::cli::queue::aws_sqs::{AWSSQSParams, QueueType}; -use utils::cli::storage::aws_s3::AWSS3Params; +use orchestrator::queue::job_queue::{JobQueueMessage, QueueType, WorkerTriggerMessage, WorkerTriggerType}; +use orchestrator::queue::sqs::AWSSQSParams; /// LocalStack struct pub struct LocalStack { diff --git a/e2e-tests/src/mongodb.rs b/e2e-tests/src/mongodb.rs index 3bafb0b6..a6daf955 100644 --- a/e2e-tests/src/mongodb.rs +++ b/e2e-tests/src/mongodb.rs @@ -1,7 +1,7 @@ use std::str::FromStr; +use orchestrator::database::mongodb::MongoDBParams; use url::Url; -use utils::cli::database::mongodb::MongoDBParams; #[allow(dead_code)] pub struct MongoDbServer { endpoint: Url, diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index 8f170ab9..166c7858 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -13,6 +13,10 @@ use e2e_tests::starknet_client::StarknetClient; use e2e_tests::utils::{get_mongo_db_client, read_state_update_from_file, vec_u8_to_hex_string}; use e2e_tests::{MongoDbServer, Orchestrator}; use mongodb::bson::doc; +use orchestrator::cli::database::DatabaseParams; +use orchestrator::cli::queue::QueueParams; +use orchestrator::cli::storage::StorageParams; +use orchestrator::cli::RunCmd; use orchestrator::data_storage::DataStorage; use orchestrator::jobs::constants::{JOB_METADATA_SNOS_BLOCK, JOB_METADATA_STATE_UPDATE_BLOCKS_TO_SETTLE_KEY}; use orchestrator::jobs::types::{ExternalId, JobItem, JobStatus, JobType}; @@ -21,10 +25,6 @@ use rstest::rstest; use serde::{Deserialize, Serialize}; use serde_json::json; use starknet::core::types::{Felt, MaybePendingStateUpdate}; -use utils::cli::database::DatabaseParams; -use utils::cli::queue::QueueParams; -use utils::cli::storage::StorageParams; -use utils::cli::RunCmd; use utils::env_utils::get_env_var_or_panic; use uuid::Uuid; From ee8195b5f8b69c04bad2a16224293e5e7fa0dfa4 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Thu, 7 Nov 2024 16:02:11 +0530 Subject: [PATCH 22/63] update: removed envsettingsprovider --- crates/da-clients/ethereum/src/config.rs | 27 ++---------- crates/da-clients/ethereum/src/lib.rs | 19 +-------- crates/orchestrator/src/cli/da/ethereum.rs | 7 +--- crates/orchestrator/src/cli/da/mod.rs | 4 +- crates/orchestrator/src/cli/database/mod.rs | 2 +- crates/orchestrator/src/cli/mod.rs | 12 +++--- crates/orchestrator/src/cli/prover/mod.rs | 2 +- crates/orchestrator/src/cli/storage/mod.rs | 2 +- .../src/data_storage/aws_s3/config.rs | 18 +------- .../src/data_storage/aws_s3/mod.rs | 6 +-- crates/orchestrator/src/data_storage/mod.rs | 8 ---- crates/orchestrator/src/database/mod.rs | 5 --- .../src/database/mongodb/config.rs | 20 ++------- .../orchestrator/src/database/mongodb/mod.rs | 7 +--- crates/orchestrator/src/tests/common/mod.rs | 3 +- .../prover-client-interface/src/lib.rs | 2 - .../sharp-service/src/client.rs | 13 +----- .../sharp-service/src/config.rs | 41 +++++-------------- .../prover-services/sharp-service/src/lib.rs | 2 +- .../sharp-service/tests/lib.rs | 4 +- .../settlement-clients/ethereum/src/config.rs | 21 ---------- .../settlement-clients/starknet/src/config.rs | 33 --------------- .../starknet/src/tests/test.rs | 39 ++++++++++-------- crates/utils/src/lib.rs | 1 - crates/utils/src/settings/env.rs | 11 ----- crates/utils/src/settings/mod.rs | 11 ----- e2e-tests/src/localstack.rs | 3 +- e2e-tests/src/mongodb.rs | 2 +- 28 files changed, 64 insertions(+), 261 deletions(-) delete mode 100644 crates/utils/src/settings/env.rs delete mode 100644 crates/utils/src/settings/mod.rs diff --git a/crates/da-clients/ethereum/src/config.rs b/crates/da-clients/ethereum/src/config.rs index 07885728..edfc7e58 100644 --- a/crates/da-clients/ethereum/src/config.rs +++ b/crates/da-clients/ethereum/src/config.rs @@ -1,29 +1,8 @@ -use std::str::FromStr; -use alloy::network::Ethereum; -use alloy::providers::ProviderBuilder; -use alloy::rpc::client::RpcClient; -use serde::{Deserialize, Serialize}; use url::Url; -use utils::settings::Settings; -use crate::EthereumDaClient; -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct EthereumDaConfig { - pub rpc_url: String, -} - -impl EthereumDaConfig { - pub fn new_with_settings(settings: &impl Settings) -> color_eyre::Result { - Ok(Self { rpc_url: settings.get_settings_or_panic("DA_RPC_URL") }) - } - - pub async fn build_client(&self) -> EthereumDaClient { - let client = - RpcClient::new_http(Url::from_str(self.rpc_url.as_str()).expect("Failed to parse SETTLEMENT_RPC_URL")); - let provider = ProviderBuilder::<_, Ethereum>::new().on_client(client); - - EthereumDaClient { provider } - } +#[derive(Debug, Clone)] +pub struct EthereumDaParams { + pub da_rpc_url: Url, } diff --git a/crates/da-clients/ethereum/src/lib.rs b/crates/da-clients/ethereum/src/lib.rs index e8c92d70..9d46b50b 100644 --- a/crates/da-clients/ethereum/src/lib.rs +++ b/crates/da-clients/ethereum/src/lib.rs @@ -1,11 +1,9 @@ #![allow(missing_docs)] #![allow(clippy::missing_docs_in_private_items)] -use std::str::FromStr; use alloy::network::Ethereum; -use alloy::providers::{ProviderBuilder, RootProvider}; -use alloy::rpc::client::RpcClient; +use alloy::providers::RootProvider; use alloy::transports::http::Http; use async_trait::async_trait; use color_eyre::Result; @@ -13,10 +11,6 @@ use da_client_interface::{DaClient, DaVerificationStatus}; use mockall::automock; use mockall::predicate::*; use reqwest::Client; -use url::Url; -use utils::settings::Settings; - -use crate::config::EthereumDaConfig; pub const DA_SETTINGS_NAME: &str = "ethereum"; @@ -47,14 +41,3 @@ impl DaClient for EthereumDaClient { 131072 } } - -impl EthereumDaClient { - pub fn new_with_settings(settings: &impl Settings) -> Self { - let config = EthereumDaConfig::new_with_settings(settings) - .expect("Not able to create EthereumDaClient from given settings."); - let client = - RpcClient::new_http(Url::from_str(config.rpc_url.as_str()).expect("Failed to parse SETTLEMENT_RPC_URL")); - let provider = ProviderBuilder::<_, Ethereum>::new().on_client(client); - EthereumDaClient { provider } - } -} diff --git a/crates/orchestrator/src/cli/da/ethereum.rs b/crates/orchestrator/src/cli/da/ethereum.rs index 0c75c757..ef6a25b1 100644 --- a/crates/orchestrator/src/cli/da/ethereum.rs +++ b/crates/orchestrator/src/cli/da/ethereum.rs @@ -4,7 +4,7 @@ use url::Url; /// Parameters used to config Ethereum. #[derive(Debug, Clone, Args)] #[group(requires_all = ["da_rpc_url"])] -pub struct EthereumDACliArgs { +pub struct EthereumDaCliArgs { /// Use the Ethereum DA layer. #[arg(long)] pub da_on_ethereum: bool, @@ -13,8 +13,3 @@ pub struct EthereumDACliArgs { #[arg(env = "DA_RPC_URL", long)] pub da_rpc_url: Option, } - -#[derive(Debug, Clone)] -pub struct EthereumDAParams { - pub da_rpc_url: Url, -} diff --git a/crates/orchestrator/src/cli/da/mod.rs b/crates/orchestrator/src/cli/da/mod.rs index 9425cd1c..1bd312a3 100644 --- a/crates/orchestrator/src/cli/da/mod.rs +++ b/crates/orchestrator/src/cli/da/mod.rs @@ -1,6 +1,8 @@ +use ethereum_da_client::config::EthereumDaParams; + pub mod ethereum; #[derive(Debug, Clone)] pub enum DaParams { - Ethereum(ethereum::EthereumDAParams), + Ethereum(EthereumDaParams), } diff --git a/crates/orchestrator/src/cli/database/mod.rs b/crates/orchestrator/src/cli/database/mod.rs index 5f80cfe6..36350dca 100644 --- a/crates/orchestrator/src/cli/database/mod.rs +++ b/crates/orchestrator/src/cli/database/mod.rs @@ -1,4 +1,4 @@ -use crate::database::mongodb::MongoDBParams; +use crate::database::mongodb::config::MongoDBParams; pub mod mongodb; diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index 08f1ac2d..be65e383 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -1,21 +1,21 @@ use alert::AlertParams; use aws_config::AWSConfigParams; use clap::{ArgGroup, Parser}; -use da::ethereum::EthereumDAParams; use da::DaParams; use database::DatabaseParams; +use ethereum_da_client::config::EthereumDaParams; use ethereum_settlement_client::config::EthereumSettlementParams; use prover::ProverParams; use queue::QueueParams; use settlement::SettlementParams; -use sharp_service::client::SharpParams; +use sharp_service::config::SharpParams; use starknet_settlement_client::config::StarknetSettlementParams; use storage::StorageParams; use url::Url; use crate::alerts::aws_sns::AWSSNSParams; -use crate::data_storage::aws_s3::AWSS3Params; -use crate::database::mongodb::MongoDBParams; +use crate::data_storage::aws_s3::config::AWSS3Params; +use crate::database::mongodb::config::MongoDBParams; use crate::queue::sqs::AWSSQSParams; use crate::routes::ServerParams; use crate::telemetry::InstrumentationParams; @@ -105,7 +105,7 @@ pub struct RunCmd { // Data Availability Layer #[clap(flatten)] - pub ethereum_da_args: da::ethereum::EthereumDACliArgs, + pub ethereum_da_args: da::ethereum::EthereumDaCliArgs, // Prover #[clap(flatten)] @@ -205,7 +205,7 @@ impl RunCmd { pub fn validate_da_params(&self) -> Result { if self.ethereum_da_args.da_on_ethereum { - Ok(DaParams::Ethereum(EthereumDAParams { da_rpc_url: self.ethereum_da_args.da_rpc_url.clone().unwrap() })) + Ok(DaParams::Ethereum(EthereumDaParams { da_rpc_url: self.ethereum_da_args.da_rpc_url.clone().unwrap() })) } else { Err("Only Ethereum is supported as of now".to_string()) } diff --git a/crates/orchestrator/src/cli/prover/mod.rs b/crates/orchestrator/src/cli/prover/mod.rs index 97eb4316..9bd8a00b 100644 --- a/crates/orchestrator/src/cli/prover/mod.rs +++ b/crates/orchestrator/src/cli/prover/mod.rs @@ -1,4 +1,4 @@ -use sharp_service::client::SharpParams; +use sharp_service::config::SharpParams; pub mod sharp; diff --git a/crates/orchestrator/src/cli/storage/mod.rs b/crates/orchestrator/src/cli/storage/mod.rs index e014db42..c6833f59 100644 --- a/crates/orchestrator/src/cli/storage/mod.rs +++ b/crates/orchestrator/src/cli/storage/mod.rs @@ -1,4 +1,4 @@ -use crate::data_storage::aws_s3::AWSS3Params; +use crate::data_storage::aws_s3::config::AWSS3Params; pub mod aws_s3; diff --git a/crates/orchestrator/src/data_storage/aws_s3/config.rs b/crates/orchestrator/src/data_storage/aws_s3/config.rs index 7217099a..2b65ac39 100644 --- a/crates/orchestrator/src/data_storage/aws_s3/config.rs +++ b/crates/orchestrator/src/data_storage/aws_s3/config.rs @@ -1,19 +1,5 @@ -use serde::{Deserialize, Serialize}; -use utils::settings::Settings; -use crate::data_storage::DataStorageConfig; - -/// Represents AWS S3 config struct with all the necessary variables. -#[derive(Clone, Serialize, Deserialize)] -pub struct AWSS3Config { - /// S3 Bucket Name +#[derive(Debug, Clone)] +pub struct AWSS3Params { pub bucket_name: String, } - -/// Implementation of `DataStorageConfig` for `AWSS3Config` -impl DataStorageConfig for AWSS3Config { - /// To return the config struct by creating it from the environment variables. - fn new_with_settings(settings: &impl Settings) -> Self { - Self { bucket_name: settings.get_settings_or_panic("AWS_S3_BUCKET_NAME") } - } -} diff --git a/crates/orchestrator/src/data_storage/aws_s3/mod.rs b/crates/orchestrator/src/data_storage/aws_s3/mod.rs index 6f8d015c..51489e6d 100644 --- a/crates/orchestrator/src/data_storage/aws_s3/mod.rs +++ b/crates/orchestrator/src/data_storage/aws_s3/mod.rs @@ -5,6 +5,7 @@ use aws_sdk_s3::primitives::ByteStream; use aws_sdk_s3::Client; use bytes::Bytes; use color_eyre::Result; +use config::AWSS3Params; use crate::config::ProviderConfig; use crate::data_storage::DataStorage; @@ -14,11 +15,6 @@ pub const S3_SETTINGS_NAME: &str = "s3"; /// Module for AWS S3 config structs and implementations pub mod config; -#[derive(Debug, Clone)] -pub struct AWSS3Params { - pub bucket_name: String, -} - /// AWSS3 represents AWS S3 client object containing the client and the config itself. pub struct AWSS3 { client: Client, diff --git a/crates/orchestrator/src/data_storage/mod.rs b/crates/orchestrator/src/data_storage/mod.rs index 6a7ba7f4..0b71e4c8 100644 --- a/crates/orchestrator/src/data_storage/mod.rs +++ b/crates/orchestrator/src/data_storage/mod.rs @@ -5,7 +5,6 @@ use async_trait::async_trait; use bytes::Bytes; use color_eyre::Result; use mockall::automock; -use utils::settings::Settings; /// Data Storage Trait /// @@ -23,10 +22,3 @@ pub trait DataStorage: Send + Sync { async fn put_data(&self, data: Bytes, key: &str) -> Result<()>; async fn build_test_bucket(&self, bucket_name: &str) -> Result<()>; } - -/// **DataStorageConfig** : Trait method to represent the config struct needed for -/// initialisation of data storage client -pub trait DataStorageConfig { - /// Get a config file from environment vars in system or - fn new_with_settings(settings: &impl Settings) -> Self; -} diff --git a/crates/orchestrator/src/database/mod.rs b/crates/orchestrator/src/database/mod.rs index 09c8ec3b..b2ff7554 100644 --- a/crates/orchestrator/src/database/mod.rs +++ b/crates/orchestrator/src/database/mod.rs @@ -2,7 +2,6 @@ use ::mongodb::bson::doc; use async_trait::async_trait; use color_eyre::Result; use mockall::automock; -use utils::settings::Settings; use uuid::Uuid; use crate::jobs::types::{JobItem, JobStatus, JobType}; @@ -51,7 +50,3 @@ pub trait Database: Send + Sync { // TODO: can be extendible to support multiple status. async fn get_jobs_by_statuses(&self, status: Vec, limit: Option) -> Result>; } - -pub trait DatabaseConfig { - fn new_with_settings(settings: &impl Settings) -> Self; -} diff --git a/crates/orchestrator/src/database/mongodb/config.rs b/crates/orchestrator/src/database/mongodb/config.rs index a41407b6..c4bf6f27 100644 --- a/crates/orchestrator/src/database/mongodb/config.rs +++ b/crates/orchestrator/src/database/mongodb/config.rs @@ -1,19 +1,5 @@ -use serde::{Deserialize, Serialize}; -use utils::settings::Settings; - -use crate::database::DatabaseConfig; - -#[derive(Debug, Serialize, Deserialize)] -pub struct MongoDbConfig { - pub url: String, +#[derive(Debug, Clone)] +pub struct MongoDBParams { + pub connection_url: String, pub database_name: String, } - -impl DatabaseConfig for MongoDbConfig { - fn new_with_settings(settings: &impl Settings) -> Self { - Self { - url: settings.get_settings_or_panic("MONGODB_CONNECTION_STRING"), - database_name: settings.get_settings_or_panic("DATABASE_NAME"), - } - } -} diff --git a/crates/orchestrator/src/database/mongodb/mod.rs b/crates/orchestrator/src/database/mongodb/mod.rs index f90e246f..0c377b53 100644 --- a/crates/orchestrator/src/database/mongodb/mod.rs +++ b/crates/orchestrator/src/database/mongodb/mod.rs @@ -3,6 +3,7 @@ use async_trait::async_trait; use chrono::{SubsecRound, Utc}; use color_eyre::eyre::eyre; use color_eyre::Result; +use config::MongoDBParams; use futures::TryStreamExt; use mongodb::bson::{doc, Bson, Document}; use mongodb::options::{ @@ -20,12 +21,6 @@ use crate::jobs::JobError; pub mod config; mod utils; -#[derive(Debug, Clone)] -pub struct MongoDBParams { - pub connection_url: String, - pub database_name: String, -} - pub struct MongoDb { client: Client, database_name: String, diff --git a/crates/orchestrator/src/tests/common/mod.rs b/crates/orchestrator/src/tests/common/mod.rs index 4d9e5a98..0e25c7d3 100644 --- a/crates/orchestrator/src/tests/common/mod.rs +++ b/crates/orchestrator/src/tests/common/mod.rs @@ -16,7 +16,8 @@ use utils::env_utils::get_env_var_or_panic; use crate::cli::database::DatabaseParams; use crate::cli::queue::QueueParams; use crate::config::ProviderConfig; -use crate::data_storage::aws_s3::{AWSS3Params, AWSS3}; +use crate::data_storage::aws_s3::config::AWSS3Params; +use crate::data_storage::aws_s3::AWSS3; use crate::data_storage::DataStorage; use crate::database::mongodb::MongoDb; use crate::jobs::types::JobStatus::Created; diff --git a/crates/prover-services/prover-client-interface/src/lib.rs b/crates/prover-services/prover-client-interface/src/lib.rs index 62299740..84d611a7 100644 --- a/crates/prover-services/prover-client-interface/src/lib.rs +++ b/crates/prover-services/prover-client-interface/src/lib.rs @@ -33,8 +33,6 @@ pub enum TaskStatus { pub enum ProverClientError { #[error("Internal prover error: {0}")] Internal(#[source] Box), - #[error("Settings provider error: {0}")] - SettingsProvider(#[from] utils::settings::SettingsProviderError), #[error("Task is invalid: {0}")] TaskInvalid(String), #[error("Fact checker error: {0}")] diff --git a/crates/prover-services/sharp-service/src/client.rs b/crates/prover-services/sharp-service/src/client.rs index 19157505..fb05b0e9 100644 --- a/crates/prover-services/sharp-service/src/client.rs +++ b/crates/prover-services/sharp-service/src/client.rs @@ -7,6 +7,7 @@ use url::Url; use utils::env_utils::get_env_var_or_panic; use uuid::Uuid; +use crate::config::SharpParams; use crate::error::SharpError; use crate::types::{SharpAddJobResponse, SharpGetStatusResponse}; @@ -123,15 +124,3 @@ fn add_params_to_url(url: &mut Url, params: Vec<(&str, &str)>) { pairs.append_pair(key, value); } } - -#[derive(Debug, Clone)] -pub struct SharpParams { - pub sharp_customer_id: String, - pub sharp_url: Url, - pub sharp_user_crt: String, - pub sharp_user_key: String, - pub sharp_rpc_node_url: Url, - pub sharp_server_crt: String, - pub sharp_proof_layout: String, - pub gps_verifier_contract_address: String, -} diff --git a/crates/prover-services/sharp-service/src/config.rs b/crates/prover-services/sharp-service/src/config.rs index b4e2cc8d..a1e49ef6 100644 --- a/crates/prover-services/sharp-service/src/config.rs +++ b/crates/prover-services/sharp-service/src/config.rs @@ -1,34 +1,13 @@ -use alloy::primitives::Address; -use serde::{Deserialize, Serialize}; use url::Url; -use utils::settings::Settings; -/// SHARP proving service configuration -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct SharpConfig { - /// SHARP service url - pub service_url: Url, - /// EVM RPC node url - pub rpc_node_url: Url, - /// GPS verifier contract address (implements FactRegistry) - pub verifier_address: Address, -} - -impl SharpConfig { - pub fn new_with_settings(settings: &impl Settings) -> color_eyre::Result { - Ok(Self { - service_url: settings - .get_settings_or_panic("SHARP_URL") - .parse() - .expect("Failed to parse to service url for SharpConfig"), - rpc_node_url: settings - .get_settings_or_panic("SETTLEMENT_RPC_URL") - .parse() - .expect("Failed to parse to rpc_node_url for SharpConfig"), - verifier_address: settings - .get_settings_or_panic("GPS_VERIFIER_CONTRACT_ADDRESS") - .parse() - .expect("Failed to parse to verifier_address for SharpConfig"), - }) - } +#[derive(Debug, Clone)] +pub struct SharpParams { + pub sharp_customer_id: String, + pub sharp_url: Url, + pub sharp_user_crt: String, + pub sharp_user_key: String, + pub sharp_rpc_node_url: Url, + pub sharp_server_crt: String, + pub sharp_proof_layout: String, + pub gps_verifier_contract_address: String, } diff --git a/crates/prover-services/sharp-service/src/lib.rs b/crates/prover-services/sharp-service/src/lib.rs index 47576de5..b26a9ecf 100644 --- a/crates/prover-services/sharp-service/src/lib.rs +++ b/crates/prover-services/sharp-service/src/lib.rs @@ -7,7 +7,7 @@ use std::str::FromStr; use alloy::primitives::B256; use async_trait::async_trait; -use client::SharpParams; +use config::SharpParams; use gps_fact_checker::FactChecker; use prover_client_interface::{ProverClient, ProverClientError, Task, TaskStatus}; use starknet_os::sharp::CairoJobStatus; diff --git a/crates/prover-services/sharp-service/tests/lib.rs b/crates/prover-services/sharp-service/tests/lib.rs index 309af91a..29c1c691 100644 --- a/crates/prover-services/sharp-service/tests/lib.rs +++ b/crates/prover-services/sharp-service/tests/lib.rs @@ -6,7 +6,7 @@ use prover_client_interface::ProverClient; use prover_client_interface::{Task, TaskStatus}; use rstest::rstest; use serde_json::json; -use sharp_service::client::SharpParams; +use sharp_service::config::SharpParams; use sharp_service::SharpProverService; use starknet_os::sharp::CairoJobStatus; use url::Url; @@ -64,8 +64,6 @@ async fn prover_client_submit_task_works() { #[case(CairoJobStatus::ONCHAIN)] #[tokio::test] async fn prover_client_get_task_status_works(#[case] cairo_job_status: CairoJobStatus) { - use sharp_service::client::SharpParams; - dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); let sharp_params = SharpParams { diff --git a/crates/settlement-clients/ethereum/src/config.rs b/crates/settlement-clients/ethereum/src/config.rs index 489aaf5a..e1779cbc 100644 --- a/crates/settlement-clients/ethereum/src/config.rs +++ b/crates/settlement-clients/ethereum/src/config.rs @@ -1,26 +1,5 @@ -use std::str::FromStr; -use serde::{Deserialize, Serialize}; use url::Url; -use utils::settings::Settings; - -pub const SETTLEMENT_RPC_URL: &str = "SETTLEMENT_RPC_URL"; -pub const L1_CORE_CONTRACT_ADDRESS: &str = "L1_CORE_CONTRACT_ADDRESS"; - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct EthereumSettlementConfig { - pub rpc_url: Url, - pub core_contract_address: String, -} - -impl EthereumSettlementConfig { - pub fn new_with_settings(settings: &impl Settings) -> Self { - let rpc_url = settings.get_settings_or_panic(SETTLEMENT_RPC_URL); - let rpc_url = Url::from_str(&rpc_url).unwrap_or_else(|_| panic!("Failed to parse {}", SETTLEMENT_RPC_URL)); - let core_contract_address = settings.get_settings_or_panic(L1_CORE_CONTRACT_ADDRESS); - Self { rpc_url, core_contract_address } - } -} #[derive(Clone, Debug)] pub struct EthereumSettlementParams { diff --git a/crates/settlement-clients/starknet/src/config.rs b/crates/settlement-clients/starknet/src/config.rs index 9e93aaaf..fc803011 100644 --- a/crates/settlement-clients/starknet/src/config.rs +++ b/crates/settlement-clients/starknet/src/config.rs @@ -1,37 +1,4 @@ -use std::str::FromStr; - -use serde::{Deserialize, Serialize}; use url::Url; -use utils::env_utils::get_env_var_or_default; -use utils::settings::Settings; - -pub const ENV_STARKNET_RPC_URL: &str = "STARKNET_RPC_URL"; -pub const ENV_CORE_CONTRACT_ADDRESS: &str = "STARKNET_CAIRO_CORE_CONTRACT_ADDRESS"; - -pub const ENV_STARKNET_FINALITY_RETRY_DELAY_IN_SECS: &str = "STARKNET_FINALITY_RETRY_WAIT_IN_SECS"; -pub const DEFAULT_FINALITY_RETRY_DELAY: &str = "60"; - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct StarknetSettlementConfig { - pub rpc_url: Url, - pub core_contract_address: String, - pub tx_finality_retry_delay_in_seconds: u64, -} - -impl StarknetSettlementConfig { - /// Should create a new instance of the DaConfig from the environment variables - pub fn new_with_settings(settings: &impl Settings) -> Self { - let rpc_url = settings.get_settings_or_panic(ENV_STARKNET_RPC_URL); - let rpc_url = Url::from_str(&rpc_url).unwrap_or_else(|_| panic!("Failed to parse {}", ENV_STARKNET_RPC_URL)); - let core_contract_address = settings.get_settings_or_panic(ENV_CORE_CONTRACT_ADDRESS); - let tx_finality_retry_delay_in_seconds: u64 = - get_env_var_or_default(ENV_STARKNET_FINALITY_RETRY_DELAY_IN_SECS, DEFAULT_FINALITY_RETRY_DELAY) - .parse() - .expect("STARKNET_FINALITY_RETRY_WAIT_IN_SECS should be a delay in seconds"); - StarknetSettlementConfig { rpc_url, core_contract_address, tx_finality_retry_delay_in_seconds } - } -} - #[derive(Clone, Debug)] pub struct StarknetSettlementParams { pub starknet_rpc_url: Url, diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 14cdb4fc..e4b494d1 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -17,8 +17,7 @@ use starknet::macros::{felt, selector}; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Provider, ProviderError, Url}; use starknet::signers::{LocalWallet, SigningKey}; -use utils::settings::env::EnvSettingsProvider; -use utils::settings::Settings; +use utils::env_utils::get_env_var_or_panic; use super::setup::{wait_for_cond, MadaraCmd, MadaraCmdBuilder}; use crate::config::StarknetSettlementParams; @@ -80,16 +79,25 @@ async fn wait_for_tx(account: &LocalWalletSignerMiddleware, transaction_hash: Fe #[fixture] async fn setup(#[future] spin_up_madara: MadaraCmd) -> (LocalWalletSignerMiddleware, MadaraCmd) { let madara_process = spin_up_madara.await; - env::set_var("STARKNET_RPC_URL", madara_process.rpc_url.to_string()); - let env_settings = EnvSettingsProvider::default(); - let rpc_url = Url::parse(&env_settings.get_settings_or_panic("STARKNET_RPC_URL")).unwrap(); + let starknet_settlement_params: StarknetSettlementParams = StarknetSettlementParams { + starknet_rpc_url: Url::parse(madara_process.rpc_url.as_ref()).unwrap(), + starknet_private_key: get_env_var_or_panic("STARKNET_PRIVATE_KEY"), + starknet_account_address: get_env_var_or_panic("STARKNET_ACCOUNT_ADDRESS"), + starknet_cairo_core_contract_address: get_env_var_or_panic("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS"), + starknet_finality_retry_wait_in_secs: get_env_var_or_panic("STARKNET_FINALITY_RETRY_WAIT_IN_SECS") + .parse::() + .unwrap(), + madara_binary_path: get_env_var_or_panic("MADARA_BINARY_PATH"), + }; + + let rpc_url = Url::parse(starknet_settlement_params.starknet_rpc_url.as_ref()).unwrap(); let provider = Arc::new(JsonRpcClient::new(HttpTransport::new(rpc_url))); let signer = LocalWallet::from(SigningKey::from_secret_scalar( - Felt::from_hex(&env_settings.get_settings_or_panic("STARKNET_PRIVATE_KEY")).expect("Invalid private key"), + Felt::from_hex(&starknet_settlement_params.starknet_private_key).expect("Invalid private key"), )); - let address = Felt::from_hex(&env_settings.get_settings_or_panic("STARKNET_ACCOUNT_ADDRESS")).unwrap(); + let address = Felt::from_hex(&starknet_settlement_params.starknet_account_address).unwrap(); let chain_id = provider.chain_id().await.unwrap(); let mut account = SingleOwnerAccount::new(provider, signer, address, chain_id, ExecutionEncoding::New); @@ -105,18 +113,15 @@ async fn setup(#[future] spin_up_madara: MadaraCmd) -> (LocalWalletSignerMiddlew async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) { dotenvy::from_filename_override(".env.test").expect("Failed to load the .env file"); - let env_settings = EnvSettingsProvider::default(); - let starknet_settlement_params = StarknetSettlementParams { - starknet_rpc_url: Url::parse(&env_settings.get_settings_or_panic("STARKNET_RPC_URL")).unwrap(), - starknet_private_key: env_settings.get_settings_or_panic("STARKNET_PRIVATE_KEY"), - starknet_account_address: env_settings.get_settings_or_panic("STARKNET_ACCOUNT_ADDRESS"), - starknet_cairo_core_contract_address: env_settings - .get_settings_or_panic("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS"), - starknet_finality_retry_wait_in_secs: env_settings - .get_settings_or_panic("STARKNET_FINALITY_RETRY_WAIT_IN_SECS") + let starknet_settlement_params: StarknetSettlementParams = StarknetSettlementParams { + starknet_rpc_url: Url::parse(&get_env_var_or_panic("STARKNET_RPC_URL")).unwrap(), + starknet_private_key: get_env_var_or_panic("STARKNET_PRIVATE_KEY"), + starknet_account_address: get_env_var_or_panic("STARKNET_ACCOUNT_ADDRESS"), + starknet_cairo_core_contract_address: get_env_var_or_panic("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS"), + starknet_finality_retry_wait_in_secs: get_env_var_or_panic("STARKNET_FINALITY_RETRY_WAIT_IN_SECS") .parse::() .unwrap(), - madara_binary_path: env_settings.get_settings_or_panic("MADARA_BINARY_PATH"), + madara_binary_path: get_env_var_or_panic("MADARA_BINARY_PATH"), }; let (account, _madara_process) = setup.await; diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs index e374f6c5..4d922e85 100644 --- a/crates/utils/src/lib.rs +++ b/crates/utils/src/lib.rs @@ -1,7 +1,6 @@ pub mod collections; pub mod env_utils; pub mod metrics; -pub mod settings; /// Evaluate `$x:expr` and if not true return `Err($y:expr)`. /// diff --git a/crates/utils/src/settings/env.rs b/crates/utils/src/settings/env.rs deleted file mode 100644 index 6a5962f0..00000000 --- a/crates/utils/src/settings/env.rs +++ /dev/null @@ -1,11 +0,0 @@ -use crate::env_utils::get_env_var_or_panic; -use crate::settings::Settings; - -#[derive(Debug, Clone, Default)] -pub struct EnvSettingsProvider {} - -impl Settings for EnvSettingsProvider { - fn get_settings_or_panic(&self, name: &'static str) -> String { - get_env_var_or_panic(name) - } -} diff --git a/crates/utils/src/settings/mod.rs b/crates/utils/src/settings/mod.rs deleted file mode 100644 index 05b0d787..00000000 --- a/crates/utils/src/settings/mod.rs +++ /dev/null @@ -1,11 +0,0 @@ -pub mod env; - -#[derive(Debug, thiserror::Error)] -pub enum SettingsProviderError { - #[error("Internal settings error: {0}")] - Internal(#[source] Box), -} - -pub trait Settings { - fn get_settings_or_panic(&self, name: &'static str) -> String; -} diff --git a/e2e-tests/src/localstack.rs b/e2e-tests/src/localstack.rs index 070d660c..3148e256 100644 --- a/e2e-tests/src/localstack.rs +++ b/e2e-tests/src/localstack.rs @@ -10,7 +10,8 @@ use aws_sdk_sqs::types::QueueAttributeName; use aws_sdk_sqs::types::QueueAttributeName::VisibilityTimeout; use orchestrator::cli::aws_config::AWSConfigParams; use orchestrator::config::ProviderConfig; -use orchestrator::data_storage::aws_s3::{AWSS3Params, AWSS3}; +use orchestrator::data_storage::aws_s3::config::AWSS3Params; +use orchestrator::data_storage::aws_s3::AWSS3; use orchestrator::data_storage::DataStorage; use orchestrator::queue::job_queue::{JobQueueMessage, QueueType, WorkerTriggerMessage, WorkerTriggerType}; use orchestrator::queue::sqs::AWSSQSParams; diff --git a/e2e-tests/src/mongodb.rs b/e2e-tests/src/mongodb.rs index a6daf955..620736c8 100644 --- a/e2e-tests/src/mongodb.rs +++ b/e2e-tests/src/mongodb.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use orchestrator::database::mongodb::MongoDBParams; +use orchestrator::database::mongodb::config::MongoDBParams; use url::Url; #[allow(dead_code)] pub struct MongoDbServer { From da11a0b46d28a84a87d508d5b5002a219738a7d5 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Thu, 7 Nov 2024 16:13:12 +0530 Subject: [PATCH 23/63] update: removed serde added strum for queuetype --- Cargo.lock | 1 + crates/orchestrator/Cargo.toml | 3 +- crates/orchestrator/src/queue/job_queue.rs | 37 ++++++++++------------ 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 511e9b26..9d361f0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6987,6 +6987,7 @@ dependencies = [ "starknet-core 0.9.0", "starknet-os", "starknet-settlement-client", + "strum 0.26.2", "strum_macros 0.26.4", "tempfile", "thiserror", diff --git a/crates/orchestrator/Cargo.toml b/crates/orchestrator/Cargo.toml index d4a85e28..26bf57bb 100644 --- a/crates/orchestrator/Cargo.toml +++ b/crates/orchestrator/Cargo.toml @@ -71,7 +71,8 @@ starknet = { workspace = true } starknet-core = "0.9.0" starknet-os = { workspace = true } starknet-settlement-client = { workspace = true } -strum_macros = "0.26.4" +strum = "0.26.0" +strum_macros = "0.26.0" tempfile = { workspace = true } thiserror = { workspace = true } tokio = { workspace = true, features = ["sync", "macros", "rt-multi-thread"] } diff --git a/crates/orchestrator/src/queue/job_queue.rs b/crates/orchestrator/src/queue/job_queue.rs index c1219160..ff588e64 100644 --- a/crates/orchestrator/src/queue/job_queue.rs +++ b/crates/orchestrator/src/queue/job_queue.rs @@ -1,4 +1,3 @@ -use std::fmt; use std::future::Future; use std::str::FromStr; use std::sync::Arc; @@ -21,35 +20,37 @@ use crate::workers::proving::ProvingWorker; use crate::workers::snos::SnosWorker; use crate::workers::update_state::UpdateStateWorker; use crate::workers::Worker; +use strum_macros::Display; -#[derive(Debug, Clone, Serialize, PartialEq, Eq)] -pub enum QueueType { - #[serde(rename = "snos_job_processing")] +#[derive(Display, Debug, Clone, PartialEq, Eq)] +enum QueueType { + #[strum(serialize = "snos_job_processing")] SnosJobProcessing, - #[serde(rename = "snos_job_verification")] + #[strum(serialize = "snos_job_verification")] SnosJobVerification, - #[serde(rename = "proving_job_processing")] + #[strum(serialize = "proving_job_processing")] ProvingJobProcessing, - #[serde(rename = "proving_job_verification")] + #[strum(serialize = "proving_job_verification")] ProvingJobVerification, - #[serde(rename = "proof_registration_job_processing")] + #[strum(serialize = "proof_registration_job_processing")] ProofRegistrationJobProcessing, - #[serde(rename = "proof_registration_job_verification")] + #[strum(serialize = "proof_registration_job_verification")] ProofRegistrationJobVerification, - #[serde(rename = "data_submission_job_processing")] + #[strum(serialize = "data_submission_job_processing")] DataSubmissionJobProcessing, - #[serde(rename = "data_submission_job_verification")] + #[strum(serialize = "data_submission_job_verification")] DataSubmissionJobVerification, - #[serde(rename = "update_state_job_processing")] + #[strum(serialize = "update_state_job_processing")] UpdateStateJobProcessing, - #[serde(rename = "update_state_job_verification")] + #[strum(serialize = "update_state_job_verification")] UpdateStateJobVerification, - #[serde(rename = "job_handle_failure")] + #[strum(serialize = "job_handle_failure")] JobHandleFailure, - #[serde(rename = "worker_trigger")] + #[strum(serialize = "worker_trigger")] WorkerTrigger, } + impl QueueType { pub fn iter() -> impl Iterator { [ @@ -71,12 +72,6 @@ impl QueueType { } } -impl fmt::Display for QueueType { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", serde_json::to_string(self).unwrap()) - } -} - #[derive(Error, Debug, PartialEq)] pub enum ConsumptionError { #[error("Failed to consume message from queue, error {error_msg:?}")] From 3fc6d65f47f1afbd41ed4bdba69de6e49b0c393f Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Thu, 7 Nov 2024 16:37:16 +0530 Subject: [PATCH 24/63] update: added orchestrator config --- crates/da-clients/ethereum/src/config.rs | 2 - crates/da-clients/ethereum/src/lib.rs | 1 - crates/orchestrator/src/cli/mod.rs | 17 +++++ crates/orchestrator/src/cli/service.rs | 13 ++++ crates/orchestrator/src/cli/snos.rs | 11 +--- crates/orchestrator/src/config.rs | 62 +++++++++---------- .../src/data_storage/aws_s3/config.rs | 1 - crates/orchestrator/src/jobs/snos_job/mod.rs | 2 +- crates/orchestrator/src/queue/job_queue.rs | 5 +- crates/orchestrator/src/queue/sqs/mod.rs | 4 +- crates/orchestrator/src/tests/config.rs | 16 +++-- crates/orchestrator/src/workers/snos.rs | 4 +- .../settlement-clients/ethereum/src/config.rs | 1 - 13 files changed, 73 insertions(+), 66 deletions(-) create mode 100644 crates/orchestrator/src/cli/service.rs diff --git a/crates/da-clients/ethereum/src/config.rs b/crates/da-clients/ethereum/src/config.rs index edfc7e58..4471e1ce 100644 --- a/crates/da-clients/ethereum/src/config.rs +++ b/crates/da-clients/ethereum/src/config.rs @@ -1,7 +1,5 @@ - use url::Url; - #[derive(Debug, Clone)] pub struct EthereumDaParams { pub da_rpc_url: Url, diff --git a/crates/da-clients/ethereum/src/lib.rs b/crates/da-clients/ethereum/src/lib.rs index 9d46b50b..2504932f 100644 --- a/crates/da-clients/ethereum/src/lib.rs +++ b/crates/da-clients/ethereum/src/lib.rs @@ -1,7 +1,6 @@ #![allow(missing_docs)] #![allow(clippy::missing_docs_in_private_items)] - use alloy::network::Ethereum; use alloy::providers::RootProvider; use alloy::transports::http::Http; diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index be65e383..a3fdeb49 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -9,11 +9,13 @@ use prover::ProverParams; use queue::QueueParams; use settlement::SettlementParams; use sharp_service::config::SharpParams; +use snos::SNOSParams; use starknet_settlement_client::config::StarknetSettlementParams; use storage::StorageParams; use url::Url; use crate::alerts::aws_sns::AWSSNSParams; +use crate::config::ServiceParams; use crate::data_storage::aws_s3::config::AWSS3Params; use crate::database::mongodb::config::MongoDBParams; use crate::queue::sqs::AWSSQSParams; @@ -28,6 +30,7 @@ pub mod instrumentation; pub mod prover; pub mod queue; pub mod server; +pub mod service; pub mod settlement; pub mod snos; pub mod storage; @@ -118,6 +121,9 @@ pub struct RunCmd { #[arg(env = "MADARA_RPC_URL", long, required = true)] pub madara_rpc_url: Url, + // Service + #[clap(flatten)] + pub service_args: service::ServiceCliArgs, #[clap(flatten)] pub instrumentation_args: instrumentation::InstrumentationCliArgs, } @@ -239,4 +245,15 @@ impl RunCmd { pub fn validate_server_params(&self) -> Result { Ok(ServerParams { host: self.server_args.host.clone(), port: self.server_args.port }) } + + pub fn validate_service_params(&self) -> Result { + Ok(ServiceParams { + max_block_to_process: self.service_args.max_block_to_process, + min_block_to_process: self.service_args.min_block_to_process, + }) + } + + pub fn validate_snos_params(&self) -> Result { + Ok(SNOSParams { rpc_for_snos: self.snos_args.rpc_for_snos.clone() }) + } } diff --git a/crates/orchestrator/src/cli/service.rs b/crates/orchestrator/src/cli/service.rs new file mode 100644 index 00000000..fe82a226 --- /dev/null +++ b/crates/orchestrator/src/cli/service.rs @@ -0,0 +1,13 @@ +use clap::Args; + +#[derive(Debug, Clone, Args)] +#[group(requires_all = ["rpc_for_snos"])] +pub struct ServiceCliArgs { + /// The maximum block to process. + #[arg(env = "MAX_BLOCK_TO_PROCESS", long)] + pub max_block_to_process: Option, + + /// The minimum block to process. + #[arg(env = "MIN_BLOCK_TO_PROCESS", long)] + pub min_block_to_process: Option, +} diff --git a/crates/orchestrator/src/cli/snos.rs b/crates/orchestrator/src/cli/snos.rs index 26e9d7d3..1fb81504 100644 --- a/crates/orchestrator/src/cli/snos.rs +++ b/crates/orchestrator/src/cli/snos.rs @@ -7,18 +7,9 @@ pub struct SNOSCliArgs { /// The RPC URL for SNOS. #[arg(env = "RPC_FOR_SNOS", long)] pub rpc_for_snos: Url, - - /// The maximum block to process. - #[arg(env = "MAX_BLOCK_TO_PROCESS", long)] - pub max_block_to_process: Option, - - /// The minimum block to process. - #[arg(env = "MIN_BLOCK_TO_PROCESS", long)] - pub min_block_to_process: Option, } + #[derive(Debug, Clone)] pub struct SNOSParams { pub rpc_for_snos: Url, - pub max_block_to_process: Option, - pub min_block_to_process: Option, } diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index b715f33e..828da38a 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -24,6 +24,7 @@ use crate::cli::database::DatabaseParams; use crate::cli::prover::ProverParams; use crate::cli::queue::QueueParams; use crate::cli::settlement::SettlementParams; +use crate::cli::snos::SNOSParams; use crate::cli::storage::StorageParams; use crate::cli::RunCmd; use crate::data_storage::aws_s3::AWSS3; @@ -37,14 +38,8 @@ use crate::routes::ServerParams; /// The app config. It can be accessed from anywhere inside the service /// by calling `config` function. pub struct Config { - /// The RPC url used by the [starknet_client] - starknet_rpc_url: Url, - - server_config: ServerParams, - /// The RPC url to be used when running SNOS - /// When Madara supports getProof, we can re use - /// starknet_rpc_url for SNOS as well - pub snos_config: SnosConfig, + /// The orchestrator config + orchestrator_config: OrchestratorConfig, /// The starknet client to get data from the node starknet_client: Arc>, /// The DA client to interact with the DA layer @@ -64,12 +59,18 @@ pub struct Config { } #[derive(Debug, Clone)] -pub struct SnosConfig { - pub rpc_url: Url, +pub struct ServiceParams { pub max_block_to_process: Option, pub min_block_to_process: Option, } +pub struct OrchestratorConfig { + pub madara_rpc_url: Url, + pub snos_config: SNOSParams, + pub service_config: ServiceParams, + pub server_config: ServerParams, +} + /// `ProviderConfig` is an enum used to represent the global config built /// using the settings provider. More providers can be added eg : GCP, AZURE etc. /// @@ -104,18 +105,14 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { let aws_config = &run_cmd.aws_config_args; let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(aws_config).await))); - // init starknet client - let rpc_url = run_cmd.madara_rpc_url.clone(); - - // init snos url - let snos_config = SnosConfig { - rpc_url: run_cmd.snos_args.rpc_for_snos.clone(), - max_block_to_process: run_cmd.snos_args.max_block_to_process, - min_block_to_process: run_cmd.snos_args.min_block_to_process, + let orchestrator_config = OrchestratorConfig { + madara_rpc_url: run_cmd.madara_rpc_url.clone(), + snos_config: run_cmd.validate_snos_params().expect("Failed to validate SNOS params"), + service_config: run_cmd.validate_service_params().expect("Failed to validate service params"), + server_config: run_cmd.validate_server_params().expect("Failed to validate server params"), }; - let server_config = run_cmd.validate_server_params().map_err(|e| eyre!("Failed to validate server params: {e}"))?; - let provider = JsonRpcClient::new(HttpTransport::new(rpc_url.clone())); + let provider = JsonRpcClient::new(HttpTransport::new(orchestrator_config.madara_rpc_url.clone())); // init database let database_params = @@ -153,9 +150,7 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { let queue = build_queue_client(&queue_params); Ok(Arc::new(Config::new( - rpc_url, - server_config, - snos_config, + orchestrator_config, Arc::new(provider), da_client, prover_client, @@ -171,9 +166,7 @@ impl Config { /// Create a new config #[allow(clippy::too_many_arguments)] pub fn new( - starknet_rpc_url: Url, - server_config: ServerParams, - snos_config: SnosConfig, + orchestrator_config: OrchestratorConfig, starknet_client: Arc>, da_client: Box, prover_client: Box, @@ -184,9 +177,7 @@ impl Config { alerts: Box, ) -> Self { Self { - starknet_rpc_url, - server_config, - snos_config, + orchestrator_config, starknet_client, da_client, prover_client, @@ -200,17 +191,22 @@ impl Config { /// Returns the starknet rpc url pub fn starknet_rpc_url(&self) -> &Url { - &self.starknet_rpc_url + &self.orchestrator_config.madara_rpc_url } /// Returns the server config pub fn server_config(&self) -> &ServerParams { - &self.server_config + &self.orchestrator_config.server_config } /// Returns the snos rpc url - pub fn snos_config(&self) -> &SnosConfig { - &self.snos_config + pub fn snos_config(&self) -> &SNOSParams { + &self.orchestrator_config.snos_config + } + + /// Returns the service config + pub fn service_config(&self) -> &ServiceParams { + &self.orchestrator_config.service_config } /// Returns the starknet client diff --git a/crates/orchestrator/src/data_storage/aws_s3/config.rs b/crates/orchestrator/src/data_storage/aws_s3/config.rs index 2b65ac39..ba8bd1dd 100644 --- a/crates/orchestrator/src/data_storage/aws_s3/config.rs +++ b/crates/orchestrator/src/data_storage/aws_s3/config.rs @@ -1,4 +1,3 @@ - #[derive(Debug, Clone)] pub struct AWSS3Params { pub bucket_name: String, diff --git a/crates/orchestrator/src/jobs/snos_job/mod.rs b/crates/orchestrator/src/jobs/snos_job/mod.rs index 2573b16b..c82d48c3 100644 --- a/crates/orchestrator/src/jobs/snos_job/mod.rs +++ b/crates/orchestrator/src/jobs/snos_job/mod.rs @@ -103,7 +103,7 @@ impl Job for SnosJob { let block_number = self.get_block_number_from_metadata(job)?; tracing::debug!(job_id = %job.internal_id, block_number = %block_number, "Retrieved block number from metadata"); - let snos_url = config.snos_config().rpc_url.to_string(); + let snos_url = config.snos_config().rpc_for_snos.to_string(); let snos_url = snos_url.trim_end_matches('/'); tracing::debug!(job_id = %job.internal_id, "Calling prove_block function"); let (cairo_pie, snos_output) = diff --git a/crates/orchestrator/src/queue/job_queue.rs b/crates/orchestrator/src/queue/job_queue.rs index ff588e64..f7a07cdd 100644 --- a/crates/orchestrator/src/queue/job_queue.rs +++ b/crates/orchestrator/src/queue/job_queue.rs @@ -7,6 +7,7 @@ use color_eyre::eyre::Context; use color_eyre::Result as EyreResult; use omniqueue::{Delivery, QueueError}; use serde::{Deserialize, Deserializer, Serialize}; +use strum_macros::Display; use thiserror::Error; use tokio::time::sleep; use uuid::Uuid; @@ -20,10 +21,9 @@ use crate::workers::proving::ProvingWorker; use crate::workers::snos::SnosWorker; use crate::workers::update_state::UpdateStateWorker; use crate::workers::Worker; -use strum_macros::Display; #[derive(Display, Debug, Clone, PartialEq, Eq)] -enum QueueType { +pub enum QueueType { #[strum(serialize = "snos_job_processing")] SnosJobProcessing, #[strum(serialize = "snos_job_verification")] @@ -50,7 +50,6 @@ enum QueueType { WorkerTrigger, } - impl QueueType { pub fn iter() -> impl Iterator { [ diff --git a/crates/orchestrator/src/queue/sqs/mod.rs b/crates/orchestrator/src/queue/sqs/mod.rs index 973a1bc7..48e1f0e9 100644 --- a/crates/orchestrator/src/queue/sqs/mod.rs +++ b/crates/orchestrator/src/queue/sqs/mod.rs @@ -21,9 +21,7 @@ impl AWSSQSParams { } pub fn get_queue_name(&self, queue_type: QueueType) -> String { - // TODO: check if serde_json is the best way to convert the enum to string - let queue_name = serde_json::to_string(&queue_type).unwrap(); - format!("{}_{}_{}", self.sqs_prefix, queue_name, self.sqs_suffix) + format!("{}_{}_{}", self.sqs_prefix, queue_type, self.sqs_suffix) } } diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 90916f3d..73685d33 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -14,7 +14,7 @@ use url::Url; use crate::alerts::Alerts; use crate::cli::RunCmd; -use crate::config::{get_aws_config, Config, ProviderConfig, SnosConfig}; +use crate::config::{get_aws_config, Config, OrchestratorConfig, ProviderConfig}; use crate::data_storage::{DataStorage, MockDataStorage}; use crate::database::{Database, MockDatabase}; use crate::queue::{MockQueueProvider, QueueProvider}; @@ -185,12 +185,12 @@ impl TestConfigBuilder { let aws_config = &run_cmd.aws_config_args; let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(aws_config).await))); - let server_config = run_cmd.validate_server_params().expect("Failed to validate server params"); - let snos_config = SnosConfig { - rpc_url: run_cmd.snos_args.rpc_for_snos.clone(), - max_block_to_process: run_cmd.snos_args.max_block_to_process, - min_block_to_process: run_cmd.snos_args.min_block_to_process, + let orchestrator_config = OrchestratorConfig { + madara_rpc_url: run_cmd.madara_rpc_url.clone(), + snos_config: run_cmd.validate_snos_params().expect("Failed to validate SNOS params"), + service_config: run_cmd.validate_service_params().expect("Failed to validate service params"), + server_config: run_cmd.validate_server_params().expect("Failed to validate server params"), }; let TestConfigBuilder { @@ -243,9 +243,7 @@ impl TestConfigBuilder { create_sns_arn(provider_config.clone()).await.expect("Unable to create the sns arn"); let config = Arc::new(Config::new( - starknet_rpc_url, - server_config, - snos_config, + orchestrator_config, starknet_client, da_client, prover_client, diff --git a/crates/orchestrator/src/workers/snos.rs b/crates/orchestrator/src/workers/snos.rs index a38a5acd..deb66500 100644 --- a/crates/orchestrator/src/workers/snos.rs +++ b/crates/orchestrator/src/workers/snos.rs @@ -22,7 +22,7 @@ impl Worker for SnosWorker { let provider = config.starknet_client(); let block_number_provider = provider.block_number().await?; - let latest_block_number = if let Some(max_block_to_process) = config.snos_config.max_block_to_process { + let latest_block_number = if let Some(max_block_to_process) = config.service_config().max_block_to_process { max_block_to_process } else { block_number_provider @@ -40,7 +40,7 @@ impl Worker for SnosWorker { .unwrap(); // To be used when testing in specific block range - let block_start = if let Some(min_block_to_process) = config.snos_config.min_block_to_process { + let block_start = if let Some(min_block_to_process) = config.service_config().min_block_to_process { min_block_to_process } else { latest_job_id diff --git a/crates/settlement-clients/ethereum/src/config.rs b/crates/settlement-clients/ethereum/src/config.rs index e1779cbc..cf6ea1ab 100644 --- a/crates/settlement-clients/ethereum/src/config.rs +++ b/crates/settlement-clients/ethereum/src/config.rs @@ -1,4 +1,3 @@ - use url::Url; #[derive(Clone, Debug)] From 752998622283abe22ee777cdc29279a623bc145f Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Thu, 7 Nov 2024 19:00:06 +0530 Subject: [PATCH 25/63] update: env vars renamed --- .env.test | 140 +++++++++--------- crates/orchestrator/src/cli/alert/aws_sns.rs | 2 +- crates/orchestrator/src/cli/aws_config.rs | 8 +- crates/orchestrator/src/cli/da/ethereum.rs | 2 +- .../orchestrator/src/cli/database/mongodb.rs | 4 +- crates/orchestrator/src/cli/prover/sharp.rs | 18 +-- crates/orchestrator/src/cli/queue/aws_sqs.rs | 6 +- crates/orchestrator/src/cli/server.rs | 4 +- crates/orchestrator/src/cli/service.rs | 4 +- .../src/cli/settlement/ethereum.rs | 8 +- .../src/cli/settlement/starknet.rs | 12 +- crates/orchestrator/src/cli/snos.rs | 2 +- crates/orchestrator/src/cli/storage/aws_s3.rs | 2 +- 13 files changed, 105 insertions(+), 107 deletions(-) diff --git a/.env.test b/.env.test index 7a4349bd..205ba14f 100644 --- a/.env.test +++ b/.env.test @@ -1,109 +1,103 @@ -##### ORCHESTRATOR ##### DONE -HOST=127.0.0.1 -PORT=3000 +#### AWS CONFIG #### -##### AWS CONFIG ##### DONE +AWS_ACCESS_KEY_ID=test +AWS_SECRET_ACCESS_KEY=test +AWS_REGION=us-east-1 -AWS_ACCESS_KEY_ID="AWS_ACCESS_KEY_ID" -AWS_SECRET_ACCESS_KEY="AWS_SECRET_ACCESS_KEY" -AWS_REGION="us-east-1" -# pick up by AWS sdk -AWS_ENDPOINT_URL="http://localhost.localstack.cloud:4566" -# Omniqueue -AWS_DEFAULT_REGION="localhost" +# For Aws sdk +MADARA_ORCHESTRATOR_AWS_ENDPOINT_URL=http://localhost.localstack.cloud:4566 +# For Omniqueue +MADARA_ORCHESTRATOR_AWS_DEFAULT_REGION=localhost -##### STORAGE ##### DONE -DATA_STORAGE="s3" +#### ALERTS #### -AWS_S3_BUCKET_NAME="madara-orchestrator-test-bucket" +MADARA_ORCHESTRATOR_AWS_SNS_ARN=arn:aws:sns:us-east-1:000000000000:madara-orchestrator-arn -##### QUEUE ##### +#### DATA AVAILABILITY #### -QUEUE_PROVIDER="sqs" +## ETHEREUM ## -SQS_SNOS_JOB_PROCESSING_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_snos_job_processing_queue" -SQS_SNOS_JOB_VERIFICATION_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_snos_job_verification_queue" +MADARA_ORCHESTRATOR_ETHEREUM_DA_RPC_URL=https://eth-sepolia.public.blastapi.io -SQS_PROVING_JOB_PROCESSING_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_proving_job_processing_queue" -SQS_PROVING_JOB_VERIFICATION_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_proving_job_verification_queue" -SQS_DATA_SUBMISSION_JOB_PROCESSING_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_data_submission_job_processing_queue" -SQS_DATA_SUBMISSION_JOB_VERIFICATION_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_data_submission_job_verification_queue" +#### DATABASE #### -SQS_UPDATE_STATE_JOB_PROCESSING_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_update_state_job_processing_queue" -SQS_UPDATE_STATE_JOB_VERIFICATION_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_update_state_job_verification_queue" +## MONGODB ## -SQS_JOB_HANDLE_FAILURE_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_job_handle_failure_queue" -SQS_WORKER_TRIGGER_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_worker_trigger_queue" +MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL=mongodb://localhost:27017 +MADARA_ORCHESTRATOR_DATABASE_NAME=madara-orchestrator-test -##### SNS ##### -ALERTS="sns" +#### PROVER #### -AWS_SNS_ARN="arn:aws:sns:us-east-1:000000000000:madara-orchestrator-arn" +## SHARP ## -##### DATABASE ##### +MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID=sharp_consumer_id +MADARA_ORCHESTRATOR_SHARP_URL=http://127.0.0.1:6000 +MADARA_ORCHESTRATOR_SHARP_USER_CRT=LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUR4ekNDQXErZ0F3SUJBZ0lVTjBSK0xpb1MzL2ZadUZsK291RjZNNFk2RnRZd0RRWUpLb1pJaHZjTkFRRUwKQlFBd2N6RUxNQWtHQTFVRUJoTUNTVTR4RXpBUkJnTlZCQWdNQ2xOdmJXVXRVM1JoZEdVeElUQWZCZ05WQkFvTQpHRWx1ZEdWeWJtVjBJRmRwWkdkcGRITWdVSFI1SUV4MFpERU5NQXNHQTFVRUF3d0VVMVJTU3pFZE1Cc0dDU3FHClNJYjNEUUVKQVJZT1lXSmpRR3RoY201dmRDNTRlWG93SGhjTk1qUXdPREV6TVRNd05UTTBXaGNOTWpVd09ERXoKTVRNd05UTTBXakJ6TVFzd0NRWURWUVFHRXdKSlRqRVRNQkVHQTFVRUNBd0tVMjl0WlMxVGRHRjBaVEVoTUI4RwpBMVVFQ2d3WVNXNTBaWEp1WlhRZ1YybGtaMmwwY3lCUWRIa2dUSFJrTVEwd0N3WURWUVFEREFSVFZGSkxNUjB3Ckd3WUpLb1pJaHZjTkFRa0JGZzVoWW1OQWEyRnlibTkwTG5oNWVqQ0NBU0l3RFFZSktvWklodmNOQVFFQkJRQUQKZ2dFUEFEQ0NBUW9DZ2dFQkFOSEtaUGRqWSs4QWo4ZFV2V0xReEl5NTNrK1BHY001T2FlYnpTV3FER0xGSlBOdgpkVzJvWjFCSnNEb2hobWZFSCt5ZEFoQXEvbzc4NDljblg2VDJTOVhta25wdnNud2dRckU5Z3lqSmV3MUxBRzNHCm10U0lOMWJJSm9peWJ3QUR5NGxPd0xrVzUzdFdueHBSazVVVmZUU1hLYVRRTnlHd2o3Q2xMSGthcnlZYVk3OVkKOXlHMFJ2RkFkb1IzczBveWthNkFLV0d1WjhOdWd4NTY2bysyWllRenJteWVNU1NGYkhNdW1aUkxYb0hpazhBSgpLZXJ0bnNBRC9LMVJRYm80Y21ubHFoTVRhQktiTEFVVjVteFVvMlpveFBJVU9tREE5N3IyMmRTYkRkRlVjeC9kCjhQcDB6VXNycXdQckJlcW5SMXdLOE80MUlHajUzRnUzVmxDeS94MENBd0VBQWFOVE1GRXdIUVlEVlIwT0JCWUUKRkc0T0lvKzcvckJyZlR4S2FFMGx2L1dwRDJ3UE1COEdBMVVkSXdRWU1CYUFGRzRPSW8rNy9yQnJmVHhLYUUwbAp2L1dwRDJ3UE1BOEdBMVVkRXdFQi93UUZNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFEMURDZkR3CnpoSXRGMWd5YVdhWURZRHErZjJSUHBFRWVaWk1BSDdJV0ZTajRrTzhmVHN1RnN6bFoyNXNlR3ZHYW4xQ3F4alQKYnJ3MXliVlJQeGZMUWgxRlZMMGhFeDZWYXhGditxMmtqUmlCQmZURFBxWGxYcmpaaUYrZTNPS3lKSVhnNkpIUAppbVpBV0dyRFBHNkorQi90bHRaQ3VLZVhLK1FUcnRSOVVCL29hOWVaQWc5RXNkOVJsZDRNeVo5b0NtdUNPU1hmCnk1THFkVlgrNENpTnJXQ3BwM1B2M2MyL28rZ0RMQjUzZ252R056RjR6Q1FIZ0RtN0RNZnpmZlY1TUMwV1MvWXkKVnpyUG11Sys0Y0tSK3dMOFZITVNEeC9ybTFhYnh0dEN2VW92MUw5dVZ1QUNGc29yNmdsR0N1RDNNQ0dIa0pNNgpxaS8rM1haeHhxeGw1Rzg9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K +MADARA_ORCHESTRATOR_SHARP_USER_KEY=LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JSUV2UUlCQURBTkJna3Foa2lHOXcwQkFRRUZBQVNDQktjd2dnU2pBZ0VBQW9JQkFRRFJ5bVQzWTJQdkFJL0gKVkwxaTBNU011ZDVQanhuRE9UbW5tODBscWd4aXhTVHpiM1Z0cUdkUVNiQTZJWVpueEIvc25RSVFLdjZPL09QWApKMStrOWt2VjVwSjZiN0o4SUVLeFBZTW95WHNOU3dCdHhwclVpRGRXeUNhSXNtOEFBOHVKVHNDNUZ1ZDdWcDhhClVaT1ZGWDAwbHltazBEY2hzSSt3cFN4NUdxOG1HbU8vV1BjaHRFYnhRSGFFZDdOS01wR3VnQ2xocm1mRGJvTWUKZXVxUHRtV0VNNjVzbmpFa2hXeHpMcG1VUzE2QjRwUEFDU25xN1o3QUEveXRVVUc2T0hKcDVhb1RFMmdTbXl3RgpGZVpzVktObWFNVHlGRHBnd1BlNjl0blVtdzNSVkhNZjNmRDZkTTFMSzZzRDZ3WHFwMGRjQ3ZEdU5TQm8rZHhiCnQxWlFzdjhkQWdNQkFBRUNnZ0VBQU9mcDFiT2xLOVFKeXVlUHhjeDIvTkNVcUMxTEJDL01FdkEyUzVKWGFWbkcKbGhLR0pFb1U0Q0RoVk83dUlLYVZLTFZvMjk4RHFHUnBLM1d0RVE1TE40bytXYTcveTA5c1drMlVzbWxrVWFOZwpSaGtVZEJSK2dLNXVsQ3FKRml2dUJoTEQvRWlnQ1VWUGZKS2JtNG96TnpYcjVSMU5ENlV1aWFtODdtenlFcTBLCmZsVXlhR0RZNGdIdFNBOVBENVBFYlUveFpKeitKaHk5T2l3aVRXV0MrSHoyb2c3UWRDRDE2RlhGcit2VHpQN0MKb2tFb0VDZFNPRWlMalVENjBhS2ZxRmFCVm5MTkVudC9QSytmY1RBM05mNGtSMnFDNk9ZWjVFb09zYm1ka29ZTgpyU3NJZW9XblMxOEhvekZud2w3Z05wTUtjNmRzQzRBTldOVDFsTkhCb1FLQmdRRHlaUDFJSlppZUh6NlExaUVTCm5zd2tnblZCQUQ0SlVLR1ZDMHA3dk4yclNDZXh4c05ZZXFPTEEyZGZCUGpOVjd3blFKcUgxT05XellOMUJVSUUKeThLTCtFZVl6Q3RZa21LL21wSGJIMzNjd2tJODBuMHJROU1BalZMTlJ2YVVEOWp1NFBsRzFqaEFZUVVyTkViZQpKRlVpSk83aDVQa1llZG50SitqSHFpQnRoUUtCZ1FEZGtPbndmL0szYk4xenR0bXZQd0VicjhkVWJjRVh5NDFOCkl5VWwrZW1WSlgzYktKM0duNDZnQ2RsTTdkYmpwS3JVZ3oxL2JsZTgvMkVFckJvSEFRNkMrU2pEaGhvL01CbnIKekZheTBoK3YxbjBnZnNNVzRoOEF4cEFwc25OYnh6K2g1Wm5uSnRTd0srUjB3U0VJVVEzRjAxL2hMWWhLQ2l5OApwbW5HQi9hU3VRS0JnRzdxd1cvVExGd214ZlYyMXBsenFzeUdHZXVObGRXalhOMGIxcEI2b3lDdW11TmhwYUFHCk5uSDFNOGNxT2tPVWd4ZWZHMWRPbGx6eEc5ZGZlWTlDUWhyVW1NYVZucndmK0NuZkxDRU43d1VtcXpLenl1MFMKVXlwc2dOaElRYXNNK1dLTjllTnhRVHBNYXhZVERONjMxM0VSWDNKazJZdFdydDh6cFBSQXFDZ1ZBb0dCQU54egpUa0NMbmJ6aFphbTNlZm9DenlCMEVma3dSdHBkSGxkc3E0NlFqTmRuK1VSd3NpTXBLR2lWeEE3bDZsU1B4NlV3CmU2VHA3Z1JQZUlHRWwxVDJ1VENacGZSODNtcVdlb1FCeVJXZE9nZmplcFkxYWZpL3ZhY3c2Y21ERTRKeXloNVUKYTMveFE5ZVJwSHFDbWxKREMxZ1V5eVlwL3B2a2FjUytNeW5sVEhHSkFvR0FQekdTSzdXOHBUYldSVEFoaTVrSQpwZk5kWk1tcnRodUxNT3F6TGhyRjZublpldk9OdTBoYXVhZktlVElFd2w0clhYZHFKQlJBaWZKMFFsLzZKWFFkCmd1VzFrZWk1Ui8rUFZ5eUhab042c3NXSTNWYklwUUloUmt6UENnTDZhbHEwSzFpT1dlV1lIOHdORGRRdlB1T2UKRkZPOEovSzNxV0NtWjU0ODBBbTNhT0U9Ci0tLS0tRU5EIFBSSVZBVEUgS0VZLS0tLS0K +MADARA_ORCHESTRATOR_SHARP_SERVER_CRT=LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURhekNDQWxPZ0F3SUJBZ0lVRUR0Rjd0YVNTUnVQQTJ6Uk1aNWNzY2JCRm5jd0RRWUpLb1pJaHZjTkFRRUwKQlFBd1JURUxNQWtHQTFVRUJoTUNTVTR4RXpBUkJnTlZCQWdNQ2xOdmJXVXRVM1JoZEdVeElUQWZCZ05WQkFvTQpHRWx1ZEdWeWJtVjBJRmRwWkdkcGRITWdVSFI1SUV4MFpEQWVGdzB5TkRBNE1UTXhNekEzTVROYUZ3MHlOVEE0Ck1UTXhNekEzTVROYU1FVXhDekFKQmdOVkJBWVRBa2xPTVJNd0VRWURWUVFJREFwVGIyMWxMVk4wWVhSbE1TRXcKSHdZRFZRUUtEQmhKYm5SbGNtNWxkQ0JYYVdSbmFYUnpJRkIwZVNCTWRHUXdnZ0VpTUEwR0NTcUdTSWIzRFFFQgpBUVVBQTRJQkR3QXdnZ0VLQW9JQkFRRFRHcEEwNEZ1QlNFaE5PNVYvMGxTaDkvSEgxeVRZT2dRVFdoOG43eDlRCnZGMHpvZFZueVFIdjE5elU5eVdia2xvOEkvOXFBVm9lRzdXTnpUVFg2Q295ZlNjb1YvazN0Q2UwVnVWMlFJTVQKdW82SzJSU05CVHB1TlNqNTlzUiszVTQ2OFRBQnY0YVpsYjU4TU5CRXM3MVRieVpLRHBGRVRkMkg3T0ZKajg4QQpNRi9MaXJkeDZPOFdZL0tDeisxd1ZXL1JRdytYYjRJSWx4bXJFOC9UZ3FNSEo4dFUxYkZiOWJNcTEvOTN5YWtJClU1V2J2NVhXKzFwZFVyTUFNcTFFaC9vZThMN2pFaFdvZXZrNzgyU0kwUk0xeG5MaEtrUUVBYXd6Zkg2ODZiR2YKUHQ3RkFIQ1pGaWJ4KzZzSkg0R1M3S25iK0x5bk9ud3phMWZPUXZEZmcvRm5BZ01CQUFHalV6QlJNQjBHQTFVZApEZ1FXQkJUYlFUdmlUTW1xNXlNK2ZJRVI4VjdTZk1pK3B6QWZCZ05WSFNNRUdEQVdnQlRiUVR2aVRNbXE1eU0rCmZJRVI4VjdTZk1pK3B6QVBCZ05WSFJNQkFmOEVCVEFEQVFIL01BMEdDU3FHU0liM0RRRUJDd1VBQTRJQkFRREYKTllyRnpBa2RIVkhjUkd5SUNsTi9IVGswaldOcTVSdTB1RUpDQ21Dbm9ZY1pRSTlDQlcwTkl3dGpZUkpTKzR1UwordWh4VWpSYTA5YXdOWDhvYmU0dDZjK25HRnhZMGZqamk0cGZnbU1kMWNJeGdsM3E3Nlp0ZkllRGR6alRLRXN1CjRFUTVadnEwMnJvTEZ0ZjEvL3dRVG0xNkNKdFpGWnhNZ1phYnNxc2JRc3M2dWdMUGtTTmdBWjI1L2VhcWhnQ20KTjFUV2FxL0xJMVBLSkxPK085NFlMa2FsNVpyOTJCOXk4Q0VKVUVuSTA1R1N1MmJUOFM2a0ZBMEpadEszTW9SbwpqRWZWV1lQVHR5TFR4amNvRndCcDlHaXZYSDdSdHBxMDlmSmFhU1pNekxmNGlyNHpBdXprbExBNWZvampPNXlKCllnYlVaQUU2aS81N1NFWjR3VmxTCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K +MADARA_ORCHESTRATOR_SHARP_RPC_NODE_URL=https://eth-sepolia.public.blastapi.io +MADARA_ORCHESTRATOR_SHARP_PROOF_LAYOUT=small +MADARA_ORCHESTRATOR_GPS_VERIFIER_CONTRACT_ADDRESS=0x07ec0D28e50322Eb0C159B9090ecF3aeA8346DFe -DATABASE="mongodb" -MONGODB_CONNECTION_STRING="mongodb://localhost:27017" -DATABASE_NAME="orchestrator" +#### QUEUE #### -##### PROVER ##### +## AWS SQS ## -PROVER_SERVICE="sharp" +MADARA_ORCHESTRATOR_SQS_PREFIX=madara_orchestrator +MADARA_ORCHESTRATOR_SQS_SUFFIX=queue +MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL=http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/ -SHARP_CUSTOMER_ID="sharp_consumer_id" -SHARP_URL="http://127.0.0.1:6000" -# [IMP!!!] These are test certificates (they don't work) -SHARP_USER_CRT="LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUR4ekNDQXErZ0F3SUJBZ0lVTjBSK0xpb1MzL2ZadUZsK291RjZNNFk2RnRZd0RRWUpLb1pJaHZjTkFRRUwKQlFBd2N6RUxNQWtHQTFVRUJoTUNTVTR4RXpBUkJnTlZCQWdNQ2xOdmJXVXRVM1JoZEdVeElUQWZCZ05WQkFvTQpHRWx1ZEdWeWJtVjBJRmRwWkdkcGRITWdVSFI1SUV4MFpERU5NQXNHQTFVRUF3d0VVMVJTU3pFZE1Cc0dDU3FHClNJYjNEUUVKQVJZT1lXSmpRR3RoY201dmRDNTRlWG93SGhjTk1qUXdPREV6TVRNd05UTTBXaGNOTWpVd09ERXoKTVRNd05UTTBXakJ6TVFzd0NRWURWUVFHRXdKSlRqRVRNQkVHQTFVRUNBd0tVMjl0WlMxVGRHRjBaVEVoTUI4RwpBMVVFQ2d3WVNXNTBaWEp1WlhRZ1YybGtaMmwwY3lCUWRIa2dUSFJrTVEwd0N3WURWUVFEREFSVFZGSkxNUjB3Ckd3WUpLb1pJaHZjTkFRa0JGZzVoWW1OQWEyRnlibTkwTG5oNWVqQ0NBU0l3RFFZSktvWklodmNOQVFFQkJRQUQKZ2dFUEFEQ0NBUW9DZ2dFQkFOSEtaUGRqWSs4QWo4ZFV2V0xReEl5NTNrK1BHY001T2FlYnpTV3FER0xGSlBOdgpkVzJvWjFCSnNEb2hobWZFSCt5ZEFoQXEvbzc4NDljblg2VDJTOVhta25wdnNud2dRckU5Z3lqSmV3MUxBRzNHCm10U0lOMWJJSm9peWJ3QUR5NGxPd0xrVzUzdFdueHBSazVVVmZUU1hLYVRRTnlHd2o3Q2xMSGthcnlZYVk3OVkKOXlHMFJ2RkFkb1IzczBveWthNkFLV0d1WjhOdWd4NTY2bysyWllRenJteWVNU1NGYkhNdW1aUkxYb0hpazhBSgpLZXJ0bnNBRC9LMVJRYm80Y21ubHFoTVRhQktiTEFVVjVteFVvMlpveFBJVU9tREE5N3IyMmRTYkRkRlVjeC9kCjhQcDB6VXNycXdQckJlcW5SMXdLOE80MUlHajUzRnUzVmxDeS94MENBd0VBQWFOVE1GRXdIUVlEVlIwT0JCWUUKRkc0T0lvKzcvckJyZlR4S2FFMGx2L1dwRDJ3UE1COEdBMVVkSXdRWU1CYUFGRzRPSW8rNy9yQnJmVHhLYUUwbAp2L1dwRDJ3UE1BOEdBMVVkRXdFQi93UUZNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFEMURDZkR3CnpoSXRGMWd5YVdhWURZRHErZjJSUHBFRWVaWk1BSDdJV0ZTajRrTzhmVHN1RnN6bFoyNXNlR3ZHYW4xQ3F4alQKYnJ3MXliVlJQeGZMUWgxRlZMMGhFeDZWYXhGditxMmtqUmlCQmZURFBxWGxYcmpaaUYrZTNPS3lKSVhnNkpIUAppbVpBV0dyRFBHNkorQi90bHRaQ3VLZVhLK1FUcnRSOVVCL29hOWVaQWc5RXNkOVJsZDRNeVo5b0NtdUNPU1hmCnk1THFkVlgrNENpTnJXQ3BwM1B2M2MyL28rZ0RMQjUzZ252R056RjR6Q1FIZ0RtN0RNZnpmZlY1TUMwV1MvWXkKVnpyUG11Sys0Y0tSK3dMOFZITVNEeC9ybTFhYnh0dEN2VW92MUw5dVZ1QUNGc29yNmdsR0N1RDNNQ0dIa0pNNgpxaS8rM1haeHhxeGw1Rzg9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K" -SHARP_USER_KEY="LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JSUV2UUlCQURBTkJna3Foa2lHOXcwQkFRRUZBQVNDQktjd2dnU2pBZ0VBQW9JQkFRRFJ5bVQzWTJQdkFJL0gKVkwxaTBNU011ZDVQanhuRE9UbW5tODBscWd4aXhTVHpiM1Z0cUdkUVNiQTZJWVpueEIvc25RSVFLdjZPL09QWApKMStrOWt2VjVwSjZiN0o4SUVLeFBZTW95WHNOU3dCdHhwclVpRGRXeUNhSXNtOEFBOHVKVHNDNUZ1ZDdWcDhhClVaT1ZGWDAwbHltazBEY2hzSSt3cFN4NUdxOG1HbU8vV1BjaHRFYnhRSGFFZDdOS01wR3VnQ2xocm1mRGJvTWUKZXVxUHRtV0VNNjVzbmpFa2hXeHpMcG1VUzE2QjRwUEFDU25xN1o3QUEveXRVVUc2T0hKcDVhb1RFMmdTbXl3RgpGZVpzVktObWFNVHlGRHBnd1BlNjl0blVtdzNSVkhNZjNmRDZkTTFMSzZzRDZ3WHFwMGRjQ3ZEdU5TQm8rZHhiCnQxWlFzdjhkQWdNQkFBRUNnZ0VBQU9mcDFiT2xLOVFKeXVlUHhjeDIvTkNVcUMxTEJDL01FdkEyUzVKWGFWbkcKbGhLR0pFb1U0Q0RoVk83dUlLYVZLTFZvMjk4RHFHUnBLM1d0RVE1TE40bytXYTcveTA5c1drMlVzbWxrVWFOZwpSaGtVZEJSK2dLNXVsQ3FKRml2dUJoTEQvRWlnQ1VWUGZKS2JtNG96TnpYcjVSMU5ENlV1aWFtODdtenlFcTBLCmZsVXlhR0RZNGdIdFNBOVBENVBFYlUveFpKeitKaHk5T2l3aVRXV0MrSHoyb2c3UWRDRDE2RlhGcit2VHpQN0MKb2tFb0VDZFNPRWlMalVENjBhS2ZxRmFCVm5MTkVudC9QSytmY1RBM05mNGtSMnFDNk9ZWjVFb09zYm1ka29ZTgpyU3NJZW9XblMxOEhvekZud2w3Z05wTUtjNmRzQzRBTldOVDFsTkhCb1FLQmdRRHlaUDFJSlppZUh6NlExaUVTCm5zd2tnblZCQUQ0SlVLR1ZDMHA3dk4yclNDZXh4c05ZZXFPTEEyZGZCUGpOVjd3blFKcUgxT05XellOMUJVSUUKeThLTCtFZVl6Q3RZa21LL21wSGJIMzNjd2tJODBuMHJROU1BalZMTlJ2YVVEOWp1NFBsRzFqaEFZUVVyTkViZQpKRlVpSk83aDVQa1llZG50SitqSHFpQnRoUUtCZ1FEZGtPbndmL0szYk4xenR0bXZQd0VicjhkVWJjRVh5NDFOCkl5VWwrZW1WSlgzYktKM0duNDZnQ2RsTTdkYmpwS3JVZ3oxL2JsZTgvMkVFckJvSEFRNkMrU2pEaGhvL01CbnIKekZheTBoK3YxbjBnZnNNVzRoOEF4cEFwc25OYnh6K2g1Wm5uSnRTd0srUjB3U0VJVVEzRjAxL2hMWWhLQ2l5OApwbW5HQi9hU3VRS0JnRzdxd1cvVExGd214ZlYyMXBsenFzeUdHZXVObGRXalhOMGIxcEI2b3lDdW11TmhwYUFHCk5uSDFNOGNxT2tPVWd4ZWZHMWRPbGx6eEc5ZGZlWTlDUWhyVW1NYVZucndmK0NuZkxDRU43d1VtcXpLenl1MFMKVXlwc2dOaElRYXNNK1dLTjllTnhRVHBNYXhZVERONjMxM0VSWDNKazJZdFdydDh6cFBSQXFDZ1ZBb0dCQU54egpUa0NMbmJ6aFphbTNlZm9DenlCMEVma3dSdHBkSGxkc3E0NlFqTmRuK1VSd3NpTXBLR2lWeEE3bDZsU1B4NlV3CmU2VHA3Z1JQZUlHRWwxVDJ1VENacGZSODNtcVdlb1FCeVJXZE9nZmplcFkxYWZpL3ZhY3c2Y21ERTRKeXloNVUKYTMveFE5ZVJwSHFDbWxKREMxZ1V5eVlwL3B2a2FjUytNeW5sVEhHSkFvR0FQekdTSzdXOHBUYldSVEFoaTVrSQpwZk5kWk1tcnRodUxNT3F6TGhyRjZublpldk9OdTBoYXVhZktlVElFd2w0clhYZHFKQlJBaWZKMFFsLzZKWFFkCmd1VzFrZWk1Ui8rUFZ5eUhab042c3NXSTNWYklwUUloUmt6UENnTDZhbHEwSzFpT1dlV1lIOHdORGRRdlB1T2UKRkZPOEovSzNxV0NtWjU0ODBBbTNhT0U9Ci0tLS0tRU5EIFBSSVZBVEUgS0VZLS0tLS0K" -SHARP_SERVER_CRT="LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURhekNDQWxPZ0F3SUJBZ0lVRUR0Rjd0YVNTUnVQQTJ6Uk1aNWNzY2JCRm5jd0RRWUpLb1pJaHZjTkFRRUwKQlFBd1JURUxNQWtHQTFVRUJoTUNTVTR4RXpBUkJnTlZCQWdNQ2xOdmJXVXRVM1JoZEdVeElUQWZCZ05WQkFvTQpHRWx1ZEdWeWJtVjBJRmRwWkdkcGRITWdVSFI1SUV4MFpEQWVGdzB5TkRBNE1UTXhNekEzTVROYUZ3MHlOVEE0Ck1UTXhNekEzTVROYU1FVXhDekFKQmdOVkJBWVRBa2xPTVJNd0VRWURWUVFJREFwVGIyMWxMVk4wWVhSbE1TRXcKSHdZRFZRUUtEQmhKYm5SbGNtNWxkQ0JYYVdSbmFYUnpJRkIwZVNCTWRHUXdnZ0VpTUEwR0NTcUdTSWIzRFFFQgpBUVVBQTRJQkR3QXdnZ0VLQW9JQkFRRFRHcEEwNEZ1QlNFaE5PNVYvMGxTaDkvSEgxeVRZT2dRVFdoOG43eDlRCnZGMHpvZFZueVFIdjE5elU5eVdia2xvOEkvOXFBVm9lRzdXTnpUVFg2Q295ZlNjb1YvazN0Q2UwVnVWMlFJTVQKdW82SzJSU05CVHB1TlNqNTlzUiszVTQ2OFRBQnY0YVpsYjU4TU5CRXM3MVRieVpLRHBGRVRkMkg3T0ZKajg4QQpNRi9MaXJkeDZPOFdZL0tDeisxd1ZXL1JRdytYYjRJSWx4bXJFOC9UZ3FNSEo4dFUxYkZiOWJNcTEvOTN5YWtJClU1V2J2NVhXKzFwZFVyTUFNcTFFaC9vZThMN2pFaFdvZXZrNzgyU0kwUk0xeG5MaEtrUUVBYXd6Zkg2ODZiR2YKUHQ3RkFIQ1pGaWJ4KzZzSkg0R1M3S25iK0x5bk9ud3phMWZPUXZEZmcvRm5BZ01CQUFHalV6QlJNQjBHQTFVZApEZ1FXQkJUYlFUdmlUTW1xNXlNK2ZJRVI4VjdTZk1pK3B6QWZCZ05WSFNNRUdEQVdnQlRiUVR2aVRNbXE1eU0rCmZJRVI4VjdTZk1pK3B6QVBCZ05WSFJNQkFmOEVCVEFEQVFIL01BMEdDU3FHU0liM0RRRUJDd1VBQTRJQkFRREYKTllyRnpBa2RIVkhjUkd5SUNsTi9IVGswaldOcTVSdTB1RUpDQ21Dbm9ZY1pRSTlDQlcwTkl3dGpZUkpTKzR1UwordWh4VWpSYTA5YXdOWDhvYmU0dDZjK25HRnhZMGZqamk0cGZnbU1kMWNJeGdsM3E3Nlp0ZkllRGR6alRLRXN1CjRFUTVadnEwMnJvTEZ0ZjEvL3dRVG0xNkNKdFpGWnhNZ1phYnNxc2JRc3M2dWdMUGtTTmdBWjI1L2VhcWhnQ20KTjFUV2FxL0xJMVBLSkxPK085NFlMa2FsNVpyOTJCOXk4Q0VKVUVuSTA1R1N1MmJUOFM2a0ZBMEpadEszTW9SbwpqRWZWV1lQVHR5TFR4amNvRndCcDlHaXZYSDdSdHBxMDlmSmFhU1pNekxmNGlyNHpBdXprbExBNWZvampPNXlKCllnYlVaQUU2aS81N1NFWjR3VmxTCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K" -SHARP_PROOF_LAYOUT="small" -GPS_VERIFIER_CONTRACT_ADDRESS="0x07ec0D28e50322Eb0C159B9090ecF3aeA8346DFe" +#### SETTLEMENT #### -##### DA ##### +## ETHEREUM ## -DA_LAYER="ethereum" -DA_RPC_URL="https://eth-sepolia.public.blastapi.io" +MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL=https://eth-sepolia.public.blastapi.io +MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 +MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS=0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057 +MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS=0x5b98B836969A60FEC50Fa925905Dd1D382a7db43 -##### SETTLEMENT ##### +## STARKNET ## -SETTLEMENT_LAYER="ethereum" +MADARA_ORCHESTRATOR_STARKNET_SETTLEMENT_RPC_URL=https://starknet-sepolia.public.blastapi.io +MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 +MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 +MADARA_ORCHESTRATOR_STARKNET_CAIRO_CORE_CONTRACT_ADDRESS="" +MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS="" +MADARA_ORCHESTRATOR_MADARA_BINARY_PATH="/path/to/madara" -# Ethereum -SETTLEMENT_RPC_URL="https://eth-sepolia.public.blastapi.io" -ETHEREUM_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" -L1_CORE_CONTRACT_ADDRESS="0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057" -STARKNET_OPERATOR_ADDRESS="0x5b98B836969A60FEC50Fa925905Dd1D382a7db43" +#### STORAGE #### -# Starknet +## AWS S3 ## -STARKNET_RPC_URL="https://starknet-sepolia.public.blastapi.io" -STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 -STARKNET_ACCOUNT_ADDRESS=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 -STARKNET_CAIRO_CORE_CONTRACT_ADDRESS="" -STARKNET_FINALITY_RETRY_WAIT_IN_SECS="" -MADARA_BINARY_PATH="/path/to/madara" +MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME=madara-orchestrator-test-bucket -##### SNOS ##### -## This is needed right now because Madara doesn't support getProof -RPC_FOR_SNOS="" -MAX_BLOCK_TO_PROCESS= -MIN_BLOCK_TO_PROCESS= +#### INSTRUMENTATION #### -## Instrumentation -OTEL_SERVICE_NAME="madara_orchestrator" -OTEL_COLLECTOR_ENDPOINT="" +## OTEL ## -##### ON CHAIN CONFIG ##### +MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME=orchestrator +MADARA_ORCHESTRATOR_OTEL_COLLECTOR_ENDPOINT=http://localhost:4317 -MADARA_RPC_URL=http://localhost:9944 -##### Tests ##### -# Can be removed, we already have AWS_SNS_ARN -AWS_SNS_ARN_NAME="madara-orchestrator-arn" +#### SERVER #### + +MADARA_ORCHESTRATOR_HOST=127.0.0.1 +MADARA_ORCHESTRATOR_PORT=3000 + + +#### SERVICE #### + +MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS=1000 +MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS=0 + + +#### SNOS #### + +MADARA_ORCHESTRATOR_RPC_FOR_SNOS=https://rpc.sepolia.madara.xyz diff --git a/crates/orchestrator/src/cli/alert/aws_sns.rs b/crates/orchestrator/src/cli/alert/aws_sns.rs index 340f7686..ff6ceb26 100644 --- a/crates/orchestrator/src/cli/alert/aws_sns.rs +++ b/crates/orchestrator/src/cli/alert/aws_sns.rs @@ -9,6 +9,6 @@ pub struct AWSSNSCliArgs { pub aws_sns: bool, /// The name of the S3 bucket. - #[arg(env = "SNS_NAME", long, default_value = Some("madara-orchestrator-arn"))] + #[arg(env = "MADARA_ORCHESTRATOR_AWS_SNS_ARN", long, default_value = Some("madara-orchestrator-arn"))] pub sns_arn: Option, } diff --git a/crates/orchestrator/src/cli/aws_config.rs b/crates/orchestrator/src/cli/aws_config.rs index c8cb4745..f24a1de3 100644 --- a/crates/orchestrator/src/cli/aws_config.rs +++ b/crates/orchestrator/src/cli/aws_config.rs @@ -16,10 +16,14 @@ pub struct AWSConfigParams { pub aws_region: String, /// The endpoint URL. - #[arg(env = "AWS_ENDPOINT_URL", long, default_value = "http://localhost.localstack.cloud:4566")] + #[arg( + env = "MADARA_ORCHESTRATOR_AWS_ENDPOINT_URL", + long, + default_value = "http://localhost.localstack.cloud:4566" + )] pub aws_endpoint_url: String, /// The default region. - #[arg(env = "AWS_DEFAULT_REGION", long, default_value = "localhost")] + #[arg(env = "MADARA_ORCHESTRATOR_AWS_DEFAULT_REGION", long, default_value = "localhost")] pub aws_default_region: String, } diff --git a/crates/orchestrator/src/cli/da/ethereum.rs b/crates/orchestrator/src/cli/da/ethereum.rs index ef6a25b1..f95551ff 100644 --- a/crates/orchestrator/src/cli/da/ethereum.rs +++ b/crates/orchestrator/src/cli/da/ethereum.rs @@ -10,6 +10,6 @@ pub struct EthereumDaCliArgs { pub da_on_ethereum: bool, /// The RPC URL of the Ethereum node. - #[arg(env = "DA_RPC_URL", long)] + #[arg(env = "MADARA_ORCHESTRATOR_ETHEREUM_DA_RPC_URL", long)] pub da_rpc_url: Option, } diff --git a/crates/orchestrator/src/cli/database/mongodb.rs b/crates/orchestrator/src/cli/database/mongodb.rs index 9a912020..e7f0bc7f 100644 --- a/crates/orchestrator/src/cli/database/mongodb.rs +++ b/crates/orchestrator/src/cli/database/mongodb.rs @@ -9,10 +9,10 @@ pub struct MongoDBCliArgs { pub mongodb: bool, /// The connection string to the MongoDB server. - #[arg(env = "MONGODB_CONNECTION_URL", long, default_value = Some("mongodb://localhost:27017"))] + #[arg(env = "MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL", long, default_value = Some("mongodb://localhost:27017"))] pub connection_url: Option, /// The name of the database. - #[arg(env = "DATABASE_NAME", long, default_value = Some("orchestrator"))] + #[arg(env = "MADARA_ORCHESTRATOR_DATABASE_NAME", long, default_value = Some("orchestrator"))] pub database_name: Option, } diff --git a/crates/orchestrator/src/cli/prover/sharp.rs b/crates/orchestrator/src/cli/prover/sharp.rs index f98c6476..e49e19e5 100644 --- a/crates/orchestrator/src/cli/prover/sharp.rs +++ b/crates/orchestrator/src/cli/prover/sharp.rs @@ -3,42 +3,42 @@ use url::Url; /// Parameters used to config Sharp. #[derive(Debug, Clone, Args)] -#[group(requires_all = ["sharp_customer_id", "sharp_url", "sharp_user_crt", "sharp_user_key", "sharp_rpc_node_url"])] +#[group(requires_all = ["sharp_customer_id", "sharp_url", "sharp_user_crt", "sharp_user_key", "sharp_server_crt", "sharp_proof_layout", "gps_verifier_contract_address"])] pub struct SharpCliArgs { /// Use the Sharp prover. #[arg(long)] pub sharp: bool, /// The customer id for Sharp. - #[arg(env = "SHARP_CUSTOMER_ID", long)] + #[arg(env = "MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID", long)] pub sharp_customer_id: Option, /// The URL of the Sharp server. - #[arg(env = "SHARP_URL", long)] + #[arg(env = "MADARA_ORCHESTRATOR_SHARP_URL", long)] pub sharp_url: Option, /// The user certificate for Sharp. - #[arg(env = "SHARP_USER_CRT", long)] + #[arg(env = "MADARA_ORCHESTRATOR_SHARP_USER_CRT", long)] pub sharp_user_crt: Option, /// The user key for Sharp. - #[arg(env = "SHARP_USER_KEY", long)] + #[arg(env = "MADARA_ORCHESTRATOR_SHARP_USER_KEY", long)] pub sharp_user_key: Option, /// The RPC node URL for Sharp. - #[arg(env = "SHARP_RPC_NODE_URL", long)] + #[arg(env = "MADARA_ORCHESTRATOR_SHARP_RPC_NODE_URL", long)] pub sharp_rpc_node_url: Option, /// The server certificate for Sharp. - #[arg(env = "SHARP_SERVER_CRT", long)] + #[arg(env = "MADARA_ORCHESTRATOR_SHARP_SERVER_CRT", long)] pub sharp_server_crt: Option, /// The proof layout for Sharp. - #[arg(env = "SHARP_PROOF_LAYOUT", long, default_value = "small")] + #[arg(env = "MADARA_ORCHESTRATOR_SHARP_PROOF_LAYOUT", long, default_value = "small")] pub sharp_proof_layout: Option, // TODO: GPS is a direct dependency of Sharp, hence GPS can be kept in SharpParams /// The GPS verifier contract address. - #[arg(env = "GPS_VERIFIER_CONTRACT_ADDRESS", long)] + #[arg(env = "MADARA_ORCHESTRATOR_GPS_VERIFIER_CONTRACT_ADDRESS", long)] pub gps_verifier_contract_address: Option, } diff --git a/crates/orchestrator/src/cli/queue/aws_sqs.rs b/crates/orchestrator/src/cli/queue/aws_sqs.rs index f6378ed3..a3f9088d 100644 --- a/crates/orchestrator/src/cli/queue/aws_sqs.rs +++ b/crates/orchestrator/src/cli/queue/aws_sqs.rs @@ -9,14 +9,14 @@ pub struct AWSSQSCliArgs { pub aws_sqs: bool, /// The name of the S3 bucket. - #[arg(env = "SQS_PREFIX", long, default_value = Some("madara_orchestrator"))] + #[arg(env = "MADARA_ORCHESTRATOR_SQS_PREFIX", long, default_value = Some("madara_orchestrator"))] pub sqs_prefix: Option, /// The suffix of the queue. - #[arg(env = "SQS_SUFFIX", long, default_value = Some("queue"))] + #[arg(env = "MADARA_ORCHESTRATOR_SQS_SUFFIX", long, default_value = Some("queue"))] pub sqs_suffix: Option, /// The QUEUE url - #[arg(env = "SQS_BASE_QUEUE_URL", long)] + #[arg(env = "MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL", long)] pub queue_base_url: Option, } diff --git a/crates/orchestrator/src/cli/server.rs b/crates/orchestrator/src/cli/server.rs index 6d4d02b3..77a2ac0b 100644 --- a/crates/orchestrator/src/cli/server.rs +++ b/crates/orchestrator/src/cli/server.rs @@ -5,10 +5,10 @@ use clap::Args; #[group(requires_all = ["host", "port"])] pub struct ServerCliArgs { /// The host to listen on. - #[arg(env = "HOST", long, default_value = "127.0.0.1")] + #[arg(env = "MADARA_ORCHESTRATOR_HOST", long, default_value = "127.0.0.1")] pub host: String, /// The port to listen on. - #[arg(env = "PORT", long, default_value = "3000")] + #[arg(env = "MADARA_ORCHESTRATOR_PORT", long, default_value = "3000")] pub port: u16, } diff --git a/crates/orchestrator/src/cli/service.rs b/crates/orchestrator/src/cli/service.rs index fe82a226..b829bc49 100644 --- a/crates/orchestrator/src/cli/service.rs +++ b/crates/orchestrator/src/cli/service.rs @@ -4,10 +4,10 @@ use clap::Args; #[group(requires_all = ["rpc_for_snos"])] pub struct ServiceCliArgs { /// The maximum block to process. - #[arg(env = "MAX_BLOCK_TO_PROCESS", long)] + #[arg(env = "MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS", long)] pub max_block_to_process: Option, /// The minimum block to process. - #[arg(env = "MIN_BLOCK_TO_PROCESS", long)] + #[arg(env = "MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS", long)] pub min_block_to_process: Option, } diff --git a/crates/orchestrator/src/cli/settlement/ethereum.rs b/crates/orchestrator/src/cli/settlement/ethereum.rs index 532955ae..ae47d197 100644 --- a/crates/orchestrator/src/cli/settlement/ethereum.rs +++ b/crates/orchestrator/src/cli/settlement/ethereum.rs @@ -9,18 +9,18 @@ pub struct EthereumSettlementCliArgs { pub settle_on_ethereum: bool, /// The URL of the Ethereum RPC node. - #[arg(env = "ETHEREUM_SETTLEMENT_RPC_URL", long)] + #[arg(env = "MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL", long)] pub ethereum_rpc_url: Option, /// The private key of the Ethereum account. - #[arg(env = "ETHEREUM_PRIVATE_KEY", long)] + #[arg(env = "MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY", long)] pub ethereum_private_key: Option, /// The address of the L1 core contract. - #[arg(env = "L1_CORE_CONTRACT_ADDRESS", long)] + #[arg(env = "MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS", long)] pub l1_core_contract_address: Option, /// The address of the Starknet operator. - #[arg(env = "STARKNET_OPERATOR_ADDRESS", long)] + #[arg(env = "MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS", long)] pub starknet_operator_address: Option, } diff --git a/crates/orchestrator/src/cli/settlement/starknet.rs b/crates/orchestrator/src/cli/settlement/starknet.rs index 23658f3c..b86bd4b3 100644 --- a/crates/orchestrator/src/cli/settlement/starknet.rs +++ b/crates/orchestrator/src/cli/settlement/starknet.rs @@ -9,26 +9,26 @@ pub struct StarknetSettlementCliArgs { pub settle_on_starknet: bool, /// The URL of the Ethereum RPC node. - #[arg(env = "STARKNET_RPC_URL", long)] + #[arg(env = "MADARA_ORCHESTRATOR_STARKNET_SETTLEMENT_RPC_URL", long)] pub starknet_rpc_url: Option, /// The private key of the Ethereum account. - #[arg(env = "STARKNET_PRIVATE_KEY", long)] + #[arg(env = "MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY", long)] pub starknet_private_key: Option, /// The address of the Starknet account. - #[arg(env = "STARKNET_ACCOUNT_ADDRESS", long)] + #[arg(env = "MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS", long)] pub starknet_account_address: Option, /// The address of the Cairo core contract. - #[arg(env = "STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", long)] + #[arg(env = "MADARA_ORCHESTRATOR_STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", long)] pub starknet_cairo_core_contract_address: Option, /// The number of seconds to wait for finality. - #[arg(env = "STARKNET_FINALITY_RETRY_WAIT_IN_SECS", long)] + #[arg(env = "MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS", long)] pub starknet_finality_retry_wait_in_secs: Option, /// The path to the Madara binary. - #[arg(env = "MADARA_BINARY_PATH", long)] + #[arg(env = "MADARA_ORCHESTRATOR_MADARA_BINARY_PATH", long)] pub madara_binary_path: Option, } diff --git a/crates/orchestrator/src/cli/snos.rs b/crates/orchestrator/src/cli/snos.rs index 1fb81504..12851ac8 100644 --- a/crates/orchestrator/src/cli/snos.rs +++ b/crates/orchestrator/src/cli/snos.rs @@ -5,7 +5,7 @@ use url::Url; #[group(requires_all = ["rpc_for_snos"])] pub struct SNOSCliArgs { /// The RPC URL for SNOS. - #[arg(env = "RPC_FOR_SNOS", long)] + #[arg(env = "MADARA_ORCHESTRATOR_RPC_FOR_SNOS", long)] pub rpc_for_snos: Url, } diff --git a/crates/orchestrator/src/cli/storage/aws_s3.rs b/crates/orchestrator/src/cli/storage/aws_s3.rs index 871a7635..3b801261 100644 --- a/crates/orchestrator/src/cli/storage/aws_s3.rs +++ b/crates/orchestrator/src/cli/storage/aws_s3.rs @@ -9,6 +9,6 @@ pub struct AWSS3CliArgs { pub aws_s3: bool, /// The name of the S3 bucket. - #[arg(env = "AWS_S3_BUCKET_NAME", long, default_value = Some("madara-orchestrator-bucket"))] + #[arg(env = "MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME", long, default_value = Some("madara-orchestrator-bucket"))] pub bucket_name: Option, } From 5b1cbc295651180b1dfef0e4b3e62ed9ce2b2c1b Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Fri, 8 Nov 2024 00:41:28 +0530 Subject: [PATCH 26/63] update: env fixes for tests --- .env.example | 16 +- .env.test | 19 +- crates/da-clients/ethereum/src/config.rs | 2 +- crates/orchestrator/src/cli/alert/aws_sns.rs | 1 - crates/orchestrator/src/cli/aws_config.rs | 12 +- crates/orchestrator/src/cli/da/ethereum.rs | 4 +- .../orchestrator/src/cli/database/mongodb.rs | 6 +- .../orchestrator/src/cli/instrumentation.rs | 4 +- crates/orchestrator/src/cli/mod.rs | 10 +- crates/orchestrator/src/cli/prover/sharp.rs | 2 +- crates/orchestrator/src/cli/queue/aws_sqs.rs | 2 +- crates/orchestrator/src/cli/storage/aws_s3.rs | 2 +- crates/orchestrator/src/config.rs | 2 +- crates/orchestrator/src/main.rs | 3 +- crates/orchestrator/src/queue/sqs/mod.rs | 6 +- crates/orchestrator/src/tests/common/mod.rs | 2 +- crates/orchestrator/src/tests/config.rs | 169 +++++++++++--- .../src/tests/server/job_routes.rs | 2 +- .../sharp-service/src/client.rs | 8 +- .../sharp-service/tests/lib.rs | 36 +-- .../ethereum/src/tests/mod.rs | 39 ++-- .../starknet/src/tests/test.rs | 34 +-- docker-compose.yml | 16 +- e2e-tests/src/anvil.rs | 5 +- e2e-tests/src/node.rs | 9 + e2e-tests/tests.rs | 209 +++++++++++++++--- 26 files changed, 454 insertions(+), 166 deletions(-) diff --git a/.env.example b/.env.example index e4dd70aa..74a8ab95 100644 --- a/.env.example +++ b/.env.example @@ -41,20 +41,20 @@ DATABASE_NAME= ##### PROVER ##### PROVER_SERVICE= -SHARP_CUSTOMER_ID= -SHARP_URL= -SHARP_USER_CRT= -SHARP_USER_KEY= -SHARP_SERVER_CRT= -SHARP_PROOF_LAYOUT= +MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID= +MADARA_ORCHESTRATOR_SHARP_URL= +MADARA_ORCHESTRATOR_SHARP_USER_CRT= +MADARA_ORCHESTRATOR_SHARP_USER_KEY= +MADARA_ORCHESTRATOR_SHARP_SERVER_CRT= +MADARA_ORCHESTRATOR_SHARP_PROOF_LAYOUT= ##### ON CHAIN CONFIG ##### DA_LAYER= SETTLEMENT_LAYER= SETTLEMENT_RPC_URL= -MADARA_RPC_URL= -GPS_VERIFIER_CONTRACT_ADDRESS= +MADARA_ORCHESTRATOR_MADARA_RPC_URL= +MADARA_ORCHESTRATOR_GPS_VERIFIER_CONTRACT_ADDRESS= PRIVATE_KEY= ETHEREUM_PRIVATE_KEY= L1_CORE_CONTRACT_ADDRESS= diff --git a/.env.test b/.env.test index 205ba14f..f2e52bbf 100644 --- a/.env.test +++ b/.env.test @@ -1,14 +1,14 @@ #### AWS CONFIG #### -AWS_ACCESS_KEY_ID=test -AWS_SECRET_ACCESS_KEY=test +AWS_ACCESS_KEY_ID=AWS_ACCESS_KEY_ID +AWS_SECRET_ACCESS_KEY=AWS_SECRET_ACCESS_KEY AWS_REGION=us-east-1 # For Aws sdk -MADARA_ORCHESTRATOR_AWS_ENDPOINT_URL=http://localhost.localstack.cloud:4566 +AWS_ENDPOINT_URL=http://localhost.localstack.cloud:4566 # For Omniqueue -MADARA_ORCHESTRATOR_AWS_DEFAULT_REGION=localhost +AWS_DEFAULT_REGION=localhost #### ALERTS #### @@ -50,7 +50,7 @@ MADARA_ORCHESTRATOR_GPS_VERIFIER_CONTRACT_ADDRESS=0x07ec0D28e50322Eb0C159B9090ec MADARA_ORCHESTRATOR_SQS_PREFIX=madara_orchestrator MADARA_ORCHESTRATOR_SQS_SUFFIX=queue -MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL=http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/ +MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL=http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000 #### SETTLEMENT #### @@ -66,9 +66,9 @@ MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS=0x5b98B836969A60FEC50Fa925905Dd1D3 MADARA_ORCHESTRATOR_STARKNET_SETTLEMENT_RPC_URL=https://starknet-sepolia.public.blastapi.io MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 -MADARA_ORCHESTRATOR_STARKNET_CAIRO_CORE_CONTRACT_ADDRESS="" -MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS="" -MADARA_ORCHESTRATOR_MADARA_BINARY_PATH="/path/to/madara" +MADARA_ORCHESTRATOR_STARKNET_CAIRO_CORE_CONTRACT_ADDRESS= +MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS=10 +MADARA_ORCHESTRATOR_MADARA_BINARY_PATH=/path/to/madara #### STORAGE #### @@ -96,8 +96,9 @@ MADARA_ORCHESTRATOR_PORT=3000 MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS=1000 MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS=0 +MADARA_ORCHESTRATOR_MADARA_RPC_URL=http://localhost:9955 #### SNOS #### -MADARA_ORCHESTRATOR_RPC_FOR_SNOS=https://rpc.sepolia.madara.xyz +MADARA_ORCHESTRATOR_RPC_FOR_SNOS=http://81.16.176.130:9545 diff --git a/crates/da-clients/ethereum/src/config.rs b/crates/da-clients/ethereum/src/config.rs index 4471e1ce..3b8d58cd 100644 --- a/crates/da-clients/ethereum/src/config.rs +++ b/crates/da-clients/ethereum/src/config.rs @@ -2,5 +2,5 @@ use url::Url; #[derive(Debug, Clone)] pub struct EthereumDaParams { - pub da_rpc_url: Url, + pub ethereum_da_rpc_url: Url, } diff --git a/crates/orchestrator/src/cli/alert/aws_sns.rs b/crates/orchestrator/src/cli/alert/aws_sns.rs index ff6ceb26..3fdebaf9 100644 --- a/crates/orchestrator/src/cli/alert/aws_sns.rs +++ b/crates/orchestrator/src/cli/alert/aws_sns.rs @@ -2,7 +2,6 @@ use clap::Args; /// Parameters used to config AWS SNS. #[derive(Debug, Clone, Args)] -#[group(requires_all = ["sns_arn"])] pub struct AWSSNSCliArgs { /// Use the AWS SNS client #[arg(long)] diff --git a/crates/orchestrator/src/cli/aws_config.rs b/crates/orchestrator/src/cli/aws_config.rs index f24a1de3..6e0aae2c 100644 --- a/crates/orchestrator/src/cli/aws_config.rs +++ b/crates/orchestrator/src/cli/aws_config.rs @@ -1,7 +1,9 @@ use clap::Args; +use serde::Serialize; /// Parameters used to config AWS. -#[derive(Debug, Clone, Args)] +#[derive(Debug, Clone, Args, Serialize)] +#[group(requires_all = ["aws_access_key_id", "aws_secret_access_key", "aws_region"])] pub struct AWSConfigParams { /// The access key ID. #[arg(env = "AWS_ACCESS_KEY_ID", long)] @@ -16,14 +18,10 @@ pub struct AWSConfigParams { pub aws_region: String, /// The endpoint URL. - #[arg( - env = "MADARA_ORCHESTRATOR_AWS_ENDPOINT_URL", - long, - default_value = "http://localhost.localstack.cloud:4566" - )] + #[arg(env = "AWS_ENDPOINT_URL", long, default_value = "http://localhost.localstack.cloud:4566")] pub aws_endpoint_url: String, /// The default region. - #[arg(env = "MADARA_ORCHESTRATOR_AWS_DEFAULT_REGION", long, default_value = "localhost")] + #[arg(env = "AWS_DEFAULT_REGION", long, default_value = "localhost")] pub aws_default_region: String, } diff --git a/crates/orchestrator/src/cli/da/ethereum.rs b/crates/orchestrator/src/cli/da/ethereum.rs index f95551ff..7c9c5cec 100644 --- a/crates/orchestrator/src/cli/da/ethereum.rs +++ b/crates/orchestrator/src/cli/da/ethereum.rs @@ -3,7 +3,7 @@ use url::Url; /// Parameters used to config Ethereum. #[derive(Debug, Clone, Args)] -#[group(requires_all = ["da_rpc_url"])] +#[group(requires_all = ["ethereum_da_rpc_url"])] pub struct EthereumDaCliArgs { /// Use the Ethereum DA layer. #[arg(long)] @@ -11,5 +11,5 @@ pub struct EthereumDaCliArgs { /// The RPC URL of the Ethereum node. #[arg(env = "MADARA_ORCHESTRATOR_ETHEREUM_DA_RPC_URL", long)] - pub da_rpc_url: Option, + pub ethereum_da_rpc_url: Option, } diff --git a/crates/orchestrator/src/cli/database/mongodb.rs b/crates/orchestrator/src/cli/database/mongodb.rs index e7f0bc7f..f357a69a 100644 --- a/crates/orchestrator/src/cli/database/mongodb.rs +++ b/crates/orchestrator/src/cli/database/mongodb.rs @@ -2,7 +2,7 @@ use clap::Args; /// Parameters used to config MongoDB. #[derive(Debug, Clone, Args)] -#[group(requires_all = ["connection_url", "database_name"])] +#[group(requires_all = ["mongodb_connection_url"])] pub struct MongoDBCliArgs { /// Use the MongoDB client #[arg(long)] @@ -10,9 +10,9 @@ pub struct MongoDBCliArgs { /// The connection string to the MongoDB server. #[arg(env = "MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL", long, default_value = Some("mongodb://localhost:27017"))] - pub connection_url: Option, + pub mongodb_connection_url: Option, /// The name of the database. #[arg(env = "MADARA_ORCHESTRATOR_DATABASE_NAME", long, default_value = Some("orchestrator"))] - pub database_name: Option, + pub mongodb_database_name: Option, } diff --git a/crates/orchestrator/src/cli/instrumentation.rs b/crates/orchestrator/src/cli/instrumentation.rs index b2ed1dc0..e63b0ae0 100644 --- a/crates/orchestrator/src/cli/instrumentation.rs +++ b/crates/orchestrator/src/cli/instrumentation.rs @@ -7,11 +7,11 @@ use url::Url; #[group(requires_all = ["otel_service_name", "otel_collector_endpoint", "log_level"])] pub struct InstrumentationCliArgs { /// The name of the instrumentation service. - #[arg(env = "OTEL_SERVICE_NAME", long, default_value = "orchestrator")] + #[arg(env = "MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME", long, default_value = "orchestrator")] pub otel_service_name: Option, /// The endpoint of the collector. - #[arg(env = "OTEL_COLLECTOR_ENDPOINT", long)] + #[arg(env = "MADARA_ORCHESTRATOR_OTEL_COLLECTOR_ENDPOINT", long)] pub otel_collector_endpoint: Option, /// The log level. diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index a3fdeb49..d9b018c0 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -118,7 +118,7 @@ pub struct RunCmd { #[clap(flatten)] pub snos_args: snos::SNOSCliArgs, - #[arg(env = "MADARA_RPC_URL", long, required = true)] + #[arg(env = "MADARA_ORCHESTRATOR_MADARA_RPC_URL", long, required = true)] pub madara_rpc_url: Url, // Service @@ -201,8 +201,8 @@ impl RunCmd { pub fn validate_database_params(&self) -> Result { if self.mongodb_args.mongodb { Ok(DatabaseParams::MongoDB(MongoDBParams { - connection_url: self.mongodb_args.connection_url.clone().unwrap(), - database_name: self.mongodb_args.database_name.clone().unwrap(), + connection_url: self.mongodb_args.mongodb_connection_url.clone().unwrap(), + database_name: self.mongodb_args.mongodb_database_name.clone().unwrap(), })) } else { Err("Only MongoDB is supported as of now".to_string()) @@ -211,7 +211,9 @@ impl RunCmd { pub fn validate_da_params(&self) -> Result { if self.ethereum_da_args.da_on_ethereum { - Ok(DaParams::Ethereum(EthereumDaParams { da_rpc_url: self.ethereum_da_args.da_rpc_url.clone().unwrap() })) + Ok(DaParams::Ethereum(EthereumDaParams { + ethereum_da_rpc_url: self.ethereum_da_args.ethereum_da_rpc_url.clone().unwrap(), + })) } else { Err("Only Ethereum is supported as of now".to_string()) } diff --git a/crates/orchestrator/src/cli/prover/sharp.rs b/crates/orchestrator/src/cli/prover/sharp.rs index e49e19e5..5a650959 100644 --- a/crates/orchestrator/src/cli/prover/sharp.rs +++ b/crates/orchestrator/src/cli/prover/sharp.rs @@ -3,7 +3,7 @@ use url::Url; /// Parameters used to config Sharp. #[derive(Debug, Clone, Args)] -#[group(requires_all = ["sharp_customer_id", "sharp_url", "sharp_user_crt", "sharp_user_key", "sharp_server_crt", "sharp_proof_layout", "gps_verifier_contract_address"])] +#[group(requires_all = ["sharp_customer_id", "sharp_url", "sharp_user_crt", "sharp_user_key", "sharp_server_crt", "sharp_proof_layout", "gps_verifier_contract_address", "sharp_rpc_node_url"])] pub struct SharpCliArgs { /// Use the Sharp prover. #[arg(long)] diff --git a/crates/orchestrator/src/cli/queue/aws_sqs.rs b/crates/orchestrator/src/cli/queue/aws_sqs.rs index a3f9088d..0a71d29f 100644 --- a/crates/orchestrator/src/cli/queue/aws_sqs.rs +++ b/crates/orchestrator/src/cli/queue/aws_sqs.rs @@ -2,7 +2,7 @@ use clap::Args; /// Parameters used to config AWS SQS. #[derive(Debug, Clone, Args)] -#[group(requires_all = ["sqs_prefix", "sqs_suffix", "queue_base_url"])] +#[group(requires_all = ["queue_base_url"])] pub struct AWSSQSCliArgs { /// Use the AWS sqs client #[arg(long)] diff --git a/crates/orchestrator/src/cli/storage/aws_s3.rs b/crates/orchestrator/src/cli/storage/aws_s3.rs index 3b801261..d678f452 100644 --- a/crates/orchestrator/src/cli/storage/aws_s3.rs +++ b/crates/orchestrator/src/cli/storage/aws_s3.rs @@ -2,7 +2,7 @@ use clap::Args; /// Parameters used to config AWS S3. #[derive(Debug, Clone, Args)] -#[group(requires_all = ["bucket_name"])] +#[group()] pub struct AWSS3CliArgs { /// Use the AWS s3 client #[arg(long)] diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 828da38a..cbe825ec 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -261,7 +261,7 @@ pub async fn build_da_client(da_params: &DaParams) -> Box { let client = RpcClient::new_http( - Url::from_str(ethereum_da_params.da_rpc_url.as_str()).expect("Failed to parse DA_RPC_URL"), + Url::from_str(ethereum_da_params.ethereum_da_rpc_url.as_str()).expect("Failed to parse DA_RPC_URL"), ); let provider = ProviderBuilder::<_, Ethereum>::new().on_client(client); Box::new(EthereumDaClient { provider }) diff --git a/crates/orchestrator/src/main.rs b/crates/orchestrator/src/main.rs index 6e1e79a6..6ff63ff9 100644 --- a/crates/orchestrator/src/main.rs +++ b/crates/orchestrator/src/main.rs @@ -16,8 +16,7 @@ async fn main() { // TODO: could this be an ARC ? let run_cmd: RunCmd = RunCmd::parse(); - // print the run cmd - println!("{:?}", run_cmd); + println!("{:?}", run_cmd.aws_sqs_args.queue_base_url); // Analytics Setup let instrumentation_params = run_cmd.validate_instrumentation_params().expect("Invalid instrumentation params"); diff --git a/crates/orchestrator/src/queue/sqs/mod.rs b/crates/orchestrator/src/queue/sqs/mod.rs index 48e1f0e9..082bf91a 100644 --- a/crates/orchestrator/src/queue/sqs/mod.rs +++ b/crates/orchestrator/src/queue/sqs/mod.rs @@ -4,11 +4,12 @@ use async_trait::async_trait; use color_eyre::Result; use omniqueue::backends::{SqsBackend, SqsConfig, SqsConsumer, SqsProducer}; use omniqueue::{Delivery, QueueError}; +use serde::Serialize; use super::job_queue::QueueType; use crate::queue::QueueProvider; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize)] pub struct AWSSQSParams { pub queue_base_url: String, pub sqs_prefix: String, @@ -17,7 +18,8 @@ pub struct AWSSQSParams { impl AWSSQSParams { pub fn get_queue_url(&self, queue_type: QueueType) -> String { - format!("{}/{}", self.queue_base_url, self.get_queue_name(queue_type)) + let name = format!("{}/{}", self.queue_base_url, self.get_queue_name(queue_type)); + name } pub fn get_queue_name(&self, queue_type: QueueType) -> String { diff --git a/crates/orchestrator/src/tests/common/mod.rs b/crates/orchestrator/src/tests/common/mod.rs index 0e25c7d3..1b3f3cd4 100644 --- a/crates/orchestrator/src/tests/common/mod.rs +++ b/crates/orchestrator/src/tests/common/mod.rs @@ -50,7 +50,7 @@ pub fn custom_job_item(default_job_item: JobItem, #[default(String::from("0"))] pub async fn create_sns_arn(provider_config: Arc) -> Result<(), SdkError> { let sns_client = get_sns_client(provider_config.get_aws_client_or_panic()).await; - sns_client.create_topic().name(get_env_var_or_panic("AWS_SNS_ARN_NAME")).send().await?; + sns_client.create_topic().name(get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_SNS_ARN")).send().await?; Ok(()) } diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 73685d33..faa11086 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -2,23 +2,37 @@ use std::net::SocketAddr; use std::sync::Arc; use axum::Router; -use clap::Parser; -use color_eyre::eyre::eyre; use da_client_interface::{DaClient, MockDaClient}; +use ethereum_da_client::config::EthereumDaParams; +use ethereum_settlement_client::config::EthereumSettlementParams; use httpmock::MockServer; use prover_client_interface::{MockProverClient, ProverClient}; use settlement_client_interface::{MockSettlementClient, SettlementClient}; +use sharp_service::config::SharpParams; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::JsonRpcClient; use url::Url; +use utils::env_utils::get_env_var_or_panic; +use crate::alerts::aws_sns::AWSSNSParams; use crate::alerts::Alerts; -use crate::cli::RunCmd; -use crate::config::{get_aws_config, Config, OrchestratorConfig, ProviderConfig}; +use crate::cli::alert::AlertParams; +use crate::cli::aws_config::AWSConfigParams; +use crate::cli::da::DaParams; +use crate::cli::database::DatabaseParams; +use crate::cli::prover::ProverParams; +use crate::cli::queue::QueueParams; +use crate::cli::settlement::SettlementParams; +use crate::cli::snos::SNOSParams; +use crate::cli::storage::StorageParams; +use crate::config::{get_aws_config, Config, OrchestratorConfig, ProviderConfig, ServiceParams}; +use crate::data_storage::aws_s3::config::AWSS3Params; use crate::data_storage::{DataStorage, MockDataStorage}; +use crate::database::mongodb::config::MongoDBParams; use crate::database::{Database, MockDatabase}; +use crate::queue::sqs::AWSSQSParams; use crate::queue::{MockQueueProvider, QueueProvider}; -use crate::routes::{get_server_url, setup_server}; +use crate::routes::{get_server_url, setup_server, ServerParams}; use crate::tests::common::{create_queues, create_sns_arn, drop_database}; // Inspiration : https://rust-unofficial.github.io/patterns/patterns/creational/builder.html @@ -181,17 +195,20 @@ impl TestConfigBuilder { pub async fn build(self) -> TestConfigBuilderReturns { dotenvy::from_filename("../.env.test").expect("Failed to load the .env.test file"); - let run_cmd = RunCmd::parse(); - let aws_config = &run_cmd.aws_config_args; - let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(aws_config).await))); + let ( + db_params, + storage_params, + queue_params, + aws_config, + orchestrator_config, + alert_params, + settlement_params, + da_params, + prover_params, + ) = get_env_params(); - let orchestrator_config = OrchestratorConfig { - madara_rpc_url: run_cmd.madara_rpc_url.clone(), - snos_config: run_cmd.validate_snos_params().expect("Failed to validate SNOS params"), - service_config: run_cmd.validate_service_params().expect("Failed to validate service params"), - server_config: run_cmd.validate_server_params().expect("Failed to validate server params"), - }; + let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(&aws_config).await))); let TestConfigBuilder { starknet_rpc_url_type, @@ -206,39 +223,31 @@ impl TestConfigBuilder { api_server_type, } = self; - let (starknet_rpc_url, starknet_client, starknet_server) = + let (_starknet_rpc_url, starknet_client, starknet_server) = implement_client::init_starknet_client(starknet_rpc_url_type, starknet_client_type).await; // init alerts - let alert_params = - run_cmd.validate_alert_params().map_err(|e| eyre!("Failed to validate alert params: {e}")).unwrap(); let alerts = implement_client::init_alerts(alerts_type, &alert_params, provider_config.clone()).await; - let da_params = run_cmd.validate_da_params().unwrap(); let da_client = implement_client::init_da_client(da_client_type, &da_params).await; - let settlement_params = run_cmd.validate_settlement_params().unwrap(); let settlement_client = implement_client::init_settlement_client(settlement_client_type, &settlement_params).await; - let prover_params = run_cmd.validate_prover_params().unwrap(); let prover_client = implement_client::init_prover_client(prover_client_type, &prover_params).await; // External Dependencies - let data_storage_params = run_cmd.validate_storage_params().unwrap(); let storage = - implement_client::init_storage_client(storage_type, &data_storage_params, provider_config.clone()).await; + implement_client::init_storage_client(storage_type, &storage_params, provider_config.clone()).await; - let database_params = run_cmd.validate_database_params().unwrap(); - let database = implement_client::init_database(database_type, &database_params).await; + let database = implement_client::init_database(database_type, &db_params).await; - let queue_params = run_cmd.validate_queue_params().unwrap(); let queue = implement_client::init_queue_client(queue_type, queue_params.clone()).await; // Deleting and Creating the queues in sqs. create_queues(provider_config.clone(), &queue_params).await.expect("Not able to delete and create the queues."); // Deleting the database - drop_database(&database_params).await.expect("Unable to drop the database."); + drop_database(&db_params).await.expect("Unable to drop the database."); // Creating the SNS ARN create_sns_arn(provider_config.clone()).await.expect("Unable to create the sns arn"); @@ -451,3 +460,111 @@ pub mod implement_client { (rpc_url, starknet_client, server) } } + +fn get_env_params() -> ( + DatabaseParams, + StorageParams, + QueueParams, + AWSConfigParams, + OrchestratorConfig, + AlertParams, + SettlementParams, + DaParams, + ProverParams, +) { + let db_params = DatabaseParams::MongoDB(MongoDBParams { + connection_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL"), + database_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_DATABASE_NAME"), + }); + + let storage_params = StorageParams::AWSS3(AWSS3Params { + bucket_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME"), + }); + let queue_params = QueueParams::AWSSQS(AWSSQSParams { + queue_base_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL"), + sqs_prefix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_PREFIX"), + sqs_suffix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_SUFFIX"), + }); + + let aws_config = AWSConfigParams { + aws_access_key_id: get_env_var_or_panic("AWS_ACCESS_KEY_ID"), + aws_secret_access_key: get_env_var_or_panic("AWS_SECRET_ACCESS_KEY"), + aws_region: get_env_var_or_panic("AWS_REGION"), + aws_endpoint_url: get_env_var_or_panic("AWS_ENDPOINT_URL"), + aws_default_region: get_env_var_or_panic("AWS_DEFAULT_REGION"), + }; + + let da_params = DaParams::Ethereum(EthereumDaParams { + ethereum_da_rpc_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_DA_RPC_URL")) + .expect("Failed to parse MADARA_ORCHESTRATOR_ETHEREUM_RPC_URL"), + }); + + let alert_params = + AlertParams::AWSSNS(AWSSNSParams { sns_arn: get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_SNS_ARN") }); + + let settlement_params = SettlementParams::Ethereum(EthereumSettlementParams { + ethereum_rpc_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL")) + .expect("Failed to parse MADARA_ORCHESTRATOR_ETHEREUM_RPC_URL"), + ethereum_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), + l1_core_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"), + starknet_operator_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"), + }); + + let snos_config = SNOSParams { + rpc_for_snos: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_RPC_FOR_SNOS")) + .expect("Failed to parse MADARA_ORCHESTRATOR_RPC_FOR_SNOS"), + }; + + let service_config = ServiceParams { + max_block_to_process: Some( + get_env_var_or_panic("MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS") + .parse() + .expect("Failed to parse MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS"), + ), + min_block_to_process: Some( + get_env_var_or_panic("MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS") + .parse() + .expect("Failed to parse MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS"), + ), + }; + + let server_config = ServerParams { + host: get_env_var_or_panic("MADARA_ORCHESTRATOR_HOST"), + port: get_env_var_or_panic("MADARA_ORCHESTRATOR_PORT") + .parse() + .expect("Failed to parse MADARA_ORCHESTRATOR_PORT"), + }; + + let orchestrator_config = OrchestratorConfig { + madara_rpc_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_MADARA_RPC_URL")) + .expect("Failed to parse MADARA_ORCHESTRATOR_MADARA_RPC_URL"), + snos_config, + service_config, + server_config, + }; + + let prover_params = ProverParams::Sharp(SharpParams { + sharp_customer_id: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID"), + sharp_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_URL")) + .expect("Failed to parse MADARA_ORCHESTRATOR_SHARP_URL"), + sharp_user_crt: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_USER_CRT"), + sharp_user_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_USER_KEY"), + sharp_rpc_node_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_RPC_NODE_URL")) + .expect("Failed to parse MADARA_ORCHESTRATOR_SHARP_RPC_NODE_URL"), + sharp_server_crt: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_SERVER_CRT"), + sharp_proof_layout: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_PROOF_LAYOUT"), + gps_verifier_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_GPS_VERIFIER_CONTRACT_ADDRESS"), + }); + + ( + db_params, + storage_params, + queue_params, + aws_config, + orchestrator_config, + alert_params, + settlement_params, + da_params, + prover_params, + ) +} diff --git a/crates/orchestrator/src/tests/server/job_routes.rs b/crates/orchestrator/src/tests/server/job_routes.rs index 458b33ff..c2a3b0cc 100644 --- a/crates/orchestrator/src/tests/server/job_routes.rs +++ b/crates/orchestrator/src/tests/server/job_routes.rs @@ -23,7 +23,7 @@ use crate::tests::config::{ConfigType, TestConfigBuilder}; async fn setup_trigger() -> (SocketAddr, Arc) { dotenvy::from_filename("../.env.test").expect("Failed to load the .env.test file"); - let madara_url = get_env_var_or_panic("MADARA_RPC_URL"); + let madara_url = get_env_var_or_panic("MADARA_ORCHESTRATOR_MADARA_RPC_URL"); let provider = JsonRpcClient::new(HttpTransport::new( Url::parse(madara_url.as_str().to_string().as_str()).expect("Failed to parse URL"), )); diff --git a/crates/prover-services/sharp-service/src/client.rs b/crates/prover-services/sharp-service/src/client.rs index fb05b0e9..09f38457 100644 --- a/crates/prover-services/sharp-service/src/client.rs +++ b/crates/prover-services/sharp-service/src/client.rs @@ -20,9 +20,9 @@ pub struct SharpClient { impl SharpClient { /// We need to set up the client with the provided certificates. /// We need to have three secrets : - /// - base64(SHARP_USER_CRT) - /// - base64(SHARP_USER_KEY) - /// - base64(SHARP_SERVER_CRT) + /// - base64(MADARA_ORCHESTRATOR_SHARP_USER_CRT) + /// - base64(MADARA_ORCHESTRATOR_SHARP_USER_KEY) + /// - base64(MADARA_ORCHESTRATOR_SHARP_SERVER_CRT) /// /// You can run this command in terminal to convert a file output into base64 /// and then copy it and paste it into .env file : @@ -69,7 +69,7 @@ impl SharpClient { let cairo_key = Uuid::new_v4(); let cairo_key_string = cairo_key.to_string(); - let proof_layout = get_env_var_or_panic("SHARP_PROOF_LAYOUT"); + let proof_layout = get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_PROOF_LAYOUT"); // Params for sending the PIE file to the prover // for temporary reference you can check this doc : diff --git a/crates/prover-services/sharp-service/tests/lib.rs b/crates/prover-services/sharp-service/tests/lib.rs index 29c1c691..e117202b 100644 --- a/crates/prover-services/sharp-service/tests/lib.rs +++ b/crates/prover-services/sharp-service/tests/lib.rs @@ -22,14 +22,14 @@ async fn prover_client_submit_task_works() { dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); let sharp_params = SharpParams { - sharp_customer_id: get_env_var_or_panic("SHARP_CUSTOMER_ID"), - sharp_url: Url::parse(&get_env_var_or_panic("SHARP_URL")).unwrap(), - sharp_user_crt: get_env_var_or_panic("SHARP_USER_CRT"), - sharp_user_key: get_env_var_or_panic("SHARP_USER_KEY"), - sharp_rpc_node_url: Url::parse(&get_env_var_or_panic("SHARP_RPC_NODE_URL")).unwrap(), - sharp_server_crt: get_env_var_or_panic("SHARP_SERVER_CRT"), - sharp_proof_layout: get_env_var_or_panic("SHARP_PROOF_LAYOUT"), - gps_verifier_contract_address: get_env_var_or_panic("GPS_VERIFIER_CONTRACT_ADDRESS"), + sharp_customer_id: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID"), + sharp_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_URL")).unwrap(), + sharp_user_crt: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_USER_CRT"), + sharp_user_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_USER_KEY"), + sharp_rpc_node_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_RPC_NODE_URL")).unwrap(), + sharp_server_crt: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_SERVER_CRT"), + sharp_proof_layout: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_PROOF_LAYOUT"), + gps_verifier_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_GPS_VERIFIER_CONTRACT_ADDRESS"), }; let server = MockServer::start(); @@ -42,7 +42,7 @@ async fn prover_client_submit_task_works() { "code" : "JOB_RECEIVED_SUCCESSFULLY" } ); - let customer_id = get_env_var_or_panic("SHARP_CUSTOMER_ID"); + let customer_id = get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID"); let sharp_add_job_call = server.mock(|when, then| { when.path_contains("/add_job").query_param("customer_id", customer_id.as_str()); then.status(200).body(serde_json::to_vec(&sharp_response).unwrap()); @@ -67,19 +67,19 @@ async fn prover_client_get_task_status_works(#[case] cairo_job_status: CairoJobS dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); let sharp_params = SharpParams { - sharp_customer_id: get_env_var_or_panic("SHARP_CUSTOMER_ID"), - sharp_url: Url::parse(&get_env_var_or_panic("SHARP_URL")).unwrap(), - sharp_user_crt: get_env_var_or_panic("SHARP_USER_CRT"), - sharp_user_key: get_env_var_or_panic("SHARP_USER_KEY"), - sharp_rpc_node_url: Url::parse(&get_env_var_or_panic("SHARP_RPC_NODE_URL")).unwrap(), - sharp_server_crt: get_env_var_or_panic("SHARP_SERVER_CRT"), - sharp_proof_layout: get_env_var_or_panic("SHARP_PROOF_LAYOUT"), - gps_verifier_contract_address: get_env_var_or_panic("GPS_VERIFIER_CONTRACT_ADDRESS"), + sharp_customer_id: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID"), + sharp_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_URL")).unwrap(), + sharp_user_crt: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_USER_CRT"), + sharp_user_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_USER_KEY"), + sharp_rpc_node_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_RPC_NODE_URL")).unwrap(), + sharp_server_crt: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_SERVER_CRT"), + sharp_proof_layout: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_PROOF_LAYOUT"), + gps_verifier_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_GPS_VERIFIER_CONTRACT_ADDRESS"), }; let server = MockServer::start(); let sharp_service = SharpProverService::with_test_settings(server.port(), &sharp_params); - let customer_id = get_env_var_or_panic("SHARP_CUSTOMER_ID"); + let customer_id = get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID"); let sharp_add_job_call = server.mock(|when, then| { when.path_contains("/get_status").query_param("customer_id", customer_id.as_str()); diff --git a/crates/settlement-clients/ethereum/src/tests/mod.rs b/crates/settlement-clients/ethereum/src/tests/mod.rs index 80a5b301..b0e6e931 100644 --- a/crates/settlement-clients/ethereum/src/tests/mod.rs +++ b/crates/settlement-clients/ethereum/src/tests/mod.rs @@ -31,13 +31,13 @@ lazy_static! { .to_str() .expect("Path contains invalid Unicode") .to_string(); - static ref ETH_RPC: String = get_env_var_or_panic("SETTLEMENT_RPC_URL"); + static ref ETH_RPC: String = get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_SETTLEMENT_RPC_URL"); pub static ref STARKNET_OPERATOR_ADDRESS: Address = - Address::from_str(get_env_var_or_panic("STARKNET_OPERATOR_ADDRESS").as_str()) - .expect("Could not parse STARKNET_OPERATOR_ADDRESS"); + Address::from_str(get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS").as_str()) + .expect("Could not parse MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"); static ref STARKNET_CORE_CONTRACT_ADDRESS: Address = - Address::from_str(get_env_var_or_panic("L1_CORE_CONTRACT_ADDRESS").as_str()) - .expect("Could not parse L1_CORE_CONTRACT_ADDRESS"); + Address::from_str(get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS").as_str()) + .expect("Could not parse MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"); pub static ref TEST_NONCE: u64 = 666068; } @@ -157,10 +157,11 @@ mod settlement_client_tests { dotenvy::from_filename(&*ENV_FILE_PATH).expect("Could not load .env.test file."); let ethereum_settlement_params = EthereumSettlementParams { - ethereum_rpc_url: Url::from_str(get_env_var_or_panic("SETTLEMENT_RPC_URL").as_str()).unwrap(), - ethereum_private_key: get_env_var_or_panic("ETHEREUM_PRIVATE_KEY"), - l1_core_contract_address: get_env_var_or_panic("L1_CORE_CONTRACT_ADDRESS"), - starknet_operator_address: get_env_var_or_panic("STARKNET_OPERATOR_ADDRESS"), + ethereum_rpc_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL")) + .expect("Failed to parse MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL"), + ethereum_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), + l1_core_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"), + starknet_operator_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"), }; let setup = EthereumTestBuilder::new().build().await; @@ -220,10 +221,13 @@ mod settlement_client_tests { dotenvy::from_filename(&*ENV_FILE_PATH).expect("Could not load .env.test file."); let ethereum_settlement_params = EthereumSettlementParams { - ethereum_rpc_url: Url::from_str(get_env_var_or_panic("SETTLEMENT_RPC_URL").as_str()).unwrap(), - ethereum_private_key: get_env_var_or_panic("ETHEREUM_PRIVATE_KEY"), - l1_core_contract_address: get_env_var_or_panic("L1_CORE_CONTRACT_ADDRESS"), - starknet_operator_address: get_env_var_or_panic("STARKNET_OPERATOR_ADDRESS"), + ethereum_rpc_url: Url::from_str( + get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL").as_str(), + ) + .unwrap(), + ethereum_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), + l1_core_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"), + starknet_operator_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"), }; let setup = EthereumTestBuilder::new() @@ -286,10 +290,11 @@ mod settlement_client_tests { dotenvy::from_filename(&*ENV_FILE_PATH).expect("Could not load .env.test file."); let ethereum_settlement_params = EthereumSettlementParams { - ethereum_rpc_url: Url::from_str(get_env_var_or_panic("SETTLEMENT_RPC_URL").as_str()).unwrap(), - ethereum_private_key: get_env_var_or_panic("ETHEREUM_PRIVATE_KEY"), - l1_core_contract_address: get_env_var_or_panic("L1_CORE_CONTRACT_ADDRESS"), - starknet_operator_address: get_env_var_or_panic("STARKNET_OPERATOR_ADDRESS"), + ethereum_rpc_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL")) + .expect("Failed to parse MADARA_ORCHESTRATOR_ETHEREUM_RPC_URL"), + ethereum_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), + l1_core_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"), + starknet_operator_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"), }; let _setup = EthereumTestBuilder::new().with_fork_block(fork_block_no).build().await; diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index e4b494d1..07de418c 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -82,12 +82,16 @@ async fn setup(#[future] spin_up_madara: MadaraCmd) -> (LocalWalletSignerMiddlew let starknet_settlement_params: StarknetSettlementParams = StarknetSettlementParams { starknet_rpc_url: Url::parse(madara_process.rpc_url.as_ref()).unwrap(), - starknet_private_key: get_env_var_or_panic("STARKNET_PRIVATE_KEY"), - starknet_account_address: get_env_var_or_panic("STARKNET_ACCOUNT_ADDRESS"), - starknet_cairo_core_contract_address: get_env_var_or_panic("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS"), - starknet_finality_retry_wait_in_secs: get_env_var_or_panic("STARKNET_FINALITY_RETRY_WAIT_IN_SECS") - .parse::() - .unwrap(), + starknet_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY"), + starknet_account_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS"), + starknet_cairo_core_contract_address: get_env_var_or_panic( + "MADARA_ORCHESTRATOR_STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", + ), + starknet_finality_retry_wait_in_secs: get_env_var_or_panic( + "MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS", + ) + .parse::() + .unwrap(), madara_binary_path: get_env_var_or_panic("MADARA_BINARY_PATH"), }; @@ -114,13 +118,17 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) dotenvy::from_filename_override(".env.test").expect("Failed to load the .env file"); let starknet_settlement_params: StarknetSettlementParams = StarknetSettlementParams { - starknet_rpc_url: Url::parse(&get_env_var_or_panic("STARKNET_RPC_URL")).unwrap(), - starknet_private_key: get_env_var_or_panic("STARKNET_PRIVATE_KEY"), - starknet_account_address: get_env_var_or_panic("STARKNET_ACCOUNT_ADDRESS"), - starknet_cairo_core_contract_address: get_env_var_or_panic("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS"), - starknet_finality_retry_wait_in_secs: get_env_var_or_panic("STARKNET_FINALITY_RETRY_WAIT_IN_SECS") - .parse::() - .unwrap(), + starknet_rpc_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_SETTLEMENT_RPC_URL")).unwrap(), + starknet_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY"), + starknet_account_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS"), + starknet_cairo_core_contract_address: get_env_var_or_panic( + "MADARA_ORCHESTRATOR_STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", + ), + starknet_finality_retry_wait_in_secs: get_env_var_or_panic( + "MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS", + ) + .parse::() + .unwrap(), madara_binary_path: get_env_var_or_panic("MADARA_BINARY_PATH"), }; diff --git a/docker-compose.yml b/docker-compose.yml index e82ac9c1..a05d7411 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,20 +28,20 @@ services: - SQS_WORKER_TRIGGER_QUEUE_URL=${SQS_WORKER_TRIGGER_QUEUE_URL} - ALERTS=${ALERTS:-sns} - AWS_SNS_ARN=${AWS_SNS_ARN} - - AWS_SNS_ARN_NAME=${AWS_SNS_ARN_NAME} + - MADARA_ORCHESTRATOR_AWS_SNS_ARN=${MADARA_ORCHESTRATOR_AWS_SNS_ARN} - DATABASE=${DATABASE:-mongodb} - MONGODB_CONNECTION_STRING=${MONGODB_CONNECTION_STRING} - PROVER_SERVICE=${PROVER_SERVICE:-sharp} - - SHARP_CUSTOMER_ID=${SHARP_CUSTOMER_ID} - - SHARP_URL=${SHARP_URL} - - SHARP_USER_CRT=${SHARP_USER_CRT} - - SHARP_USER_KEY=${SHARP_USER_KEY} - - SHARP_SERVER_CRT=${SHARP_SERVER_CRT} - - SHARP_PROOF_LAYOUT=${SHARP_PROOF_LAYOUT:-small} + - MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID=${MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID} + - MADARA_ORCHESTRATOR_SHARP_URL=${MADARA_ORCHESTRATOR_SHARP_URL} + - MADARA_ORCHESTRATOR_SHARP_USER_CRT=${MADARA_ORCHESTRATOR_SHARP_USER_CRT} + - MADARA_ORCHESTRATOR_SHARP_USER_KEY=${MADARA_ORCHESTRATOR_SHARP_USER_KEY} + - MADARA_ORCHESTRATOR_SHARP_SERVER_CRT=${MADARA_ORCHESTRATOR_SHARP_SERVER_CRT} + - MADARA_ORCHESTRATOR_SHARP_PROOF_LAYOUT=${MADARA_ORCHESTRATOR_SHARP_PROOF_LAYOUT:-small} - DA_LAYER=${DA_LAYER:-ethereum} - SETTLEMENT_LAYER=${SETTLEMENT_LAYER:-ethereum} - SETTLEMENT_RPC_URL=${SETTLEMENT_RPC_URL} - - MADARA_RPC_URL=${MADARA_RPC_URL} + - MADARA_ORCHESTRATOR_MADARA_RPC_URL=${MADARA_ORCHESTRATOR_MADARA_RPC_URL} - MEMORY_PAGES_CONTRACT_ADDRESS=${MEMORY_PAGES_CONTRACT_ADDRESS} - ETHEREUM_PRIVATE_KEY=${ETHEREUM_PRIVATE_KEY} - L1_CORE_CONTRACT_ADDRESS=${L1_CORE_CONTRACT_ADDRESS} diff --git a/e2e-tests/src/anvil.rs b/e2e-tests/src/anvil.rs index 5d939f88..0a5ff759 100644 --- a/e2e-tests/src/anvil.rs +++ b/e2e-tests/src/anvil.rs @@ -50,8 +50,9 @@ impl AnvilSetup { } pub async fn deploy_contracts(&self) -> (Address, Address) { - let wallet = - EthereumWallet::from(PrivateKeySigner::from_str(&get_env_var_or_panic("ETHEREUM_PRIVATE_KEY")).unwrap()); + let wallet = EthereumWallet::from( + PrivateKeySigner::from_str(&get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY")).unwrap(), + ); let provider = ProviderBuilder::new().with_recommended_fillers().wallet(wallet).on_http(self.rpc_url.clone()); let starknet_core_contract_client = StarknetCoreContract::deploy(&provider).await.unwrap(); diff --git a/e2e-tests/src/node.rs b/e2e-tests/src/node.rs index ef4c626f..a09f99e2 100644 --- a/e2e-tests/src/node.rs +++ b/e2e-tests/src/node.rs @@ -45,6 +45,15 @@ impl Orchestrator { .arg("orchestrator") .arg("--features") .arg("testing") + .arg("--") + // --settle-on-ethereum --aws-s3 --aws-sqs --aws-sns --mongodb --sharp --da-on-ethereum ") + .arg("--settle-on-ethereum") + .arg("--aws-s3") + .arg("--aws-sqs") + .arg("--aws-sns") + .arg("--mongodb") + .arg("--sharp") + .arg("--da-on-ethereum") .current_dir(repository_root) .envs(envs) .stdout(Stdio::piped()) diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index 166c7858..39cbe157 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -4,7 +4,6 @@ use std::io::Read; use std::time::{Duration, Instant}; use chrono::{SubsecRound, Utc}; -use clap::Parser as _; use e2e_tests::anvil::AnvilSetup; use e2e_tests::localstack::LocalStack; use e2e_tests::mock_server::MockResponseBodyType; @@ -13,14 +12,17 @@ use e2e_tests::starknet_client::StarknetClient; use e2e_tests::utils::{get_mongo_db_client, read_state_update_from_file, vec_u8_to_hex_string}; use e2e_tests::{MongoDbServer, Orchestrator}; use mongodb::bson::doc; +use orchestrator::cli::aws_config::AWSConfigParams; use orchestrator::cli::database::DatabaseParams; use orchestrator::cli::queue::QueueParams; use orchestrator::cli::storage::StorageParams; -use orchestrator::cli::RunCmd; +use orchestrator::data_storage::aws_s3::config::AWSS3Params; use orchestrator::data_storage::DataStorage; +use orchestrator::database::mongodb::config::MongoDBParams; use orchestrator::jobs::constants::{JOB_METADATA_SNOS_BLOCK, JOB_METADATA_STATE_UPDATE_BLOCKS_TO_SETTLE_KEY}; use orchestrator::jobs::types::{ExternalId, JobItem, JobStatus, JobType}; -use orchestrator::queue::job_queue::{JobQueueMessage, WorkerTriggerType}; +use orchestrator::queue::job_queue::{JobQueueMessage, QueueType, WorkerTriggerType}; +use orchestrator::queue::sqs::AWSSQSParams; use rstest::rstest; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -51,10 +53,28 @@ struct Setup { impl Setup { /// Initialise a new setup - pub async fn new(l2_block_number: String, run_cmd: RunCmd) -> Self { - let db_params = run_cmd.validate_database_params().expect("Invalid database params"); - let storage_params = run_cmd.validate_storage_params().expect("Invalid storage params"); - let queue_params = run_cmd.validate_queue_params().expect("Invalid queue params"); + pub async fn new(l2_block_number: String) -> Self { + let db_params = DatabaseParams::MongoDB(MongoDBParams { + connection_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL"), + database_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_DATABASE_NAME"), + }); + + let storage_params = StorageParams::AWSS3(AWSS3Params { + bucket_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME"), + }); + let queue_params = QueueParams::AWSSQS(AWSSQSParams { + queue_base_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL"), + sqs_prefix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_PREFIX"), + sqs_suffix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_SUFFIX"), + }); + + let aws_config = AWSConfigParams { + aws_access_key_id: get_env_var_or_panic("AWS_ACCESS_KEY_ID"), + aws_secret_access_key: get_env_var_or_panic("AWS_SECRET_ACCESS_KEY"), + aws_region: get_env_var_or_panic("AWS_REGION"), + aws_endpoint_url: get_env_var_or_panic("AWS_ENDPOINT_URL"), + aws_default_region: get_env_var_or_panic("AWS_DEFAULT_REGION"), + }; let DatabaseParams::MongoDB(mongodb_params) = db_params; @@ -72,7 +92,6 @@ impl Setup { println!("✅ Anvil setup completed"); // Setting up LocalStack - let aws_config = run_cmd.aws_config_args; let StorageParams::AWSS3(s3_params) = storage_params; let QueueParams::AWSSQS(sqs_params) = queue_params; let localstack_instance = LocalStack::new(aws_config, &s3_params).await; @@ -83,32 +102,34 @@ impl Setup { localstack_instance.setup_event_bridge(WorkerTriggerType::DataSubmission, &sqs_params).await.unwrap(); localstack_instance.setup_event_bridge(WorkerTriggerType::UpdateState, &sqs_params).await.unwrap(); - println!("✅ Localstack instance setup completed"); - let mut env_vec: Vec<(String, String)> = - vec![("MONGODB_CONNECTION_STRING".to_string(), mongo_db_instance.endpoint().to_string())]; + vec![("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL".to_string(), mongo_db_instance.endpoint().to_string())]; // Adding other values to the environment variables vector - env_vec.push(("MADARA_RPC_URL".to_string(), get_env_var_or_panic("RPC_FOR_SNOS"))); - env_vec.push(("SETTLEMENT_RPC_URL".to_string(), anvil_setup.rpc_url.to_string())); - env_vec.push(("SHARP_URL".to_string(), sharp_client.url())); - - // Sharp envs - env_vec.push(("SHARP_CUSTOMER_ID".to_string(), get_env_var_or_panic("SHARP_CUSTOMER_ID"))); - env_vec.push(("SHARP_USER_CRT".to_string(), get_env_var_or_panic("SHARP_USER_CRT"))); - env_vec.push(("SHARP_USER_KEY".to_string(), get_env_var_or_panic("SHARP_USER_KEY"))); - env_vec.push(("SHARP_SERVER_CRT".to_string(), get_env_var_or_panic("SHARP_SERVER_CRT"))); + env_vec.push(("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL".to_string(), anvil_setup.rpc_url.to_string())); + env_vec.push(("MADARA_ORCHESTRATOR_SHARP_URL".to_string(), sharp_client.url())); // Adding impersonation for operator as our own address here. // As we are using test contracts thus we don't need any impersonation. // But that logic is being used in integration tests so to keep that. We // add this address here. // Anvil.addresses[0] - env_vec - .push(("STARKNET_OPERATOR_ADDRESS".to_string(), "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266".to_string())); - env_vec.push(("GPS_VERIFIER_CONTRACT_ADDRESS".to_string(), verifier_contract_address.to_string())); - env_vec.push(("L1_CORE_CONTRACT_ADDRESS".to_string(), starknet_core_contract_address.to_string())); - env_vec.push(("MAX_BLOCK_TO_PROCESS".to_string(), l2_block_number)); + env_vec.push(( + "MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS".to_string(), + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266".to_string(), + )); + env_vec.push(( + "MADARA_ORCHESTRATOR_GPS_VERIFIER_CONTRACT_ADDRESS".to_string(), + verifier_contract_address.to_string(), + )); + env_vec.push(( + "MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS".to_string(), + starknet_core_contract_address.to_string(), + )); + env_vec.push(("MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS".to_string(), l2_block_number)); + + let env_vec_2: Vec<(String, String)> = set_env_vars(); + env_vec.extend(env_vec_2); Self { mongo_db_instance, starknet_client, sharp_client, env_vector: env_vec, localstack_instance } } @@ -143,16 +164,20 @@ async fn test_orchestrator_workflow(#[case] l2_block_number: String) { // setting up of the test and during orchestrator run too. dotenvy::from_filename(".env.test").expect("Failed to load the .env file"); - let run_cmd = RunCmd::parse(); + let queue_params = AWSSQSParams { + queue_base_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL"), + sqs_prefix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_PREFIX"), + sqs_suffix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_SUFFIX"), + }; - let mut setup_config = Setup::new(l2_block_number.clone(), run_cmd).await; + let mut setup_config = Setup::new(l2_block_number.clone()).await; // Setup S3 setup_s3(setup_config.localstack().s3_client()).await.unwrap(); // Step 1 : SNOS job runs ========================================= // Updates the job in the db let job_id = put_job_data_in_db_snos(setup_config.mongo_db_instance(), l2_block_number.clone()).await; - put_snos_job_in_processing_queue(setup_config.localstack(), job_id).await.unwrap(); + put_snos_job_in_processing_queue(setup_config.localstack(), job_id, queue_params).await.unwrap(); // Step 2: Proving Job ============================================ // Mocking the endpoint @@ -172,6 +197,8 @@ async fn test_orchestrator_workflow(#[case] l2_block_number: String) { let mut orchestrator = Orchestrator::run(setup_config.envs()); orchestrator.wait_till_started().await; + println!("✅ Orchestrator started"); + // Adding State checks in DB for validation of tests // Check 1 : After Proving Job state (15 mins. approx time) @@ -295,9 +322,13 @@ pub async fn put_job_data_in_db_snos(mongo_db: &MongoDbServer, l2_block_number: /// Adding SNOS job in JOB_PROCESSING_QUEUE so that the job is triggered /// as soon as it is picked up by orchestrator -pub async fn put_snos_job_in_processing_queue(local_stack: &LocalStack, id: Uuid) -> color_eyre::Result<()> { +pub async fn put_snos_job_in_processing_queue( + local_stack: &LocalStack, + id: Uuid, + queue_params: AWSSQSParams, +) -> color_eyre::Result<()> { let message = JobQueueMessage { id }; - local_stack.put_message_in_queue(message, get_env_var_or_panic("SQS_SNOS_JOB_PROCESSING_QUEUE_URL")).await?; + local_stack.put_message_in_queue(message, queue_params.get_queue_url(QueueType::SnosJobProcessing)).await?; Ok(()) } @@ -453,6 +484,122 @@ pub async fn put_job_data_in_db_proving(mongo_db: &MongoDbServer, l2_block_numbe /// To set up s3 files needed for e2e test (test_orchestrator_workflow) #[allow(clippy::borrowed_box)] pub async fn setup_s3(s3_client: &Box) -> color_eyre::Result<()> { - s3_client.build_test_bucket(&get_env_var_or_panic("AWS_S3_BUCKET_NAME")).await.unwrap(); + s3_client.build_test_bucket(&get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME")).await.unwrap(); Ok(()) } + +fn set_env_vars() -> Vec<(String, String)> { + let env_vec: Vec<(String, String)> = vec![ + // AWS Config + ("AWS_ACCESS_KEY_ID".to_string(), get_env_var_or_panic("AWS_ACCESS_KEY_ID")), + ("AWS_SECRET_ACCESS_KEY".to_string(), get_env_var_or_panic("AWS_SECRET_ACCESS_KEY")), + ("AWS_REGION".to_string(), get_env_var_or_panic("AWS_REGION")), + ("AWS_ENDPOINT_URL".to_string(), get_env_var_or_panic("AWS_ENDPOINT_URL")), + ("AWS_DEFAULT_REGION".to_string(), get_env_var_or_panic("AWS_DEFAULT_REGION")), + // Alerts + ("MADARA_ORCHESTRATOR_AWS_SNS_ARN".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_SNS_ARN")), + // Data Availability + ( + "MADARA_ORCHESTRATOR_ETHEREUM_DA_RPC_URL".to_string(), + get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_DA_RPC_URL"), + ), + // Database + // ("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL".to_string(), + // get_env_var_or_panic("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL")), + ("MADARA_ORCHESTRATOR_DATABASE_NAME".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_DATABASE_NAME")), + // Prover + ( + "MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID".to_string(), + get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID"), + ), + // ("MADARA_ORCHESTRATOR_SHARP_URL".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_URL")), + ("MADARA_ORCHESTRATOR_SHARP_USER_CRT".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_USER_CRT")), + ("MADARA_ORCHESTRATOR_SHARP_USER_KEY".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_USER_KEY")), + ( + "MADARA_ORCHESTRATOR_SHARP_SERVER_CRT".to_string(), + get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_SERVER_CRT"), + ), + ( + "MADARA_ORCHESTRATOR_SHARP_RPC_NODE_URL".to_string(), + get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_RPC_NODE_URL"), + ), + ( + "MADARA_ORCHESTRATOR_SHARP_PROOF_LAYOUT".to_string(), + get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_PROOF_LAYOUT"), + ), + // ("MADARA_ORCHESTRATOR_GPS_VERIFIER_CONTRACT_ADDRESS".to_string(), + // get_env_var_or_panic("MADARA_ORCHESTRATOR_GPS_VERIFIER_CONTRACT_ADDRESS")), + + // Queue + ("MADARA_ORCHESTRATOR_SQS_PREFIX".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_PREFIX")), + ("MADARA_ORCHESTRATOR_SQS_SUFFIX".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_SUFFIX")), + ( + "MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL".to_string(), + get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL"), + ), + // Settlement - Ethereum + // ("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL".to_string(), + // get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL")), + ( + "MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY".to_string(), + get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), + ), + // ("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS".to_string(), + // get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS")), + // ("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS".to_string(), + // get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS")), + + // Settlement - Starknet + ( + "MADARA_ORCHESTRATOR_STARKNET_SETTLEMENT_RPC_URL".to_string(), + get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_SETTLEMENT_RPC_URL"), + ), + ( + "MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY".to_string(), + get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY"), + ), + ( + "MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS".to_string(), + get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS"), + ), + ( + "MADARA_ORCHESTRATOR_STARKNET_CAIRO_CORE_CONTRACT_ADDRESS".to_string(), + get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_CAIRO_CORE_CONTRACT_ADDRESS"), + ), + ( + "MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS".to_string(), + get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS"), + ), + ( + "MADARA_ORCHESTRATOR_MADARA_BINARY_PATH".to_string(), + get_env_var_or_panic("MADARA_ORCHESTRATOR_MADARA_BINARY_PATH"), + ), + // Storage + ( + "MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME".to_string(), + get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME"), + ), + // Instrumentation + ( + "MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME".to_string(), + get_env_var_or_panic("MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME"), + ), + ( + "MADARA_ORCHESTRATOR_OTEL_COLLECTOR_ENDPOINT".to_string(), + get_env_var_or_panic("MADARA_ORCHESTRATOR_OTEL_COLLECTOR_ENDPOINT"), + ), + // Server + ("MADARA_ORCHESTRATOR_HOST".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_HOST")), + ("MADARA_ORCHESTRATOR_PORT".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_PORT")), + // Service + // ("MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS".to_string(), + // get_env_var_or_panic("MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS")), + ( + "MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS".to_string(), + get_env_var_or_panic("MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS"), + ), + // SNOS + ("MADARA_ORCHESTRATOR_RPC_FOR_SNOS".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_RPC_FOR_SNOS")), + ]; + env_vec +} From 103e462fbee8e78f5af525c593bd13495441a9dc Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Fri, 8 Nov 2024 00:57:10 +0530 Subject: [PATCH 27/63] update: fixed aws related issue --- .env.test | 4 ++-- crates/orchestrator/src/cli/instrumentation.rs | 2 +- e2e-tests/tests.rs | 7 ++----- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.env.test b/.env.test index f2e52bbf..178ef376 100644 --- a/.env.test +++ b/.env.test @@ -83,7 +83,7 @@ MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME=madara-orchestrator-test-bucket ## OTEL ## MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME=orchestrator -MADARA_ORCHESTRATOR_OTEL_COLLECTOR_ENDPOINT=http://localhost:4317 + #### SERVER #### @@ -96,7 +96,7 @@ MADARA_ORCHESTRATOR_PORT=3000 MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS=1000 MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS=0 -MADARA_ORCHESTRATOR_MADARA_RPC_URL=http://localhost:9955 +MADARA_ORCHESTRATOR_MADARA_RPC_URL=http://localhost:9944 #### SNOS #### diff --git a/crates/orchestrator/src/cli/instrumentation.rs b/crates/orchestrator/src/cli/instrumentation.rs index e63b0ae0..342efd9c 100644 --- a/crates/orchestrator/src/cli/instrumentation.rs +++ b/crates/orchestrator/src/cli/instrumentation.rs @@ -4,7 +4,7 @@ use url::Url; /// Parameters used to config instrumentation. #[derive(Debug, Clone, Args)] -#[group(requires_all = ["otel_service_name", "otel_collector_endpoint", "log_level"])] +#[group(requires_all = ["log_level"])] pub struct InstrumentationCliArgs { /// The name of the instrumentation service. #[arg(env = "MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME", long, default_value = "orchestrator")] diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index 39cbe157..f748bf45 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -27,7 +27,7 @@ use rstest::rstest; use serde::{Deserialize, Serialize}; use serde_json::json; use starknet::core::types::{Felt, MaybePendingStateUpdate}; -use utils::env_utils::get_env_var_or_panic; +use utils::env_utils::{get_env_var_optional, get_env_var_or_panic}; use uuid::Uuid; extern crate e2e_tests; @@ -584,10 +584,7 @@ fn set_env_vars() -> Vec<(String, String)> { "MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME"), ), - ( - "MADARA_ORCHESTRATOR_OTEL_COLLECTOR_ENDPOINT".to_string(), - get_env_var_or_panic("MADARA_ORCHESTRATOR_OTEL_COLLECTOR_ENDPOINT"), - ), + // Server ("MADARA_ORCHESTRATOR_HOST".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_HOST")), ("MADARA_ORCHESTRATOR_PORT".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_PORT")), From 44bbe5520349cd809ca7780c0d222f2ef203f120 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Fri, 8 Nov 2024 09:35:22 +0530 Subject: [PATCH 28/63] update: fixing env --- .env.example | 28 ++++++++-------- .env.test | 2 +- .github/workflows/coverage.yml | 6 ++-- .github/workflows/e2e-test.yml | 4 +-- crates/orchestrator/src/alerts/aws_sns/mod.rs | 6 ++++ crates/orchestrator/src/config.rs | 14 +++++--- crates/orchestrator/src/telemetry.rs | 2 +- crates/orchestrator/src/tests/alerts/mod.rs | 2 +- crates/orchestrator/src/tests/common/mod.rs | 10 ++++-- crates/orchestrator/src/tests/config.rs | 2 +- .../src/tests/jobs/snos_job/mod.rs | 2 +- crates/settlement-clients/ethereum/src/lib.rs | 2 +- .../ethereum/src/tests/mod.rs | 10 +++--- crates/settlement-clients/starknet/src/lib.rs | 4 +-- .../starknet/src/tests/setup.rs | 2 +- .../starknet/src/tests/test.rs | 4 +-- docker-compose.yml | 32 +++++++++---------- e2e-tests/src/mock_server.rs | 2 +- e2e-tests/src/node.rs | 2 +- e2e-tests/tests.rs | 3 +- migrate-mongo-config.js | 4 +-- scripts/init_state.js | 4 +-- 22 files changed, 80 insertions(+), 67 deletions(-) diff --git a/.env.example b/.env.example index 74a8ab95..5a902bbb 100644 --- a/.env.example +++ b/.env.example @@ -1,8 +1,8 @@ ##### ORCHESTRATOR ##### -HOST= -PORT= -MAX_BLOCK_TO_PROCESS= +MADARA_ORCHESTRATOR_HOST= +MADARA_ORCHESTRATOR_PORT= +MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS= ##### AWS CONFIG ##### @@ -17,7 +17,7 @@ AWS_DEFAULT_REGION="localhost" ##### STORAGE ##### DATA_STORAGE= -AWS_S3_BUCKET_NAME= +MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME= ##### QUEUE ##### @@ -30,13 +30,13 @@ SQS_WORKER_TRIGGER_QUEUE_URL= ##### SNS ##### ALERTS="sns" -AWS_SNS_ARN="arn:aws:sns:us-east-1:000000000000:madara-orchestrator-arn" +MADARA_ORCHESTRATOR_AWS_SNS_ARN="arn:aws:sns:us-east-1:000000000000:madara-orchestrator-arn" ##### DATABASE ##### DATABASE= -MONGODB_CONNECTION_STRING= -DATABASE_NAME= +MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL= +MADARA_ORCHESTRATOR_DATABASE_NAME= ##### PROVER ##### @@ -52,17 +52,17 @@ MADARA_ORCHESTRATOR_SHARP_PROOF_LAYOUT= DA_LAYER= SETTLEMENT_LAYER= -SETTLEMENT_RPC_URL= +MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL= MADARA_ORCHESTRATOR_MADARA_RPC_URL= MADARA_ORCHESTRATOR_GPS_VERIFIER_CONTRACT_ADDRESS= PRIVATE_KEY= -ETHEREUM_PRIVATE_KEY= -L1_CORE_CONTRACT_ADDRESS= +MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY= +MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS= ##### STARKNET SETTLEMENT (L3s) ##### -STARKNET_PRIVATE_KEY= -STARKNET_ACCOUNT_ADDRESS= +MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY= +MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS= ##### Instrumentation ##### -OTEL_SERVICE_NAME= -OTEL_COLLECTOR_ENDPOINT= +MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME= +MADARA_ORCHESTRATOR_OTEL_COLLECTOR_ENDPOINT= diff --git a/.env.test b/.env.test index 178ef376..3e0dbc40 100644 --- a/.env.test +++ b/.env.test @@ -96,7 +96,7 @@ MADARA_ORCHESTRATOR_PORT=3000 MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS=1000 MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS=0 -MADARA_ORCHESTRATOR_MADARA_RPC_URL=http://localhost:9944 +MADARA_ORCHESTRATOR_MADARA_RPC_URL=http://81.16.176.130:9545 #### SNOS #### diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 3efd0897..8db529c8 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -110,7 +110,7 @@ jobs: mv target/debug/madara ../madara-binary cd .. echo -e " - MADARA_BINARY_PATH=\"$(pwd)/madara-binary\"" >> .env.test + MADARA_ORCHESTRATOR_MADARA_BINARY_PATH=\"$(pwd)/madara-binary\"" >> .env.test cat .env.test - name: Getting neccesary files for testing @@ -128,8 +128,8 @@ jobs: - name: Run llvm-cov tests env: - SETTLEMENT_RPC_URL: ${{ secrets.ETHEREUM_SEPOLIA_BLAST_RPC }} - RPC_FOR_SNOS: ${{ secrets.RPC_FOR_SNOS }} + MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL: ${{ secrets.ETHEREUM_SEPOLIA_BLAST_RPC }} + MADARA_ORCHESTRATOR_RPC_FOR_SNOS: ${{ secrets.RPC_FOR_SNOS }} # the self hosted runner has a different region so we override it here AWS_REGION: us-east-1 run: RUST_LOG=debug RUST_BACKTRACE=1 cargo llvm-cov nextest --release --features testing --lcov --output-path lcov.info --test-threads=1 --workspace --exclude=e2e-tests --no-fail-fast diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 6391f2fb..ecf3466a 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -83,8 +83,8 @@ jobs: - name: Run e2e test env: - SETTLEMENT_RPC_URL: ${{ secrets.ETHEREUM_SEPOLIA_BLAST_RPC }} - RPC_FOR_SNOS: ${{ secrets.RPC_FOR_SNOS }} + MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL: ${{ secrets.ETHEREUM_SEPOLIA_BLAST_RPC }} + MADARA_ORCHESTRATOR_RPC_FOR_SNOS: ${{ secrets.RPC_FOR_SNOS }} # the self hosted runner has a different region so we override it here AWS_REGION: us-east-1 run: | diff --git a/crates/orchestrator/src/alerts/aws_sns/mod.rs b/crates/orchestrator/src/alerts/aws_sns/mod.rs index bd989613..66643535 100644 --- a/crates/orchestrator/src/alerts/aws_sns/mod.rs +++ b/crates/orchestrator/src/alerts/aws_sns/mod.rs @@ -11,6 +11,12 @@ pub struct AWSSNSParams { pub sns_arn: String, } +impl AWSSNSParams { + pub fn get_topic_name(&self) -> String { + self.sns_arn.split(":").last().unwrap().to_string() + } +} + pub struct AWSSNS { client: Client, topic_arn: String, diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index cbe825ec..46b42b3f 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -306,12 +306,15 @@ pub async fn build_settlement_client( // { // Ok(Box::new(EthereumSettlementClient::with_test_settings( // - // RootProvider::new_http(get_env_var_or_panic("SETTLEMENT_RPC_URL").as_str().parse()?), - // Address::from_str(&get_env_var_or_panic("L1_CORE_CONTRACT_ADDRESS"))?, - // Url::from_str(get_env_var_or_panic("SETTLEMENT_RPC_URL").as_str())?, + // RootProvider::new_http(get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL" + // ).as_str().parse()?), + // Address::from_str(&get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"))?, + // + // Url::from_str(get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL"). + // as_str())?, // - // Some(Address::from_str(get_env_var_or_panic("STARKNET_OPERATOR_ADDRESS").as_str())?), - // ))) + // Some(Address::from_str(get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"). + // as_str())?), ))) // } // } // "starknet" => @@ -334,6 +337,7 @@ pub async fn build_alert_client( ) -> Box { match alert_params { AlertParams::AWSSNS(aws_sns_params) => { + println!("Building alert client {}", aws_sns_params.sns_arn); Box::new(AWSSNS::new_with_settings(aws_sns_params, provider_config).await) } } diff --git a/crates/orchestrator/src/telemetry.rs b/crates/orchestrator/src/telemetry.rs index c41375c7..7e29e51d 100644 --- a/crates/orchestrator/src/telemetry.rs +++ b/crates/orchestrator/src/telemetry.rs @@ -57,7 +57,7 @@ fn get_otel_config(instrumentation: &InstrumentationParams) -> Option Some(OTELConfig { endpoint, service_name: otel_service_name }), _ => { - tracing::warn!("OTEL_COLLECTOR_ENDPOINT is not set"); + tracing::warn!("MADARA_ORCHESTRATOR_OTEL_COLLECTOR_ENDPOINT is not set"); None } } diff --git a/crates/orchestrator/src/tests/alerts/mod.rs b/crates/orchestrator/src/tests/alerts/mod.rs index bcd38407..abe8da2c 100644 --- a/crates/orchestrator/src/tests/alerts/mod.rs +++ b/crates/orchestrator/src/tests/alerts/mod.rs @@ -29,7 +29,7 @@ async fn sns_alert_subscribe_to_topic_receive_alert_works() { // subscribing the queue with the alerts sns_client .subscribe() - .topic_arn(get_env_var_or_panic("AWS_SNS_ARN").as_str()) + .topic_arn(get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_SNS_ARN").as_str()) .protocol("sqs") .endpoint(queue_arn) .send() diff --git a/crates/orchestrator/src/tests/common/mod.rs b/crates/orchestrator/src/tests/common/mod.rs index 1b3f3cd4..8164bead 100644 --- a/crates/orchestrator/src/tests/common/mod.rs +++ b/crates/orchestrator/src/tests/common/mod.rs @@ -11,8 +11,8 @@ use chrono::{SubsecRound, Utc}; use mongodb::Client; use rstest::*; use serde::Deserialize; -use utils::env_utils::get_env_var_or_panic; +use crate::cli::alert::AlertParams; use crate::cli::database::DatabaseParams; use crate::cli::queue::QueueParams; use crate::config::ProviderConfig; @@ -48,9 +48,13 @@ pub fn custom_job_item(default_job_item: JobItem, #[default(String::from("0"))] job_item } -pub async fn create_sns_arn(provider_config: Arc) -> Result<(), SdkError> { +pub async fn create_sns_arn( + provider_config: Arc, + alert_params: &AlertParams, +) -> Result<(), SdkError> { + let AlertParams::AWSSNS(aws_sns_params) = alert_params; let sns_client = get_sns_client(provider_config.get_aws_client_or_panic()).await; - sns_client.create_topic().name(get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_SNS_ARN")).send().await?; + sns_client.create_topic().name(aws_sns_params.get_topic_name()).send().await?; Ok(()) } diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index faa11086..1637b211 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -249,7 +249,7 @@ impl TestConfigBuilder { // Deleting the database drop_database(&db_params).await.expect("Unable to drop the database."); // Creating the SNS ARN - create_sns_arn(provider_config.clone()).await.expect("Unable to create the sns arn"); + create_sns_arn(provider_config.clone(), &alert_params).await.expect("Unable to create the sns arn"); let config = Arc::new(Config::new( orchestrator_config, diff --git a/crates/orchestrator/src/tests/jobs/snos_job/mod.rs b/crates/orchestrator/src/tests/jobs/snos_job/mod.rs index 306a5fce..8a48f86e 100644 --- a/crates/orchestrator/src/tests/jobs/snos_job/mod.rs +++ b/crates/orchestrator/src/tests/jobs/snos_job/mod.rs @@ -48,7 +48,7 @@ async fn test_verify_job(#[from(default_job_item)] mut job_item: JobItem) { /// We have a private pathfinder node used to run the Snos [prove_block] function. /// It must be set or the test below will be ignored, since the Snos cannot run /// without a Pathinder node for the moment. -const SNOS_PATHFINDER_RPC_URL_ENV: &str = "RPC_FOR_SNOS"; +const SNOS_PATHFINDER_RPC_URL_ENV: &str = "MADARA_ORCHESTRATOR_RPC_FOR_SNOS"; #[rstest] #[tokio::test(flavor = "multi_thread")] diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index 5800213e..3f38670b 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -42,7 +42,7 @@ use tokio::time::sleep; use crate::types::{bytes_be_to_u128, convert_stark_bigint_to_u256}; -pub const ENV_PRIVATE_KEY: &str = "ETHEREUM_PRIVATE_KEY"; +pub const ENV_PRIVATE_KEY: &str = "MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"; const X_0_POINT_OFFSET: usize = 10; const Y_LOW_POINT_OFFSET: usize = 14; const Y_HIGH_POINT_OFFSET: usize = Y_LOW_POINT_OFFSET + 1; diff --git a/crates/settlement-clients/ethereum/src/tests/mod.rs b/crates/settlement-clients/ethereum/src/tests/mod.rs index b0e6e931..bfbd0b20 100644 --- a/crates/settlement-clients/ethereum/src/tests/mod.rs +++ b/crates/settlement-clients/ethereum/src/tests/mod.rs @@ -32,7 +32,7 @@ lazy_static! { .expect("Path contains invalid Unicode") .to_string(); static ref ETH_RPC: String = get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_SETTLEMENT_RPC_URL"); - pub static ref STARKNET_OPERATOR_ADDRESS: Address = + pub static ref MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS: Address = Address::from_str(get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS").as_str()) .expect("Could not parse MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"); static ref STARKNET_CORE_CONTRACT_ADDRESS: Address = @@ -139,8 +139,8 @@ mod settlement_client_tests { use super::{BLOCK_TIME, ENV_FILE_PATH}; use crate::conversion::to_padded_hex; use crate::tests::{ - DummyCoreContract, EthereumTestBuilder, Pipe, CURRENT_PATH, STARKNET_CORE_CONTRACT, - STARKNET_CORE_CONTRACT_ADDRESS, STARKNET_OPERATOR_ADDRESS, + DummyCoreContract, EthereumTestBuilder, Pipe, CURRENT_PATH, MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS, + STARKNET_CORE_CONTRACT, STARKNET_CORE_CONTRACT_ADDRESS, }; use crate::types::{bytes_be_to_u128, convert_stark_bigint_to_u256}; use crate::{EthereumSettlementClient, EthereumSettlementParams, Y_HIGH_POINT_OFFSET, Y_LOW_POINT_OFFSET}; @@ -232,7 +232,7 @@ mod settlement_client_tests { let setup = EthereumTestBuilder::new() .with_fork_block(fork_block_no) - .with_impersonator(*STARKNET_OPERATOR_ADDRESS) + .with_impersonator(*MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS) .build() .await; @@ -242,7 +242,7 @@ mod settlement_client_tests { let nonce = setup .provider - .get_transaction_count(*STARKNET_OPERATOR_ADDRESS) + .get_transaction_count(*MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS) .await .unwrap() .to_string() diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 5072162d..4f3d56b9 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -35,8 +35,8 @@ pub struct StarknetSettlementClient { pub tx_finality_retry_delay_in_seconds: u64, } -pub const ENV_ACCOUNT_ADDRESS: &str = "STARKNET_ACCOUNT_ADDRESS"; -pub const ENV_PRIVATE_KEY: &str = "STARKNET_PRIVATE_KEY"; +pub const ENV_ACCOUNT_ADDRESS: &str = "MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS"; +pub const ENV_PRIVATE_KEY: &str = "MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY"; const MAX_RETRIES_VERIFY_TX_FINALITY: usize = 10; diff --git a/crates/settlement-clients/starknet/src/tests/setup.rs b/crates/settlement-clients/starknet/src/tests/setup.rs index ae75a622..ec68dc53 100644 --- a/crates/settlement-clients/starknet/src/tests/setup.rs +++ b/crates/settlement-clients/starknet/src/tests/setup.rs @@ -153,7 +153,7 @@ impl MadaraCmdBuilder { } pub fn run(self) -> MadaraCmd { - let target_bin = env::var("MADARA_BINARY_PATH").expect("failed to get binary path"); + let target_bin = env::var("MADARA_ORCHESTRATOR_MADARA_BINARY_PATH").expect("failed to get binary path"); let target_bin = PathBuf::from(target_bin); if !target_bin.exists() { diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 07de418c..2ecb5b73 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -92,7 +92,7 @@ async fn setup(#[future] spin_up_madara: MadaraCmd) -> (LocalWalletSignerMiddlew ) .parse::() .unwrap(), - madara_binary_path: get_env_var_or_panic("MADARA_BINARY_PATH"), + madara_binary_path: get_env_var_or_panic("MADARA_ORCHESTRATOR_MADARA_BINARY_PATH"), }; let rpc_url = Url::parse(starknet_settlement_params.starknet_rpc_url.as_ref()).unwrap(); @@ -129,7 +129,7 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) ) .parse::() .unwrap(), - madara_binary_path: get_env_var_or_panic("MADARA_BINARY_PATH"), + madara_binary_path: get_env_var_or_panic("MADARA_ORCHESTRATOR_MADARA_BINARY_PATH"), }; let (account, _madara_process) = setup.await; diff --git a/docker-compose.yml b/docker-compose.yml index a05d7411..e4b1fd07 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,17 +2,17 @@ services: app: build: . ports: - - "${PORT}:3000" + - "${MADARA_ORCHESTRATOR_PORT}:3000" environment: - - HOST=${HOST:-127.0.0.1} - - PORT=${PORT:-3000} + - MADARA_ORCHESTRATOR_HOST=${MADARA_ORCHESTRATOR_HOST:-127.0.0.1} + - MADARA_ORCHESTRATOR_PORT=${MADARA_ORCHESTRATOR_PORT:-3000} - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} - AWS_REGION=${AWS_REGION:-us-east-1} - AWS_ENDPOINT_URL=${AWS_ENDPOINT_URL} - AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:-localhost} - DATA_STORAGE=${DATA_STORAGE:-s3} - - AWS_S3_BUCKET_NAME=${AWS_S3_BUCKET_NAME} + - MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME=${MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME} - QUEUE_PROVIDER=${QUEUE_PROVIDER:-sqs} - SQS_SNOS_JOB_PROCESSING_QUEUE_URL=${SQS_SNOS_JOB_PROCESSING_QUEUE_URL} - SQS_SNOS_JOB_VERIFICATION_QUEUE_URL=${SQS_SNOS_JOB_VERIFICATION_QUEUE_URL} @@ -27,10 +27,10 @@ services: - SQS_JOB_HANDLE_FAILURE_QUEUE_URL=${SQS_JOB_HANDLE_FAILURE_QUEUE_URL} - SQS_WORKER_TRIGGER_QUEUE_URL=${SQS_WORKER_TRIGGER_QUEUE_URL} - ALERTS=${ALERTS:-sns} - - AWS_SNS_ARN=${AWS_SNS_ARN} + - MADARA_ORCHESTRATOR_AWS_SNS_ARN=${MADARA_ORCHESTRATOR_AWS_SNS_ARN} - MADARA_ORCHESTRATOR_AWS_SNS_ARN=${MADARA_ORCHESTRATOR_AWS_SNS_ARN} - DATABASE=${DATABASE:-mongodb} - - MONGODB_CONNECTION_STRING=${MONGODB_CONNECTION_STRING} + - MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL=${MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL} - PROVER_SERVICE=${PROVER_SERVICE:-sharp} - MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID=${MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID} - MADARA_ORCHESTRATOR_SHARP_URL=${MADARA_ORCHESTRATOR_SHARP_URL} @@ -40,19 +40,19 @@ services: - MADARA_ORCHESTRATOR_SHARP_PROOF_LAYOUT=${MADARA_ORCHESTRATOR_SHARP_PROOF_LAYOUT:-small} - DA_LAYER=${DA_LAYER:-ethereum} - SETTLEMENT_LAYER=${SETTLEMENT_LAYER:-ethereum} - - SETTLEMENT_RPC_URL=${SETTLEMENT_RPC_URL} + - MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL=${MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL} - MADARA_ORCHESTRATOR_MADARA_RPC_URL=${MADARA_ORCHESTRATOR_MADARA_RPC_URL} - MEMORY_PAGES_CONTRACT_ADDRESS=${MEMORY_PAGES_CONTRACT_ADDRESS} - - ETHEREUM_PRIVATE_KEY=${ETHEREUM_PRIVATE_KEY} - - L1_CORE_CONTRACT_ADDRESS=${L1_CORE_CONTRACT_ADDRESS} - - RPC_FOR_SNOS=${RPC_FOR_SNOS} - - STARKNET_PRIVATE_KEY=${STARKNET_PRIVATE_KEY} - - STARKNET_ACCOUNT_ADDRESS=${STARKNET_ACCOUNT_ADDRESS} - - MADARA_BINARY_PATH=${MADARA_BINARY_PATH} - - OTEL_SERVICE_NAME=${OTEL_SERVICE_NAME:-madara_orchestrator} - - OTEL_COLLECTOR_ENDPOINT=${OTEL_COLLECTOR_ENDPOINT} + - MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY=${MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY} + - MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS=${MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS} + - MADARA_ORCHESTRATOR_RPC_FOR_SNOS=${MADARA_ORCHESTRATOR_RPC_FOR_SNOS} + - MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY=${MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY} + - MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS=${MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS} + - MADARA_ORCHESTRATOR_MADARA_BINARY_PATH=${MADARA_ORCHESTRATOR_MADARA_BINARY_PATH} + - MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME=${MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME:-madara_orchestrator} + - MADARA_ORCHESTRATOR_OTEL_COLLECTOR_ENDPOINT=${MADARA_ORCHESTRATOR_OTEL_COLLECTOR_ENDPOINT} - TRACING_LEVEL=${TRACING_LEVEL:-info} - - STARKNET_OPERATOR_ADDRESS=${STARKNET_OPERATOR_ADDRESS} + - MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS=${MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS} depends_on: - mongodb - localstack diff --git a/e2e-tests/src/mock_server.rs b/e2e-tests/src/mock_server.rs index 8597ef0b..aea13ed7 100644 --- a/e2e-tests/src/mock_server.rs +++ b/e2e-tests/src/mock_server.rs @@ -81,7 +81,7 @@ impl MockServerGlobal { then.json_body(return_val); }); - let snos_url = get_env_var_or_panic("RPC_FOR_SNOS"); + let snos_url = get_env_var_or_panic("MADARA_ORCHESTRATOR_RPC_FOR_SNOS"); let snos_host = snos_url.split("://").last().unwrap().split(":").next().unwrap(); let snos_port = snos_url.split("://").last().unwrap().split(":").last().unwrap(); proxy_server.proxy(|rule| { diff --git a/e2e-tests/src/node.rs b/e2e-tests/src/node.rs index a09f99e2..44bcb002 100644 --- a/e2e-tests/src/node.rs +++ b/e2e-tests/src/node.rs @@ -35,7 +35,7 @@ impl Orchestrator { std::env::set_current_dir(repository_root).expect("Failed to change working directory"); let port_str = format!("{}", port); - let envs = [envs, vec![("PORT".to_string(), port_str)]].concat(); + let envs = [envs, vec![("MADARA_ORCHESTRATOR_PORT".to_string(), port_str)]].concat(); let mut command = Command::new("cargo"); command diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index f748bf45..fd0855ec 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -27,7 +27,7 @@ use rstest::rstest; use serde::{Deserialize, Serialize}; use serde_json::json; use starknet::core::types::{Felt, MaybePendingStateUpdate}; -use utils::env_utils::{get_env_var_optional, get_env_var_or_panic}; +use utils::env_utils::get_env_var_or_panic; use uuid::Uuid; extern crate e2e_tests; @@ -584,7 +584,6 @@ fn set_env_vars() -> Vec<(String, String)> { "MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME"), ), - // Server ("MADARA_ORCHESTRATOR_HOST".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_HOST")), ("MADARA_ORCHESTRATOR_PORT".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_PORT")), diff --git a/migrate-mongo-config.js b/migrate-mongo-config.js index 9bb33951..cb6cdb9f 100644 --- a/migrate-mongo-config.js +++ b/migrate-mongo-config.js @@ -3,10 +3,10 @@ const config = { mongodb: { // TODO Change (or review) the url to your MongoDB: - url: process.env.MONGODB_CONNECTION_STRING || "mongodb://localhost:27017", + url: process.env.MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URLDB_CONNECTION_URL || "mongodb://localhost:27017", // TODO Change this to your database name: - databaseName: process.env.DATABASE_NAME || "orchestrator", + databaseName: process.env.MADARA_ORCHESTRATOR_DATABASE_NAME || "orchestrator", options: { useNewUrlParser: true, // removes a deprecation warning when connecting diff --git a/scripts/init_state.js b/scripts/init_state.js index cd2a7b0c..fea92340 100644 --- a/scripts/init_state.js +++ b/scripts/init_state.js @@ -13,10 +13,10 @@ const { MongoClient } = require("mongodb"); const { v4 } = require("uuid"); // using default anvil key which has funds -const ETHEREUM_PRIVATE_KEY = +const MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; const eth_provider = new ethers.JsonRpcProvider("http://localhost:8545"); -const wallet = new ethers.Wallet(ETHEREUM_PRIVATE_KEY, eth_provider); +const wallet = new ethers.Wallet(MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY, eth_provider); const starknet_provider = new starknet.RpcProvider({ nodeUrl: "http://localhost:9944", From 4cf17869c18cef1d542ecc9f553b7c27bab73332 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Fri, 8 Nov 2024 10:54:05 +0530 Subject: [PATCH 29/63] update: coverage fixes --- .env.test | 5 +- Cargo.lock | 2 +- crates/da-clients/ethereum/src/config.rs | 27 +++++++++ crates/orchestrator/Cargo.toml | 11 +--- crates/orchestrator/src/config.rs | 39 ++++++++----- crates/settlement-clients/ethereum/src/lib.rs | 27 +++++---- .../ethereum/src/tests/mod.rs | 55 +++++++++++-------- 7 files changed, 103 insertions(+), 63 deletions(-) diff --git a/.env.test b/.env.test index 3e0dbc40..373b910e 100644 --- a/.env.test +++ b/.env.test @@ -39,7 +39,8 @@ MADARA_ORCHESTRATOR_SHARP_URL=http://127.0.0.1:6000 MADARA_ORCHESTRATOR_SHARP_USER_CRT=LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUR4ekNDQXErZ0F3SUJBZ0lVTjBSK0xpb1MzL2ZadUZsK291RjZNNFk2RnRZd0RRWUpLb1pJaHZjTkFRRUwKQlFBd2N6RUxNQWtHQTFVRUJoTUNTVTR4RXpBUkJnTlZCQWdNQ2xOdmJXVXRVM1JoZEdVeElUQWZCZ05WQkFvTQpHRWx1ZEdWeWJtVjBJRmRwWkdkcGRITWdVSFI1SUV4MFpERU5NQXNHQTFVRUF3d0VVMVJTU3pFZE1Cc0dDU3FHClNJYjNEUUVKQVJZT1lXSmpRR3RoY201dmRDNTRlWG93SGhjTk1qUXdPREV6TVRNd05UTTBXaGNOTWpVd09ERXoKTVRNd05UTTBXakJ6TVFzd0NRWURWUVFHRXdKSlRqRVRNQkVHQTFVRUNBd0tVMjl0WlMxVGRHRjBaVEVoTUI4RwpBMVVFQ2d3WVNXNTBaWEp1WlhRZ1YybGtaMmwwY3lCUWRIa2dUSFJrTVEwd0N3WURWUVFEREFSVFZGSkxNUjB3Ckd3WUpLb1pJaHZjTkFRa0JGZzVoWW1OQWEyRnlibTkwTG5oNWVqQ0NBU0l3RFFZSktvWklodmNOQVFFQkJRQUQKZ2dFUEFEQ0NBUW9DZ2dFQkFOSEtaUGRqWSs4QWo4ZFV2V0xReEl5NTNrK1BHY001T2FlYnpTV3FER0xGSlBOdgpkVzJvWjFCSnNEb2hobWZFSCt5ZEFoQXEvbzc4NDljblg2VDJTOVhta25wdnNud2dRckU5Z3lqSmV3MUxBRzNHCm10U0lOMWJJSm9peWJ3QUR5NGxPd0xrVzUzdFdueHBSazVVVmZUU1hLYVRRTnlHd2o3Q2xMSGthcnlZYVk3OVkKOXlHMFJ2RkFkb1IzczBveWthNkFLV0d1WjhOdWd4NTY2bysyWllRenJteWVNU1NGYkhNdW1aUkxYb0hpazhBSgpLZXJ0bnNBRC9LMVJRYm80Y21ubHFoTVRhQktiTEFVVjVteFVvMlpveFBJVU9tREE5N3IyMmRTYkRkRlVjeC9kCjhQcDB6VXNycXdQckJlcW5SMXdLOE80MUlHajUzRnUzVmxDeS94MENBd0VBQWFOVE1GRXdIUVlEVlIwT0JCWUUKRkc0T0lvKzcvckJyZlR4S2FFMGx2L1dwRDJ3UE1COEdBMVVkSXdRWU1CYUFGRzRPSW8rNy9yQnJmVHhLYUUwbAp2L1dwRDJ3UE1BOEdBMVVkRXdFQi93UUZNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFEMURDZkR3CnpoSXRGMWd5YVdhWURZRHErZjJSUHBFRWVaWk1BSDdJV0ZTajRrTzhmVHN1RnN6bFoyNXNlR3ZHYW4xQ3F4alQKYnJ3MXliVlJQeGZMUWgxRlZMMGhFeDZWYXhGditxMmtqUmlCQmZURFBxWGxYcmpaaUYrZTNPS3lKSVhnNkpIUAppbVpBV0dyRFBHNkorQi90bHRaQ3VLZVhLK1FUcnRSOVVCL29hOWVaQWc5RXNkOVJsZDRNeVo5b0NtdUNPU1hmCnk1THFkVlgrNENpTnJXQ3BwM1B2M2MyL28rZ0RMQjUzZ252R056RjR6Q1FIZ0RtN0RNZnpmZlY1TUMwV1MvWXkKVnpyUG11Sys0Y0tSK3dMOFZITVNEeC9ybTFhYnh0dEN2VW92MUw5dVZ1QUNGc29yNmdsR0N1RDNNQ0dIa0pNNgpxaS8rM1haeHhxeGw1Rzg9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K MADARA_ORCHESTRATOR_SHARP_USER_KEY=LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JSUV2UUlCQURBTkJna3Foa2lHOXcwQkFRRUZBQVNDQktjd2dnU2pBZ0VBQW9JQkFRRFJ5bVQzWTJQdkFJL0gKVkwxaTBNU011ZDVQanhuRE9UbW5tODBscWd4aXhTVHpiM1Z0cUdkUVNiQTZJWVpueEIvc25RSVFLdjZPL09QWApKMStrOWt2VjVwSjZiN0o4SUVLeFBZTW95WHNOU3dCdHhwclVpRGRXeUNhSXNtOEFBOHVKVHNDNUZ1ZDdWcDhhClVaT1ZGWDAwbHltazBEY2hzSSt3cFN4NUdxOG1HbU8vV1BjaHRFYnhRSGFFZDdOS01wR3VnQ2xocm1mRGJvTWUKZXVxUHRtV0VNNjVzbmpFa2hXeHpMcG1VUzE2QjRwUEFDU25xN1o3QUEveXRVVUc2T0hKcDVhb1RFMmdTbXl3RgpGZVpzVktObWFNVHlGRHBnd1BlNjl0blVtdzNSVkhNZjNmRDZkTTFMSzZzRDZ3WHFwMGRjQ3ZEdU5TQm8rZHhiCnQxWlFzdjhkQWdNQkFBRUNnZ0VBQU9mcDFiT2xLOVFKeXVlUHhjeDIvTkNVcUMxTEJDL01FdkEyUzVKWGFWbkcKbGhLR0pFb1U0Q0RoVk83dUlLYVZLTFZvMjk4RHFHUnBLM1d0RVE1TE40bytXYTcveTA5c1drMlVzbWxrVWFOZwpSaGtVZEJSK2dLNXVsQ3FKRml2dUJoTEQvRWlnQ1VWUGZKS2JtNG96TnpYcjVSMU5ENlV1aWFtODdtenlFcTBLCmZsVXlhR0RZNGdIdFNBOVBENVBFYlUveFpKeitKaHk5T2l3aVRXV0MrSHoyb2c3UWRDRDE2RlhGcit2VHpQN0MKb2tFb0VDZFNPRWlMalVENjBhS2ZxRmFCVm5MTkVudC9QSytmY1RBM05mNGtSMnFDNk9ZWjVFb09zYm1ka29ZTgpyU3NJZW9XblMxOEhvekZud2w3Z05wTUtjNmRzQzRBTldOVDFsTkhCb1FLQmdRRHlaUDFJSlppZUh6NlExaUVTCm5zd2tnblZCQUQ0SlVLR1ZDMHA3dk4yclNDZXh4c05ZZXFPTEEyZGZCUGpOVjd3blFKcUgxT05XellOMUJVSUUKeThLTCtFZVl6Q3RZa21LL21wSGJIMzNjd2tJODBuMHJROU1BalZMTlJ2YVVEOWp1NFBsRzFqaEFZUVVyTkViZQpKRlVpSk83aDVQa1llZG50SitqSHFpQnRoUUtCZ1FEZGtPbndmL0szYk4xenR0bXZQd0VicjhkVWJjRVh5NDFOCkl5VWwrZW1WSlgzYktKM0duNDZnQ2RsTTdkYmpwS3JVZ3oxL2JsZTgvMkVFckJvSEFRNkMrU2pEaGhvL01CbnIKekZheTBoK3YxbjBnZnNNVzRoOEF4cEFwc25OYnh6K2g1Wm5uSnRTd0srUjB3U0VJVVEzRjAxL2hMWWhLQ2l5OApwbW5HQi9hU3VRS0JnRzdxd1cvVExGd214ZlYyMXBsenFzeUdHZXVObGRXalhOMGIxcEI2b3lDdW11TmhwYUFHCk5uSDFNOGNxT2tPVWd4ZWZHMWRPbGx6eEc5ZGZlWTlDUWhyVW1NYVZucndmK0NuZkxDRU43d1VtcXpLenl1MFMKVXlwc2dOaElRYXNNK1dLTjllTnhRVHBNYXhZVERONjMxM0VSWDNKazJZdFdydDh6cFBSQXFDZ1ZBb0dCQU54egpUa0NMbmJ6aFphbTNlZm9DenlCMEVma3dSdHBkSGxkc3E0NlFqTmRuK1VSd3NpTXBLR2lWeEE3bDZsU1B4NlV3CmU2VHA3Z1JQZUlHRWwxVDJ1VENacGZSODNtcVdlb1FCeVJXZE9nZmplcFkxYWZpL3ZhY3c2Y21ERTRKeXloNVUKYTMveFE5ZVJwSHFDbWxKREMxZ1V5eVlwL3B2a2FjUytNeW5sVEhHSkFvR0FQekdTSzdXOHBUYldSVEFoaTVrSQpwZk5kWk1tcnRodUxNT3F6TGhyRjZublpldk9OdTBoYXVhZktlVElFd2w0clhYZHFKQlJBaWZKMFFsLzZKWFFkCmd1VzFrZWk1Ui8rUFZ5eUhab042c3NXSTNWYklwUUloUmt6UENnTDZhbHEwSzFpT1dlV1lIOHdORGRRdlB1T2UKRkZPOEovSzNxV0NtWjU0ODBBbTNhT0U9Ci0tLS0tRU5EIFBSSVZBVEUgS0VZLS0tLS0K MADARA_ORCHESTRATOR_SHARP_SERVER_CRT=LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURhekNDQWxPZ0F3SUJBZ0lVRUR0Rjd0YVNTUnVQQTJ6Uk1aNWNzY2JCRm5jd0RRWUpLb1pJaHZjTkFRRUwKQlFBd1JURUxNQWtHQTFVRUJoTUNTVTR4RXpBUkJnTlZCQWdNQ2xOdmJXVXRVM1JoZEdVeElUQWZCZ05WQkFvTQpHRWx1ZEdWeWJtVjBJRmRwWkdkcGRITWdVSFI1SUV4MFpEQWVGdzB5TkRBNE1UTXhNekEzTVROYUZ3MHlOVEE0Ck1UTXhNekEzTVROYU1FVXhDekFKQmdOVkJBWVRBa2xPTVJNd0VRWURWUVFJREFwVGIyMWxMVk4wWVhSbE1TRXcKSHdZRFZRUUtEQmhKYm5SbGNtNWxkQ0JYYVdSbmFYUnpJRkIwZVNCTWRHUXdnZ0VpTUEwR0NTcUdTSWIzRFFFQgpBUVVBQTRJQkR3QXdnZ0VLQW9JQkFRRFRHcEEwNEZ1QlNFaE5PNVYvMGxTaDkvSEgxeVRZT2dRVFdoOG43eDlRCnZGMHpvZFZueVFIdjE5elU5eVdia2xvOEkvOXFBVm9lRzdXTnpUVFg2Q295ZlNjb1YvazN0Q2UwVnVWMlFJTVQKdW82SzJSU05CVHB1TlNqNTlzUiszVTQ2OFRBQnY0YVpsYjU4TU5CRXM3MVRieVpLRHBGRVRkMkg3T0ZKajg4QQpNRi9MaXJkeDZPOFdZL0tDeisxd1ZXL1JRdytYYjRJSWx4bXJFOC9UZ3FNSEo4dFUxYkZiOWJNcTEvOTN5YWtJClU1V2J2NVhXKzFwZFVyTUFNcTFFaC9vZThMN2pFaFdvZXZrNzgyU0kwUk0xeG5MaEtrUUVBYXd6Zkg2ODZiR2YKUHQ3RkFIQ1pGaWJ4KzZzSkg0R1M3S25iK0x5bk9ud3phMWZPUXZEZmcvRm5BZ01CQUFHalV6QlJNQjBHQTFVZApEZ1FXQkJUYlFUdmlUTW1xNXlNK2ZJRVI4VjdTZk1pK3B6QWZCZ05WSFNNRUdEQVdnQlRiUVR2aVRNbXE1eU0rCmZJRVI4VjdTZk1pK3B6QVBCZ05WSFJNQkFmOEVCVEFEQVFIL01BMEdDU3FHU0liM0RRRUJDd1VBQTRJQkFRREYKTllyRnpBa2RIVkhjUkd5SUNsTi9IVGswaldOcTVSdTB1RUpDQ21Dbm9ZY1pRSTlDQlcwTkl3dGpZUkpTKzR1UwordWh4VWpSYTA5YXdOWDhvYmU0dDZjK25HRnhZMGZqamk0cGZnbU1kMWNJeGdsM3E3Nlp0ZkllRGR6alRLRXN1CjRFUTVadnEwMnJvTEZ0ZjEvL3dRVG0xNkNKdFpGWnhNZ1phYnNxc2JRc3M2dWdMUGtTTmdBWjI1L2VhcWhnQ20KTjFUV2FxL0xJMVBLSkxPK085NFlMa2FsNVpyOTJCOXk4Q0VKVUVuSTA1R1N1MmJUOFM2a0ZBMEpadEszTW9SbwpqRWZWV1lQVHR5TFR4amNvRndCcDlHaXZYSDdSdHBxMDlmSmFhU1pNekxmNGlyNHpBdXprbExBNWZvampPNXlKCllnYlVaQUU2aS81N1NFWjR3VmxTCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K -MADARA_ORCHESTRATOR_SHARP_RPC_NODE_URL=https://eth-sepolia.public.blastapi.io +# MADARA_ORCHESTRATOR_SHARP_RPC_NODE_URL should be same as MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL +MADARA_ORCHESTRATOR_SHARP_RPC_NODE_URL=http://127.0.0.1:8545 MADARA_ORCHESTRATOR_SHARP_PROOF_LAYOUT=small MADARA_ORCHESTRATOR_GPS_VERIFIER_CONTRACT_ADDRESS=0x07ec0D28e50322Eb0C159B9090ecF3aeA8346DFe @@ -56,7 +57,7 @@ MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL=http://sqs.us-east-1.localhost.localstack ## ETHEREUM ## -MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL=https://eth-sepolia.public.blastapi.io +MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL=http://127.0.0.1:8545 MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS=0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057 MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS=0x5b98B836969A60FEC50Fa925905Dd1D382a7db43 diff --git a/Cargo.lock b/Cargo.lock index 9d361f0d..983cad3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6931,7 +6931,7 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" name = "orchestrator" version = "0.1.0" dependencies = [ - "alloy 0.1.0", + "alloy 0.2.1", "assert_matches", "async-std", "async-trait", diff --git a/crates/da-clients/ethereum/src/config.rs b/crates/da-clients/ethereum/src/config.rs index 3b8d58cd..a535d986 100644 --- a/crates/da-clients/ethereum/src/config.rs +++ b/crates/da-clients/ethereum/src/config.rs @@ -1,5 +1,32 @@ +use std::str::FromStr; + +use alloy::network::Ethereum; +use alloy::providers::ProviderBuilder; +use alloy::rpc::client::RpcClient; +use serde::{Deserialize, Serialize}; use url::Url; +use crate::EthereumDaClient; + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct EthereumDaConfig { + pub rpc_url: String, +} + +impl EthereumDaConfig { + pub fn new_with_params(ethereum_da_params: &EthereumDaParams) -> color_eyre::Result { + Ok(Self { rpc_url: ethereum_da_params.ethereum_da_rpc_url.to_string() }) + } + + pub async fn build_client(&self) -> EthereumDaClient { + let client = + RpcClient::new_http(Url::from_str(self.rpc_url.as_str()).expect("Failed to parse SETTLEMENT_RPC_URL")); + let provider = ProviderBuilder::<_, Ethereum>::new().on_client(client); + + EthereumDaClient { provider } + } +} + #[derive(Debug, Clone)] pub struct EthereumDaParams { pub ethereum_da_rpc_url: Url, diff --git a/crates/orchestrator/Cargo.toml b/crates/orchestrator/Cargo.toml index 26bf57bb..eb9f0729 100644 --- a/crates/orchestrator/Cargo.toml +++ b/crates/orchestrator/Cargo.toml @@ -12,16 +12,7 @@ name = "orchestrator" path = "src/main.rs" [dependencies] -alloy = { git = "https://github.com/alloy-rs/alloy", rev = "68952c0", features = [ - "consensus", - "providers", - "rpc-client", - "transport-http", - "network", - "eips", - "signers", - "signer-wallet", -] } +alloy = { workspace = true } assert_matches = "1.5.0" async-std = "1.12.0" async-trait = { workspace = true } diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 46b42b3f..5afba02a 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -1,12 +1,18 @@ +#[cfg(feature = "testing")] +use std::str::FromStr; use std::sync::Arc; +#[cfg(feature = "testing")] +use alloy::primitives::Address; +#[cfg(feature = "testing")] +use alloy::providers::RootProvider; use aws_config::meta::region::RegionProviderChain; use aws_config::{Region, SdkConfig}; use aws_credential_types::Credentials; use color_eyre::eyre::eyre; use da_client_interface::DaClient; use dotenvy::dotenv; -use ethereum_da_client::EthereumDaClient; +use ethereum_da_client::config::EthereumDaConfig; use ethereum_settlement_client::EthereumSettlementClient; use prover_client_interface::ProverClient; use settlement_client_interface::SettlementClient; @@ -14,6 +20,8 @@ use sharp_service::SharpProverService; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Url}; use starknet_settlement_client::StarknetSettlementClient; +#[cfg(feature = "testing")] +use utils::env_utils::get_env_var_or_panic; use crate::alerts::aws_sns::AWSSNS; use crate::alerts::Alerts; @@ -250,21 +258,13 @@ impl Config { } } -use std::str::FromStr; - -use alloy::network::Ethereum; -use alloy::providers::ProviderBuilder; -use alloy::rpc::client::RpcClient; - /// Builds the DA client based on the environment variable DA_LAYER pub async fn build_da_client(da_params: &DaParams) -> Box { match da_params { DaParams::Ethereum(ethereum_da_params) => { - let client = RpcClient::new_http( - Url::from_str(ethereum_da_params.ethereum_da_rpc_url.as_str()).expect("Failed to parse DA_RPC_URL"), - ); - let provider = ProviderBuilder::<_, Ethereum>::new().on_client(client); - Box::new(EthereumDaClient { provider }) + let config = EthereumDaConfig::new_with_params(ethereum_da_params) + .expect("Not able to build config from the given settings provider."); + Box::new(config.build_client().await) } } } @@ -288,7 +288,16 @@ pub async fn build_settlement_client( } #[cfg(feature = "testing")] { - Ok(Box::new(EthereumSettlementClient::with_test_settings(ethereum_settlement_params))) + Ok(Box::new(EthereumSettlementClient::with_test_settings( + RootProvider::new_http( + get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL").as_str().parse()?, + ), + Address::from_str(&get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"))?, + Url::from_str(get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL").as_str())?, + Some(Address::from_str( + get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS").as_str(), + )?), + ))) } } SettlementParams::Starknet(starknet_settlement_params) => { @@ -307,9 +316,9 @@ pub async fn build_settlement_client( // Ok(Box::new(EthereumSettlementClient::with_test_settings( // // RootProvider::new_http(get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL" - // ).as_str().parse()?), + // ).as_str().parse()?), // Address::from_str(&get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"))?, - // + // // Url::from_str(get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL"). // as_str())?, // diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index 3f38670b..655dac5a 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -24,6 +24,10 @@ use color_eyre::Result; use config::EthereumSettlementParams; use conversion::{get_input_data_for_eip_4844, prepare_sidecar}; use settlement_client_interface::{SettlementClient, SettlementVerificationStatus}; +#[cfg(feature = "testing")] +use url::Url; +#[cfg(feature = "testing")] +use utils::env_utils::get_env_var_or_panic; use crate::clients::interfaces::validity_interface::StarknetValidityContractTrait; use crate::clients::StarknetValidityContractClient; @@ -101,29 +105,28 @@ impl EthereumSettlementClient { } #[cfg(feature = "testing")] - pub fn with_test_settings(settlement_cfg: &EthereumSettlementParams) -> Self { - let root_provider = RootProvider::new_http(settlement_cfg.ethereum_rpc_url.clone().as_str().parse().unwrap()); - let core_contract_address = Address::from_str(&settlement_cfg.l1_core_contract_address.clone()).unwrap(); - let operator_address = Address::from_str(&settlement_cfg.starknet_operator_address.clone()).unwrap(); - - let settlement_rpc_url = settlement_cfg.ethereum_rpc_url.clone(); - let private_key = settlement_cfg.ethereum_private_key.clone(); + pub fn with_test_settings( + provider: RootProvider>, + core_contract_address: Address, + rpc_url: Url, + impersonate_account: Option
, + ) -> Self { + let private_key = get_env_var_or_panic(ENV_PRIVATE_KEY); let signer: PrivateKeySigner = private_key.parse().expect("Failed to parse private key"); let wallet_address = signer.address(); let wallet = EthereumWallet::from(signer); - let fill_provider = Arc::new( - ProviderBuilder::new().with_recommended_fillers().wallet(wallet.clone()).on_http(settlement_rpc_url), - ); + let fill_provider = + Arc::new(ProviderBuilder::new().with_recommended_fillers().wallet(wallet.clone()).on_http(rpc_url)); let core_contract_client = StarknetValidityContractClient::new(core_contract_address, fill_provider); EthereumSettlementClient { - provider: Arc::new(root_provider), + provider: Arc::new(provider), core_contract_client, wallet, wallet_address, - impersonate_account: Some(operator_address), + impersonate_account, } } diff --git a/crates/settlement-clients/ethereum/src/tests/mod.rs b/crates/settlement-clients/ethereum/src/tests/mod.rs index bfbd0b20..44ff547b 100644 --- a/crates/settlement-clients/ethereum/src/tests/mod.rs +++ b/crates/settlement-clients/ethereum/src/tests/mod.rs @@ -3,10 +3,10 @@ use std::path::PathBuf; use std::str::FromStr; use alloy::node_bindings::{Anvil, AnvilInstance}; +use alloy::primitives::Address; use alloy::providers::ext::AnvilApi; use alloy::providers::ProviderBuilder; use alloy::sol; -use alloy_primitives::Address; use utils::env_utils::get_env_var_or_panic; // Using the Pipe trait to write chained operations easier #[allow(dead_code)] @@ -126,6 +126,7 @@ mod settlement_client_tests { use std::time::Duration; use alloy::eips::eip4844::BYTES_PER_BLOB; + use alloy::primitives::Address; use alloy::providers::Provider; use alloy::sol_types::private::U256; use alloy_primitives::FixedBytes; @@ -133,7 +134,6 @@ mod settlement_client_tests { use rstest::rstest; use settlement_client_interface::{SettlementClient, SettlementVerificationStatus}; use tokio::time::sleep; - use url::Url; use utils::env_utils::get_env_var_or_panic; use super::{BLOCK_TIME, ENV_FILE_PATH}; @@ -156,19 +156,23 @@ mod settlement_client_tests { async fn update_state_blob_with_dummy_contract_works() { dotenvy::from_filename(&*ENV_FILE_PATH).expect("Could not load .env.test file."); + let setup = EthereumTestBuilder::new().build().await; + let ethereum_settlement_params = EthereumSettlementParams { - ethereum_rpc_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL")) - .expect("Failed to parse MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL"), + ethereum_rpc_url: setup.rpc_url, ethereum_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), l1_core_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"), starknet_operator_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"), }; - let setup = EthereumTestBuilder::new().build().await; - // Deploying a dummy contract let contract = DummyCoreContract::deploy(&setup.provider).await.expect("Unable to deploy address"); - let ethereum_settlement_client = EthereumSettlementClient::with_test_settings(ðereum_settlement_params); + let ethereum_settlement_client = EthereumSettlementClient::with_test_settings( + setup.provider.clone(), + *contract.address(), + ethereum_settlement_params.ethereum_rpc_url, + None, + ); // Getting latest nonce after deployment let nonce = ethereum_settlement_client.get_nonce().await.expect("Unable to fetch nonce"); @@ -220,23 +224,25 @@ mod settlement_client_tests { async fn update_state_blob_with_impersonation_works(#[case] fork_block_no: u64) { dotenvy::from_filename(&*ENV_FILE_PATH).expect("Could not load .env.test file."); - let ethereum_settlement_params = EthereumSettlementParams { - ethereum_rpc_url: Url::from_str( - get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL").as_str(), - ) - .unwrap(), - ethereum_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), - l1_core_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"), - starknet_operator_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"), - }; - let setup = EthereumTestBuilder::new() .with_fork_block(fork_block_no) .with_impersonator(*MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS) .build() .await; - let ethereum_settlement_client = EthereumSettlementClient::with_test_settings(ðereum_settlement_params); + let ethereum_settlement_params = EthereumSettlementParams { + ethereum_rpc_url: setup.rpc_url, + ethereum_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), + l1_core_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"), + starknet_operator_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"), + }; + + let ethereum_settlement_client = EthereumSettlementClient::with_test_settings( + setup.provider.clone(), + Address::from_str(ðereum_settlement_params.l1_core_contract_address).unwrap(), + ethereum_settlement_params.ethereum_rpc_url, + Some(Address::from_str(ðereum_settlement_params.starknet_operator_address).unwrap()), + ); // let nonce = ethereum_settlement_client.get_nonce().await.expect("Unable to fetch nonce"); @@ -288,18 +294,21 @@ mod settlement_client_tests { #[case::typical(6806847)] async fn get_last_settled_block_typical_works(#[case] fork_block_no: u64) { dotenvy::from_filename(&*ENV_FILE_PATH).expect("Could not load .env.test file."); + let setup = EthereumTestBuilder::new().with_fork_block(fork_block_no).build().await; let ethereum_settlement_params = EthereumSettlementParams { - ethereum_rpc_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL")) - .expect("Failed to parse MADARA_ORCHESTRATOR_ETHEREUM_RPC_URL"), + ethereum_rpc_url: setup.rpc_url, ethereum_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), l1_core_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"), starknet_operator_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"), }; - let _setup = EthereumTestBuilder::new().with_fork_block(fork_block_no).build().await; - let ethereum_settlement_client = EthereumSettlementClient::with_test_settings(ðereum_settlement_params); - + let ethereum_settlement_client = EthereumSettlementClient::with_test_settings( + setup.provider.clone(), + Address::from_str(ðereum_settlement_params.l1_core_contract_address).unwrap(), + ethereum_settlement_params.ethereum_rpc_url, + None, + ); assert_eq!( ethereum_settlement_client.get_last_settled_block().await.expect("Could not get last settled block."), 218378 From 815437d190f0e63619d4117676e1d50107824a75 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Fri, 8 Nov 2024 12:05:35 +0530 Subject: [PATCH 30/63] update: coverage fixes --- .env.test | 9 ++++---- crates/orchestrator/src/tests/config.rs | 21 +++++++------------ .../ethereum/src/tests/mod.rs | 2 +- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/.env.test b/.env.test index 373b910e..3904d289 100644 --- a/.env.test +++ b/.env.test @@ -57,7 +57,7 @@ MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL=http://sqs.us-east-1.localhost.localstack ## ETHEREUM ## -MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL=http://127.0.0.1:8545 +# MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL= MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS=0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057 MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS=0x5b98B836969A60FEC50Fa925905Dd1D382a7db43 @@ -69,8 +69,7 @@ MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31 MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 MADARA_ORCHESTRATOR_STARKNET_CAIRO_CORE_CONTRACT_ADDRESS= MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS=10 -MADARA_ORCHESTRATOR_MADARA_BINARY_PATH=/path/to/madara - +# MADARA_ORCHESTRATOR_MADARA_BINARY_PATH= #### STORAGE #### @@ -95,8 +94,8 @@ MADARA_ORCHESTRATOR_PORT=3000 #### SERVICE #### -MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS=1000 -MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS=0 +MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS= +MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS= MADARA_ORCHESTRATOR_MADARA_RPC_URL=http://81.16.176.130:9545 diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 1637b211..77fafac5 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -12,7 +12,7 @@ use sharp_service::config::SharpParams; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::JsonRpcClient; use url::Url; -use utils::env_utils::get_env_var_or_panic; +use utils::env_utils::{get_env_var_optional, get_env_var_or_panic}; use crate::alerts::aws_sns::AWSSNSParams; use crate::alerts::Alerts; @@ -515,18 +515,13 @@ fn get_env_params() -> ( .expect("Failed to parse MADARA_ORCHESTRATOR_RPC_FOR_SNOS"), }; - let service_config = ServiceParams { - max_block_to_process: Some( - get_env_var_or_panic("MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS") - .parse() - .expect("Failed to parse MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS"), - ), - min_block_to_process: Some( - get_env_var_or_panic("MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS") - .parse() - .expect("Failed to parse MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS"), - ), - }; + let env = get_env_var_optional("MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS").expect("Couldn't get max block"); + let max_block: Option = env.expect("Couldn't get max block").parse().ok(); + + let env = get_env_var_optional("MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS").expect("Couldn't get min block"); + let min_block: Option = env.expect("Couldn't get min block").parse().ok(); + + let service_config = ServiceParams { max_block_to_process: max_block, min_block_to_process: min_block }; let server_config = ServerParams { host: get_env_var_or_panic("MADARA_ORCHESTRATOR_HOST"), diff --git a/crates/settlement-clients/ethereum/src/tests/mod.rs b/crates/settlement-clients/ethereum/src/tests/mod.rs index 44ff547b..5fe895f6 100644 --- a/crates/settlement-clients/ethereum/src/tests/mod.rs +++ b/crates/settlement-clients/ethereum/src/tests/mod.rs @@ -31,7 +31,7 @@ lazy_static! { .to_str() .expect("Path contains invalid Unicode") .to_string(); - static ref ETH_RPC: String = get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_SETTLEMENT_RPC_URL"); + static ref ETH_RPC: String = get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL"); pub static ref MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS: Address = Address::from_str(get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS").as_str()) .expect("Could not parse MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"); From fd6e88e23670b77c34b241a0e984528bd77ae257 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Fri, 8 Nov 2024 12:44:20 +0530 Subject: [PATCH 31/63] update: fixes for test_Settle and e2e --- .env.test | 4 ++-- .../orchestrator/src/cli/settlement/starknet.rs | 2 +- crates/orchestrator/src/config.rs | 14 ++++---------- .../starknet/src/tests/test.rs | 3 +-- e2e-tests/tests.rs | 16 ++++++++-------- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/.env.test b/.env.test index 3904d289..13297e8b 100644 --- a/.env.test +++ b/.env.test @@ -94,8 +94,8 @@ MADARA_ORCHESTRATOR_PORT=3000 #### SERVICE #### -MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS= -MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS= +# MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS= +# MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS= MADARA_ORCHESTRATOR_MADARA_RPC_URL=http://81.16.176.130:9545 diff --git a/crates/orchestrator/src/cli/settlement/starknet.rs b/crates/orchestrator/src/cli/settlement/starknet.rs index b86bd4b3..6c1223ee 100644 --- a/crates/orchestrator/src/cli/settlement/starknet.rs +++ b/crates/orchestrator/src/cli/settlement/starknet.rs @@ -2,7 +2,7 @@ use clap::Args; use url::Url; #[derive(Debug, Clone, Args)] -#[group(requires_all = ["starknet_rpc_url", "starknet_private_key", "starknet_account_address", "starknet_cairo_core_contract_address", "starknet_finality_retry_wait_in_secs", "madara_binary_path"])] +#[group(requires_all = ["starknet_rpc_url", "starknet_private_key", "starknet_account_address", "starknet_cairo_core_contract_address", "starknet_finality_retry_wait_in_secs"])] pub struct StarknetSettlementCliArgs { /// Use the Starknet settlement layer. #[arg(long)] diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 5afba02a..1f43ae12 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -20,8 +20,6 @@ use sharp_service::SharpProverService; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Url}; use starknet_settlement_client::StarknetSettlementClient; -#[cfg(feature = "testing")] -use utils::env_utils::get_env_var_or_panic; use crate::alerts::aws_sns::AWSSNS; use crate::alerts::Alerts; @@ -289,14 +287,10 @@ pub async fn build_settlement_client( #[cfg(feature = "testing")] { Ok(Box::new(EthereumSettlementClient::with_test_settings( - RootProvider::new_http( - get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL").as_str().parse()?, - ), - Address::from_str(&get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"))?, - Url::from_str(get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL").as_str())?, - Some(Address::from_str( - get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS").as_str(), - )?), + RootProvider::new_http(ethereum_settlement_params.ethereum_rpc_url.clone()), + Address::from_str(ðereum_settlement_params.l1_core_contract_address)?, + ethereum_settlement_params.ethereum_rpc_url.clone(), + Some(Address::from_str(ðereum_settlement_params.starknet_operator_address)?), ))) } } diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 2ecb5b73..a41436dd 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -144,8 +144,7 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) let compiled_class: CompiledClass = serde_json::from_reader( std::fs::File::open(contract_path.join( - "mock_contracts_Piltover.compiled_contract_class. -json", + "mock_contracts_Piltover.compiled_contract_class.json", )) .expect("Could not open compiled class file"), ) diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index fd0855ec..7ea53872 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -570,10 +570,10 @@ fn set_env_vars() -> Vec<(String, String)> { "MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS"), ), - ( - "MADARA_ORCHESTRATOR_MADARA_BINARY_PATH".to_string(), - get_env_var_or_panic("MADARA_ORCHESTRATOR_MADARA_BINARY_PATH"), - ), + // ( + // "MADARA_ORCHESTRATOR_MADARA_BINARY_PATH".to_string(), + // get_env_var_or_panic("MADARA_ORCHESTRATOR_MADARA_BINARY_PATH"), + // ), // Storage ( "MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME".to_string(), @@ -590,10 +590,10 @@ fn set_env_vars() -> Vec<(String, String)> { // Service // ("MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS".to_string(), // get_env_var_or_panic("MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS")), - ( - "MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS".to_string(), - get_env_var_or_panic("MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS"), - ), + // ( + // "MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS".to_string(), + // get_env_var_or_panic("MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS"), + // ), // SNOS ("MADARA_ORCHESTRATOR_RPC_FOR_SNOS".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_RPC_FOR_SNOS")), ]; From e1d09febd3b428646d8ae386ba21bb5bd26f9486 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Fri, 8 Nov 2024 13:51:26 +0530 Subject: [PATCH 32/63] fixed: coverage tests --- .env.test | 4 ++-- crates/settlement-clients/starknet/src/tests/test.rs | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.env.test b/.env.test index 13297e8b..3904d289 100644 --- a/.env.test +++ b/.env.test @@ -94,8 +94,8 @@ MADARA_ORCHESTRATOR_PORT=3000 #### SERVICE #### -# MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS= -# MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS= +MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS= +MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS= MADARA_ORCHESTRATOR_MADARA_RPC_URL=http://81.16.176.130:9545 diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index a41436dd..22766660 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -117,7 +117,7 @@ async fn setup(#[future] spin_up_madara: MadaraCmd) -> (LocalWalletSignerMiddlew async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) { dotenvy::from_filename_override(".env.test").expect("Failed to load the .env file"); - let starknet_settlement_params: StarknetSettlementParams = StarknetSettlementParams { + let mut starknet_settlement_params: StarknetSettlementParams = StarknetSettlementParams { starknet_rpc_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_SETTLEMENT_RPC_URL")).unwrap(), starknet_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY"), starknet_account_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS"), @@ -164,7 +164,9 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) let deploy_v1 = contract_factory.deploy_v1(vec![], felt!("1122"), false); let deployed_address = deploy_v1.deployed_address(); - env::set_var("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", deployed_address.to_hex_string()); + // env::set_var("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", deployed_address.to_hex_string()); + starknet_settlement_params.starknet_cairo_core_contract_address = deployed_address.to_hex_string(); + let InvokeTransactionResult { transaction_hash: deploy_tx_hash } = deploy_v1.send().await.expect("Unable to deploy contract"); From c1046cc915b1cac29221875cee5cc4ffa75d809d Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Fri, 8 Nov 2024 14:32:44 +0530 Subject: [PATCH 33/63] update: test_settle fixed --- crates/settlement-clients/starknet/src/tests/test.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 22766660..b4015d80 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -117,8 +117,10 @@ async fn setup(#[future] spin_up_madara: MadaraCmd) -> (LocalWalletSignerMiddlew async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) { dotenvy::from_filename_override(".env.test").expect("Failed to load the .env file"); + let (account, madara_process) = setup.await; + let mut starknet_settlement_params: StarknetSettlementParams = StarknetSettlementParams { - starknet_rpc_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_SETTLEMENT_RPC_URL")).unwrap(), + starknet_rpc_url: madara_process.rpc_url.clone(), starknet_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY"), starknet_account_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS"), starknet_cairo_core_contract_address: get_env_var_or_panic( @@ -132,8 +134,6 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) madara_binary_path: get_env_var_or_panic("MADARA_ORCHESTRATOR_MADARA_BINARY_PATH"), }; - let (account, _madara_process) = setup.await; - let project_root = Path::new(env!("CARGO_MANIFEST_DIR")).ancestors().nth(3).unwrap(); let contract_path = project_root.join("crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev"); let sierra_class: SierraClass = serde_json::from_reader( @@ -158,7 +158,7 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) tracing::debug!("declare tx hash {:?}", declare_tx_hash); let is_success = wait_for_tx(&account, declare_tx_hash, Duration::from_secs(2)).await; - assert!(is_success, "Declare trasactiion failed"); + assert!(is_success, "Declare transaction failed"); let contract_factory = ContractFactory::new(flattened_class.class_hash(), account.clone()); let deploy_v1 = contract_factory.deploy_v1(vec![], felt!("1122"), false); From 6525c633abc57a9628ac2ec54a922ecb35ac4fb4 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Fri, 8 Nov 2024 14:58:19 +0530 Subject: [PATCH 34/63] update: allow e2e and coverage to work together based off env --- .env.test | 1 - crates/orchestrator/src/cli/mod.rs | 5 +- crates/orchestrator/src/cli/service.rs | 5 +- crates/orchestrator/src/tests/config.rs | 95 ++++++++++--------- .../starknet/src/tests/test.rs | 6 +- crates/utils/src/env_utils.rs | 2 + migrate-mongo-config.js | 7 +- scripts/init_state.js | 5 +- 8 files changed, 70 insertions(+), 56 deletions(-) diff --git a/.env.test b/.env.test index 3904d289..a8da70c1 100644 --- a/.env.test +++ b/.env.test @@ -85,7 +85,6 @@ MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME=madara-orchestrator-test-bucket MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME=orchestrator - #### SERVER #### MADARA_ORCHESTRATOR_HOST=127.0.0.1 diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index d9b018c0..d68baac0 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -250,8 +250,9 @@ impl RunCmd { pub fn validate_service_params(&self) -> Result { Ok(ServiceParams { - max_block_to_process: self.service_args.max_block_to_process, - min_block_to_process: self.service_args.min_block_to_process, + // return None if the value is empty string + max_block_to_process: self.service_args.max_block_to_process.clone().and_then(|s| if s.is_empty() { None } else { Some(s.parse::().unwrap()) }), + min_block_to_process: self.service_args.min_block_to_process.clone().and_then(|s| if s.is_empty() { None } else { Some(s.parse::().unwrap()) }), }) } diff --git a/crates/orchestrator/src/cli/service.rs b/crates/orchestrator/src/cli/service.rs index b829bc49..1512eb97 100644 --- a/crates/orchestrator/src/cli/service.rs +++ b/crates/orchestrator/src/cli/service.rs @@ -1,13 +1,12 @@ use clap::Args; #[derive(Debug, Clone, Args)] -#[group(requires_all = ["rpc_for_snos"])] pub struct ServiceCliArgs { /// The maximum block to process. #[arg(env = "MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS", long)] - pub max_block_to_process: Option, + pub max_block_to_process: Option, /// The minimum block to process. #[arg(env = "MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS", long)] - pub min_block_to_process: Option, + pub min_block_to_process: Option, } diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 77fafac5..44b148ee 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -1,4 +1,5 @@ use std::net::SocketAddr; +use std::str::FromStr as _; use std::sync::Arc; use axum::Router; @@ -11,8 +12,9 @@ use settlement_client_interface::{MockSettlementClient, SettlementClient}; use sharp_service::config::SharpParams; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::JsonRpcClient; +use tracing::Level; use url::Url; -use utils::env_utils::{get_env_var_optional, get_env_var_or_panic}; +use utils::env_utils::{get_env_var_optional, get_env_var_or_default, get_env_var_or_panic}; use crate::alerts::aws_sns::AWSSNSParams; use crate::alerts::Alerts; @@ -33,6 +35,7 @@ use crate::database::{Database, MockDatabase}; use crate::queue::sqs::AWSSQSParams; use crate::queue::{MockQueueProvider, QueueProvider}; use crate::routes::{get_server_url, setup_server, ServerParams}; +use crate::telemetry::InstrumentationParams; use crate::tests::common::{create_queues, create_sns_arn, drop_database}; // Inspiration : https://rust-unofficial.github.io/patterns/patterns/creational/builder.html @@ -196,19 +199,9 @@ impl TestConfigBuilder { pub async fn build(self) -> TestConfigBuilderReturns { dotenvy::from_filename("../.env.test").expect("Failed to load the .env.test file"); - let ( - db_params, - storage_params, - queue_params, - aws_config, - orchestrator_config, - alert_params, - settlement_params, - da_params, - prover_params, - ) = get_env_params(); + let params = get_env_params(); - let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(&aws_config).await))); + let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(¶ms.aws_config).await))); let TestConfigBuilder { starknet_rpc_url_type, @@ -227,32 +220,32 @@ impl TestConfigBuilder { implement_client::init_starknet_client(starknet_rpc_url_type, starknet_client_type).await; // init alerts - let alerts = implement_client::init_alerts(alerts_type, &alert_params, provider_config.clone()).await; + let alerts = implement_client::init_alerts(alerts_type, ¶ms.alert_params, provider_config.clone()).await; - let da_client = implement_client::init_da_client(da_client_type, &da_params).await; + let da_client = implement_client::init_da_client(da_client_type, ¶ms.da_params).await; let settlement_client = - implement_client::init_settlement_client(settlement_client_type, &settlement_params).await; + implement_client::init_settlement_client(settlement_client_type, ¶ms.settlement_params).await; - let prover_client = implement_client::init_prover_client(prover_client_type, &prover_params).await; + let prover_client = implement_client::init_prover_client(prover_client_type, ¶ms.prover_params).await; // External Dependencies - let storage = - implement_client::init_storage_client(storage_type, &storage_params, provider_config.clone()).await; + let storage = implement_client::init_storage_client(storage_type, ¶ms.storage_params, provider_config.clone()) + .await; - let database = implement_client::init_database(database_type, &db_params).await; + let database = implement_client::init_database(database_type, ¶ms.db_params).await; - let queue = implement_client::init_queue_client(queue_type, queue_params.clone()).await; + let queue = implement_client::init_queue_client(queue_type, params.queue_params.clone()).await; // Deleting and Creating the queues in sqs. - create_queues(provider_config.clone(), &queue_params).await.expect("Not able to delete and create the queues."); + create_queues(provider_config.clone(), ¶ms.queue_params).await.expect("Not able to delete and create the queues."); // Deleting the database - drop_database(&db_params).await.expect("Unable to drop the database."); + drop_database(¶ms.db_params).await.expect("Unable to drop the database."); // Creating the SNS ARN - create_sns_arn(provider_config.clone(), &alert_params).await.expect("Unable to create the sns arn"); + create_sns_arn(provider_config.clone(), ¶ms.alert_params).await.expect("Unable to create the sns arn"); let config = Arc::new(Config::new( - orchestrator_config, + params.orchestrator_config, starknet_client, da_client, prover_client, @@ -461,17 +454,23 @@ pub mod implement_client { } } -fn get_env_params() -> ( - DatabaseParams, - StorageParams, - QueueParams, - AWSConfigParams, - OrchestratorConfig, - AlertParams, - SettlementParams, - DaParams, - ProverParams, -) { + + +struct EnvParams { + aws_config: AWSConfigParams, + alert_params: AlertParams, + queue_params: QueueParams, + storage_params: StorageParams, + db_params: DatabaseParams, + da_params: DaParams, + settlement_params: SettlementParams, + prover_params: ProverParams, + instrumentation_params: InstrumentationParams, + orchestrator_config: OrchestratorConfig, +} + +fn get_env_params() -> EnvParams { + let db_params = DatabaseParams::MongoDB(MongoDBParams { connection_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL"), database_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_DATABASE_NAME"), @@ -480,6 +479,7 @@ fn get_env_params() -> ( let storage_params = StorageParams::AWSS3(AWSS3Params { bucket_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME"), }); + let queue_params = QueueParams::AWSSQS(AWSSQSParams { queue_base_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL"), sqs_prefix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_PREFIX"), @@ -538,6 +538,14 @@ fn get_env_params() -> ( server_config, }; + let instrumentation_params = InstrumentationParams { + otel_service_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME"), + otel_collector_endpoint: get_env_var_optional("MADARA_ORCHESTRATOR_OTEL_COLLECTOR_ENDPOINT") + .expect("Couldn't get otel collector endpoint") + .map(|url| Url::parse(&url).expect("Failed to parse MADARA_ORCHESTRATOR_OTEL_COLLECTOR_ENDPOINT")), + log_level: Level::from_str(&get_env_var_or_default("RUST_LOG", "info")).expect("Failed to parse RUST_LOG"), + }; + let prover_params = ProverParams::Sharp(SharpParams { sharp_customer_id: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID"), sharp_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_URL")) @@ -551,15 +559,16 @@ fn get_env_params() -> ( gps_verifier_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_GPS_VERIFIER_CONTRACT_ADDRESS"), }); - ( - db_params, - storage_params, - queue_params, + EnvParams { aws_config, - orchestrator_config, alert_params, - settlement_params, + queue_params, + storage_params, + db_params, da_params, + settlement_params, prover_params, - ) + instrumentation_params, + orchestrator_config, + } } diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index b4015d80..66631f99 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -143,10 +143,8 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) .expect("Failed to parse SierraClass"); let compiled_class: CompiledClass = serde_json::from_reader( - std::fs::File::open(contract_path.join( - "mock_contracts_Piltover.compiled_contract_class.json", - )) - .expect("Could not open compiled class file"), + std::fs::File::open(contract_path.join("mock_contracts_Piltover.compiled_contract_class.json")) + .expect("Could not open compiled class file"), ) .expect("Failed to parse CompiledClass"); diff --git a/crates/utils/src/env_utils.rs b/crates/utils/src/env_utils.rs index e62d32ce..11771f08 100644 --- a/crates/utils/src/env_utils.rs +++ b/crates/utils/src/env_utils.rs @@ -14,6 +14,8 @@ pub fn get_env_var_or_default(key: &str, default: &str) -> String { pub fn get_env_var_optional(key: &str) -> Result, VarError> { match get_env_var(key) { + // if value is empty string, return None + Ok(s) if s.is_empty() => Ok(None), Ok(s) => Ok(Some(s)), Err(VarError::NotPresent) => Ok(None), Err(e) => Err(e), diff --git a/migrate-mongo-config.js b/migrate-mongo-config.js index cb6cdb9f..52fa1e17 100644 --- a/migrate-mongo-config.js +++ b/migrate-mongo-config.js @@ -3,10 +3,13 @@ const config = { mongodb: { // TODO Change (or review) the url to your MongoDB: - url: process.env.MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URLDB_CONNECTION_URL || "mongodb://localhost:27017", + url: + process.env.MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URLDB_CONNECTION_URL || + "mongodb://localhost:27017", // TODO Change this to your database name: - databaseName: process.env.MADARA_ORCHESTRATOR_DATABASE_NAME || "orchestrator", + databaseName: + process.env.MADARA_ORCHESTRATOR_DATABASE_NAME || "orchestrator", options: { useNewUrlParser: true, // removes a deprecation warning when connecting diff --git a/scripts/init_state.js b/scripts/init_state.js index fea92340..0c041972 100644 --- a/scripts/init_state.js +++ b/scripts/init_state.js @@ -16,7 +16,10 @@ const { v4 } = require("uuid"); const MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; const eth_provider = new ethers.JsonRpcProvider("http://localhost:8545"); -const wallet = new ethers.Wallet(MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY, eth_provider); +const wallet = new ethers.Wallet( + MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY, + eth_provider, +); const starknet_provider = new starknet.RpcProvider({ nodeUrl: "http://localhost:9944", From b8a7e4a54c62093908d97fc10f612e1a73ba78c0 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Fri, 8 Nov 2024 16:24:18 +0530 Subject: [PATCH 35/63] update: fixed db issue --- .env.test | 5 ++--- crates/orchestrator/src/tests/config.rs | 4 ++-- crates/orchestrator/src/workers/snos.rs | 10 ++++------ 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.env.test b/.env.test index a8da70c1..a4ad346a 100644 --- a/.env.test +++ b/.env.test @@ -27,8 +27,7 @@ MADARA_ORCHESTRATOR_ETHEREUM_DA_RPC_URL=https://eth-sepolia.public.blastapi.io ## MONGODB ## MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL=mongodb://localhost:27017 -MADARA_ORCHESTRATOR_DATABASE_NAME=madara-orchestrator-test - +MADARA_ORCHESTRATOR_DATABASE_NAME=orchestrator #### PROVER #### @@ -57,7 +56,7 @@ MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL=http://sqs.us-east-1.localhost.localstack ## ETHEREUM ## -# MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL= +MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL=https://eth-sepolia.public.blastapi.io MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS=0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057 MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS=0x5b98B836969A60FEC50Fa925905Dd1D382a7db43 diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 44b148ee..bc1f9e43 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -516,10 +516,10 @@ fn get_env_params() -> EnvParams { }; let env = get_env_var_optional("MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS").expect("Couldn't get max block"); - let max_block: Option = env.expect("Couldn't get max block").parse().ok(); + let max_block: Option = env.and_then(|s| if s.is_empty() { None } else { Some(s.parse::().unwrap()) }); let env = get_env_var_optional("MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS").expect("Couldn't get min block"); - let min_block: Option = env.expect("Couldn't get min block").parse().ok(); + let min_block: Option = env.and_then(|s| if s.is_empty() { None } else { Some(s.parse::().unwrap()) }); let service_config = ServiceParams { max_block_to_process: max_block, min_block_to_process: min_block }; diff --git a/crates/orchestrator/src/workers/snos.rs b/crates/orchestrator/src/workers/snos.rs index deb66500..56ee612e 100644 --- a/crates/orchestrator/src/workers/snos.rs +++ b/crates/orchestrator/src/workers/snos.rs @@ -32,18 +32,16 @@ impl Worker for SnosWorker { let latest_job_in_db = config.database().get_latest_job_by_type(JobType::SnosRun).await?; - let latest_job_id: u64 = match latest_job_in_db { + let latest_job_id = match latest_job_in_db { Some(job) => job.internal_id, None => "0".to_string(), - } - .parse::() - .unwrap(); + }; // To be used when testing in specific block range let block_start = if let Some(min_block_to_process) = config.service_config().min_block_to_process { min_block_to_process } else { - latest_job_id + latest_job_id.parse::().unwrap() }; for block_num in block_start..latest_block_number + 1 { @@ -57,4 +55,4 @@ impl Worker for SnosWorker { tracing::trace!(log_type = "completed", category = "SnosWorker", "SnosWorker completed."); Ok(()) } -} +} \ No newline at end of file From 82738c08871408594da0165d161bb8b793ce15f2 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Fri, 8 Nov 2024 16:50:19 +0530 Subject: [PATCH 36/63] update: lint fixes --- crates/orchestrator/src/cli/mod.rs | 12 ++++++++++-- crates/orchestrator/src/tests/config.rs | 13 ++++++------- crates/orchestrator/src/workers/snos.rs | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index d68baac0..ad3dfe73 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -251,8 +251,16 @@ impl RunCmd { pub fn validate_service_params(&self) -> Result { Ok(ServiceParams { // return None if the value is empty string - max_block_to_process: self.service_args.max_block_to_process.clone().and_then(|s| if s.is_empty() { None } else { Some(s.parse::().unwrap()) }), - min_block_to_process: self.service_args.min_block_to_process.clone().and_then(|s| if s.is_empty() { None } else { Some(s.parse::().unwrap()) }), + max_block_to_process: self + .service_args + .max_block_to_process + .clone() + .and_then(|s| if s.is_empty() { None } else { Some(s.parse::().unwrap()) }), + min_block_to_process: self + .service_args + .min_block_to_process + .clone() + .and_then(|s| if s.is_empty() { None } else { Some(s.parse::().unwrap()) }), }) } diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index bc1f9e43..d519c60e 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -230,15 +230,17 @@ impl TestConfigBuilder { let prover_client = implement_client::init_prover_client(prover_client_type, ¶ms.prover_params).await; // External Dependencies - let storage = implement_client::init_storage_client(storage_type, ¶ms.storage_params, provider_config.clone()) - .await; + let storage = + implement_client::init_storage_client(storage_type, ¶ms.storage_params, provider_config.clone()).await; let database = implement_client::init_database(database_type, ¶ms.db_params).await; let queue = implement_client::init_queue_client(queue_type, params.queue_params.clone()).await; // Deleting and Creating the queues in sqs. - create_queues(provider_config.clone(), ¶ms.queue_params).await.expect("Not able to delete and create the queues."); + create_queues(provider_config.clone(), ¶ms.queue_params) + .await + .expect("Not able to delete and create the queues."); // Deleting the database drop_database(¶ms.db_params).await.expect("Unable to drop the database."); // Creating the SNS ARN @@ -454,8 +456,6 @@ pub mod implement_client { } } - - struct EnvParams { aws_config: AWSConfigParams, alert_params: AlertParams, @@ -470,7 +470,6 @@ struct EnvParams { } fn get_env_params() -> EnvParams { - let db_params = DatabaseParams::MongoDB(MongoDBParams { connection_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL"), database_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_DATABASE_NAME"), @@ -541,7 +540,7 @@ fn get_env_params() -> EnvParams { let instrumentation_params = InstrumentationParams { otel_service_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME"), otel_collector_endpoint: get_env_var_optional("MADARA_ORCHESTRATOR_OTEL_COLLECTOR_ENDPOINT") - .expect("Couldn't get otel collector endpoint") + .expect("Couldn't get otel collector endpoint") .map(|url| Url::parse(&url).expect("Failed to parse MADARA_ORCHESTRATOR_OTEL_COLLECTOR_ENDPOINT")), log_level: Level::from_str(&get_env_var_or_default("RUST_LOG", "info")).expect("Failed to parse RUST_LOG"), }; diff --git a/crates/orchestrator/src/workers/snos.rs b/crates/orchestrator/src/workers/snos.rs index 56ee612e..d7900b21 100644 --- a/crates/orchestrator/src/workers/snos.rs +++ b/crates/orchestrator/src/workers/snos.rs @@ -55,4 +55,4 @@ impl Worker for SnosWorker { tracing::trace!(log_type = "completed", category = "SnosWorker", "SnosWorker completed."); Ok(()) } -} \ No newline at end of file +} From cde59b3670725b7a260f235eaeadb38cd8c2da88 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Fri, 8 Nov 2024 17:00:19 +0530 Subject: [PATCH 37/63] update: lint fix --- crates/orchestrator/src/tests/config.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index d519c60e..097c89a6 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -465,8 +465,9 @@ struct EnvParams { da_params: DaParams, settlement_params: SettlementParams, prover_params: ProverParams, - instrumentation_params: InstrumentationParams, orchestrator_config: OrchestratorConfig, + #[allow(dead_code)] + instrumentation_params: InstrumentationParams, } fn get_env_params() -> EnvParams { From 98a5bc0bc654926d29bca0a9e15d03c7ac6041a7 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Fri, 8 Nov 2024 18:19:41 +0530 Subject: [PATCH 38/63] update: clean up --- crates/orchestrator/src/alerts/aws_sns/mod.rs | 4 +- crates/orchestrator/src/cli/aws_config.rs | 15 +-- crates/orchestrator/src/cli/mod.rs | 102 ++++++++++-------- crates/orchestrator/src/config.rs | 63 ++++------- .../src/data_storage/aws_s3/mod.rs | 2 +- .../orchestrator/src/database/mongodb/mod.rs | 2 +- crates/orchestrator/src/main.rs | 2 - crates/orchestrator/src/tests/common/mod.rs | 4 +- crates/orchestrator/src/tests/config.rs | 21 ++-- .../sharp-service/src/client.rs | 2 +- .../prover-services/sharp-service/src/lib.rs | 8 +- .../sharp-service/tests/lib.rs | 4 +- crates/settlement-clients/ethereum/src/lib.rs | 6 +- .../ethereum/src/tests/mod.rs | 6 +- crates/settlement-clients/starknet/src/lib.rs | 2 +- .../starknet/src/tests/test.rs | 2 +- e2e-tests/src/localstack.rs | 2 +- e2e-tests/tests.rs | 4 +- 18 files changed, 118 insertions(+), 133 deletions(-) diff --git a/crates/orchestrator/src/alerts/aws_sns/mod.rs b/crates/orchestrator/src/alerts/aws_sns/mod.rs index 66643535..45cd1902 100644 --- a/crates/orchestrator/src/alerts/aws_sns/mod.rs +++ b/crates/orchestrator/src/alerts/aws_sns/mod.rs @@ -8,6 +8,8 @@ use crate::config::ProviderConfig; #[derive(Debug, Clone)] pub struct AWSSNSParams { + // TODO: convert to ARN type, and validate it + // NOTE: aws is using str to represent ARN : https://docs.aws.amazon.com/sdk-for-rust/latest/dg/rust_sns_code_examples.html pub sns_arn: String, } @@ -23,7 +25,7 @@ pub struct AWSSNS { } impl AWSSNS { - pub async fn new_with_settings(aws_sns_params: &AWSSNSParams, provider_config: Arc) -> Self { + pub async fn new_with_params(aws_sns_params: &AWSSNSParams, provider_config: Arc) -> Self { let config = provider_config.get_aws_client_or_panic(); Self { client: Client::new(config), topic_arn: aws_sns_params.sns_arn.clone() } } diff --git a/crates/orchestrator/src/cli/aws_config.rs b/crates/orchestrator/src/cli/aws_config.rs index 6e0aae2c..d65b5bee 100644 --- a/crates/orchestrator/src/cli/aws_config.rs +++ b/crates/orchestrator/src/cli/aws_config.rs @@ -1,10 +1,11 @@ use clap::Args; use serde::Serialize; +use url::Url; /// Parameters used to config AWS. #[derive(Debug, Clone, Args, Serialize)] #[group(requires_all = ["aws_access_key_id", "aws_secret_access_key", "aws_region"])] -pub struct AWSConfigParams { +pub struct AWSConfigCliArgs { /// The access key ID. #[arg(env = "AWS_ACCESS_KEY_ID", long)] pub aws_access_key_id: String, @@ -16,12 +17,12 @@ pub struct AWSConfigParams { /// The region. #[arg(env = "AWS_REGION", long)] pub aws_region: String, +} - /// The endpoint URL. - #[arg(env = "AWS_ENDPOINT_URL", long, default_value = "http://localhost.localstack.cloud:4566")] - pub aws_endpoint_url: String, - - /// The default region. - #[arg(env = "AWS_DEFAULT_REGION", long, default_value = "localhost")] +pub struct AWSConfigParams { + pub aws_access_key_id: String, + pub aws_secret_access_key: String, + pub aws_region: String, + pub aws_endpoint_url: Url, pub aws_default_region: String, } diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index ad3dfe73..4a3aaeb5 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -1,5 +1,5 @@ use alert::AlertParams; -use aws_config::AWSConfigParams; +use aws_config::{AWSConfigCliArgs, AWSConfigParams}; use clap::{ArgGroup, Parser}; use da::DaParams; use database::DatabaseParams; @@ -78,7 +78,7 @@ pub mod storage; pub struct RunCmd { // AWS Config #[clap(flatten)] - pub aws_config_args: AWSConfigParams, + pub aws_config_args: AWSConfigCliArgs, // Settlement Layer #[command(flatten)] @@ -129,52 +129,27 @@ pub struct RunCmd { } impl RunCmd { - pub fn validate_settlement_params(&self) -> Result { - match (self.ethereum_args.settle_on_ethereum, self.starknet_args.settle_on_starknet) { - (true, false) => { - // TODO: Ensure Starknet params are not provided + pub fn validate_aws_config_params(&self) -> Result { + let aws_endpoint_url = Url::parse("http://localhost.localstack.cloud:4566").unwrap(); + let aws_default_region = "localhost".to_string(); - // Get Ethereum params or error if none provided - // Either all the values are provided or panic - let ethereum_params = EthereumSettlementParams { - ethereum_rpc_url: self.ethereum_args.ethereum_rpc_url.clone().unwrap(), - ethereum_private_key: self.ethereum_args.ethereum_private_key.clone().unwrap(), - l1_core_contract_address: self.ethereum_args.l1_core_contract_address.clone().unwrap(), - starknet_operator_address: self.ethereum_args.starknet_operator_address.clone().unwrap(), - }; - Ok(SettlementParams::Ethereum(ethereum_params)) - } - (false, true) => { - // TODO: Ensure Ethereum params are not provided + tracing::warn!("Setting AWS_ENDPOINT_URL to {} for AWS SDK to use", aws_endpoint_url); + tracing::warn!("Setting AWS_DEFAULT_REGION to {} for Omniqueue to use", aws_default_region); - // Get Starknet params or error if none provided - // Either all the values are provided or panic - let starknet_params = StarknetSettlementParams { - starknet_rpc_url: self.starknet_args.starknet_rpc_url.clone().unwrap(), - starknet_private_key: self.starknet_args.starknet_private_key.clone().unwrap(), - starknet_account_address: self.starknet_args.starknet_account_address.clone().unwrap(), - starknet_cairo_core_contract_address: self - .starknet_args - .starknet_cairo_core_contract_address - .clone() - .unwrap(), - starknet_finality_retry_wait_in_secs: self - .starknet_args - .starknet_finality_retry_wait_in_secs - .unwrap(), - madara_binary_path: self.starknet_args.madara_binary_path.clone().unwrap(), - }; - Ok(SettlementParams::Starknet(starknet_params)) - } - (true, true) | (false, false) => Err("Exactly one settlement layer must be selected".to_string()), - } + Ok(AWSConfigParams { + aws_access_key_id: self.aws_config_args.aws_access_key_id.clone(), + aws_secret_access_key: self.aws_config_args.aws_secret_access_key.clone(), + aws_region: self.aws_config_args.aws_region.clone(), + aws_endpoint_url, + aws_default_region, + }) } - pub fn validate_storage_params(&self) -> Result { - if self.aws_s3_args.aws_s3 { - Ok(StorageParams::AWSS3(AWSS3Params { bucket_name: self.aws_s3_args.bucket_name.clone().unwrap() })) + pub fn validate_alert_params(&self) -> Result { + if self.aws_sns_args.aws_sns { + Ok(AlertParams::AWSSNS(AWSSNSParams { sns_arn: self.aws_sns_args.sns_arn.clone().unwrap() })) } else { - Err("Only AWS S3 is supported as of now".to_string()) + Err("Only AWS SNS is supported as of now".to_string()) } } @@ -190,11 +165,11 @@ impl RunCmd { } } - pub fn validate_alert_params(&self) -> Result { - if self.aws_sns_args.aws_sns { - Ok(AlertParams::AWSSNS(AWSSNSParams { sns_arn: self.aws_sns_args.sns_arn.clone().unwrap() })) + pub fn validate_storage_params(&self) -> Result { + if self.aws_s3_args.aws_s3 { + Ok(StorageParams::AWSS3(AWSS3Params { bucket_name: self.aws_s3_args.bucket_name.clone().unwrap() })) } else { - Err("Only AWS SNS is supported as of now".to_string()) + Err("Only AWS S3 is supported as of now".to_string()) } } @@ -219,6 +194,39 @@ impl RunCmd { } } + pub fn validate_settlement_params(&self) -> Result { + match (self.ethereum_args.settle_on_ethereum, self.starknet_args.settle_on_starknet) { + (true, false) => { + let ethereum_params = EthereumSettlementParams { + ethereum_rpc_url: self.ethereum_args.ethereum_rpc_url.clone().unwrap(), + ethereum_private_key: self.ethereum_args.ethereum_private_key.clone().unwrap(), + l1_core_contract_address: self.ethereum_args.l1_core_contract_address.clone().unwrap(), + starknet_operator_address: self.ethereum_args.starknet_operator_address.clone().unwrap(), + }; + Ok(SettlementParams::Ethereum(ethereum_params)) + } + (false, true) => { + let starknet_params = StarknetSettlementParams { + starknet_rpc_url: self.starknet_args.starknet_rpc_url.clone().unwrap(), + starknet_private_key: self.starknet_args.starknet_private_key.clone().unwrap(), + starknet_account_address: self.starknet_args.starknet_account_address.clone().unwrap(), + starknet_cairo_core_contract_address: self + .starknet_args + .starknet_cairo_core_contract_address + .clone() + .unwrap(), + starknet_finality_retry_wait_in_secs: self + .starknet_args + .starknet_finality_retry_wait_in_secs + .unwrap(), + madara_binary_path: self.starknet_args.madara_binary_path.clone().unwrap(), + }; + Ok(SettlementParams::Starknet(starknet_params)) + } + (true, true) | (false, false) => Err("Exactly one settlement layer must be selected".to_string()), + } + } + pub fn validate_prover_params(&self) -> Result { if self.sharp_args.sharp { Ok(ProverParams::Sharp(SharpParams { diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 1f43ae12..1d8cf511 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -45,7 +45,7 @@ use crate::routes::ServerParams; /// by calling `config` function. pub struct Config { /// The orchestrator config - orchestrator_config: OrchestratorConfig, + orchestrator_params: OrchestratorParams, /// The starknet client to get data from the node starknet_client: Arc>, /// The DA client to interact with the DA layer @@ -70,7 +70,7 @@ pub struct ServiceParams { pub min_block_to_process: Option, } -pub struct OrchestratorConfig { +pub struct OrchestratorParams { pub madara_rpc_url: Url, pub snos_config: SNOSParams, pub service_config: ServiceParams, @@ -108,17 +108,17 @@ pub async fn get_aws_config(aws_config: &AWSConfigParams) -> SdkConfig { pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { dotenv().ok(); - let aws_config = &run_cmd.aws_config_args; + let aws_config = &run_cmd.validate_aws_config_params().expect("Failed to validate AWS config params"); let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(aws_config).await))); - let orchestrator_config = OrchestratorConfig { + let orchestrator_params = OrchestratorParams { madara_rpc_url: run_cmd.madara_rpc_url.clone(), snos_config: run_cmd.validate_snos_params().expect("Failed to validate SNOS params"), service_config: run_cmd.validate_service_params().expect("Failed to validate service params"), server_config: run_cmd.validate_server_params().expect("Failed to validate server params"), }; - let provider = JsonRpcClient::new(HttpTransport::new(orchestrator_config.madara_rpc_url.clone())); + let provider = JsonRpcClient::new(HttpTransport::new(orchestrator_params.madara_rpc_url.clone())); // init database let database_params = @@ -156,7 +156,7 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { let queue = build_queue_client(&queue_params); Ok(Arc::new(Config::new( - orchestrator_config, + orchestrator_params, Arc::new(provider), da_client, prover_client, @@ -172,7 +172,7 @@ impl Config { /// Create a new config #[allow(clippy::too_many_arguments)] pub fn new( - orchestrator_config: OrchestratorConfig, + orchestrator_params: OrchestratorParams, starknet_client: Arc>, da_client: Box, prover_client: Box, @@ -183,7 +183,7 @@ impl Config { alerts: Box, ) -> Self { Self { - orchestrator_config, + orchestrator_params, starknet_client, da_client, prover_client, @@ -197,22 +197,22 @@ impl Config { /// Returns the starknet rpc url pub fn starknet_rpc_url(&self) -> &Url { - &self.orchestrator_config.madara_rpc_url + &self.orchestrator_params.madara_rpc_url } /// Returns the server config pub fn server_config(&self) -> &ServerParams { - &self.orchestrator_config.server_config + &self.orchestrator_params.server_config } /// Returns the snos rpc url pub fn snos_config(&self) -> &SNOSParams { - &self.orchestrator_config.snos_config + &self.orchestrator_params.snos_config } /// Returns the service config pub fn service_config(&self) -> &ServiceParams { - &self.orchestrator_config.service_config + &self.orchestrator_params.service_config } /// Returns the starknet client @@ -270,7 +270,7 @@ pub async fn build_da_client(da_params: &DaParams) -> Box Box { match prover_params { - ProverParams::Sharp(sharp_params) => Box::new(SharpProverService::new_with_settings(sharp_params)), + ProverParams::Sharp(sharp_params) => Box::new(SharpProverService::new_with_params(sharp_params)), } } @@ -282,11 +282,11 @@ pub async fn build_settlement_client( SettlementParams::Ethereum(ethereum_settlement_params) => { #[cfg(not(feature = "testing"))] { - Ok(Box::new(EthereumSettlementClient::new_with_settings(ethereum_settlement_params))) + Ok(Box::new(EthereumSettlementClient::new_with_params(ethereum_settlement_params))) } #[cfg(feature = "testing")] { - Ok(Box::new(EthereumSettlementClient::with_test_settings( + Ok(Box::new(EthereumSettlementClient::with_test_params( RootProvider::new_http(ethereum_settlement_params.ethereum_rpc_url.clone()), Address::from_str(ðereum_settlement_params.l1_core_contract_address)?, ethereum_settlement_params.ethereum_rpc_url.clone(), @@ -295,34 +295,9 @@ pub async fn build_settlement_client( } } SettlementParams::Starknet(starknet_settlement_params) => { - Ok(Box::new(StarknetSettlementClient::new_with_settings(starknet_settlement_params).await)) + Ok(Box::new(StarknetSettlementClient::new_with_params(starknet_settlement_params).await)) } } - - // match settlement_params { - // "ethereum" => { - // #[cfg(not(feature = "testing"))] - // { - // Ok(Box::new(EthereumSettlementClient::new_with_settings(settings_provider))) - // } - // #[cfg(feature = "testing")] - // { - // Ok(Box::new(EthereumSettlementClient::with_test_settings( - // - // RootProvider::new_http(get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL" - // ).as_str().parse()?), - // Address::from_str(&get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"))?, - // - // Url::from_str(get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL"). - // as_str())?, - // - // Some(Address::from_str(get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"). - // as_str())?), ))) - // } - // } - // "starknet" => - // Ok(Box::new(StarknetSettlementClient::new_with_settings(settings_provider).await)), _ - // => panic!("Unsupported Settlement layer"), } } pub async fn build_storage_client( @@ -330,7 +305,7 @@ pub async fn build_storage_client( provider_config: Arc, ) -> Box { match data_storage_params { - StorageParams::AWSS3(aws_s3_params) => Box::new(AWSS3::new_with_settings(aws_s3_params, provider_config).await), + StorageParams::AWSS3(aws_s3_params) => Box::new(AWSS3::new_with_params(aws_s3_params, provider_config).await), } } @@ -341,7 +316,7 @@ pub async fn build_alert_client( match alert_params { AlertParams::AWSSNS(aws_sns_params) => { println!("Building alert client {}", aws_sns_params.sns_arn); - Box::new(AWSSNS::new_with_settings(aws_sns_params, provider_config).await) + Box::new(AWSSNS::new_with_params(aws_sns_params, provider_config).await) } } } @@ -354,6 +329,6 @@ pub fn build_queue_client(queue_params: &QueueParams) -> Box Box { match database_params { - DatabaseParams::MongoDB(mongodb_params) => Box::new(MongoDb::new_with_settings(mongodb_params).await), + DatabaseParams::MongoDB(mongodb_params) => Box::new(MongoDb::new_with_params(mongodb_params).await), } } diff --git a/crates/orchestrator/src/data_storage/aws_s3/mod.rs b/crates/orchestrator/src/data_storage/aws_s3/mod.rs index 51489e6d..92dc818a 100644 --- a/crates/orchestrator/src/data_storage/aws_s3/mod.rs +++ b/crates/orchestrator/src/data_storage/aws_s3/mod.rs @@ -26,7 +26,7 @@ pub struct AWSS3 { /// - initializing a new AWS S3 client impl AWSS3 { /// To init the struct with main settings - pub async fn new_with_settings(s3_config: &AWSS3Params, provider_config: Arc) -> Self { + pub async fn new_with_params(s3_config: &AWSS3Params, provider_config: Arc) -> Self { let aws_config = provider_config.get_aws_client_or_panic(); // Building AWS S3 config let mut s3_config_builder = aws_sdk_s3::config::Builder::from(aws_config); diff --git a/crates/orchestrator/src/database/mongodb/mod.rs b/crates/orchestrator/src/database/mongodb/mod.rs index 0c377b53..a8154f4f 100644 --- a/crates/orchestrator/src/database/mongodb/mod.rs +++ b/crates/orchestrator/src/database/mongodb/mod.rs @@ -27,7 +27,7 @@ pub struct MongoDb { } impl MongoDb { - pub async fn new_with_settings(mongodb_params: &MongoDBParams) -> Self { + pub async fn new_with_params(mongodb_params: &MongoDBParams) -> Self { let mut client_options = ClientOptions::parse(mongodb_params.connection_url.clone()).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 diff --git a/crates/orchestrator/src/main.rs b/crates/orchestrator/src/main.rs index 6ff63ff9..2a143f2c 100644 --- a/crates/orchestrator/src/main.rs +++ b/crates/orchestrator/src/main.rs @@ -16,8 +16,6 @@ async fn main() { // TODO: could this be an ARC ? let run_cmd: RunCmd = RunCmd::parse(); - println!("{:?}", run_cmd.aws_sqs_args.queue_base_url); - // Analytics Setup let instrumentation_params = run_cmd.validate_instrumentation_params().expect("Invalid instrumentation params"); let meter_provider = setup_analytics(&instrumentation_params); diff --git a/crates/orchestrator/src/tests/common/mod.rs b/crates/orchestrator/src/tests/common/mod.rs index 8164bead..e7948d50 100644 --- a/crates/orchestrator/src/tests/common/mod.rs +++ b/crates/orchestrator/src/tests/common/mod.rs @@ -65,7 +65,7 @@ pub async fn get_sns_client(aws_config: &SdkConfig) -> aws_sdk_sns::client::Clie pub async fn drop_database(database_params: &DatabaseParams) -> color_eyre::Result<()> { match database_params { DatabaseParams::MongoDB(mongodb_params) => { - let db_client: Client = MongoDb::new_with_settings(mongodb_params).await.client(); + let db_client: Client = MongoDb::new_with_params(mongodb_params).await.client(); // dropping all the collection. // use .collection::("") // if only particular collection is to be dropped @@ -117,5 +117,5 @@ pub async fn get_storage_client( storage_cfg: &AWSS3Params, provider_config: Arc, ) -> Box { - Box::new(AWSS3::new_with_settings(storage_cfg, provider_config).await) + Box::new(AWSS3::new_with_params(storage_cfg, provider_config).await) } diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 097c89a6..69b58201 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -27,7 +27,7 @@ use crate::cli::queue::QueueParams; use crate::cli::settlement::SettlementParams; use crate::cli::snos::SNOSParams; use crate::cli::storage::StorageParams; -use crate::config::{get_aws_config, Config, OrchestratorConfig, ProviderConfig, ServiceParams}; +use crate::config::{get_aws_config, Config, OrchestratorParams, ProviderConfig, ServiceParams}; use crate::data_storage::aws_s3::config::AWSS3Params; use crate::data_storage::{DataStorage, MockDataStorage}; use crate::database::mongodb::config::MongoDBParams; @@ -201,7 +201,7 @@ impl TestConfigBuilder { let params = get_env_params(); - let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(¶ms.aws_config).await))); + let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(¶ms.aws_params).await))); let TestConfigBuilder { starknet_rpc_url_type, @@ -247,7 +247,7 @@ impl TestConfigBuilder { create_sns_arn(provider_config.clone(), ¶ms.alert_params).await.expect("Unable to create the sns arn"); let config = Arc::new(Config::new( - params.orchestrator_config, + params.orchestrator_params, starknet_client, da_client, prover_client, @@ -457,7 +457,7 @@ pub mod implement_client { } struct EnvParams { - aws_config: AWSConfigParams, + aws_params: AWSConfigParams, alert_params: AlertParams, queue_params: QueueParams, storage_params: StorageParams, @@ -465,7 +465,7 @@ struct EnvParams { da_params: DaParams, settlement_params: SettlementParams, prover_params: ProverParams, - orchestrator_config: OrchestratorConfig, + orchestrator_params: OrchestratorParams, #[allow(dead_code)] instrumentation_params: InstrumentationParams, } @@ -486,11 +486,12 @@ fn get_env_params() -> EnvParams { sqs_suffix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_SUFFIX"), }); - let aws_config = AWSConfigParams { + let aws_params = AWSConfigParams { aws_access_key_id: get_env_var_or_panic("AWS_ACCESS_KEY_ID"), aws_secret_access_key: get_env_var_or_panic("AWS_SECRET_ACCESS_KEY"), aws_region: get_env_var_or_panic("AWS_REGION"), - aws_endpoint_url: get_env_var_or_panic("AWS_ENDPOINT_URL"), + aws_endpoint_url: Url::parse(&get_env_var_or_panic("AWS_ENDPOINT_URL")) + .expect("Failed to parse AWS_ENDPOINT_URL"), aws_default_region: get_env_var_or_panic("AWS_DEFAULT_REGION"), }; @@ -530,7 +531,7 @@ fn get_env_params() -> EnvParams { .expect("Failed to parse MADARA_ORCHESTRATOR_PORT"), }; - let orchestrator_config = OrchestratorConfig { + let orchestrator_params = OrchestratorParams { madara_rpc_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_MADARA_RPC_URL")) .expect("Failed to parse MADARA_ORCHESTRATOR_MADARA_RPC_URL"), snos_config, @@ -560,7 +561,7 @@ fn get_env_params() -> EnvParams { }); EnvParams { - aws_config, + aws_params, alert_params, queue_params, storage_params, @@ -569,6 +570,6 @@ fn get_env_params() -> EnvParams { settlement_params, prover_params, instrumentation_params, - orchestrator_config, + orchestrator_params, } } diff --git a/crates/prover-services/sharp-service/src/client.rs b/crates/prover-services/sharp-service/src/client.rs index 09f38457..ff061862 100644 --- a/crates/prover-services/sharp-service/src/client.rs +++ b/crates/prover-services/sharp-service/src/client.rs @@ -28,7 +28,7 @@ impl SharpClient { /// and then copy it and paste it into .env file : /// /// `cat | base64` - pub fn new_with_settings(url: Url, sharp_params: &SharpParams) -> Self { + pub fn new_with_params(url: Url, sharp_params: &SharpParams) -> Self { // Getting the cert files from the .env and then decoding it from base64 let cert = general_purpose::STANDARD diff --git a/crates/prover-services/sharp-service/src/lib.rs b/crates/prover-services/sharp-service/src/lib.rs index b26a9ecf..51512fcf 100644 --- a/crates/prover-services/sharp-service/src/lib.rs +++ b/crates/prover-services/sharp-service/src/lib.rs @@ -133,8 +133,8 @@ impl SharpProverService { Self { sharp_client, fact_checker } } - pub fn new_with_settings(sharp_params: &SharpParams) -> Self { - let sharp_client = SharpClient::new_with_settings(sharp_params.sharp_url.clone(), sharp_params); + pub fn new_with_params(sharp_params: &SharpParams) -> Self { + let sharp_client = SharpClient::new_with_params(sharp_params.sharp_url.clone(), sharp_params); let fact_checker = FactChecker::new( sharp_params.sharp_rpc_node_url.clone(), sharp_params.gps_verifier_contract_address.clone(), @@ -142,8 +142,8 @@ impl SharpProverService { Self::new(sharp_client, fact_checker) } - pub fn with_test_settings(port: u16, sharp_params: &SharpParams) -> Self { - let sharp_client = SharpClient::new_with_settings( + pub fn with_test_params(port: u16, sharp_params: &SharpParams) -> Self { + let sharp_client = SharpClient::new_with_params( format!("http://127.0.0.1:{}", port).parse().expect("Failed to create sharp client with the given params"), sharp_params, ); diff --git a/crates/prover-services/sharp-service/tests/lib.rs b/crates/prover-services/sharp-service/tests/lib.rs index e117202b..23633c81 100644 --- a/crates/prover-services/sharp-service/tests/lib.rs +++ b/crates/prover-services/sharp-service/tests/lib.rs @@ -33,7 +33,7 @@ async fn prover_client_submit_task_works() { }; let server = MockServer::start(); - let sharp_service = SharpProverService::with_test_settings(server.port(), &sharp_params); + let sharp_service = SharpProverService::with_test_params(server.port(), &sharp_params); let cairo_pie_path = env!("CARGO_MANIFEST_DIR").to_string() + CAIRO_PIE_PATH; let cairo_pie = CairoPie::read_zip_file(cairo_pie_path.as_ref()).unwrap(); @@ -78,7 +78,7 @@ async fn prover_client_get_task_status_works(#[case] cairo_job_status: CairoJobS }; let server = MockServer::start(); - let sharp_service = SharpProverService::with_test_settings(server.port(), &sharp_params); + let sharp_service = SharpProverService::with_test_params(server.port(), &sharp_params); let customer_id = get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID"); let sharp_add_job_call = server.mock(|when, then| { diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index 655dac5a..3c9c5515 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -74,9 +74,7 @@ pub struct EthereumSettlementClient { } impl EthereumSettlementClient { - pub fn new_with_settings(settlement_cfg: &EthereumSettlementParams) -> Self { - // let settlement_cfg = EthereumSettlementConfig::new_with_settings(settings);3 - // TODO: can pass the actual struct here no ned for reference + pub fn new_with_params(settlement_cfg: &EthereumSettlementParams) -> Self { let private_key = settlement_cfg.ethereum_private_key.clone(); let signer: PrivateKeySigner = private_key.parse().expect("Failed to parse private key"); let wallet_address = signer.address(); @@ -105,7 +103,7 @@ impl EthereumSettlementClient { } #[cfg(feature = "testing")] - pub fn with_test_settings( + pub fn with_test_params( provider: RootProvider>, core_contract_address: Address, rpc_url: Url, diff --git a/crates/settlement-clients/ethereum/src/tests/mod.rs b/crates/settlement-clients/ethereum/src/tests/mod.rs index 5fe895f6..430bc291 100644 --- a/crates/settlement-clients/ethereum/src/tests/mod.rs +++ b/crates/settlement-clients/ethereum/src/tests/mod.rs @@ -167,7 +167,7 @@ mod settlement_client_tests { // Deploying a dummy contract let contract = DummyCoreContract::deploy(&setup.provider).await.expect("Unable to deploy address"); - let ethereum_settlement_client = EthereumSettlementClient::with_test_settings( + let ethereum_settlement_client = EthereumSettlementClient::with_test_params( setup.provider.clone(), *contract.address(), ethereum_settlement_params.ethereum_rpc_url, @@ -237,7 +237,7 @@ mod settlement_client_tests { starknet_operator_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"), }; - let ethereum_settlement_client = EthereumSettlementClient::with_test_settings( + let ethereum_settlement_client = EthereumSettlementClient::with_test_params( setup.provider.clone(), Address::from_str(ðereum_settlement_params.l1_core_contract_address).unwrap(), ethereum_settlement_params.ethereum_rpc_url, @@ -303,7 +303,7 @@ mod settlement_client_tests { starknet_operator_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"), }; - let ethereum_settlement_client = EthereumSettlementClient::with_test_settings( + let ethereum_settlement_client = EthereumSettlementClient::with_test_params( setup.provider.clone(), Address::from_str(ðereum_settlement_params.l1_core_contract_address).unwrap(), ethereum_settlement_params.ethereum_rpc_url, diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 4f3d56b9..646bb59e 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -44,7 +44,7 @@ const MAX_RETRIES_VERIFY_TX_FINALITY: usize = 10; // https://github.com/keep-starknet-strange/piltover impl StarknetSettlementClient { - pub async fn new_with_settings(settlement_cfg: &StarknetSettlementParams) -> Self { + pub async fn new_with_params(settlement_cfg: &StarknetSettlementParams) -> Self { let provider: Arc> = Arc::new(JsonRpcClient::new(HttpTransport::new(settlement_cfg.starknet_rpc_url.clone()))); diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 66631f99..6938b52b 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -171,7 +171,7 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) let is_success = wait_for_tx(&account, deploy_tx_hash, Duration::from_secs(2)).await; assert!(is_success, "Deploy trasaction failed"); - let settlement_client = StarknetSettlementClient::new_with_settings(&starknet_settlement_params).await; + let settlement_client = StarknetSettlementClient::new_with_params(&starknet_settlement_params).await; let onchain_data_hash = [1; 32]; let mut program_output = Vec::with_capacity(32); program_output.fill(onchain_data_hash); diff --git a/e2e-tests/src/localstack.rs b/e2e-tests/src/localstack.rs index 3148e256..78d4afdc 100644 --- a/e2e-tests/src/localstack.rs +++ b/e2e-tests/src/localstack.rs @@ -33,7 +33,7 @@ impl LocalStack { Self { sqs_client: aws_sdk_sqs::Client::new(&config), - s3_client: Box::new(AWSS3::new_with_settings(s3_config, provider_config).await), + s3_client: Box::new(AWSS3::new_with_params(s3_config, provider_config).await), event_bridge_client: aws_sdk_eventbridge::Client::new(&config), } } diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index 7ea53872..700623d3 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -27,6 +27,7 @@ use rstest::rstest; use serde::{Deserialize, Serialize}; use serde_json::json; use starknet::core::types::{Felt, MaybePendingStateUpdate}; +use url::Url; use utils::env_utils::get_env_var_or_panic; use uuid::Uuid; @@ -72,7 +73,8 @@ impl Setup { aws_access_key_id: get_env_var_or_panic("AWS_ACCESS_KEY_ID"), aws_secret_access_key: get_env_var_or_panic("AWS_SECRET_ACCESS_KEY"), aws_region: get_env_var_or_panic("AWS_REGION"), - aws_endpoint_url: get_env_var_or_panic("AWS_ENDPOINT_URL"), + aws_endpoint_url: Url::parse(&get_env_var_or_panic("AWS_ENDPOINT_URL")) + .expect("Failed to parse AWS_ENDPOINT_URL"), aws_default_region: get_env_var_or_panic("AWS_DEFAULT_REGION"), }; From 7c904905839056dfcbeb610367290c67413014de Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Sat, 9 Nov 2024 13:14:19 +0530 Subject: [PATCH 39/63] update: unwraps to expect and regrouping --- crates/orchestrator/src/cli/alert/aws_sns.rs | 1 + .../orchestrator/src/cli/instrumentation.rs | 2 +- crates/orchestrator/src/cli/mod.rs | 134 +++++++++++++----- crates/orchestrator/src/cli/prover/sharp.rs | 2 +- crates/orchestrator/src/cli/server.rs | 2 +- .../src/cli/settlement/starknet.rs | 4 +- 6 files changed, 102 insertions(+), 43 deletions(-) diff --git a/crates/orchestrator/src/cli/alert/aws_sns.rs b/crates/orchestrator/src/cli/alert/aws_sns.rs index 3fdebaf9..c335cee0 100644 --- a/crates/orchestrator/src/cli/alert/aws_sns.rs +++ b/crates/orchestrator/src/cli/alert/aws_sns.rs @@ -2,6 +2,7 @@ use clap::Args; /// Parameters used to config AWS SNS. #[derive(Debug, Clone, Args)] +#[group()] pub struct AWSSNSCliArgs { /// Use the AWS SNS client #[arg(long)] diff --git a/crates/orchestrator/src/cli/instrumentation.rs b/crates/orchestrator/src/cli/instrumentation.rs index 342efd9c..648806f3 100644 --- a/crates/orchestrator/src/cli/instrumentation.rs +++ b/crates/orchestrator/src/cli/instrumentation.rs @@ -4,7 +4,7 @@ use url::Url; /// Parameters used to config instrumentation. #[derive(Debug, Clone, Args)] -#[group(requires_all = ["log_level"])] +#[group()] pub struct InstrumentationCliArgs { /// The name of the instrumentation service. #[arg(env = "MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME", long, default_value = "orchestrator")] diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index 4a3aaeb5..efb5bbc0 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -91,6 +91,7 @@ pub struct RunCmd { #[clap(flatten)] pub aws_s3_args: storage::aws_s3::AWSS3CliArgs, + // Queue #[clap(flatten)] pub aws_sqs_args: queue::aws_sqs::AWSSQSCliArgs, @@ -130,7 +131,8 @@ pub struct RunCmd { impl RunCmd { pub fn validate_aws_config_params(&self) -> Result { - let aws_endpoint_url = Url::parse("http://localhost.localstack.cloud:4566").unwrap(); + let aws_endpoint_url = + Url::parse("http://localhost.localstack.cloud:4566").expect("Failed to parse AWS endpoint URL"); let aws_default_region = "localhost".to_string(); tracing::warn!("Setting AWS_ENDPOINT_URL to {} for AWS SDK to use", aws_endpoint_url); @@ -147,7 +149,9 @@ impl RunCmd { pub fn validate_alert_params(&self) -> Result { if self.aws_sns_args.aws_sns { - Ok(AlertParams::AWSSNS(AWSSNSParams { sns_arn: self.aws_sns_args.sns_arn.clone().unwrap() })) + Ok(AlertParams::AWSSNS(AWSSNSParams { + sns_arn: self.aws_sns_args.sns_arn.clone().expect("SNS ARN is required"), + })) } else { Err("Only AWS SNS is supported as of now".to_string()) } @@ -156,9 +160,9 @@ impl RunCmd { pub fn validate_queue_params(&self) -> Result { if self.aws_sqs_args.aws_sqs { Ok(QueueParams::AWSSQS(AWSSQSParams { - queue_base_url: self.aws_sqs_args.queue_base_url.clone().unwrap(), - sqs_prefix: self.aws_sqs_args.sqs_prefix.clone().unwrap(), - sqs_suffix: self.aws_sqs_args.sqs_suffix.clone().unwrap(), + queue_base_url: self.aws_sqs_args.queue_base_url.clone().expect("Queue base URL is required"), + sqs_prefix: self.aws_sqs_args.sqs_prefix.clone().expect("SQS prefix is required"), + sqs_suffix: self.aws_sqs_args.sqs_suffix.clone().expect("SQS suffix is required"), })) } else { Err("Only AWS SQS is supported as of now".to_string()) @@ -167,7 +171,9 @@ impl RunCmd { pub fn validate_storage_params(&self) -> Result { if self.aws_s3_args.aws_s3 { - Ok(StorageParams::AWSS3(AWSS3Params { bucket_name: self.aws_s3_args.bucket_name.clone().unwrap() })) + Ok(StorageParams::AWSS3(AWSS3Params { + bucket_name: self.aws_s3_args.bucket_name.clone().expect("Bucket name is required"), + })) } else { Err("Only AWS S3 is supported as of now".to_string()) } @@ -176,8 +182,16 @@ impl RunCmd { pub fn validate_database_params(&self) -> Result { if self.mongodb_args.mongodb { Ok(DatabaseParams::MongoDB(MongoDBParams { - connection_url: self.mongodb_args.mongodb_connection_url.clone().unwrap(), - database_name: self.mongodb_args.mongodb_database_name.clone().unwrap(), + connection_url: self + .mongodb_args + .mongodb_connection_url + .clone() + .expect("MongoDB connection URL is required"), + database_name: self + .mongodb_args + .mongodb_database_name + .clone() + .expect("MongoDB database name is required"), })) } else { Err("Only MongoDB is supported as of now".to_string()) @@ -187,7 +201,11 @@ impl RunCmd { pub fn validate_da_params(&self) -> Result { if self.ethereum_da_args.da_on_ethereum { Ok(DaParams::Ethereum(EthereumDaParams { - ethereum_da_rpc_url: self.ethereum_da_args.ethereum_da_rpc_url.clone().unwrap(), + ethereum_da_rpc_url: self + .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()) @@ -198,28 +216,60 @@ impl RunCmd { match (self.ethereum_args.settle_on_ethereum, self.starknet_args.settle_on_starknet) { (true, false) => { let ethereum_params = EthereumSettlementParams { - ethereum_rpc_url: self.ethereum_args.ethereum_rpc_url.clone().unwrap(), - ethereum_private_key: self.ethereum_args.ethereum_private_key.clone().unwrap(), - l1_core_contract_address: self.ethereum_args.l1_core_contract_address.clone().unwrap(), - starknet_operator_address: self.ethereum_args.starknet_operator_address.clone().unwrap(), + ethereum_rpc_url: self + .ethereum_args + .ethereum_rpc_url + .clone() + .expect("Ethereum RPC URL is required"), + ethereum_private_key: self + .ethereum_args + .ethereum_private_key + .clone() + .expect("Ethereum private key is required"), + l1_core_contract_address: self + .ethereum_args + .l1_core_contract_address + .clone() + .expect("L1 core contract address is required"), + starknet_operator_address: self + .ethereum_args + .starknet_operator_address + .clone() + .expect("Starknet operator address is required"), }; Ok(SettlementParams::Ethereum(ethereum_params)) } (false, true) => { let starknet_params = StarknetSettlementParams { - starknet_rpc_url: self.starknet_args.starknet_rpc_url.clone().unwrap(), - starknet_private_key: self.starknet_args.starknet_private_key.clone().unwrap(), - starknet_account_address: self.starknet_args.starknet_account_address.clone().unwrap(), + starknet_rpc_url: self + .starknet_args + .starknet_rpc_url + .clone() + .expect("Starknet RPC URL is required"), + starknet_private_key: self + .starknet_args + .starknet_private_key + .clone() + .expect("Starknet private key is required"), + starknet_account_address: self + .starknet_args + .starknet_account_address + .clone() + .expect("Starknet account address is required"), starknet_cairo_core_contract_address: self .starknet_args .starknet_cairo_core_contract_address .clone() - .unwrap(), + .expect("Starknet Cairo core contract address is required"), starknet_finality_retry_wait_in_secs: self .starknet_args .starknet_finality_retry_wait_in_secs - .unwrap(), - madara_binary_path: self.starknet_args.madara_binary_path.clone().unwrap(), + .expect("Starknet finality retry wait in seconds is required"), + madara_binary_path: self + .starknet_args + .starknet_madara_binary_path + .clone() + .expect("Starknet Madara binary path is required"), }; Ok(SettlementParams::Starknet(starknet_params)) } @@ -230,14 +280,22 @@ impl RunCmd { pub fn validate_prover_params(&self) -> Result { if self.sharp_args.sharp { Ok(ProverParams::Sharp(SharpParams { - sharp_customer_id: self.sharp_args.sharp_customer_id.clone().unwrap(), - sharp_url: self.sharp_args.sharp_url.clone().unwrap(), - sharp_user_crt: self.sharp_args.sharp_user_crt.clone().unwrap(), - sharp_user_key: self.sharp_args.sharp_user_key.clone().unwrap(), - sharp_rpc_node_url: self.sharp_args.sharp_rpc_node_url.clone().unwrap(), - sharp_proof_layout: self.sharp_args.sharp_proof_layout.clone().unwrap(), - gps_verifier_contract_address: self.sharp_args.gps_verifier_contract_address.clone().unwrap(), - sharp_server_crt: self.sharp_args.sharp_server_crt.clone().unwrap(), + sharp_customer_id: self.sharp_args.sharp_customer_id.clone().expect("Sharp customer ID is required"), + sharp_url: self.sharp_args.sharp_url.clone().expect("Sharp URL is required"), + sharp_user_crt: self.sharp_args.sharp_user_crt.clone().expect("Sharp user certificate is required"), + sharp_user_key: self.sharp_args.sharp_user_key.clone().expect("Sharp user key is required"), + sharp_rpc_node_url: self.sharp_args.sharp_rpc_node_url.clone().expect("Sharp RPC node URL is required"), + sharp_proof_layout: self.sharp_args.sharp_proof_layout.clone().expect("Sharp proof layout is required"), + gps_verifier_contract_address: self + .sharp_args + .gps_verifier_contract_address + .clone() + .expect("GPS verifier contract address is required"), + sharp_server_crt: self + .sharp_args + .sharp_server_crt + .clone() + .expect("Sharp server certificate is required"), })) } else { Err("Only Sharp is supported as of now".to_string()) @@ -246,7 +304,11 @@ impl RunCmd { pub fn validate_instrumentation_params(&self) -> Result { Ok(InstrumentationParams { - otel_service_name: self.instrumentation_args.otel_service_name.clone().unwrap(), + otel_service_name: self + .instrumentation_args + .otel_service_name + .clone() + .expect("OTel service name is required"), otel_collector_endpoint: self.instrumentation_args.otel_collector_endpoint.clone(), log_level: self.instrumentation_args.log_level, }) @@ -259,16 +321,12 @@ impl RunCmd { pub fn validate_service_params(&self) -> Result { Ok(ServiceParams { // return None if the value is empty string - max_block_to_process: self - .service_args - .max_block_to_process - .clone() - .and_then(|s| if s.is_empty() { None } else { Some(s.parse::().unwrap()) }), - min_block_to_process: self - .service_args - .min_block_to_process - .clone() - .and_then(|s| if s.is_empty() { None } else { Some(s.parse::().unwrap()) }), + max_block_to_process: self.service_args.max_block_to_process.clone().and_then(|s| { + if s.is_empty() { None } else { Some(s.parse::().expect("Failed to parse max block to process")) } + }), + min_block_to_process: self.service_args.min_block_to_process.clone().and_then(|s| { + if s.is_empty() { None } else { Some(s.parse::().expect("Failed to parse min block to process")) } + }), }) } diff --git a/crates/orchestrator/src/cli/prover/sharp.rs b/crates/orchestrator/src/cli/prover/sharp.rs index 5a650959..6c324d1c 100644 --- a/crates/orchestrator/src/cli/prover/sharp.rs +++ b/crates/orchestrator/src/cli/prover/sharp.rs @@ -3,7 +3,7 @@ use url::Url; /// Parameters used to config Sharp. #[derive(Debug, Clone, Args)] -#[group(requires_all = ["sharp_customer_id", "sharp_url", "sharp_user_crt", "sharp_user_key", "sharp_server_crt", "sharp_proof_layout", "gps_verifier_contract_address", "sharp_rpc_node_url"])] +#[group(requires_all = ["sharp_customer_id", "sharp_url", "sharp_user_crt", "sharp_user_key", "sharp_server_crt", "gps_verifier_contract_address", "sharp_rpc_node_url"])] pub struct SharpCliArgs { /// Use the Sharp prover. #[arg(long)] diff --git a/crates/orchestrator/src/cli/server.rs b/crates/orchestrator/src/cli/server.rs index 77a2ac0b..6f365ef9 100644 --- a/crates/orchestrator/src/cli/server.rs +++ b/crates/orchestrator/src/cli/server.rs @@ -2,7 +2,7 @@ use clap::Args; /// Parameters used to config the server. #[derive(Debug, Clone, Args)] -#[group(requires_all = ["host", "port"])] +#[group()] pub struct ServerCliArgs { /// The host to listen on. #[arg(env = "MADARA_ORCHESTRATOR_HOST", long, default_value = "127.0.0.1")] diff --git a/crates/orchestrator/src/cli/settlement/starknet.rs b/crates/orchestrator/src/cli/settlement/starknet.rs index 6c1223ee..dfa85dbb 100644 --- a/crates/orchestrator/src/cli/settlement/starknet.rs +++ b/crates/orchestrator/src/cli/settlement/starknet.rs @@ -2,7 +2,7 @@ use clap::Args; use url::Url; #[derive(Debug, Clone, Args)] -#[group(requires_all = ["starknet_rpc_url", "starknet_private_key", "starknet_account_address", "starknet_cairo_core_contract_address", "starknet_finality_retry_wait_in_secs"])] +#[group(requires_all = ["starknet_rpc_url", "starknet_private_key", "starknet_account_address", "starknet_cairo_core_contract_address", "starknet_finality_retry_wait_in_secs", "starknet_madara_binary_path"])] pub struct StarknetSettlementCliArgs { /// Use the Starknet settlement layer. #[arg(long)] @@ -30,5 +30,5 @@ pub struct StarknetSettlementCliArgs { /// The path to the Madara binary. #[arg(env = "MADARA_ORCHESTRATOR_MADARA_BINARY_PATH", long)] - pub madara_binary_path: Option, + pub starknet_madara_binary_path: Option, } From 306ddad977be878719a7a0bc120b816d7e2ff837 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Sat, 9 Nov 2024 13:26:26 +0530 Subject: [PATCH 40/63] update: env correctiong --- crates/orchestrator/src/cli/settlement/starknet.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/orchestrator/src/cli/settlement/starknet.rs b/crates/orchestrator/src/cli/settlement/starknet.rs index dfa85dbb..0d74ec82 100644 --- a/crates/orchestrator/src/cli/settlement/starknet.rs +++ b/crates/orchestrator/src/cli/settlement/starknet.rs @@ -2,7 +2,7 @@ use clap::Args; use url::Url; #[derive(Debug, Clone, Args)] -#[group(requires_all = ["starknet_rpc_url", "starknet_private_key", "starknet_account_address", "starknet_cairo_core_contract_address", "starknet_finality_retry_wait_in_secs", "starknet_madara_binary_path"])] +#[group(requires_all = ["starknet_rpc_url", "starknet_private_key", "starknet_account_address", "starknet_cairo_core_contract_address", "starknet_finality_retry_wait_in_secs"])] pub struct StarknetSettlementCliArgs { /// Use the Starknet settlement layer. #[arg(long)] From 498e5c33d45498024107fa69cfd912906329a99d Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Sat, 9 Nov 2024 15:44:31 +0530 Subject: [PATCH 41/63] update: removed config --- crates/da-clients/ethereum/src/config.rs | 24 ------------------------ crates/da-clients/ethereum/src/lib.rs | 17 ++++++++++++++++- crates/orchestrator/src/config.rs | 16 +++++----------- crates/orchestrator/src/queue/sqs/mod.rs | 6 ++++++ 4 files changed, 27 insertions(+), 36 deletions(-) diff --git a/crates/da-clients/ethereum/src/config.rs b/crates/da-clients/ethereum/src/config.rs index a535d986..b766b0c0 100644 --- a/crates/da-clients/ethereum/src/config.rs +++ b/crates/da-clients/ethereum/src/config.rs @@ -1,33 +1,9 @@ -use std::str::FromStr; -use alloy::network::Ethereum; -use alloy::providers::ProviderBuilder; -use alloy::rpc::client::RpcClient; use serde::{Deserialize, Serialize}; use url::Url; -use crate::EthereumDaClient; #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct EthereumDaConfig { - pub rpc_url: String, -} - -impl EthereumDaConfig { - pub fn new_with_params(ethereum_da_params: &EthereumDaParams) -> color_eyre::Result { - Ok(Self { rpc_url: ethereum_da_params.ethereum_da_rpc_url.to_string() }) - } - - pub async fn build_client(&self) -> EthereumDaClient { - let client = - RpcClient::new_http(Url::from_str(self.rpc_url.as_str()).expect("Failed to parse SETTLEMENT_RPC_URL")); - let provider = ProviderBuilder::<_, Ethereum>::new().on_client(client); - - EthereumDaClient { provider } - } -} - -#[derive(Debug, Clone)] pub struct EthereumDaParams { pub ethereum_da_rpc_url: Url, } diff --git a/crates/da-clients/ethereum/src/lib.rs b/crates/da-clients/ethereum/src/lib.rs index 2504932f..4403568d 100644 --- a/crates/da-clients/ethereum/src/lib.rs +++ b/crates/da-clients/ethereum/src/lib.rs @@ -1,15 +1,20 @@ #![allow(missing_docs)] #![allow(clippy::missing_docs_in_private_items)] +use std::str::FromStr; + use alloy::network::Ethereum; -use alloy::providers::RootProvider; +use alloy::providers::{ProviderBuilder, RootProvider}; +use alloy::rpc::client::RpcClient; use alloy::transports::http::Http; use async_trait::async_trait; use color_eyre::Result; +use config::EthereumDaParams; use da_client_interface::{DaClient, DaVerificationStatus}; use mockall::automock; use mockall::predicate::*; use reqwest::Client; +use url::Url; pub const DA_SETTINGS_NAME: &str = "ethereum"; @@ -19,6 +24,16 @@ pub struct EthereumDaClient { pub provider: RootProvider>, } +impl EthereumDaClient { + pub async fn new_with_params(ethereum_da_params: &EthereumDaParams) -> Self { + let client = RpcClient::new_http( + Url::from_str(ethereum_da_params.ethereum_da_rpc_url.as_str()).expect("Failed to parse SETTLEMENT_RPC_URL"), + ); + let provider = ProviderBuilder::<_, Ethereum>::new().on_client(client); + Self { provider } + } +} + #[automock] #[async_trait] impl DaClient for EthereumDaClient { diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 1d8cf511..85742025 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -12,7 +12,7 @@ use aws_credential_types::Credentials; use color_eyre::eyre::eyre; use da_client_interface::DaClient; 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; @@ -257,13 +257,10 @@ impl Config { } /// Builds the DA client based on the environment variable DA_LAYER +// TODO: convert this to use new_with_params pub async fn build_da_client(da_params: &DaParams) -> Box { match da_params { - DaParams::Ethereum(ethereum_da_params) => { - let config = EthereumDaConfig::new_with_params(ethereum_da_params) - .expect("Not able to build config from the given settings provider."); - Box::new(config.build_client().await) - } + DaParams::Ethereum(ethereum_da_params) => Box::new(EthereumDaClient::new_with_params(ethereum_da_params).await), } } @@ -314,16 +311,13 @@ pub async fn build_alert_client( provider_config: Arc, ) -> Box { match alert_params { - AlertParams::AWSSNS(aws_sns_params) => { - println!("Building alert client {}", aws_sns_params.sns_arn); - Box::new(AWSSNS::new_with_params(aws_sns_params, provider_config).await) - } + AlertParams::AWSSNS(aws_sns_params) => Box::new(AWSSNS::new_with_params(aws_sns_params, provider_config).await), } } pub fn build_queue_client(queue_params: &QueueParams) -> Box { match queue_params { - QueueParams::AWSSQS(aws_sqs_params) => Box::new(SqsQueue { params: aws_sqs_params.clone() }), + QueueParams::AWSSQS(aws_sqs_params) => Box::new(SqsQueue::new_with_params(aws_sqs_params.clone())), } } diff --git a/crates/orchestrator/src/queue/sqs/mod.rs b/crates/orchestrator/src/queue/sqs/mod.rs index 082bf91a..3ac95a91 100644 --- a/crates/orchestrator/src/queue/sqs/mod.rs +++ b/crates/orchestrator/src/queue/sqs/mod.rs @@ -31,6 +31,12 @@ pub struct SqsQueue { pub params: AWSSQSParams, } +impl SqsQueue { + pub fn new_with_params(params: AWSSQSParams) -> Self { + Self { params } + } +} + #[async_trait] impl QueueProvider for SqsQueue { async fn send_message_to_queue(&self, queue: QueueType, payload: String, delay: Option) -> Result<()> { From b477b29149918c877eb1612a9a1afc254f8f0555 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Sat, 9 Nov 2024 16:04:16 +0530 Subject: [PATCH 42/63] update: removed config.rs --- crates/da-clients/ethereum/src/config.rs | 9 --------- crates/da-clients/ethereum/src/lib.rs | 8 ++++++-- crates/orchestrator/src/cli/da/mod.rs | 2 +- crates/orchestrator/src/cli/database/mod.rs | 2 +- crates/orchestrator/src/cli/mod.rs | 12 ++++++------ crates/orchestrator/src/cli/prover/mod.rs | 2 +- crates/orchestrator/src/cli/settlement/mod.rs | 4 ++-- crates/orchestrator/src/cli/storage/mod.rs | 2 +- .../src/data_storage/aws_s3/config.rs | 4 ---- .../orchestrator/src/data_storage/aws_s3/mod.rs | 7 ++++--- .../orchestrator/src/database/mongodb/config.rs | 5 ----- crates/orchestrator/src/database/mongodb/mod.rs | 8 ++++++-- crates/orchestrator/src/tests/common/mod.rs | 3 +-- crates/orchestrator/src/tests/config.rs | 10 +++++----- .../prover-services/sharp-service/src/client.rs | 2 +- .../prover-services/sharp-service/src/config.rs | 13 ------------- crates/prover-services/sharp-service/src/lib.rs | 16 ++++++++++++++-- .../prover-services/sharp-service/tests/lib.rs | 3 +-- .../settlement-clients/ethereum/src/config.rs | 12 ------------ crates/settlement-clients/ethereum/src/lib.rs | 15 +++++++++++++-- .../settlement-clients/starknet/src/config.rs | 14 -------------- crates/settlement-clients/starknet/src/lib.rs | 17 ++++++++++++++++- .../starknet/src/tests/test.rs | 3 +-- e2e-tests/src/localstack.rs | 3 +-- e2e-tests/src/mongodb.rs | 2 +- e2e-tests/tests.rs | 4 ++-- 26 files changed, 84 insertions(+), 98 deletions(-) delete mode 100644 crates/da-clients/ethereum/src/config.rs delete mode 100644 crates/orchestrator/src/data_storage/aws_s3/config.rs delete mode 100644 crates/orchestrator/src/database/mongodb/config.rs delete mode 100644 crates/prover-services/sharp-service/src/config.rs delete mode 100644 crates/settlement-clients/ethereum/src/config.rs diff --git a/crates/da-clients/ethereum/src/config.rs b/crates/da-clients/ethereum/src/config.rs deleted file mode 100644 index b766b0c0..00000000 --- a/crates/da-clients/ethereum/src/config.rs +++ /dev/null @@ -1,9 +0,0 @@ - -use serde::{Deserialize, Serialize}; -use url::Url; - - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct EthereumDaParams { - pub ethereum_da_rpc_url: Url, -} diff --git a/crates/da-clients/ethereum/src/lib.rs b/crates/da-clients/ethereum/src/lib.rs index 4403568d..aa6bc3ae 100644 --- a/crates/da-clients/ethereum/src/lib.rs +++ b/crates/da-clients/ethereum/src/lib.rs @@ -9,16 +9,20 @@ use alloy::rpc::client::RpcClient; use alloy::transports::http::Http; use async_trait::async_trait; use color_eyre::Result; -use config::EthereumDaParams; use da_client_interface::{DaClient, DaVerificationStatus}; use mockall::automock; use mockall::predicate::*; use reqwest::Client; +use serde::{Deserialize, Serialize}; use url::Url; +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct EthereumDaParams { + pub ethereum_da_rpc_url: Url, +} + pub const DA_SETTINGS_NAME: &str = "ethereum"; -pub mod config; pub struct EthereumDaClient { #[allow(dead_code)] pub provider: RootProvider>, diff --git a/crates/orchestrator/src/cli/da/mod.rs b/crates/orchestrator/src/cli/da/mod.rs index 1bd312a3..4f60d63c 100644 --- a/crates/orchestrator/src/cli/da/mod.rs +++ b/crates/orchestrator/src/cli/da/mod.rs @@ -1,4 +1,4 @@ -use ethereum_da_client::config::EthereumDaParams; +use ethereum_da_client::EthereumDaParams; pub mod ethereum; diff --git a/crates/orchestrator/src/cli/database/mod.rs b/crates/orchestrator/src/cli/database/mod.rs index 36350dca..5f80cfe6 100644 --- a/crates/orchestrator/src/cli/database/mod.rs +++ b/crates/orchestrator/src/cli/database/mod.rs @@ -1,4 +1,4 @@ -use crate::database::mongodb::config::MongoDBParams; +use crate::database::mongodb::MongoDBParams; pub mod mongodb; diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index efb5bbc0..cc694d63 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -3,21 +3,21 @@ use aws_config::{AWSConfigCliArgs, AWSConfigParams}; use clap::{ArgGroup, Parser}; use da::DaParams; use database::DatabaseParams; -use ethereum_da_client::config::EthereumDaParams; -use ethereum_settlement_client::config::EthereumSettlementParams; +use ethereum_da_client::EthereumDaParams; +use ethereum_settlement_client::EthereumSettlementParams; use prover::ProverParams; use queue::QueueParams; use settlement::SettlementParams; -use sharp_service::config::SharpParams; +use sharp_service::SharpParams; use snos::SNOSParams; -use starknet_settlement_client::config::StarknetSettlementParams; +use starknet_settlement_client::StarknetSettlementParams; use storage::StorageParams; use url::Url; use crate::alerts::aws_sns::AWSSNSParams; use crate::config::ServiceParams; -use crate::data_storage::aws_s3::config::AWSS3Params; -use crate::database::mongodb::config::MongoDBParams; +use crate::data_storage::aws_s3::AWSS3Params; +use crate::database::mongodb::MongoDBParams; use crate::queue::sqs::AWSSQSParams; use crate::routes::ServerParams; use crate::telemetry::InstrumentationParams; diff --git a/crates/orchestrator/src/cli/prover/mod.rs b/crates/orchestrator/src/cli/prover/mod.rs index 9bd8a00b..88ef6ce9 100644 --- a/crates/orchestrator/src/cli/prover/mod.rs +++ b/crates/orchestrator/src/cli/prover/mod.rs @@ -1,4 +1,4 @@ -use sharp_service::config::SharpParams; +use sharp_service::SharpParams; pub mod sharp; diff --git a/crates/orchestrator/src/cli/settlement/mod.rs b/crates/orchestrator/src/cli/settlement/mod.rs index 8dd9f0f9..79a81fb6 100644 --- a/crates/orchestrator/src/cli/settlement/mod.rs +++ b/crates/orchestrator/src/cli/settlement/mod.rs @@ -1,5 +1,5 @@ -use ethereum_settlement_client::config::EthereumSettlementParams; -use starknet_settlement_client::config::StarknetSettlementParams; +use ethereum_settlement_client::EthereumSettlementParams; +use starknet_settlement_client::StarknetSettlementParams; pub mod ethereum; pub mod starknet; diff --git a/crates/orchestrator/src/cli/storage/mod.rs b/crates/orchestrator/src/cli/storage/mod.rs index c6833f59..e014db42 100644 --- a/crates/orchestrator/src/cli/storage/mod.rs +++ b/crates/orchestrator/src/cli/storage/mod.rs @@ -1,4 +1,4 @@ -use crate::data_storage::aws_s3::config::AWSS3Params; +use crate::data_storage::aws_s3::AWSS3Params; pub mod aws_s3; diff --git a/crates/orchestrator/src/data_storage/aws_s3/config.rs b/crates/orchestrator/src/data_storage/aws_s3/config.rs deleted file mode 100644 index ba8bd1dd..00000000 --- a/crates/orchestrator/src/data_storage/aws_s3/config.rs +++ /dev/null @@ -1,4 +0,0 @@ -#[derive(Debug, Clone)] -pub struct AWSS3Params { - pub bucket_name: String, -} diff --git a/crates/orchestrator/src/data_storage/aws_s3/mod.rs b/crates/orchestrator/src/data_storage/aws_s3/mod.rs index 92dc818a..efe5146b 100644 --- a/crates/orchestrator/src/data_storage/aws_s3/mod.rs +++ b/crates/orchestrator/src/data_storage/aws_s3/mod.rs @@ -5,15 +5,16 @@ use aws_sdk_s3::primitives::ByteStream; use aws_sdk_s3::Client; use bytes::Bytes; use color_eyre::Result; -use config::AWSS3Params; use crate::config::ProviderConfig; use crate::data_storage::DataStorage; pub const S3_SETTINGS_NAME: &str = "s3"; -/// Module for AWS S3 config structs and implementations -pub mod config; +#[derive(Debug, Clone)] +pub struct AWSS3Params { + pub bucket_name: String, +} /// AWSS3 represents AWS S3 client object containing the client and the config itself. pub struct AWSS3 { diff --git a/crates/orchestrator/src/database/mongodb/config.rs b/crates/orchestrator/src/database/mongodb/config.rs deleted file mode 100644 index c4bf6f27..00000000 --- a/crates/orchestrator/src/database/mongodb/config.rs +++ /dev/null @@ -1,5 +0,0 @@ -#[derive(Debug, Clone)] -pub struct MongoDBParams { - pub connection_url: String, - pub database_name: String, -} diff --git a/crates/orchestrator/src/database/mongodb/mod.rs b/crates/orchestrator/src/database/mongodb/mod.rs index a8154f4f..425dd898 100644 --- a/crates/orchestrator/src/database/mongodb/mod.rs +++ b/crates/orchestrator/src/database/mongodb/mod.rs @@ -3,7 +3,6 @@ use async_trait::async_trait; use chrono::{SubsecRound, Utc}; use color_eyre::eyre::eyre; use color_eyre::Result; -use config::MongoDBParams; use futures::TryStreamExt; use mongodb::bson::{doc, Bson, Document}; use mongodb::options::{ @@ -18,9 +17,14 @@ use crate::database::Database; use crate::jobs::types::{JobItem, JobItemUpdates, JobStatus, JobType}; use crate::jobs::JobError; -pub mod config; mod utils; +#[derive(Debug, Clone)] +pub struct MongoDBParams { + pub connection_url: String, + pub database_name: String, +} + pub struct MongoDb { client: Client, database_name: String, diff --git a/crates/orchestrator/src/tests/common/mod.rs b/crates/orchestrator/src/tests/common/mod.rs index e7948d50..81e6a1f2 100644 --- a/crates/orchestrator/src/tests/common/mod.rs +++ b/crates/orchestrator/src/tests/common/mod.rs @@ -16,8 +16,7 @@ use crate::cli::alert::AlertParams; use crate::cli::database::DatabaseParams; use crate::cli::queue::QueueParams; use crate::config::ProviderConfig; -use crate::data_storage::aws_s3::config::AWSS3Params; -use crate::data_storage::aws_s3::AWSS3; +use crate::data_storage::aws_s3::{AWSS3Params, AWSS3}; use crate::data_storage::DataStorage; use crate::database::mongodb::MongoDb; use crate::jobs::types::JobStatus::Created; diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 69b58201..7cbefd14 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -4,12 +4,12 @@ use std::sync::Arc; use axum::Router; use da_client_interface::{DaClient, MockDaClient}; -use ethereum_da_client::config::EthereumDaParams; -use ethereum_settlement_client::config::EthereumSettlementParams; +use ethereum_da_client::EthereumDaParams; +use ethereum_settlement_client::EthereumSettlementParams; use httpmock::MockServer; use prover_client_interface::{MockProverClient, ProverClient}; use settlement_client_interface::{MockSettlementClient, SettlementClient}; -use sharp_service::config::SharpParams; +use sharp_service::SharpParams; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::JsonRpcClient; use tracing::Level; @@ -28,9 +28,9 @@ use crate::cli::settlement::SettlementParams; use crate::cli::snos::SNOSParams; use crate::cli::storage::StorageParams; use crate::config::{get_aws_config, Config, OrchestratorParams, ProviderConfig, ServiceParams}; -use crate::data_storage::aws_s3::config::AWSS3Params; +use crate::data_storage::aws_s3::AWSS3Params; use crate::data_storage::{DataStorage, MockDataStorage}; -use crate::database::mongodb::config::MongoDBParams; +use crate::database::mongodb::MongoDBParams; use crate::database::{Database, MockDatabase}; use crate::queue::sqs::AWSSQSParams; use crate::queue::{MockQueueProvider, QueueProvider}; diff --git a/crates/prover-services/sharp-service/src/client.rs b/crates/prover-services/sharp-service/src/client.rs index ff061862..18c4649d 100644 --- a/crates/prover-services/sharp-service/src/client.rs +++ b/crates/prover-services/sharp-service/src/client.rs @@ -7,9 +7,9 @@ use url::Url; use utils::env_utils::get_env_var_or_panic; use uuid::Uuid; -use crate::config::SharpParams; use crate::error::SharpError; use crate::types::{SharpAddJobResponse, SharpGetStatusResponse}; +use crate::SharpParams; /// SHARP API async wrapper pub struct SharpClient { diff --git a/crates/prover-services/sharp-service/src/config.rs b/crates/prover-services/sharp-service/src/config.rs deleted file mode 100644 index a1e49ef6..00000000 --- a/crates/prover-services/sharp-service/src/config.rs +++ /dev/null @@ -1,13 +0,0 @@ -use url::Url; - -#[derive(Debug, Clone)] -pub struct SharpParams { - pub sharp_customer_id: String, - pub sharp_url: Url, - pub sharp_user_crt: String, - pub sharp_user_key: String, - pub sharp_rpc_node_url: Url, - pub sharp_server_crt: String, - pub sharp_proof_layout: String, - pub gps_verifier_contract_address: String, -} diff --git a/crates/prover-services/sharp-service/src/lib.rs b/crates/prover-services/sharp-service/src/lib.rs index 51512fcf..b1a1796c 100644 --- a/crates/prover-services/sharp-service/src/lib.rs +++ b/crates/prover-services/sharp-service/src/lib.rs @@ -1,5 +1,4 @@ pub mod client; -pub mod config; pub mod error; mod types; @@ -7,7 +6,6 @@ use std::str::FromStr; use alloy::primitives::B256; use async_trait::async_trait; -use config::SharpParams; use gps_fact_checker::FactChecker; use prover_client_interface::{ProverClient, ProverClientError, Task, TaskStatus}; use starknet_os::sharp::CairoJobStatus; @@ -17,6 +15,20 @@ use crate::client::SharpClient; pub const SHARP_SETTINGS_NAME: &str = "sharp"; +use url::Url; + +#[derive(Debug, Clone)] +pub struct SharpParams { + pub sharp_customer_id: String, + pub sharp_url: Url, + pub sharp_user_crt: String, + pub sharp_user_key: String, + pub sharp_rpc_node_url: Url, + pub sharp_server_crt: String, + pub sharp_proof_layout: String, + pub gps_verifier_contract_address: String, +} + /// SHARP (aka GPS) is a shared proving service hosted by Starkware. pub struct SharpProverService { sharp_client: SharpClient, diff --git a/crates/prover-services/sharp-service/tests/lib.rs b/crates/prover-services/sharp-service/tests/lib.rs index 23633c81..d01517a3 100644 --- a/crates/prover-services/sharp-service/tests/lib.rs +++ b/crates/prover-services/sharp-service/tests/lib.rs @@ -6,8 +6,7 @@ use prover_client_interface::ProverClient; use prover_client_interface::{Task, TaskStatus}; use rstest::rstest; use serde_json::json; -use sharp_service::config::SharpParams; -use sharp_service::SharpProverService; +use sharp_service::{SharpParams, SharpProverService}; use starknet_os::sharp::CairoJobStatus; use url::Url; use utils::env_utils::get_env_var_or_panic; diff --git a/crates/settlement-clients/ethereum/src/config.rs b/crates/settlement-clients/ethereum/src/config.rs deleted file mode 100644 index cf6ea1ab..00000000 --- a/crates/settlement-clients/ethereum/src/config.rs +++ /dev/null @@ -1,12 +0,0 @@ -use url::Url; - -#[derive(Clone, Debug)] -pub struct EthereumSettlementParams { - pub ethereum_rpc_url: Url, - - pub ethereum_private_key: String, - - pub l1_core_contract_address: String, - - pub starknet_operator_address: String, -} diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index 3c9c5515..42f59987 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -21,7 +21,6 @@ use async_trait::async_trait; use c_kzg::{Blob, Bytes32, KzgCommitment, KzgProof, KzgSettings}; use color_eyre::eyre::{bail, eyre, Ok}; use color_eyre::Result; -use config::EthereumSettlementParams; use conversion::{get_input_data_for_eip_4844, prepare_sidecar}; use settlement_client_interface::{SettlementClient, SettlementVerificationStatus}; #[cfg(feature = "testing")] @@ -33,7 +32,6 @@ use crate::clients::interfaces::validity_interface::StarknetValidityContractTrai use crate::clients::StarknetValidityContractClient; use crate::conversion::{slice_u8_to_u256, vec_u8_32_to_vec_u256}; pub mod clients; -pub mod config; pub mod conversion; pub mod tests; pub mod types; @@ -64,6 +62,19 @@ lazy_static! { .expect("Error loading trusted setup file"); } +use url::Url; + +#[derive(Clone, Debug)] +pub struct EthereumSettlementParams { + pub ethereum_rpc_url: Url, + + pub ethereum_private_key: String, + + pub l1_core_contract_address: String, + + pub starknet_operator_address: String, +} + #[allow(dead_code)] pub struct EthereumSettlementClient { core_contract_client: StarknetValidityContractClient, diff --git a/crates/settlement-clients/starknet/src/config.rs b/crates/settlement-clients/starknet/src/config.rs index fc803011..8b137891 100644 --- a/crates/settlement-clients/starknet/src/config.rs +++ b/crates/settlement-clients/starknet/src/config.rs @@ -1,15 +1 @@ -use url::Url; -#[derive(Clone, Debug)] -pub struct StarknetSettlementParams { - pub starknet_rpc_url: Url, - pub starknet_private_key: String, - - pub starknet_account_address: String, - - pub starknet_cairo_core_contract_address: String, - - pub starknet_finality_retry_wait_in_secs: u64, - - pub madara_binary_path: String, -} diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 646bb59e..8bf9798c 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -10,7 +10,6 @@ use appchain_core_contract_client::interfaces::core_contract::CoreContract; use async_trait::async_trait; use color_eyre::eyre::eyre; use color_eyre::Result; -use config::StarknetSettlementParams; use crypto_bigint::Encoding; use lazy_static::lazy_static; use mockall::automock; @@ -40,6 +39,22 @@ pub const ENV_PRIVATE_KEY: &str = "MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY"; const MAX_RETRIES_VERIFY_TX_FINALITY: usize = 10; +use url::Url; +#[derive(Clone, Debug)] +pub struct StarknetSettlementParams { + pub starknet_rpc_url: Url, + + pub starknet_private_key: String, + + pub starknet_account_address: String, + + pub starknet_cairo_core_contract_address: String, + + pub starknet_finality_retry_wait_in_secs: u64, + + pub madara_binary_path: String, +} + // Assumed the contract called for settlement looks like: // https://github.com/keep-starknet-strange/piltover diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 6938b52b..ecd6a154 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -20,8 +20,7 @@ use starknet::signers::{LocalWallet, SigningKey}; use utils::env_utils::get_env_var_or_panic; use super::setup::{wait_for_cond, MadaraCmd, MadaraCmdBuilder}; -use crate::config::StarknetSettlementParams; -use crate::{LocalWalletSignerMiddleware, StarknetSettlementClient}; +use crate::{LocalWalletSignerMiddleware, StarknetSettlementClient, StarknetSettlementParams}; #[fixture] pub async fn spin_up_madara() -> MadaraCmd { diff --git a/e2e-tests/src/localstack.rs b/e2e-tests/src/localstack.rs index 78d4afdc..4c366ce3 100644 --- a/e2e-tests/src/localstack.rs +++ b/e2e-tests/src/localstack.rs @@ -10,8 +10,7 @@ use aws_sdk_sqs::types::QueueAttributeName; use aws_sdk_sqs::types::QueueAttributeName::VisibilityTimeout; use orchestrator::cli::aws_config::AWSConfigParams; use orchestrator::config::ProviderConfig; -use orchestrator::data_storage::aws_s3::config::AWSS3Params; -use orchestrator::data_storage::aws_s3::AWSS3; +use orchestrator::data_storage::aws_s3::{AWSS3Params, AWSS3}; use orchestrator::data_storage::DataStorage; use orchestrator::queue::job_queue::{JobQueueMessage, QueueType, WorkerTriggerMessage, WorkerTriggerType}; use orchestrator::queue::sqs::AWSSQSParams; diff --git a/e2e-tests/src/mongodb.rs b/e2e-tests/src/mongodb.rs index 620736c8..a6daf955 100644 --- a/e2e-tests/src/mongodb.rs +++ b/e2e-tests/src/mongodb.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use orchestrator::database::mongodb::config::MongoDBParams; +use orchestrator::database::mongodb::MongoDBParams; use url::Url; #[allow(dead_code)] pub struct MongoDbServer { diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index 700623d3..de36d058 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -16,9 +16,9 @@ use orchestrator::cli::aws_config::AWSConfigParams; use orchestrator::cli::database::DatabaseParams; use orchestrator::cli::queue::QueueParams; use orchestrator::cli::storage::StorageParams; -use orchestrator::data_storage::aws_s3::config::AWSS3Params; +use orchestrator::data_storage::aws_s3::AWSS3Params; use orchestrator::data_storage::DataStorage; -use orchestrator::database::mongodb::config::MongoDBParams; +use orchestrator::database::mongodb::MongoDBParams; use orchestrator::jobs::constants::{JOB_METADATA_SNOS_BLOCK, JOB_METADATA_STATE_UPDATE_BLOCKS_TO_SETTLE_KEY}; use orchestrator::jobs::types::{ExternalId, JobItem, JobStatus, JobType}; use orchestrator::queue::job_queue::{JobQueueMessage, QueueType, WorkerTriggerType}; From 83114fe1b2e7882f5f3e0427e0388da4699a3ba5 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Sat, 9 Nov 2024 16:19:39 +0530 Subject: [PATCH 43/63] update: renamed XYZParams to XYZValidatedArgs --- crates/da-clients/ethereum/src/lib.rs | 4 +-- crates/orchestrator/src/alerts/aws_sns/mod.rs | 6 ++-- crates/orchestrator/src/cli/alert/mod.rs | 4 +-- crates/orchestrator/src/cli/da/mod.rs | 4 +-- crates/orchestrator/src/cli/database/mod.rs | 4 +-- crates/orchestrator/src/cli/mod.rs | 32 +++++++++---------- crates/orchestrator/src/cli/prover/mod.rs | 4 +-- crates/orchestrator/src/cli/prover/sharp.rs | 2 +- crates/orchestrator/src/cli/queue/mod.rs | 4 +-- crates/orchestrator/src/cli/settlement/mod.rs | 8 ++--- crates/orchestrator/src/cli/storage/mod.rs | 4 +-- .../src/data_storage/aws_s3/mod.rs | 4 +-- .../orchestrator/src/database/mongodb/mod.rs | 4 +-- crates/orchestrator/src/queue/sqs/mod.rs | 8 ++--- crates/orchestrator/src/tests/common/mod.rs | 4 +-- crates/orchestrator/src/tests/config.rs | 28 ++++++++-------- .../sharp-service/src/client.rs | 4 +-- .../prover-services/sharp-service/src/lib.rs | 6 ++-- .../sharp-service/tests/lib.rs | 6 ++-- crates/settlement-clients/ethereum/src/lib.rs | 4 +-- .../ethereum/src/tests/mod.rs | 8 ++--- crates/settlement-clients/starknet/src/lib.rs | 4 +-- .../starknet/src/tests/test.rs | 6 ++-- e2e-tests/src/localstack.rs | 10 +++--- e2e-tests/src/mongodb.rs | 4 +-- e2e-tests/tests.rs | 16 +++++----- 26 files changed, 96 insertions(+), 96 deletions(-) diff --git a/crates/da-clients/ethereum/src/lib.rs b/crates/da-clients/ethereum/src/lib.rs index aa6bc3ae..583ab7c8 100644 --- a/crates/da-clients/ethereum/src/lib.rs +++ b/crates/da-clients/ethereum/src/lib.rs @@ -17,7 +17,7 @@ use serde::{Deserialize, Serialize}; use url::Url; #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct EthereumDaParams { +pub struct EthereumDaValidatedArgs { pub ethereum_da_rpc_url: Url, } @@ -29,7 +29,7 @@ pub struct EthereumDaClient { } impl EthereumDaClient { - pub async fn new_with_params(ethereum_da_params: &EthereumDaParams) -> Self { + pub async fn new_with_params(ethereum_da_params: &EthereumDaValidatedArgs) -> Self { let client = RpcClient::new_http( Url::from_str(ethereum_da_params.ethereum_da_rpc_url.as_str()).expect("Failed to parse SETTLEMENT_RPC_URL"), ); diff --git a/crates/orchestrator/src/alerts/aws_sns/mod.rs b/crates/orchestrator/src/alerts/aws_sns/mod.rs index 45cd1902..fd496a41 100644 --- a/crates/orchestrator/src/alerts/aws_sns/mod.rs +++ b/crates/orchestrator/src/alerts/aws_sns/mod.rs @@ -7,13 +7,13 @@ use crate::alerts::Alerts; use crate::config::ProviderConfig; #[derive(Debug, Clone)] -pub struct AWSSNSParams { +pub struct AWSSNSValidatedArgs { // TODO: convert to ARN type, and validate it // NOTE: aws is using str to represent ARN : https://docs.aws.amazon.com/sdk-for-rust/latest/dg/rust_sns_code_examples.html pub sns_arn: String, } -impl AWSSNSParams { +impl AWSSNSValidatedArgs { pub fn get_topic_name(&self) -> String { self.sns_arn.split(":").last().unwrap().to_string() } @@ -25,7 +25,7 @@ pub struct AWSSNS { } impl AWSSNS { - pub async fn new_with_params(aws_sns_params: &AWSSNSParams, provider_config: Arc) -> Self { + pub async fn new_with_params(aws_sns_params: &AWSSNSValidatedArgs, provider_config: Arc) -> Self { let config = provider_config.get_aws_client_or_panic(); Self { client: Client::new(config), topic_arn: aws_sns_params.sns_arn.clone() } } diff --git a/crates/orchestrator/src/cli/alert/mod.rs b/crates/orchestrator/src/cli/alert/mod.rs index 6a1f4957..fb5ee30f 100644 --- a/crates/orchestrator/src/cli/alert/mod.rs +++ b/crates/orchestrator/src/cli/alert/mod.rs @@ -1,8 +1,8 @@ -use crate::alerts::aws_sns::AWSSNSParams; +use crate::alerts::aws_sns::AWSSNSValidatedArgs; pub mod aws_sns; #[derive(Clone, Debug)] pub enum AlertParams { - AWSSNS(AWSSNSParams), + AWSSNS(AWSSNSValidatedArgs), } diff --git a/crates/orchestrator/src/cli/da/mod.rs b/crates/orchestrator/src/cli/da/mod.rs index 4f60d63c..e3814759 100644 --- a/crates/orchestrator/src/cli/da/mod.rs +++ b/crates/orchestrator/src/cli/da/mod.rs @@ -1,8 +1,8 @@ -use ethereum_da_client::EthereumDaParams; +use ethereum_da_client::EthereumDaValidatedArgs; pub mod ethereum; #[derive(Debug, Clone)] pub enum DaParams { - Ethereum(EthereumDaParams), + Ethereum(EthereumDaValidatedArgs), } diff --git a/crates/orchestrator/src/cli/database/mod.rs b/crates/orchestrator/src/cli/database/mod.rs index 5f80cfe6..6db38f30 100644 --- a/crates/orchestrator/src/cli/database/mod.rs +++ b/crates/orchestrator/src/cli/database/mod.rs @@ -1,8 +1,8 @@ -use crate::database::mongodb::MongoDBParams; +use crate::database::mongodb::MongoDBValidatedArgs; pub mod mongodb; #[derive(Debug, Clone)] pub enum DatabaseParams { - MongoDB(MongoDBParams), + MongoDB(MongoDBValidatedArgs), } diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index cc694d63..84ef28fc 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -3,22 +3,22 @@ use aws_config::{AWSConfigCliArgs, AWSConfigParams}; use clap::{ArgGroup, Parser}; use da::DaParams; use database::DatabaseParams; -use ethereum_da_client::EthereumDaParams; -use ethereum_settlement_client::EthereumSettlementParams; +use ethereum_da_client::EthereumDaValidatedArgs; +use ethereum_settlement_client::EthereumSettlementValidatedArgs; use prover::ProverParams; use queue::QueueParams; use settlement::SettlementParams; -use sharp_service::SharpParams; +use sharp_service::SharpValidatedArgs; use snos::SNOSParams; -use starknet_settlement_client::StarknetSettlementParams; +use starknet_settlement_client::StarknetSettlementValidatedArgs; use storage::StorageParams; use url::Url; -use crate::alerts::aws_sns::AWSSNSParams; +use crate::alerts::aws_sns::AWSSNSValidatedArgs; use crate::config::ServiceParams; -use crate::data_storage::aws_s3::AWSS3Params; -use crate::database::mongodb::MongoDBParams; -use crate::queue::sqs::AWSSQSParams; +use crate::data_storage::aws_s3::AWSS3ValidatedArgs; +use crate::database::mongodb::MongoDBValidatedArgs; +use crate::queue::sqs::AWSSQSValidatedArgs; use crate::routes::ServerParams; use crate::telemetry::InstrumentationParams; @@ -149,7 +149,7 @@ impl RunCmd { pub fn validate_alert_params(&self) -> Result { if self.aws_sns_args.aws_sns { - Ok(AlertParams::AWSSNS(AWSSNSParams { + Ok(AlertParams::AWSSNS(AWSSNSValidatedArgs { sns_arn: self.aws_sns_args.sns_arn.clone().expect("SNS ARN is required"), })) } else { @@ -159,7 +159,7 @@ impl RunCmd { pub fn validate_queue_params(&self) -> Result { if self.aws_sqs_args.aws_sqs { - Ok(QueueParams::AWSSQS(AWSSQSParams { + Ok(QueueParams::AWSSQS(AWSSQSValidatedArgs { queue_base_url: self.aws_sqs_args.queue_base_url.clone().expect("Queue base URL is required"), sqs_prefix: self.aws_sqs_args.sqs_prefix.clone().expect("SQS prefix is required"), sqs_suffix: self.aws_sqs_args.sqs_suffix.clone().expect("SQS suffix is required"), @@ -171,7 +171,7 @@ impl RunCmd { pub fn validate_storage_params(&self) -> Result { if self.aws_s3_args.aws_s3 { - Ok(StorageParams::AWSS3(AWSS3Params { + Ok(StorageParams::AWSS3(AWSS3ValidatedArgs { bucket_name: self.aws_s3_args.bucket_name.clone().expect("Bucket name is required"), })) } else { @@ -181,7 +181,7 @@ impl RunCmd { pub fn validate_database_params(&self) -> Result { if self.mongodb_args.mongodb { - Ok(DatabaseParams::MongoDB(MongoDBParams { + Ok(DatabaseParams::MongoDB(MongoDBValidatedArgs { connection_url: self .mongodb_args .mongodb_connection_url @@ -200,7 +200,7 @@ impl RunCmd { pub fn validate_da_params(&self) -> Result { if self.ethereum_da_args.da_on_ethereum { - Ok(DaParams::Ethereum(EthereumDaParams { + Ok(DaParams::Ethereum(EthereumDaValidatedArgs { ethereum_da_rpc_url: self .ethereum_da_args .ethereum_da_rpc_url @@ -215,7 +215,7 @@ impl RunCmd { pub fn validate_settlement_params(&self) -> Result { match (self.ethereum_args.settle_on_ethereum, self.starknet_args.settle_on_starknet) { (true, false) => { - let ethereum_params = EthereumSettlementParams { + let ethereum_params = EthereumSettlementValidatedArgs { ethereum_rpc_url: self .ethereum_args .ethereum_rpc_url @@ -240,7 +240,7 @@ impl RunCmd { Ok(SettlementParams::Ethereum(ethereum_params)) } (false, true) => { - let starknet_params = StarknetSettlementParams { + let starknet_params = StarknetSettlementValidatedArgs { starknet_rpc_url: self .starknet_args .starknet_rpc_url @@ -279,7 +279,7 @@ impl RunCmd { pub fn validate_prover_params(&self) -> Result { if self.sharp_args.sharp { - Ok(ProverParams::Sharp(SharpParams { + Ok(ProverParams::Sharp(SharpValidatedArgs { sharp_customer_id: self.sharp_args.sharp_customer_id.clone().expect("Sharp customer ID is required"), sharp_url: self.sharp_args.sharp_url.clone().expect("Sharp URL is required"), sharp_user_crt: self.sharp_args.sharp_user_crt.clone().expect("Sharp user certificate is required"), diff --git a/crates/orchestrator/src/cli/prover/mod.rs b/crates/orchestrator/src/cli/prover/mod.rs index 88ef6ce9..90f02845 100644 --- a/crates/orchestrator/src/cli/prover/mod.rs +++ b/crates/orchestrator/src/cli/prover/mod.rs @@ -1,8 +1,8 @@ -use sharp_service::SharpParams; +use sharp_service::SharpValidatedArgs; pub mod sharp; #[derive(Debug, Clone)] pub enum ProverParams { - Sharp(SharpParams), + Sharp(SharpValidatedArgs), } diff --git a/crates/orchestrator/src/cli/prover/sharp.rs b/crates/orchestrator/src/cli/prover/sharp.rs index 6c324d1c..46e3ffee 100644 --- a/crates/orchestrator/src/cli/prover/sharp.rs +++ b/crates/orchestrator/src/cli/prover/sharp.rs @@ -37,7 +37,7 @@ pub struct SharpCliArgs { #[arg(env = "MADARA_ORCHESTRATOR_SHARP_PROOF_LAYOUT", long, default_value = "small")] pub sharp_proof_layout: Option, - // TODO: GPS is a direct dependency of Sharp, hence GPS can be kept in SharpParams + // TODO: GPS is a direct dependency of Sharp, hence GPS can be kept in SharpValidatedArgs /// The GPS verifier contract address. #[arg(env = "MADARA_ORCHESTRATOR_GPS_VERIFIER_CONTRACT_ADDRESS", long)] pub gps_verifier_contract_address: Option, diff --git a/crates/orchestrator/src/cli/queue/mod.rs b/crates/orchestrator/src/cli/queue/mod.rs index 5a0cc95c..3970e98e 100644 --- a/crates/orchestrator/src/cli/queue/mod.rs +++ b/crates/orchestrator/src/cli/queue/mod.rs @@ -1,8 +1,8 @@ -use crate::queue::sqs::AWSSQSParams; +use crate::queue::sqs::AWSSQSValidatedArgs; pub mod aws_sqs; #[derive(Clone, Debug)] pub enum QueueParams { - AWSSQS(AWSSQSParams), + AWSSQS(AWSSQSValidatedArgs), } diff --git a/crates/orchestrator/src/cli/settlement/mod.rs b/crates/orchestrator/src/cli/settlement/mod.rs index 79a81fb6..ef625159 100644 --- a/crates/orchestrator/src/cli/settlement/mod.rs +++ b/crates/orchestrator/src/cli/settlement/mod.rs @@ -1,11 +1,11 @@ -use ethereum_settlement_client::EthereumSettlementParams; -use starknet_settlement_client::StarknetSettlementParams; +use ethereum_settlement_client::EthereumSettlementValidatedArgs; +use starknet_settlement_client::StarknetSettlementValidatedArgs; pub mod ethereum; pub mod starknet; #[derive(Clone, Debug)] pub enum SettlementParams { - Ethereum(EthereumSettlementParams), - Starknet(StarknetSettlementParams), + Ethereum(EthereumSettlementValidatedArgs), + Starknet(StarknetSettlementValidatedArgs), } diff --git a/crates/orchestrator/src/cli/storage/mod.rs b/crates/orchestrator/src/cli/storage/mod.rs index e014db42..a86b0786 100644 --- a/crates/orchestrator/src/cli/storage/mod.rs +++ b/crates/orchestrator/src/cli/storage/mod.rs @@ -1,8 +1,8 @@ -use crate::data_storage::aws_s3::AWSS3Params; +use crate::data_storage::aws_s3::AWSS3ValidatedArgs; pub mod aws_s3; #[derive(Clone, Debug)] pub enum StorageParams { - AWSS3(AWSS3Params), + AWSS3(AWSS3ValidatedArgs), } diff --git a/crates/orchestrator/src/data_storage/aws_s3/mod.rs b/crates/orchestrator/src/data_storage/aws_s3/mod.rs index efe5146b..544bc354 100644 --- a/crates/orchestrator/src/data_storage/aws_s3/mod.rs +++ b/crates/orchestrator/src/data_storage/aws_s3/mod.rs @@ -12,7 +12,7 @@ use crate::data_storage::DataStorage; pub const S3_SETTINGS_NAME: &str = "s3"; #[derive(Debug, Clone)] -pub struct AWSS3Params { +pub struct AWSS3ValidatedArgs { pub bucket_name: String, } @@ -27,7 +27,7 @@ pub struct AWSS3 { /// - initializing a new AWS S3 client impl AWSS3 { /// To init the struct with main settings - pub async fn new_with_params(s3_config: &AWSS3Params, provider_config: Arc) -> Self { + pub async fn new_with_params(s3_config: &AWSS3ValidatedArgs, provider_config: Arc) -> Self { let aws_config = provider_config.get_aws_client_or_panic(); // Building AWS S3 config let mut s3_config_builder = aws_sdk_s3::config::Builder::from(aws_config); diff --git a/crates/orchestrator/src/database/mongodb/mod.rs b/crates/orchestrator/src/database/mongodb/mod.rs index 425dd898..5fbcf380 100644 --- a/crates/orchestrator/src/database/mongodb/mod.rs +++ b/crates/orchestrator/src/database/mongodb/mod.rs @@ -20,7 +20,7 @@ use crate::jobs::JobError; mod utils; #[derive(Debug, Clone)] -pub struct MongoDBParams { +pub struct MongoDBValidatedArgs { pub connection_url: String, pub database_name: String, } @@ -31,7 +31,7 @@ pub struct MongoDb { } impl MongoDb { - pub async fn new_with_params(mongodb_params: &MongoDBParams) -> Self { + pub async fn new_with_params(mongodb_params: &MongoDBValidatedArgs) -> Self { let mut client_options = ClientOptions::parse(mongodb_params.connection_url.clone()).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 diff --git a/crates/orchestrator/src/queue/sqs/mod.rs b/crates/orchestrator/src/queue/sqs/mod.rs index 3ac95a91..66b661fa 100644 --- a/crates/orchestrator/src/queue/sqs/mod.rs +++ b/crates/orchestrator/src/queue/sqs/mod.rs @@ -10,13 +10,13 @@ use super::job_queue::QueueType; use crate::queue::QueueProvider; #[derive(Debug, Clone, Serialize)] -pub struct AWSSQSParams { +pub struct AWSSQSValidatedArgs { pub queue_base_url: String, pub sqs_prefix: String, pub sqs_suffix: String, } -impl AWSSQSParams { +impl AWSSQSValidatedArgs { pub fn get_queue_url(&self, queue_type: QueueType) -> String { let name = format!("{}/{}", self.queue_base_url, self.get_queue_name(queue_type)); name @@ -28,11 +28,11 @@ impl AWSSQSParams { } pub struct SqsQueue { - pub params: AWSSQSParams, + pub params: AWSSQSValidatedArgs, } impl SqsQueue { - pub fn new_with_params(params: AWSSQSParams) -> Self { + pub fn new_with_params(params: AWSSQSValidatedArgs) -> Self { Self { params } } } diff --git a/crates/orchestrator/src/tests/common/mod.rs b/crates/orchestrator/src/tests/common/mod.rs index 81e6a1f2..ed285f64 100644 --- a/crates/orchestrator/src/tests/common/mod.rs +++ b/crates/orchestrator/src/tests/common/mod.rs @@ -16,7 +16,7 @@ use crate::cli::alert::AlertParams; use crate::cli::database::DatabaseParams; use crate::cli::queue::QueueParams; use crate::config::ProviderConfig; -use crate::data_storage::aws_s3::{AWSS3Params, AWSS3}; +use crate::data_storage::aws_s3::{AWSS3ValidatedArgs, AWSS3}; use crate::data_storage::DataStorage; use crate::database::mongodb::MongoDb; use crate::jobs::types::JobStatus::Created; @@ -113,7 +113,7 @@ pub struct MessagePayloadType { } pub async fn get_storage_client( - storage_cfg: &AWSS3Params, + storage_cfg: &AWSS3ValidatedArgs, provider_config: Arc, ) -> Box { Box::new(AWSS3::new_with_params(storage_cfg, provider_config).await) diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 7cbefd14..478e4a76 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -4,19 +4,19 @@ use std::sync::Arc; use axum::Router; use da_client_interface::{DaClient, MockDaClient}; -use ethereum_da_client::EthereumDaParams; -use ethereum_settlement_client::EthereumSettlementParams; +use ethereum_da_client::EthereumDaValidatedArgs; +use ethereum_settlement_client::EthereumSettlementValidatedArgs; use httpmock::MockServer; use prover_client_interface::{MockProverClient, ProverClient}; use settlement_client_interface::{MockSettlementClient, SettlementClient}; -use sharp_service::SharpParams; +use sharp_service::SharpValidatedArgs; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::JsonRpcClient; use tracing::Level; use url::Url; use utils::env_utils::{get_env_var_optional, get_env_var_or_default, get_env_var_or_panic}; -use crate::alerts::aws_sns::AWSSNSParams; +use crate::alerts::aws_sns::AWSSNSValidatedArgs; use crate::alerts::Alerts; use crate::cli::alert::AlertParams; use crate::cli::aws_config::AWSConfigParams; @@ -28,11 +28,11 @@ use crate::cli::settlement::SettlementParams; use crate::cli::snos::SNOSParams; use crate::cli::storage::StorageParams; use crate::config::{get_aws_config, Config, OrchestratorParams, ProviderConfig, ServiceParams}; -use crate::data_storage::aws_s3::AWSS3Params; +use crate::data_storage::aws_s3::AWSS3ValidatedArgs; use crate::data_storage::{DataStorage, MockDataStorage}; -use crate::database::mongodb::MongoDBParams; +use crate::database::mongodb::MongoDBValidatedArgs; use crate::database::{Database, MockDatabase}; -use crate::queue::sqs::AWSSQSParams; +use crate::queue::sqs::AWSSQSValidatedArgs; use crate::queue::{MockQueueProvider, QueueProvider}; use crate::routes::{get_server_url, setup_server, ServerParams}; use crate::telemetry::InstrumentationParams; @@ -471,16 +471,16 @@ struct EnvParams { } fn get_env_params() -> EnvParams { - let db_params = DatabaseParams::MongoDB(MongoDBParams { + let db_params = DatabaseParams::MongoDB(MongoDBValidatedArgs { connection_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL"), database_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_DATABASE_NAME"), }); - let storage_params = StorageParams::AWSS3(AWSS3Params { + let storage_params = StorageParams::AWSS3(AWSS3ValidatedArgs { bucket_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME"), }); - let queue_params = QueueParams::AWSSQS(AWSSQSParams { + let queue_params = QueueParams::AWSSQS(AWSSQSValidatedArgs { queue_base_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL"), sqs_prefix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_PREFIX"), sqs_suffix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_SUFFIX"), @@ -495,15 +495,15 @@ fn get_env_params() -> EnvParams { aws_default_region: get_env_var_or_panic("AWS_DEFAULT_REGION"), }; - let da_params = DaParams::Ethereum(EthereumDaParams { + let da_params = DaParams::Ethereum(EthereumDaValidatedArgs { ethereum_da_rpc_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_DA_RPC_URL")) .expect("Failed to parse MADARA_ORCHESTRATOR_ETHEREUM_RPC_URL"), }); let alert_params = - AlertParams::AWSSNS(AWSSNSParams { sns_arn: get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_SNS_ARN") }); + AlertParams::AWSSNS(AWSSNSValidatedArgs { sns_arn: get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_SNS_ARN") }); - let settlement_params = SettlementParams::Ethereum(EthereumSettlementParams { + let settlement_params = SettlementParams::Ethereum(EthereumSettlementValidatedArgs { ethereum_rpc_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL")) .expect("Failed to parse MADARA_ORCHESTRATOR_ETHEREUM_RPC_URL"), ethereum_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), @@ -547,7 +547,7 @@ fn get_env_params() -> EnvParams { log_level: Level::from_str(&get_env_var_or_default("RUST_LOG", "info")).expect("Failed to parse RUST_LOG"), }; - let prover_params = ProverParams::Sharp(SharpParams { + let prover_params = ProverParams::Sharp(SharpValidatedArgs { sharp_customer_id: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID"), sharp_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_URL")) .expect("Failed to parse MADARA_ORCHESTRATOR_SHARP_URL"), diff --git a/crates/prover-services/sharp-service/src/client.rs b/crates/prover-services/sharp-service/src/client.rs index 18c4649d..9a0dd62a 100644 --- a/crates/prover-services/sharp-service/src/client.rs +++ b/crates/prover-services/sharp-service/src/client.rs @@ -9,7 +9,7 @@ use uuid::Uuid; use crate::error::SharpError; use crate::types::{SharpAddJobResponse, SharpGetStatusResponse}; -use crate::SharpParams; +use crate::SharpValidatedArgs; /// SHARP API async wrapper pub struct SharpClient { @@ -28,7 +28,7 @@ impl SharpClient { /// and then copy it and paste it into .env file : /// /// `cat | base64` - pub fn new_with_params(url: Url, sharp_params: &SharpParams) -> Self { + pub fn new_with_params(url: Url, sharp_params: &SharpValidatedArgs) -> Self { // Getting the cert files from the .env and then decoding it from base64 let cert = general_purpose::STANDARD diff --git a/crates/prover-services/sharp-service/src/lib.rs b/crates/prover-services/sharp-service/src/lib.rs index b1a1796c..f5dc1207 100644 --- a/crates/prover-services/sharp-service/src/lib.rs +++ b/crates/prover-services/sharp-service/src/lib.rs @@ -18,7 +18,7 @@ pub const SHARP_SETTINGS_NAME: &str = "sharp"; use url::Url; #[derive(Debug, Clone)] -pub struct SharpParams { +pub struct SharpValidatedArgs { pub sharp_customer_id: String, pub sharp_url: Url, pub sharp_user_crt: String, @@ -145,7 +145,7 @@ impl SharpProverService { Self { sharp_client, fact_checker } } - pub fn new_with_params(sharp_params: &SharpParams) -> Self { + pub fn new_with_params(sharp_params: &SharpValidatedArgs) -> Self { let sharp_client = SharpClient::new_with_params(sharp_params.sharp_url.clone(), sharp_params); let fact_checker = FactChecker::new( sharp_params.sharp_rpc_node_url.clone(), @@ -154,7 +154,7 @@ impl SharpProverService { Self::new(sharp_client, fact_checker) } - pub fn with_test_params(port: u16, sharp_params: &SharpParams) -> Self { + pub fn with_test_params(port: u16, sharp_params: &SharpValidatedArgs) -> Self { let sharp_client = SharpClient::new_with_params( format!("http://127.0.0.1:{}", port).parse().expect("Failed to create sharp client with the given params"), sharp_params, diff --git a/crates/prover-services/sharp-service/tests/lib.rs b/crates/prover-services/sharp-service/tests/lib.rs index d01517a3..178e03d4 100644 --- a/crates/prover-services/sharp-service/tests/lib.rs +++ b/crates/prover-services/sharp-service/tests/lib.rs @@ -6,7 +6,7 @@ use prover_client_interface::ProverClient; use prover_client_interface::{Task, TaskStatus}; use rstest::rstest; use serde_json::json; -use sharp_service::{SharpParams, SharpProverService}; +use sharp_service::{SharpValidatedArgs, SharpProverService}; use starknet_os::sharp::CairoJobStatus; use url::Url; use utils::env_utils::get_env_var_or_panic; @@ -20,7 +20,7 @@ mod constants; async fn prover_client_submit_task_works() { dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); - let sharp_params = SharpParams { + let sharp_params = SharpValidatedArgs { sharp_customer_id: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID"), sharp_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_URL")).unwrap(), sharp_user_crt: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_USER_CRT"), @@ -65,7 +65,7 @@ async fn prover_client_submit_task_works() { async fn prover_client_get_task_status_works(#[case] cairo_job_status: CairoJobStatus) { dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); - let sharp_params = SharpParams { + let sharp_params = SharpValidatedArgs { sharp_customer_id: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID"), sharp_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_URL")).unwrap(), sharp_user_crt: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_USER_CRT"), diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index 42f59987..be018833 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -65,7 +65,7 @@ lazy_static! { use url::Url; #[derive(Clone, Debug)] -pub struct EthereumSettlementParams { +pub struct EthereumSettlementValidatedArgs { pub ethereum_rpc_url: Url, pub ethereum_private_key: String, @@ -85,7 +85,7 @@ pub struct EthereumSettlementClient { } impl EthereumSettlementClient { - pub fn new_with_params(settlement_cfg: &EthereumSettlementParams) -> Self { + pub fn new_with_params(settlement_cfg: &EthereumSettlementValidatedArgs) -> Self { let private_key = settlement_cfg.ethereum_private_key.clone(); let signer: PrivateKeySigner = private_key.parse().expect("Failed to parse private key"); let wallet_address = signer.address(); diff --git a/crates/settlement-clients/ethereum/src/tests/mod.rs b/crates/settlement-clients/ethereum/src/tests/mod.rs index 430bc291..6389f1fb 100644 --- a/crates/settlement-clients/ethereum/src/tests/mod.rs +++ b/crates/settlement-clients/ethereum/src/tests/mod.rs @@ -143,7 +143,7 @@ mod settlement_client_tests { STARKNET_CORE_CONTRACT, STARKNET_CORE_CONTRACT_ADDRESS, }; use crate::types::{bytes_be_to_u128, convert_stark_bigint_to_u256}; - use crate::{EthereumSettlementClient, EthereumSettlementParams, Y_HIGH_POINT_OFFSET, Y_LOW_POINT_OFFSET}; + use crate::{EthereumSettlementClient, EthereumSettlementValidatedArgs, Y_HIGH_POINT_OFFSET, Y_LOW_POINT_OFFSET}; #[rstest] #[tokio::test] @@ -158,7 +158,7 @@ mod settlement_client_tests { let setup = EthereumTestBuilder::new().build().await; - let ethereum_settlement_params = EthereumSettlementParams { + let ethereum_settlement_params = EthereumSettlementValidatedArgs { ethereum_rpc_url: setup.rpc_url, ethereum_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), l1_core_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"), @@ -230,7 +230,7 @@ mod settlement_client_tests { .build() .await; - let ethereum_settlement_params = EthereumSettlementParams { + let ethereum_settlement_params = EthereumSettlementValidatedArgs { ethereum_rpc_url: setup.rpc_url, ethereum_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), l1_core_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"), @@ -296,7 +296,7 @@ mod settlement_client_tests { dotenvy::from_filename(&*ENV_FILE_PATH).expect("Could not load .env.test file."); let setup = EthereumTestBuilder::new().with_fork_block(fork_block_no).build().await; - let ethereum_settlement_params = EthereumSettlementParams { + let ethereum_settlement_params = EthereumSettlementValidatedArgs { ethereum_rpc_url: setup.rpc_url, ethereum_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), l1_core_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"), diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 8bf9798c..7b1bb010 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -41,7 +41,7 @@ const MAX_RETRIES_VERIFY_TX_FINALITY: usize = 10; use url::Url; #[derive(Clone, Debug)] -pub struct StarknetSettlementParams { +pub struct StarknetSettlementValidatedArgs { pub starknet_rpc_url: Url, pub starknet_private_key: String, @@ -59,7 +59,7 @@ pub struct StarknetSettlementParams { // https://github.com/keep-starknet-strange/piltover impl StarknetSettlementClient { - pub async fn new_with_params(settlement_cfg: &StarknetSettlementParams) -> Self { + pub async fn new_with_params(settlement_cfg: &StarknetSettlementValidatedArgs) -> Self { let provider: Arc> = Arc::new(JsonRpcClient::new(HttpTransport::new(settlement_cfg.starknet_rpc_url.clone()))); diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index ecd6a154..fa4c2d22 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -20,7 +20,7 @@ use starknet::signers::{LocalWallet, SigningKey}; use utils::env_utils::get_env_var_or_panic; use super::setup::{wait_for_cond, MadaraCmd, MadaraCmdBuilder}; -use crate::{LocalWalletSignerMiddleware, StarknetSettlementClient, StarknetSettlementParams}; +use crate::{LocalWalletSignerMiddleware, StarknetSettlementClient, StarknetSettlementValidatedArgs}; #[fixture] pub async fn spin_up_madara() -> MadaraCmd { @@ -79,7 +79,7 @@ async fn wait_for_tx(account: &LocalWalletSignerMiddleware, transaction_hash: Fe async fn setup(#[future] spin_up_madara: MadaraCmd) -> (LocalWalletSignerMiddleware, MadaraCmd) { let madara_process = spin_up_madara.await; - let starknet_settlement_params: StarknetSettlementParams = StarknetSettlementParams { + let starknet_settlement_params: StarknetSettlementValidatedArgs = StarknetSettlementValidatedArgs { starknet_rpc_url: Url::parse(madara_process.rpc_url.as_ref()).unwrap(), starknet_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY"), starknet_account_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS"), @@ -118,7 +118,7 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) let (account, madara_process) = setup.await; - let mut starknet_settlement_params: StarknetSettlementParams = StarknetSettlementParams { + let mut starknet_settlement_params: StarknetSettlementValidatedArgs = StarknetSettlementValidatedArgs { starknet_rpc_url: madara_process.rpc_url.clone(), starknet_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY"), starknet_account_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS"), diff --git a/e2e-tests/src/localstack.rs b/e2e-tests/src/localstack.rs index 4c366ce3..b8f26ded 100644 --- a/e2e-tests/src/localstack.rs +++ b/e2e-tests/src/localstack.rs @@ -10,10 +10,10 @@ use aws_sdk_sqs::types::QueueAttributeName; use aws_sdk_sqs::types::QueueAttributeName::VisibilityTimeout; use orchestrator::cli::aws_config::AWSConfigParams; use orchestrator::config::ProviderConfig; -use orchestrator::data_storage::aws_s3::{AWSS3Params, AWSS3}; +use orchestrator::data_storage::aws_s3::{AWSS3ValidatedArgs, AWSS3}; use orchestrator::data_storage::DataStorage; use orchestrator::queue::job_queue::{JobQueueMessage, QueueType, WorkerTriggerMessage, WorkerTriggerType}; -use orchestrator::queue::sqs::AWSSQSParams; +use orchestrator::queue::sqs::AWSSQSValidatedArgs; /// LocalStack struct pub struct LocalStack { @@ -23,7 +23,7 @@ pub struct LocalStack { } impl LocalStack { - pub async fn new(aws_config: AWSConfigParams, s3_config: &AWSS3Params) -> Self { + pub async fn new(aws_config: AWSConfigParams, s3_config: &AWSS3ValidatedArgs) -> Self { let region_provider = Region::new(aws_config.aws_region); let creds = EnvironmentVariableCredentialsProvider::new().provide_credentials().await.unwrap(); @@ -43,7 +43,7 @@ impl LocalStack { } /// To set up SQS on localstack instance - pub async fn setup_sqs(&self, sqs_config: &AWSSQSParams) -> color_eyre::Result<()> { + pub async fn setup_sqs(&self, sqs_config: &AWSSQSValidatedArgs) -> color_eyre::Result<()> { let list_queues_output = self.sqs_client.list_queues().send().await?; let queue_urls = list_queues_output.queue_urls(); println!("Found {} queues", queue_urls.len()); @@ -77,7 +77,7 @@ impl LocalStack { pub async fn setup_event_bridge( &self, worker_trigger_type: WorkerTriggerType, - sqs_config: &AWSSQSParams, + sqs_config: &AWSSQSValidatedArgs, ) -> color_eyre::Result<()> { let rule_name = "worker_trigger_scheduled"; diff --git a/e2e-tests/src/mongodb.rs b/e2e-tests/src/mongodb.rs index a6daf955..cc9a28a0 100644 --- a/e2e-tests/src/mongodb.rs +++ b/e2e-tests/src/mongodb.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use orchestrator::database::mongodb::MongoDBParams; +use orchestrator::database::mongodb::MongoDBValidatedArgs; use url::Url; #[allow(dead_code)] pub struct MongoDbServer { @@ -8,7 +8,7 @@ pub struct MongoDbServer { } impl MongoDbServer { - pub fn run(mongodb_params: MongoDBParams) -> Self { + pub fn run(mongodb_params: MongoDBValidatedArgs) -> Self { Self { endpoint: Url::from_str(&mongodb_params.connection_url).unwrap() } } diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index de36d058..4695c5b2 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -16,13 +16,13 @@ use orchestrator::cli::aws_config::AWSConfigParams; use orchestrator::cli::database::DatabaseParams; use orchestrator::cli::queue::QueueParams; use orchestrator::cli::storage::StorageParams; -use orchestrator::data_storage::aws_s3::AWSS3Params; +use orchestrator::data_storage::aws_s3::AWSS3ValidatedArgs; use orchestrator::data_storage::DataStorage; -use orchestrator::database::mongodb::MongoDBParams; +use orchestrator::database::mongodb::MongoDBValidatedArgs; use orchestrator::jobs::constants::{JOB_METADATA_SNOS_BLOCK, JOB_METADATA_STATE_UPDATE_BLOCKS_TO_SETTLE_KEY}; use orchestrator::jobs::types::{ExternalId, JobItem, JobStatus, JobType}; use orchestrator::queue::job_queue::{JobQueueMessage, QueueType, WorkerTriggerType}; -use orchestrator::queue::sqs::AWSSQSParams; +use orchestrator::queue::sqs::AWSSQSValidatedArgs; use rstest::rstest; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -55,15 +55,15 @@ struct Setup { impl Setup { /// Initialise a new setup pub async fn new(l2_block_number: String) -> Self { - let db_params = DatabaseParams::MongoDB(MongoDBParams { + let db_params = DatabaseParams::MongoDB(MongoDBValidatedArgs { connection_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL"), database_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_DATABASE_NAME"), }); - let storage_params = StorageParams::AWSS3(AWSS3Params { + let storage_params = StorageParams::AWSS3(AWSS3ValidatedArgs { bucket_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME"), }); - let queue_params = QueueParams::AWSSQS(AWSSQSParams { + let queue_params = QueueParams::AWSSQS(AWSSQSValidatedArgs { queue_base_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL"), sqs_prefix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_PREFIX"), sqs_suffix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_SUFFIX"), @@ -166,7 +166,7 @@ async fn test_orchestrator_workflow(#[case] l2_block_number: String) { // setting up of the test and during orchestrator run too. dotenvy::from_filename(".env.test").expect("Failed to load the .env file"); - let queue_params = AWSSQSParams { + let queue_params = AWSSQSValidatedArgs { queue_base_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL"), sqs_prefix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_PREFIX"), sqs_suffix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_SUFFIX"), @@ -327,7 +327,7 @@ pub async fn put_job_data_in_db_snos(mongo_db: &MongoDbServer, l2_block_number: pub async fn put_snos_job_in_processing_queue( local_stack: &LocalStack, id: Uuid, - queue_params: AWSSQSParams, + queue_params: AWSSQSValidatedArgs, ) -> color_eyre::Result<()> { let message = JobQueueMessage { id }; local_stack.put_message_in_queue(message, queue_params.get_queue_url(QueueType::SnosJobProcessing)).await?; From 4cbb3a13bfc5316fef07cba767023eee3697922e Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Sat, 9 Nov 2024 16:20:54 +0530 Subject: [PATCH 44/63] update: lint fixes --- crates/prover-services/sharp-service/tests/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/prover-services/sharp-service/tests/lib.rs b/crates/prover-services/sharp-service/tests/lib.rs index 178e03d4..1434ab79 100644 --- a/crates/prover-services/sharp-service/tests/lib.rs +++ b/crates/prover-services/sharp-service/tests/lib.rs @@ -6,7 +6,7 @@ use prover_client_interface::ProverClient; use prover_client_interface::{Task, TaskStatus}; use rstest::rstest; use serde_json::json; -use sharp_service::{SharpValidatedArgs, SharpProverService}; +use sharp_service::{SharpProverService, SharpValidatedArgs}; use starknet_os::sharp::CairoJobStatus; use url::Url; use utils::env_utils::get_env_var_or_panic; From ef3127caf6525071121caeb58d0b0eb9b169130c Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Sat, 9 Nov 2024 16:29:45 +0530 Subject: [PATCH 45/63] update: lint fixes --- crates/settlement-clients/ethereum/src/lib.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index be018833..888441ba 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -23,7 +23,6 @@ use color_eyre::eyre::{bail, eyre, Ok}; use color_eyre::Result; use conversion::{get_input_data_for_eip_4844, prepare_sidecar}; use settlement_client_interface::{SettlementClient, SettlementVerificationStatus}; -#[cfg(feature = "testing")] use url::Url; #[cfg(feature = "testing")] use utils::env_utils::get_env_var_or_panic; @@ -62,8 +61,6 @@ lazy_static! { .expect("Error loading trusted setup file"); } -use url::Url; - #[derive(Clone, Debug)] pub struct EthereumSettlementValidatedArgs { pub ethereum_rpc_url: Url, From ccabb493e5eb283719014814b18fc3c8f92d5485 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Tue, 12 Nov 2024 14:08:28 +0530 Subject: [PATCH 46/63] update: fixed e2e testcase --- e2e-tests/src/node.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e-tests/src/node.rs b/e2e-tests/src/node.rs index 44bcb002..ca342af3 100644 --- a/e2e-tests/src/node.rs +++ b/e2e-tests/src/node.rs @@ -46,7 +46,6 @@ impl Orchestrator { .arg("--features") .arg("testing") .arg("--") - // --settle-on-ethereum --aws-s3 --aws-sqs --aws-sns --mongodb --sharp --da-on-ethereum ") .arg("--settle-on-ethereum") .arg("--aws-s3") .arg("--aws-sqs") @@ -54,6 +53,7 @@ impl Orchestrator { .arg("--mongodb") .arg("--sharp") .arg("--da-on-ethereum") + .arg("--aws-event-bridge") .current_dir(repository_root) .envs(envs) .stdout(Stdio::piped()) From 58dd6bba0af915585bb74b16cff1407937ce9805 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Tue, 12 Nov 2024 15:27:13 +0530 Subject: [PATCH 47/63] update: added tests for validate fns --- crates/orchestrator/src/cli/mod.rs | 187 +++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index 79e0b1bd..3c130856 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -377,3 +377,190 @@ impl RunCmd { Ok(SNOSParams { rpc_for_snos: self.snos_args.rpc_for_snos.clone() }) } } + +#[cfg(test)] +pub mod test { + + use rstest::{fixture, rstest}; + use tracing::Level; + use url::Url; + + use super::alert::aws_sns::AWSSNSCliArgs; + use super::aws_config::AWSConfigCliArgs; + use super::cron::event_bridge::AWSEventBridgeCliArgs; + use super::da::ethereum::EthereumDaCliArgs; + use super::database::mongodb::MongoDBCliArgs; + use super::instrumentation::InstrumentationCliArgs; + use super::prover::sharp::SharpCliArgs; + use super::queue::aws_sqs::AWSSQSCliArgs; + use super::server::ServerCliArgs; + use super::service::ServiceCliArgs; + use super::settlement::ethereum::EthereumSettlementCliArgs; + use super::settlement::starknet::StarknetSettlementCliArgs; + use super::snos::SNOSCliArgs; + use super::storage::aws_s3::AWSS3CliArgs; + use crate::cli::RunCmd; + + // create a fixture for the CLI + #[fixture] + pub fn setup_cmd() -> RunCmd { + RunCmd { + aws_config_args: AWSConfigCliArgs { + aws_access_key_id: "".to_string(), + aws_secret_access_key: "".to_string(), + aws_region: "".to_string(), + }, + aws_event_bridge_args: AWSEventBridgeCliArgs { + aws_event_bridge: true, + target_queue_name: Some("".to_string()), + cron_time: Some("".to_string()), + trigger_rule_name: Some("".to_string()), + }, + aws_s3_args: AWSS3CliArgs { aws_s3: true, bucket_name: Some("".to_string()) }, + aws_sqs_args: AWSSQSCliArgs { + aws_sqs: true, + queue_base_url: Some("".to_string()), + sqs_prefix: Some("".to_string()), + sqs_suffix: Some("".to_string()), + }, + server_args: ServerCliArgs { host: "".to_string(), port: 0 }, + aws_sns_args: AWSSNSCliArgs { aws_sns: true, sns_arn: Some("".to_string()) }, + + instrumentation_args: InstrumentationCliArgs { + otel_service_name: Some("".to_string()), + otel_collector_endpoint: None, + log_level: Level::INFO, + }, + + mongodb_args: MongoDBCliArgs { + mongodb: true, + mongodb_connection_url: Some("".to_string()), + mongodb_database_name: Some("".to_string()), + }, + + madara_rpc_url: Url::parse("http://localhost:8545").unwrap(), + + sharp_args: SharpCliArgs { + sharp: true, + sharp_customer_id: Some("".to_string()), + sharp_url: Some(Url::parse("http://localhost:8545").unwrap()), + sharp_user_crt: Some("".to_string()), + sharp_user_key: Some("".to_string()), + sharp_rpc_node_url: Some(Url::parse("http://localhost:8545").unwrap()), + sharp_proof_layout: Some("".to_string()), + gps_verifier_contract_address: Some("".to_string()), + sharp_server_crt: Some("".to_string()), + }, + + starknet_args: StarknetSettlementCliArgs { + starknet_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), + starknet_private_key: Some("".to_string()), + starknet_account_address: Some("".to_string()), + starknet_cairo_core_contract_address: Some("".to_string()), + starknet_finality_retry_wait_in_secs: Some(0), + starknet_madara_binary_path: Some("".to_string()), + settle_on_starknet: false, + }, + + ethereum_args: EthereumSettlementCliArgs { + ethereum_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), + ethereum_private_key: Some("".to_string()), + l1_core_contract_address: Some("".to_string()), + starknet_operator_address: Some("".to_string()), + settle_on_ethereum: true, + }, + + ethereum_da_args: EthereumDaCliArgs { + da_on_ethereum: true, + ethereum_da_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), + }, + + snos_args: SNOSCliArgs { rpc_for_snos: Url::parse("http://localhost:8545").unwrap() }, + + service_args: ServiceCliArgs { + max_block_to_process: Some("".to_string()), + min_block_to_process: Some("".to_string()), + }, + } + } + + // Let's create a test for the CLI each validator + + #[rstest] + fn test_validate_aws_config_params(setup_cmd: RunCmd) { + let aws_config_params = setup_cmd.validate_aws_config_params(); + assert!(aws_config_params.is_ok()); + } + + #[rstest] + fn test_validate_alert_params(setup_cmd: RunCmd) { + let alert_params = setup_cmd.validate_alert_params(); + assert!(alert_params.is_ok()); + } + + #[rstest] + fn test_validate_queue_params(setup_cmd: RunCmd) { + let queue_params = setup_cmd.validate_queue_params(); + assert!(queue_params.is_ok()); + } + + #[rstest] + fn test_validate_storage_params(setup_cmd: RunCmd) { + let storage_params = setup_cmd.validate_storage_params(); + assert!(storage_params.is_ok()); + } + + #[rstest] + fn test_validate_database_params(setup_cmd: RunCmd) { + let database_params = setup_cmd.validate_database_params(); + assert!(database_params.is_ok()); + } + + #[rstest] + fn test_validate_da_params(setup_cmd: RunCmd) { + let da_params = setup_cmd.validate_da_params(); + assert!(da_params.is_ok()); + } + + #[rstest] + fn test_validate_settlement_params(setup_cmd: RunCmd) { + let settlement_params = setup_cmd.validate_settlement_params(); + assert!(settlement_params.is_ok()); + } + + #[rstest] + fn test_validate_prover_params(setup_cmd: RunCmd) { + let prover_params = setup_cmd.validate_prover_params(); + assert!(prover_params.is_ok()); + } + + #[rstest] + fn test_validate_cron_params(setup_cmd: RunCmd) { + let cron_params = setup_cmd.validate_cron_params(); + assert!(cron_params.is_ok()); + } + + #[rstest] + fn test_validate_instrumentation_params(setup_cmd: RunCmd) { + let instrumentation_params = setup_cmd.validate_instrumentation_params(); + assert!(instrumentation_params.is_ok()); + } + + #[rstest] + fn test_validate_server_params(setup_cmd: RunCmd) { + let server_params = setup_cmd.validate_server_params(); + assert!(server_params.is_ok()); + } + + #[rstest] + fn test_validate_snos_params(setup_cmd: RunCmd) { + let snos_params = setup_cmd.validate_snos_params(); + assert!(snos_params.is_ok()); + } + + #[rstest] + fn test_validate_service_params(setup_cmd: RunCmd) { + let service_params = setup_cmd.validate_service_params(); + assert!(service_params.is_ok()); + } +} From 602f1a2bdf156d2c5b1c0c88878ed25b2965c39d Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Tue, 12 Nov 2024 15:46:34 +0530 Subject: [PATCH 48/63] update: testcase fix --- crates/orchestrator/src/cli/cron/event_bridge.rs | 2 +- crates/orchestrator/src/cli/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/orchestrator/src/cli/cron/event_bridge.rs b/crates/orchestrator/src/cli/cron/event_bridge.rs index a78b4e2f..8719a597 100644 --- a/crates/orchestrator/src/cli/cron/event_bridge.rs +++ b/crates/orchestrator/src/cli/cron/event_bridge.rs @@ -13,7 +13,7 @@ pub struct AWSEventBridgeCliArgs { pub target_queue_name: Option, /// The cron time for the event bridge trigger rule. - #[arg(env = "MADARA_ORCHESTRATOR_EVENT_BRIDGE_CRON_TIME", long, default_value = Some("madara-orchestrator-event-bridge-cron-time"))] + #[arg(env = "MADARA_ORCHESTRATOR_EVENT_BRIDGE_CRON_TIME", long, default_value = Some("10"))] pub cron_time: Option, /// The name of the event bridge trigger rule. diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index 3c130856..0a8a0f02 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -413,7 +413,7 @@ pub mod test { aws_event_bridge_args: AWSEventBridgeCliArgs { aws_event_bridge: true, target_queue_name: Some("".to_string()), - cron_time: Some("".to_string()), + cron_time: Some("12".to_string()), trigger_rule_name: Some("".to_string()), }, aws_s3_args: AWSS3CliArgs { aws_s3: true, bucket_name: Some("".to_string()) }, From fa75b561e27f2cefad78bd80f65d4dd899b26696 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Tue, 12 Nov 2024 21:11:18 +0530 Subject: [PATCH 49/63] update: added command run / setup and e2e with setup_config --- Cargo.lock | 2 + crates/orchestrator/src/cli/mod.rs | 15 ++ crates/orchestrator/src/main.rs | 6 + crates/orchestrator/src/queue/sqs/mod.rs | 2 +- crates/orchestrator/src/setup/mod.rs | 38 ++--- e2e-tests/Cargo.toml | 2 + e2e-tests/src/lib.rs | 1 - e2e-tests/src/localstack.rs | 180 ----------------------- e2e-tests/src/node.rs | 14 +- e2e-tests/tests.rs | 77 ++++------ 10 files changed, 78 insertions(+), 259 deletions(-) delete mode 100644 e2e-tests/src/localstack.rs diff --git a/Cargo.lock b/Cargo.lock index 5d7704d4..2b9c25ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4277,6 +4277,8 @@ dependencies = [ "serde", "serde_json", "starknet", + "strum 0.26.2", + "strum_macros 0.26.4", "testcontainers", "tokio", "tokio-stream", diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index 0a8a0f02..08c6e54a 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -44,6 +44,12 @@ pub mod storage; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] #[clap( + group( + ArgGroup::new("mode") + .args(&["run", "setup"]) + .required(true) + .multiple(false) + ), group( ArgGroup::new("settlement_layer") .args(&["settle_on_ethereum", "settle_on_starknet"]) @@ -88,6 +94,13 @@ pub mod storage; ), )] pub struct RunCmd { + // Run mode + #[arg(long)] + pub run: bool, + + #[arg(long)] + pub setup: bool, + // AWS Config #[clap(flatten)] pub aws_config_args: AWSConfigCliArgs, @@ -405,6 +418,8 @@ pub mod test { #[fixture] pub fn setup_cmd() -> RunCmd { RunCmd { + run: true, + setup: false, aws_config_args: AWSConfigCliArgs { aws_access_key_id: "".to_string(), aws_secret_access_key: "".to_string(), diff --git a/crates/orchestrator/src/main.rs b/crates/orchestrator/src/main.rs index 2a143f2c..d63087b3 100644 --- a/crates/orchestrator/src/main.rs +++ b/crates/orchestrator/src/main.rs @@ -4,6 +4,7 @@ use orchestrator::cli::RunCmd; use orchestrator::config::init_config; use orchestrator::queue::init_consumers; use orchestrator::routes::setup_server; +use orchestrator::setup::setup_cloud; use orchestrator::telemetry::{setup_analytics, shutdown_analytics}; /// Start the server @@ -16,6 +17,11 @@ async fn main() { // TODO: could this be an ARC ? let run_cmd: RunCmd = RunCmd::parse(); + if run_cmd.setup { + setup_cloud(&run_cmd).await.expect("Failed to setup cloud"); + return; + } + // Analytics Setup let instrumentation_params = run_cmd.validate_instrumentation_params().expect("Invalid instrumentation params"); let meter_provider = setup_analytics(&instrumentation_params); diff --git a/crates/orchestrator/src/queue/sqs/mod.rs b/crates/orchestrator/src/queue/sqs/mod.rs index 8b7e4ca2..bffa8b8b 100644 --- a/crates/orchestrator/src/queue/sqs/mod.rs +++ b/crates/orchestrator/src/queue/sqs/mod.rs @@ -70,7 +70,7 @@ impl QueueProvider for SqsQueue { }; let sqs_client = Client::new(config); let res = - sqs_client.create_queue().queue_name(self.params.get_queue_url(queue_config.name.clone())).send().await?; + sqs_client.create_queue().queue_name(self.params.get_queue_name(queue_config.name.clone())).send().await?; let queue_url = res.queue_url().ok_or_else(|| eyre!("Not able to get queue url from result"))?; let mut attributes = HashMap::new(); diff --git a/crates/orchestrator/src/setup/mod.rs b/crates/orchestrator/src/setup/mod.rs index 14d412cd..5ad754eb 100644 --- a/crates/orchestrator/src/setup/mod.rs +++ b/crates/orchestrator/src/setup/mod.rs @@ -1,9 +1,9 @@ use std::process::Command; use std::sync::Arc; -use aws_config::{Region, SdkConfig}; -use aws_credential_types::Credentials; -use aws_sdk_s3::config::SharedCredentialsProvider; +use aws_config::environment::EnvironmentVariableCredentialsProvider; +use aws_config::{from_env, Region, SdkConfig}; +use aws_credential_types::provider::ProvideCredentials; use crate::alerts::aws_sns::AWSSNS; use crate::alerts::Alerts; @@ -33,29 +33,19 @@ async fn setup_config_from_params(client_type: ConfigType) -> SetupConfig { match client_type { ConfigType::AWS(aws_config) => { let region_provider = Region::new(aws_config.aws_region); - let sdk_config = SdkConfig::builder() - .region(region_provider) - .credentials_provider(SharedCredentialsProvider::new(Credentials::new( - aws_config.aws_access_key_id, - aws_config.aws_secret_access_key, - None, - None, - "madara-orchestrator", - ))) - .build(); - - SetupConfig::AWS(sdk_config) + let creds = EnvironmentVariableCredentialsProvider::new().provide_credentials().await.unwrap(); + SetupConfig::AWS(from_env().region(region_provider).credentials_provider(creds).load().await) } } } // TODO : move this to main.rs after moving to clap. pub async fn setup_cloud(run_cmd: &RunCmd) -> color_eyre::Result<()> { - tracing::info!("Setting up cloud."); + println!("Setting up cloud."); let aws_config = run_cmd.validate_aws_config_params().expect("Failed to validate AWS config params"); let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(&aws_config).await))); - tracing::info!("Setting up data storage."); + println!("Setting up data storage."); let data_storage_params = run_cmd.validate_storage_params().expect("Failed to validate storage params"); match data_storage_params { @@ -64,9 +54,9 @@ pub async fn setup_cloud(run_cmd: &RunCmd) -> color_eyre::Result<()> { s3.setup(&StorageParams::AWSS3(aws_s3_params.clone())).await? } } - tracing::info!("Data storage setup completed ✅"); + println!("Data storage setup completed ✅"); - tracing::info!("Setting up queues"); + println!("Setting up queues"); let queue_params = run_cmd.validate_queue_params().expect("Failed to validate queue params"); match queue_params { QueueParams::AWSSQS(aws_sqs_params) => { @@ -75,9 +65,9 @@ pub async fn setup_cloud(run_cmd: &RunCmd) -> color_eyre::Result<()> { sqs.setup(config).await? } } - tracing::info!("Queues setup completed ✅"); + println!("Queues setup completed ✅"); - tracing::info!("Setting up cron"); + println!("Setting up cron"); let cron_params = run_cmd.validate_cron_params().expect("Failed to validate cron params"); match cron_params { CronParams::EventBridge(aws_event_bridge_params) => { @@ -86,9 +76,9 @@ pub async fn setup_cloud(run_cmd: &RunCmd) -> color_eyre::Result<()> { event_bridge.setup(config).await? } } - tracing::info!("Cron setup completed ✅"); + println!("Cron setup completed ✅"); - tracing::info!("Setting up alerts."); + println!("Setting up alerts."); let alert_params = run_cmd.validate_alert_params().expect("Failed to validate alert params"); match alert_params { AlertParams::AWSSNS(aws_sns_params) => { @@ -96,7 +86,7 @@ pub async fn setup_cloud(run_cmd: &RunCmd) -> color_eyre::Result<()> { sns.setup(AlertParams::AWSSNS(aws_sns_params.clone())).await? } } - tracing::info!("Alerts setup completed ✅"); + println!("Alerts setup completed ✅"); Ok(()) } diff --git a/e2e-tests/Cargo.toml b/e2e-tests/Cargo.toml index 34ac6249..dfb042d6 100644 --- a/e2e-tests/Cargo.toml +++ b/e2e-tests/Cargo.toml @@ -26,6 +26,8 @@ rstest.workspace = true serde.workspace = true serde_json.workspace = true starknet.workspace = true +strum = "0.26.0" +strum_macros = "0.26.0" testcontainers.workspace = true tokio = { workspace = true, features = ["full"] } tokio-stream.workspace = true diff --git a/e2e-tests/src/lib.rs b/e2e-tests/src/lib.rs index ea1c326f..a68276c8 100644 --- a/e2e-tests/src/lib.rs +++ b/e2e-tests/src/lib.rs @@ -1,5 +1,4 @@ pub mod anvil; -pub mod localstack; pub mod mock_server; pub mod mongodb; pub mod node; diff --git a/e2e-tests/src/localstack.rs b/e2e-tests/src/localstack.rs deleted file mode 100644 index ef991781..00000000 --- a/e2e-tests/src/localstack.rs +++ /dev/null @@ -1,180 +0,0 @@ -use std::collections::HashMap; -use std::sync::Arc; - -use aws_config::environment::EnvironmentVariableCredentialsProvider; -use aws_config::meta::region::RegionProviderChain; -use aws_config::{from_env, Region}; -use aws_sdk_eventbridge::types::{InputTransformer, RuleState, Target}; -use aws_sdk_s3::config::ProvideCredentials; -use aws_sdk_sqs::types::QueueAttributeName; -use aws_sdk_sqs::types::QueueAttributeName::VisibilityTimeout; -use orchestrator::cli::aws_config::AWSConfigParams; -use orchestrator::config::ProviderConfig; -use orchestrator::data_storage::aws_s3::{AWSS3ValidatedArgs, AWSS3}; -use orchestrator::data_storage::DataStorage; -use orchestrator::queue::job_queue::{JobQueueMessage, WorkerTriggerMessage, WorkerTriggerType}; -use orchestrator::queue::sqs::AWSSQSValidatedArgs; -use orchestrator::queue::QueueType; - -/// LocalStack struct -pub struct LocalStack { - pub sqs_client: aws_sdk_sqs::Client, - pub s3_client: Box, - event_bridge_client: aws_sdk_eventbridge::Client, -} - -impl LocalStack { - pub async fn new(aws_config: AWSConfigParams, s3_config: &AWSS3ValidatedArgs) -> Self { - let region_provider = Region::new(aws_config.aws_region); - - let creds = EnvironmentVariableCredentialsProvider::new().provide_credentials().await.unwrap(); - let config = from_env().region(region_provider).credentials_provider(creds).load().await; - let provider_config = Arc::new(ProviderConfig::AWS(Box::from(config.clone()))); - - Self { - sqs_client: aws_sdk_sqs::Client::new(&config), - s3_client: Box::new(AWSS3::new_with_params(s3_config, provider_config).await), - event_bridge_client: aws_sdk_eventbridge::Client::new(&config), - } - } - - #[allow(clippy::borrowed_box)] - pub fn s3_client(&self) -> &Box { - &self.s3_client - } - - /// To set up SQS on localstack instance - pub async fn setup_sqs(&self, sqs_config: &AWSSQSValidatedArgs) -> color_eyre::Result<()> { - let list_queues_output = self.sqs_client.list_queues().send().await?; - let queue_urls = list_queues_output.queue_urls(); - println!("Found {} queues", queue_urls.len()); - for queue_url in queue_urls { - match self.sqs_client.delete_queue().queue_url(queue_url).send().await { - Ok(_) => println!("Successfully deleted queue: {}", queue_url), - Err(e) => eprintln!("Error deleting queue {}: {:?}", queue_url, e), - } - } - - // Creating SQS queues - let mut queue_attributes = HashMap::new(); - queue_attributes.insert(VisibilityTimeout, "10000".into()); - - for queue_type in QueueType::iter() { - let queue_name = sqs_config.get_queue_name(queue_type); - self.sqs_client - .create_queue() - .queue_name(queue_name) - .set_attributes(Some(queue_attributes.clone())) - .send() - .await?; - } - - println!("🌊 SQS queues creation completed."); - - Ok(()) - } - - /// Event Bridge setup - pub async fn setup_event_bridge( - &self, - worker_trigger_type: WorkerTriggerType, - sqs_config: &AWSSQSValidatedArgs, - ) -> color_eyre::Result<()> { - let rule_name = "worker_trigger_scheduled"; - - self.event_bridge_client - .put_rule() - .name(rule_name) - .schedule_expression("rate(1 minute)") - .state(RuleState::Enabled) - .send() - .await?; - let queue_url = self - .sqs_client - .get_queue_url() - .queue_name(sqs_config.get_queue_name(QueueType::WorkerTrigger)) - .send() - .await?; - - let queue_attributes = self - .sqs_client - .get_queue_attributes() - .queue_url(queue_url.queue_url.unwrap()) - .attribute_names(QueueAttributeName::QueueArn) - .send() - .await?; - let queue_arn = queue_attributes.attributes().unwrap().get(&QueueAttributeName::QueueArn).unwrap(); - - // Create a sample WorkerTriggerMessage - let message = WorkerTriggerMessage { worker: worker_trigger_type.clone() }; - let event_detail = serde_json::to_string(&message)?; - - // Create the EventBridge target with the input transformer - let input_transformer = InputTransformer::builder() - .input_paths_map("$.time", "time") - .input_template(event_detail.to_string()) - .build()?; - - self.event_bridge_client - .put_targets() - .rule(rule_name) - .targets( - Target::builder() - .id(format!("worker-trigger-target-{:?}", worker_trigger_type)) - .arn(queue_arn) - .input_transformer(input_transformer) - .build()?, - ) - .send() - .await?; - - println!("🌉 Event bridge setup completed. Trigger Type : {:?}", worker_trigger_type); - - Ok(()) - } - - /// Generic function to send message to any of the queues - pub async fn send_message_to_queue(&self, queue_url: &str, message_body: &str) -> color_eyre::Result<()> { - self.sqs_client.send_message().queue_url(queue_url).message_body(message_body).send().await?; - Ok(()) - } - - pub async fn delete_event_bridge_rule(&self, rule_name: &str) -> color_eyre::Result<()> { - let list_targets_output = self.event_bridge_client.list_targets_by_rule().rule(rule_name).send().await; - - match list_targets_output { - Ok(output) => { - let targets = output.targets(); - if !targets.is_empty() { - let target_ids: Vec = targets.iter().map(|t| t.id().to_string()).collect(); - - self.event_bridge_client.remove_targets().rule(rule_name).set_ids(Some(target_ids)).send().await?; - - println!("🧹 Removed targets from rule: {}", rule_name); - } - - // Step 2: Delete the rule - self.event_bridge_client.delete_rule().name(rule_name).send().await?; - - println!("🧹 Deleted EventBridge rule: {}", rule_name); - println!("🧹 Rule deleted successfully."); - - Ok(()) - } - Err(_) => Ok(()), - } - } - - pub async fn put_message_in_queue(&self, message: JobQueueMessage, queue_url: String) -> color_eyre::Result<()> { - let region_provider = RegionProviderChain::default_provider().or_else("us-east-1"); - let config = aws_config::from_env().region(region_provider).load().await; - let client = aws_sdk_sqs::Client::new(&config); - - let rsp = - client.send_message().queue_url(queue_url).message_body(serde_json::to_string(&message)?).send().await?; - - println!("Successfully sent message with ID: {:?}", rsp.message_id()); - - Ok(()) - } -} diff --git a/e2e-tests/src/node.rs b/e2e-tests/src/node.rs index ca342af3..e34544de 100644 --- a/e2e-tests/src/node.rs +++ b/e2e-tests/src/node.rs @@ -3,6 +3,7 @@ use std::process::{Child, Command, ExitStatus, Stdio}; use std::thread; use std::time::Duration; +use strum_macros::Display; use tokio::net::TcpStream; use url::Url; @@ -26,8 +27,16 @@ impl Drop for Orchestrator { } } +#[derive(Display, Debug, Clone, PartialEq, Eq)] +pub enum OrchestratorMode { + #[strum(serialize = "run")] + Run, + #[strum(serialize = "setup")] + Setup, +} + impl Orchestrator { - pub fn run(envs: Vec<(String, String)>) -> Self { + pub fn run(envs: Vec<(String, String)>, mode: OrchestratorMode) -> Self { let port = get_free_port(); let address = format!("127.0.0.1:{}", port); let repository_root = &get_repository_root(); @@ -37,6 +46,7 @@ impl Orchestrator { let port_str = format!("{}", port); let envs = [envs, vec![("MADARA_ORCHESTRATOR_PORT".to_string(), port_str)]].concat(); + println!("Running orchestrator in {:?} mode", mode); let mut command = Command::new("cargo"); command .arg("run") @@ -46,6 +56,8 @@ impl Orchestrator { .arg("--features") .arg("testing") .arg("--") + // if mode::Run then --run else if mode::Setup then --setup + .arg(format!("--{}", mode)) .arg("--settle-on-ethereum") .arg("--aws-s3") .arg("--aws-sqs") diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index f2866969..cb38e9e6 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -3,32 +3,27 @@ use std::fs::File; use std::io::Read; use std::time::{Duration, Instant}; +use aws_config::meta::region::RegionProviderChain; use chrono::{SubsecRound, Utc}; use e2e_tests::anvil::AnvilSetup; -use e2e_tests::localstack::LocalStack; use e2e_tests::mock_server::MockResponseBodyType; use e2e_tests::sharp::SharpClient; use e2e_tests::starknet_client::StarknetClient; use e2e_tests::utils::{get_mongo_db_client, read_state_update_from_file, vec_u8_to_hex_string}; use e2e_tests::{MongoDbServer, Orchestrator}; use mongodb::bson::doc; -use orchestrator::cli::aws_config::AWSConfigParams; use orchestrator::cli::database::DatabaseParams; -use orchestrator::cli::queue::QueueParams; -use orchestrator::cli::storage::StorageParams; -use orchestrator::data_storage::aws_s3::AWSS3ValidatedArgs; use orchestrator::data_storage::DataStorage; use orchestrator::database::mongodb::MongoDBValidatedArgs; use orchestrator::jobs::constants::{JOB_METADATA_SNOS_BLOCK, JOB_METADATA_STATE_UPDATE_BLOCKS_TO_SETTLE_KEY}; use orchestrator::jobs::types::{ExternalId, JobItem, JobStatus, JobType}; -use orchestrator::queue::job_queue::{JobQueueMessage, WorkerTriggerType}; +use orchestrator::queue::job_queue::JobQueueMessage; use orchestrator::queue::sqs::AWSSQSValidatedArgs; use orchestrator::queue::QueueType; use rstest::rstest; use serde::{Deserialize, Serialize}; use serde_json::json; use starknet::core::types::{Felt, MaybePendingStateUpdate}; -use url::Url; use utils::env_utils::get_env_var_or_panic; use uuid::Uuid; @@ -50,7 +45,6 @@ struct Setup { starknet_client: StarknetClient, sharp_client: SharpClient, env_vector: Vec<(String, String)>, - localstack_instance: LocalStack, } impl Setup { @@ -61,24 +55,6 @@ impl Setup { database_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_DATABASE_NAME"), }); - let storage_params = StorageParams::AWSS3(AWSS3ValidatedArgs { - bucket_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME"), - }); - let queue_params = QueueParams::AWSSQS(AWSSQSValidatedArgs { - queue_base_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL"), - sqs_prefix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_PREFIX"), - sqs_suffix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_SUFFIX"), - }); - - let aws_config = AWSConfigParams { - aws_access_key_id: get_env_var_or_panic("AWS_ACCESS_KEY_ID"), - aws_secret_access_key: get_env_var_or_panic("AWS_SECRET_ACCESS_KEY"), - aws_region: get_env_var_or_panic("AWS_REGION"), - aws_endpoint_url: Url::parse(&get_env_var_or_panic("AWS_ENDPOINT_URL")) - .expect("Failed to parse AWS_ENDPOINT_URL"), - aws_default_region: get_env_var_or_panic("AWS_DEFAULT_REGION"), - }; - let DatabaseParams::MongoDB(mongodb_params) = db_params; let mongo_db_instance = MongoDbServer::run(mongodb_params); @@ -94,17 +70,6 @@ impl Setup { let (starknet_core_contract_address, verifier_contract_address) = anvil_setup.deploy_contracts().await; println!("✅ Anvil setup completed"); - // Setting up LocalStack - let StorageParams::AWSS3(s3_params) = storage_params; - let QueueParams::AWSSQS(sqs_params) = queue_params; - let localstack_instance = LocalStack::new(aws_config, &s3_params).await; - localstack_instance.setup_sqs(&sqs_params).await.unwrap(); - localstack_instance.delete_event_bridge_rule("worker_trigger_scheduled").await.unwrap(); - localstack_instance.setup_event_bridge(WorkerTriggerType::Snos, &sqs_params).await.unwrap(); - localstack_instance.setup_event_bridge(WorkerTriggerType::Proving, &sqs_params).await.unwrap(); - localstack_instance.setup_event_bridge(WorkerTriggerType::DataSubmission, &sqs_params).await.unwrap(); - localstack_instance.setup_event_bridge(WorkerTriggerType::UpdateState, &sqs_params).await.unwrap(); - let mut env_vec: Vec<(String, String)> = vec![("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL".to_string(), mongo_db_instance.endpoint().to_string())]; @@ -134,7 +99,7 @@ impl Setup { let env_vec_2: Vec<(String, String)> = set_env_vars(); env_vec.extend(env_vec_2); - Self { mongo_db_instance, starknet_client, sharp_client, env_vector: env_vec, localstack_instance } + Self { mongo_db_instance, starknet_client, sharp_client, env_vector: env_vec } } pub fn mongo_db_instance(&self) -> &MongoDbServer { @@ -153,10 +118,6 @@ impl Setup { pub fn envs(&self) -> Vec<(String, String)> { self.env_vector.clone() } - - pub fn localstack(&self) -> &LocalStack { - &self.localstack_instance - } } #[rstest] @@ -165,6 +126,7 @@ impl Setup { async fn test_orchestrator_workflow(#[case] l2_block_number: String) { // Fetching the env vars from the test env file as these will be used in // setting up of the test and during orchestrator run too. + use e2e_tests::node::OrchestratorMode; dotenvy::from_filename(".env.test").expect("Failed to load the .env file"); let queue_params = AWSSQSValidatedArgs { @@ -174,13 +136,16 @@ async fn test_orchestrator_workflow(#[case] l2_block_number: String) { }; let mut setup_config = Setup::new(l2_block_number.clone()).await; - // Setup S3 - setup_s3(setup_config.localstack().s3_client()).await.unwrap(); + // Setup Cloud + // Setup orchestrator cloud + let _orchestrator = Orchestrator::run(setup_config.envs(), OrchestratorMode::Setup); + + println!("✅ Orchestrator cloud setup completed"); // Step 1 : SNOS job runs ========================================= // Updates the job in the db let job_id = put_job_data_in_db_snos(setup_config.mongo_db_instance(), l2_block_number.clone()).await; - put_snos_job_in_processing_queue(setup_config.localstack(), job_id, queue_params).await.unwrap(); + put_snos_job_in_processing_queue(job_id, queue_params).await.unwrap(); // Step 2: Proving Job ============================================ // Mocking the endpoint @@ -197,7 +162,7 @@ async fn test_orchestrator_workflow(#[case] l2_block_number: String) { println!("✅ Orchestrator setup completed."); // Run orchestrator - let mut orchestrator = Orchestrator::run(setup_config.envs()); + let mut orchestrator = Orchestrator::run(setup_config.envs(), OrchestratorMode::Run); orchestrator.wait_till_started().await; println!("✅ Orchestrator started"); @@ -325,13 +290,21 @@ pub async fn put_job_data_in_db_snos(mongo_db: &MongoDbServer, l2_block_number: /// Adding SNOS job in JOB_PROCESSING_QUEUE so that the job is triggered /// as soon as it is picked up by orchestrator -pub async fn put_snos_job_in_processing_queue( - local_stack: &LocalStack, - id: Uuid, - queue_params: AWSSQSValidatedArgs, -) -> color_eyre::Result<()> { +pub async fn put_snos_job_in_processing_queue(id: Uuid, queue_params: AWSSQSValidatedArgs) -> color_eyre::Result<()> { let message = JobQueueMessage { id }; - local_stack.put_message_in_queue(message, queue_params.get_queue_url(QueueType::SnosJobProcessing)).await?; + put_message_in_queue(message, queue_params.get_queue_url(QueueType::SnosJobProcessing)).await?; + Ok(()) +} + +pub async fn put_message_in_queue(message: JobQueueMessage, queue_url: String) -> color_eyre::Result<()> { + let region_provider = RegionProviderChain::default_provider().or_else("us-east-1"); + let config = aws_config::from_env().region(region_provider).load().await; + let client = aws_sdk_sqs::Client::new(&config); + + let rsp = client.send_message().queue_url(queue_url).message_body(serde_json::to_string(&message)?).send().await?; + + println!("Successfully sent message with ID: {:?}", rsp.message_id()); + Ok(()) } From 55c44540cec4ebb4dd526a05024d472e7e8d3704 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Tue, 12 Nov 2024 22:13:15 +0530 Subject: [PATCH 50/63] update: setup and run fns --- e2e-tests/src/node.rs | 57 ++++++++++++++++++++++++++++++++++++++++--- e2e-tests/tests.rs | 6 ++--- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/e2e-tests/src/node.rs b/e2e-tests/src/node.rs index e34544de..030e3a09 100644 --- a/e2e-tests/src/node.rs +++ b/e2e-tests/src/node.rs @@ -36,7 +36,58 @@ pub enum OrchestratorMode { } impl Orchestrator { - pub fn run(envs: Vec<(String, String)>, mode: OrchestratorMode) -> Self { + pub fn setup(envs: Vec<(String, String)>) { + let port = get_free_port(); + let repository_root = &get_repository_root(); + let port_str = format!("{}", port); + + std::env::set_current_dir(repository_root).expect("Failed to change working directory"); + let envs = [envs, vec![("MADARA_ORCHESTRATOR_PORT".to_string(), port_str)]].concat(); + + println!("Running orchestrator in Setup mode"); + let mut command = Command::new("cargo"); + command + .arg("run") + .arg("--release") + .arg("--bin") + .arg("orchestrator") + .arg("--features") + .arg("testing") + .arg("--") + // if mode::Run then --run else if mode::Setup then --setup + .arg("--setup") + .arg("--settle-on-ethereum") + .arg("--aws-s3") + .arg("--aws-sqs") + .arg("--aws-sns") + .arg("--mongodb") + .arg("--sharp") + .arg("--da-on-ethereum") + .arg("--aws-event-bridge") + .current_dir(repository_root) + .envs(envs) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()); + + let mut process = command.spawn().expect("Failed to start process"); + + // Wait for the process to complete and get its exit status + let status = process.wait().expect("Failed to wait for process"); + + // You can check if the process succeeded + if status.success() { + println!("Setup Orchestrator completed successfully"); + } else { + // Get the exit code if available + if let Some(code) = status.code() { + println!("Setup Orchestrator failed with exit code: {}", code); + } else { + println!("Setup Orchestrator terminated by signal"); + } + } + } + + pub fn run(envs: Vec<(String, String)>) -> Self { let port = get_free_port(); let address = format!("127.0.0.1:{}", port); let repository_root = &get_repository_root(); @@ -46,7 +97,7 @@ impl Orchestrator { let port_str = format!("{}", port); let envs = [envs, vec![("MADARA_ORCHESTRATOR_PORT".to_string(), port_str)]].concat(); - println!("Running orchestrator in {:?} mode", mode); + println!("Running orchestrator in Run mode"); let mut command = Command::new("cargo"); command .arg("run") @@ -57,7 +108,7 @@ impl Orchestrator { .arg("testing") .arg("--") // if mode::Run then --run else if mode::Setup then --setup - .arg(format!("--{}", mode)) + .arg("--run") .arg("--settle-on-ethereum") .arg("--aws-s3") .arg("--aws-sqs") diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index cb38e9e6..c1404091 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -126,7 +126,6 @@ impl Setup { async fn test_orchestrator_workflow(#[case] l2_block_number: String) { // Fetching the env vars from the test env file as these will be used in // setting up of the test and during orchestrator run too. - use e2e_tests::node::OrchestratorMode; dotenvy::from_filename(".env.test").expect("Failed to load the .env file"); let queue_params = AWSSQSValidatedArgs { @@ -138,8 +137,7 @@ async fn test_orchestrator_workflow(#[case] l2_block_number: String) { let mut setup_config = Setup::new(l2_block_number.clone()).await; // Setup Cloud // Setup orchestrator cloud - let _orchestrator = Orchestrator::run(setup_config.envs(), OrchestratorMode::Setup); - + Orchestrator::setup(setup_config.envs()); println!("✅ Orchestrator cloud setup completed"); // Step 1 : SNOS job runs ========================================= @@ -162,7 +160,7 @@ async fn test_orchestrator_workflow(#[case] l2_block_number: String) { println!("✅ Orchestrator setup completed."); // Run orchestrator - let mut orchestrator = Orchestrator::run(setup_config.envs(), OrchestratorMode::Run); + let mut orchestrator = Orchestrator::run(setup_config.envs()); orchestrator.wait_till_started().await; println!("✅ Orchestrator started"); From 2c980a0eb38e9703b51de352f12f3c0d4503f71f Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 13 Nov 2024 13:57:08 +0530 Subject: [PATCH 51/63] update: systematic rework --- crates/da-clients/ethereum/src/lib.rs | 7 +- crates/orchestrator/src/alerts/aws_sns/mod.rs | 21 ++-- crates/orchestrator/src/alerts/mod.rs | 13 +-- crates/orchestrator/src/cli/alert/mod.rs | 2 +- crates/orchestrator/src/cli/cron/mod.rs | 2 +- crates/orchestrator/src/cli/da/mod.rs | 2 +- crates/orchestrator/src/cli/database/mod.rs | 2 +- crates/orchestrator/src/cli/mod.rs | 102 +++++++++--------- crates/orchestrator/src/cli/prover/mod.rs | 2 +- .../cli/{aws_config.rs => provider/aws.rs} | 9 +- crates/orchestrator/src/cli/provider/mod.rs | 8 ++ crates/orchestrator/src/cli/queue/mod.rs | 2 +- crates/orchestrator/src/cli/settlement/mod.rs | 2 +- crates/orchestrator/src/cli/storage/mod.rs | 2 +- crates/orchestrator/src/config.rs | 87 +++++++++------ crates/orchestrator/src/cron/event_bridge.rs | 46 ++++---- crates/orchestrator/src/cron/mod.rs | 18 +--- .../src/data_storage/aws_s3/mod.rs | 7 +- crates/orchestrator/src/data_storage/mod.rs | 6 +- .../orchestrator/src/database/mongodb/mod.rs | 2 +- crates/orchestrator/src/queue/mod.rs | 7 +- crates/orchestrator/src/queue/sqs/mod.rs | 54 +++++----- crates/orchestrator/src/setup/mod.rs | 63 ++++------- crates/orchestrator/src/tests/common/mod.rs | 30 +++--- crates/orchestrator/src/tests/config.rs | 99 +++++++++-------- .../sharp-service/src/client.rs | 2 +- .../prover-services/sharp-service/src/lib.rs | 6 +- crates/settlement-clients/ethereum/src/lib.rs | 2 +- crates/settlement-clients/starknet/src/lib.rs | 2 +- .../starknet/src/tests/test.rs | 2 +- e2e-tests/tests.rs | 18 +++- 31 files changed, 321 insertions(+), 306 deletions(-) rename crates/orchestrator/src/cli/{aws_config.rs => provider/aws.rs} (84%) create mode 100644 crates/orchestrator/src/cli/provider/mod.rs diff --git a/crates/da-clients/ethereum/src/lib.rs b/crates/da-clients/ethereum/src/lib.rs index 583ab7c8..e9b4aefa 100644 --- a/crates/da-clients/ethereum/src/lib.rs +++ b/crates/da-clients/ethereum/src/lib.rs @@ -25,13 +25,14 @@ pub const DA_SETTINGS_NAME: &str = "ethereum"; pub struct EthereumDaClient { #[allow(dead_code)] - pub provider: RootProvider>, + provider: RootProvider>, } impl EthereumDaClient { - pub async fn new_with_params(ethereum_da_params: &EthereumDaValidatedArgs) -> Self { + pub async fn new_with_args(ethereum_da_params: &EthereumDaValidatedArgs) -> Self { let client = RpcClient::new_http( - Url::from_str(ethereum_da_params.ethereum_da_rpc_url.as_str()).expect("Failed to parse SETTLEMENT_RPC_URL"), + Url::from_str(ethereum_da_params.ethereum_da_rpc_url.as_str()) + .expect("Failed to parse ethereum_da_rpc_url"), ); let provider = ProviderBuilder::<_, Ethereum>::new().on_client(client); Self { provider } diff --git a/crates/orchestrator/src/alerts/aws_sns/mod.rs b/crates/orchestrator/src/alerts/aws_sns/mod.rs index 9012f090..e7416d6e 100644 --- a/crates/orchestrator/src/alerts/aws_sns/mod.rs +++ b/crates/orchestrator/src/alerts/aws_sns/mod.rs @@ -1,22 +1,14 @@ -use std::sync::Arc; - use async_trait::async_trait; +use aws_config::SdkConfig; use aws_sdk_sns::Client; use crate::alerts::Alerts; -use crate::config::ProviderConfig; #[derive(Debug, Clone)] pub struct AWSSNSValidatedArgs { // TODO: convert to ARN type, and validate it // NOTE: aws is using str to represent ARN : https://docs.aws.amazon.com/sdk-for-rust/latest/dg/rust_sns_code_examples.html - pub sns_arn: String, -} - -impl AWSSNSValidatedArgs { - pub fn get_topic_name(&self) -> String { - self.sns_arn.split(":").last().unwrap().to_string() - } + pub topic_arn: String, } pub struct AWSSNS { @@ -25,9 +17,8 @@ pub struct AWSSNS { } impl AWSSNS { - pub async fn new_with_params(aws_sns_params: &AWSSNSValidatedArgs, provider_config: Arc) -> Self { - let config = provider_config.get_aws_client_or_panic(); - Self { client: Client::new(config), topic_arn: aws_sns_params.sns_arn.clone() } + pub async fn new_with_args(aws_sns_params: &AWSSNSValidatedArgs, aws_config: &SdkConfig) -> Self { + Self { client: Client::new(aws_config), topic_arn: aws_sns_params.topic_arn.clone() } } } @@ -44,4 +35,8 @@ impl Alerts for AWSSNS { log::info!("SNS topic created. Topic ARN: {}", topic_arn); Ok(()) } + + async fn get_topic_name(&self) -> String { + self.topic_arn.split(":").last().unwrap().to_string() + } } diff --git a/crates/orchestrator/src/alerts/mod.rs b/crates/orchestrator/src/alerts/mod.rs index 75e87a9a..bef94150 100644 --- a/crates/orchestrator/src/alerts/mod.rs +++ b/crates/orchestrator/src/alerts/mod.rs @@ -1,8 +1,6 @@ use async_trait::async_trait; use mockall::automock; -use crate::cli::alert::AlertParams; - pub mod aws_sns; #[automock] @@ -10,14 +8,11 @@ pub mod aws_sns; pub trait Alerts: Send + Sync { /// To send an alert message to our alert service async fn send_alert_message(&self, message_body: String) -> color_eyre::Result<()>; + async fn get_topic_name(&self) -> String; async fn create_alert(&self, topic_name: &str) -> color_eyre::Result<()>; - async fn setup(&self, params: AlertParams) -> color_eyre::Result<()> { - match params { - AlertParams::AWSSNS(aws_sns_params) => { - let sns_topic_name = aws_sns_params.get_topic_name(); - self.create_alert(&sns_topic_name).await?; - } - } + async fn setup(&self) -> color_eyre::Result<()> { + let topic_name = self.get_topic_name().await; + self.create_alert(&topic_name).await?; Ok(()) } } diff --git a/crates/orchestrator/src/cli/alert/mod.rs b/crates/orchestrator/src/cli/alert/mod.rs index fb5ee30f..f22dd0ac 100644 --- a/crates/orchestrator/src/cli/alert/mod.rs +++ b/crates/orchestrator/src/cli/alert/mod.rs @@ -3,6 +3,6 @@ use crate::alerts::aws_sns::AWSSNSValidatedArgs; pub mod aws_sns; #[derive(Clone, Debug)] -pub enum AlertParams { +pub enum AlertValidatedArgs { AWSSNS(AWSSNSValidatedArgs), } diff --git a/crates/orchestrator/src/cli/cron/mod.rs b/crates/orchestrator/src/cli/cron/mod.rs index cffe6261..f1b9e35a 100644 --- a/crates/orchestrator/src/cli/cron/mod.rs +++ b/crates/orchestrator/src/cli/cron/mod.rs @@ -3,6 +3,6 @@ use crate::alerts::aws_sns::AWSSNSValidatedArgs; pub mod event_bridge; #[derive(Clone, Debug)] -pub enum CronParams { +pub enum CronValidatedArgs { AWSSNS(AWSSNSValidatedArgs), } diff --git a/crates/orchestrator/src/cli/da/mod.rs b/crates/orchestrator/src/cli/da/mod.rs index e3814759..54c98496 100644 --- a/crates/orchestrator/src/cli/da/mod.rs +++ b/crates/orchestrator/src/cli/da/mod.rs @@ -3,6 +3,6 @@ use ethereum_da_client::EthereumDaValidatedArgs; pub mod ethereum; #[derive(Debug, Clone)] -pub enum DaParams { +pub enum DaValidatedArgs { Ethereum(EthereumDaValidatedArgs), } diff --git a/crates/orchestrator/src/cli/database/mod.rs b/crates/orchestrator/src/cli/database/mod.rs index 6db38f30..b2bd6cb1 100644 --- a/crates/orchestrator/src/cli/database/mod.rs +++ b/crates/orchestrator/src/cli/database/mod.rs @@ -3,6 +3,6 @@ use crate::database::mongodb::MongoDBValidatedArgs; pub mod mongodb; #[derive(Debug, Clone)] -pub enum DatabaseParams { +pub enum DatabaseValidatedArgs { MongoDB(MongoDBValidatedArgs), } diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index 08c6e54a..a5b42a5a 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -1,26 +1,27 @@ use std::time::Duration; -use alert::AlertParams; -use aws_config::{AWSConfigCliArgs, AWSConfigParams}; +use alert::AlertValidatedArgs; use clap::{ArgGroup, Parser}; use cron::event_bridge::AWSEventBridgeCliArgs; -use da::DaParams; -use database::DatabaseParams; +use da::DaValidatedArgs; +use database::DatabaseValidatedArgs; use ethereum_da_client::EthereumDaValidatedArgs; use ethereum_settlement_client::EthereumSettlementValidatedArgs; -use prover::ProverParams; -use queue::QueueParams; -use settlement::SettlementParams; +use prover::ProverValidatedArgs; +use provider::aws::{AWSConfigCliArgs, AWSConfigValidatedArgs}; +use provider::ProviderValidatedArgs; +use queue::QueueValidatedArgs; +use settlement::SettlementValidatedArgs; use sharp_service::SharpValidatedArgs; use snos::SNOSParams; use starknet_settlement_client::StarknetSettlementValidatedArgs; -use storage::StorageParams; +use storage::StorageValidatedArgs; use url::Url; use crate::alerts::aws_sns::AWSSNSValidatedArgs; use crate::config::ServiceParams; use crate::cron::event_bridge::AWSEventBridgeValidatedArgs; -use crate::cron::CronParams; +use crate::cron::CronValidatedArgs; use crate::data_storage::aws_s3::AWSS3ValidatedArgs; use crate::database::mongodb::MongoDBValidatedArgs; use crate::queue::sqs::AWSSQSValidatedArgs; @@ -28,12 +29,12 @@ use crate::routes::ServerParams; use crate::telemetry::InstrumentationParams; pub mod alert; -pub mod aws_config; pub mod cron; pub mod da; pub mod database; pub mod instrumentation; pub mod prover; +pub mod provider; pub mod queue; pub mod server; pub mod service; @@ -50,6 +51,13 @@ pub mod storage; .required(true) .multiple(false) ), + + group( + ArgGroup::new("provider") + .args(&["aws"]) + .required(true) + .multiple(false) + ), group( ArgGroup::new("settlement_layer") .args(&["settle_on_ethereum", "settle_on_starknet"]) @@ -106,10 +114,10 @@ pub struct RunCmd { pub aws_config_args: AWSConfigCliArgs, // Settlement Layer - #[command(flatten)] + #[clap(flatten)] ethereum_args: settlement::ethereum::EthereumSettlementCliArgs, - #[command(flatten)] + #[clap(flatten)] starknet_args: settlement::starknet::StarknetSettlementCliArgs, // Storage @@ -159,36 +167,31 @@ pub struct RunCmd { } impl RunCmd { - pub fn validate_aws_config_params(&self) -> Result { - let aws_endpoint_url = - Url::parse("http://localhost.localstack.cloud:4566").expect("Failed to parse AWS endpoint URL"); - let aws_default_region = "localhost".to_string(); - - tracing::warn!("Setting AWS_ENDPOINT_URL to {} for AWS SDK to use", aws_endpoint_url); - tracing::warn!("Setting AWS_DEFAULT_REGION to {} for Omniqueue to use", aws_default_region); - - Ok(AWSConfigParams { - aws_access_key_id: self.aws_config_args.aws_access_key_id.clone(), - aws_secret_access_key: self.aws_config_args.aws_secret_access_key.clone(), - aws_region: self.aws_config_args.aws_region.clone(), - aws_endpoint_url, - aws_default_region, - }) + pub fn validate_provider_params(&self) -> Result { + if self.aws_config_args.aws { + Ok(ProviderValidatedArgs::AWS(AWSConfigValidatedArgs { + aws_access_key_id: self.aws_config_args.aws_access_key_id.clone(), + aws_secret_access_key: self.aws_config_args.aws_secret_access_key.clone(), + aws_region: self.aws_config_args.aws_region.clone(), + })) + } else { + Err("Only AWS is supported as of now".to_string()) + } } - pub fn validate_alert_params(&self) -> Result { + pub fn validate_alert_params(&self) -> Result { if self.aws_sns_args.aws_sns { - Ok(AlertParams::AWSSNS(AWSSNSValidatedArgs { - sns_arn: self.aws_sns_args.sns_arn.clone().expect("SNS ARN is required"), + Ok(AlertValidatedArgs::AWSSNS(AWSSNSValidatedArgs { + topic_arn: self.aws_sns_args.sns_arn.clone().expect("SNS ARN is required"), })) } else { Err("Only AWS SNS is supported as of now".to_string()) } } - pub fn validate_queue_params(&self) -> Result { + pub fn validate_queue_params(&self) -> Result { if self.aws_sqs_args.aws_sqs { - Ok(QueueParams::AWSSQS(AWSSQSValidatedArgs { + Ok(QueueValidatedArgs::AWSSQS(AWSSQSValidatedArgs { queue_base_url: self.aws_sqs_args.queue_base_url.clone().expect("Queue base URL is required"), sqs_prefix: self.aws_sqs_args.sqs_prefix.clone().expect("SQS prefix is required"), sqs_suffix: self.aws_sqs_args.sqs_suffix.clone().expect("SQS suffix is required"), @@ -198,9 +201,9 @@ impl RunCmd { } } - pub fn validate_storage_params(&self) -> Result { + pub fn validate_storage_params(&self) -> Result { if self.aws_s3_args.aws_s3 { - Ok(StorageParams::AWSS3(AWSS3ValidatedArgs { + Ok(StorageValidatedArgs::AWSS3(AWSS3ValidatedArgs { bucket_name: self.aws_s3_args.bucket_name.clone().expect("Bucket name is required"), })) } else { @@ -208,9 +211,9 @@ impl RunCmd { } } - pub fn validate_database_params(&self) -> Result { + pub fn validate_database_params(&self) -> Result { if self.mongodb_args.mongodb { - Ok(DatabaseParams::MongoDB(MongoDBValidatedArgs { + Ok(DatabaseValidatedArgs::MongoDB(MongoDBValidatedArgs { connection_url: self .mongodb_args .mongodb_connection_url @@ -227,9 +230,9 @@ impl RunCmd { } } - pub fn validate_da_params(&self) -> Result { + pub fn validate_da_params(&self) -> Result { if self.ethereum_da_args.da_on_ethereum { - Ok(DaParams::Ethereum(EthereumDaValidatedArgs { + Ok(DaValidatedArgs::Ethereum(EthereumDaValidatedArgs { ethereum_da_rpc_url: self .ethereum_da_args .ethereum_da_rpc_url @@ -241,7 +244,7 @@ impl RunCmd { } } - pub fn validate_settlement_params(&self) -> Result { + pub fn validate_settlement_params(&self) -> Result { match (self.ethereum_args.settle_on_ethereum, self.starknet_args.settle_on_starknet) { (true, false) => { let ethereum_params = EthereumSettlementValidatedArgs { @@ -266,7 +269,7 @@ impl RunCmd { .clone() .expect("Starknet operator address is required"), }; - Ok(SettlementParams::Ethereum(ethereum_params)) + Ok(SettlementValidatedArgs::Ethereum(ethereum_params)) } (false, true) => { let starknet_params = StarknetSettlementValidatedArgs { @@ -300,15 +303,15 @@ impl RunCmd { .clone() .expect("Starknet Madara binary path is required"), }; - Ok(SettlementParams::Starknet(starknet_params)) + Ok(SettlementValidatedArgs::Starknet(starknet_params)) } (true, true) | (false, false) => Err("Exactly one settlement layer must be selected".to_string()), } } - pub fn validate_prover_params(&self) -> Result { + pub fn validate_prover_params(&self) -> Result { if self.sharp_args.sharp { - Ok(ProverParams::Sharp(SharpValidatedArgs { + Ok(ProverValidatedArgs::Sharp(SharpValidatedArgs { sharp_customer_id: self.sharp_args.sharp_customer_id.clone().expect("Sharp customer ID is required"), sharp_url: self.sharp_args.sharp_url.clone().expect("Sharp URL is required"), sharp_user_crt: self.sharp_args.sharp_user_crt.clone().expect("Sharp user certificate is required"), @@ -331,9 +334,9 @@ impl RunCmd { } } - pub fn validate_cron_params(&self) -> Result { + pub fn validate_cron_params(&self) -> Result { if self.aws_event_bridge_args.aws_event_bridge { - Ok(CronParams::EventBridge(AWSEventBridgeValidatedArgs { + Ok(CronValidatedArgs::AWSEventBridge(AWSEventBridgeValidatedArgs { target_queue_name: self .aws_event_bridge_args .target_queue_name @@ -399,12 +402,12 @@ pub mod test { use url::Url; use super::alert::aws_sns::AWSSNSCliArgs; - use super::aws_config::AWSConfigCliArgs; use super::cron::event_bridge::AWSEventBridgeCliArgs; use super::da::ethereum::EthereumDaCliArgs; use super::database::mongodb::MongoDBCliArgs; use super::instrumentation::InstrumentationCliArgs; use super::prover::sharp::SharpCliArgs; + use super::provider::aws::AWSConfigCliArgs; use super::queue::aws_sqs::AWSSQSCliArgs; use super::server::ServerCliArgs; use super::service::ServiceCliArgs; @@ -421,6 +424,7 @@ pub mod test { run: true, setup: false, aws_config_args: AWSConfigCliArgs { + aws: true, aws_access_key_id: "".to_string(), aws_secret_access_key: "".to_string(), aws_region: "".to_string(), @@ -502,9 +506,9 @@ pub mod test { // Let's create a test for the CLI each validator #[rstest] - fn test_validate_aws_config_params(setup_cmd: RunCmd) { - let aws_config_params = setup_cmd.validate_aws_config_params(); - assert!(aws_config_params.is_ok()); + fn test_validate_provider_params(setup_cmd: RunCmd) { + let provider_params = setup_cmd.validate_provider_params(); + assert!(provider_params.is_ok()); } #[rstest] diff --git a/crates/orchestrator/src/cli/prover/mod.rs b/crates/orchestrator/src/cli/prover/mod.rs index 90f02845..01a4cf02 100644 --- a/crates/orchestrator/src/cli/prover/mod.rs +++ b/crates/orchestrator/src/cli/prover/mod.rs @@ -3,6 +3,6 @@ use sharp_service::SharpValidatedArgs; pub mod sharp; #[derive(Debug, Clone)] -pub enum ProverParams { +pub enum ProverValidatedArgs { Sharp(SharpValidatedArgs), } diff --git a/crates/orchestrator/src/cli/aws_config.rs b/crates/orchestrator/src/cli/provider/aws.rs similarity index 84% rename from crates/orchestrator/src/cli/aws_config.rs rename to crates/orchestrator/src/cli/provider/aws.rs index 1031e749..b7f00b9a 100644 --- a/crates/orchestrator/src/cli/aws_config.rs +++ b/crates/orchestrator/src/cli/provider/aws.rs @@ -1,11 +1,14 @@ use clap::Args; use serde::Serialize; -use url::Url; /// Parameters used to config AWS. #[derive(Debug, Clone, Args, Serialize)] #[group(requires_all = ["aws_access_key_id", "aws_secret_access_key", "aws_region"])] pub struct AWSConfigCliArgs { + /// Use this flag to enable AWS provider. + #[arg(long)] + pub aws: bool, + /// The access key ID. #[arg(env = "AWS_ACCESS_KEY_ID", long)] pub aws_access_key_id: String, @@ -20,10 +23,8 @@ pub struct AWSConfigCliArgs { } #[derive(Debug, Clone)] -pub struct AWSConfigParams { +pub struct AWSConfigValidatedArgs { pub aws_access_key_id: String, pub aws_secret_access_key: String, pub aws_region: String, - pub aws_endpoint_url: Url, - pub aws_default_region: String, } diff --git a/crates/orchestrator/src/cli/provider/mod.rs b/crates/orchestrator/src/cli/provider/mod.rs new file mode 100644 index 00000000..e4080548 --- /dev/null +++ b/crates/orchestrator/src/cli/provider/mod.rs @@ -0,0 +1,8 @@ +pub mod aws; + +use aws::AWSConfigValidatedArgs; + +#[derive(Debug, Clone)] +pub enum ProviderValidatedArgs { + AWS(AWSConfigValidatedArgs), +} diff --git a/crates/orchestrator/src/cli/queue/mod.rs b/crates/orchestrator/src/cli/queue/mod.rs index 3970e98e..c3efd271 100644 --- a/crates/orchestrator/src/cli/queue/mod.rs +++ b/crates/orchestrator/src/cli/queue/mod.rs @@ -3,6 +3,6 @@ use crate::queue::sqs::AWSSQSValidatedArgs; pub mod aws_sqs; #[derive(Clone, Debug)] -pub enum QueueParams { +pub enum QueueValidatedArgs { AWSSQS(AWSSQSValidatedArgs), } diff --git a/crates/orchestrator/src/cli/settlement/mod.rs b/crates/orchestrator/src/cli/settlement/mod.rs index ef625159..1cf7c848 100644 --- a/crates/orchestrator/src/cli/settlement/mod.rs +++ b/crates/orchestrator/src/cli/settlement/mod.rs @@ -5,7 +5,7 @@ pub mod ethereum; pub mod starknet; #[derive(Clone, Debug)] -pub enum SettlementParams { +pub enum SettlementValidatedArgs { Ethereum(EthereumSettlementValidatedArgs), Starknet(StarknetSettlementValidatedArgs), } diff --git a/crates/orchestrator/src/cli/storage/mod.rs b/crates/orchestrator/src/cli/storage/mod.rs index a86b0786..f905f899 100644 --- a/crates/orchestrator/src/cli/storage/mod.rs +++ b/crates/orchestrator/src/cli/storage/mod.rs @@ -3,6 +3,6 @@ use crate::data_storage::aws_s3::AWSS3ValidatedArgs; pub mod aws_s3; #[derive(Clone, Debug)] -pub enum StorageParams { +pub enum StorageValidatedArgs { AWSS3(AWSS3ValidatedArgs), } diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 85742025..67788398 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -23,15 +23,16 @@ use starknet_settlement_client::StarknetSettlementClient; use crate::alerts::aws_sns::AWSSNS; use crate::alerts::Alerts; -use crate::cli::alert::AlertParams; -use crate::cli::aws_config::AWSConfigParams; -use crate::cli::da::DaParams; -use crate::cli::database::DatabaseParams; -use crate::cli::prover::ProverParams; -use crate::cli::queue::QueueParams; -use crate::cli::settlement::SettlementParams; +use crate::cli::alert::AlertValidatedArgs; +use crate::cli::da::DaValidatedArgs; +use crate::cli::database::DatabaseValidatedArgs; +use crate::cli::prover::ProverValidatedArgs; +use crate::cli::provider::aws::AWSConfigValidatedArgs; +use crate::cli::provider::ProviderValidatedArgs; +use crate::cli::queue::QueueValidatedArgs; +use crate::cli::settlement::SettlementValidatedArgs; use crate::cli::snos::SNOSParams; -use crate::cli::storage::StorageParams; +use crate::cli::storage::StorageValidatedArgs; use crate::cli::RunCmd; use crate::data_storage::aws_s3::AWSS3; use crate::data_storage::DataStorage; @@ -96,7 +97,7 @@ impl ProviderConfig { } /// To build a `SdkConfig` for AWS provider. -pub async fn get_aws_config(aws_config: &AWSConfigParams) -> SdkConfig { +pub async fn get_aws_config(aws_config: &AWSConfigValidatedArgs) -> SdkConfig { let region = aws_config.aws_region.clone(); let region_provider = RegionProviderChain::first_try(Region::new(region)).or_default_provider(); let credentials = @@ -108,8 +109,8 @@ pub async fn get_aws_config(aws_config: &AWSConfigParams) -> SdkConfig { pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { dotenv().ok(); - let aws_config = &run_cmd.validate_aws_config_params().expect("Failed to validate AWS config params"); - let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(aws_config).await))); + let provider_params = run_cmd.validate_provider_params().expect("Failed to validate provider params"); + let provider_config = build_provider_config(&provider_params).await; let orchestrator_params = OrchestratorParams { madara_rpc_url: run_cmd.madara_rpc_url.clone(), @@ -118,7 +119,7 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { server_config: run_cmd.validate_server_params().expect("Failed to validate server params"), }; - let provider = JsonRpcClient::new(HttpTransport::new(orchestrator_params.madara_rpc_url.clone())); + let rpc_client = JsonRpcClient::new(HttpTransport::new(orchestrator_params.madara_rpc_url.clone())); // init database let database_params = @@ -153,11 +154,11 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { // us stop using the generic omniqueue abstractions for message ack/nack // init queue let queue_params = run_cmd.validate_queue_params().map_err(|e| eyre!("Failed to validate queue params: {e}"))?; - let queue = build_queue_client(&queue_params); + let queue = build_queue_client(&queue_params, provider_config.clone()).await; Ok(Arc::new(Config::new( orchestrator_params, - Arc::new(provider), + Arc::new(rpc_client), da_client, prover_client, settlement_client, @@ -256,30 +257,40 @@ impl Config { } } +/// Builds the provider config +pub async fn build_provider_config(provider_params: &ProviderValidatedArgs) -> Arc { + match provider_params { + ProviderValidatedArgs::AWS(aws_params) => { + Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(aws_params).await))) + } + } +} + /// Builds the DA client based on the environment variable DA_LAYER -// TODO: convert this to use new_with_params -pub async fn build_da_client(da_params: &DaParams) -> Box { +pub async fn build_da_client(da_params: &DaValidatedArgs) -> Box { match da_params { - DaParams::Ethereum(ethereum_da_params) => Box::new(EthereumDaClient::new_with_params(ethereum_da_params).await), + DaValidatedArgs::Ethereum(ethereum_da_params) => { + Box::new(EthereumDaClient::new_with_args(ethereum_da_params).await) + } } } /// Builds the prover service based on the environment variable PROVER_SERVICE -pub fn build_prover_service(prover_params: &ProverParams) -> Box { +pub fn build_prover_service(prover_params: &ProverValidatedArgs) -> Box { match prover_params { - ProverParams::Sharp(sharp_params) => Box::new(SharpProverService::new_with_params(sharp_params)), + ProverValidatedArgs::Sharp(sharp_params) => Box::new(SharpProverService::new_with_args(sharp_params)), } } /// Builds the settlement client depending on the env variable SETTLEMENT_LAYER pub async fn build_settlement_client( - settlement_params: &SettlementParams, + settlement_params: &SettlementValidatedArgs, ) -> color_eyre::Result> { match settlement_params { - SettlementParams::Ethereum(ethereum_settlement_params) => { + SettlementValidatedArgs::Ethereum(ethereum_settlement_params) => { #[cfg(not(feature = "testing"))] { - Ok(Box::new(EthereumSettlementClient::new_with_params(ethereum_settlement_params))) + Ok(Box::new(EthereumSettlementClient::new_with_args(ethereum_settlement_params))) } #[cfg(feature = "testing")] { @@ -291,38 +302,50 @@ pub async fn build_settlement_client( ))) } } - SettlementParams::Starknet(starknet_settlement_params) => { - Ok(Box::new(StarknetSettlementClient::new_with_params(starknet_settlement_params).await)) + SettlementValidatedArgs::Starknet(starknet_settlement_params) => { + Ok(Box::new(StarknetSettlementClient::new_with_args(starknet_settlement_params).await)) } } } pub async fn build_storage_client( - data_storage_params: &StorageParams, + data_storage_params: &StorageValidatedArgs, provider_config: Arc, ) -> Box { match data_storage_params { - StorageParams::AWSS3(aws_s3_params) => Box::new(AWSS3::new_with_params(aws_s3_params, provider_config).await), + StorageValidatedArgs::AWSS3(aws_s3_params) => { + let aws_config = provider_config.get_aws_client_or_panic(); + Box::new(AWSS3::new_with_args(aws_s3_params, aws_config).await) + } } } pub async fn build_alert_client( - alert_params: &AlertParams, + alert_params: &AlertValidatedArgs, provider_config: Arc, ) -> Box { match alert_params { - AlertParams::AWSSNS(aws_sns_params) => Box::new(AWSSNS::new_with_params(aws_sns_params, provider_config).await), + AlertValidatedArgs::AWSSNS(aws_sns_params) => { + let aws_config = provider_config.get_aws_client_or_panic(); + Box::new(AWSSNS::new_with_args(aws_sns_params, aws_config).await) + } } } -pub fn build_queue_client(queue_params: &QueueParams) -> Box { +pub async fn build_queue_client( + queue_params: &QueueValidatedArgs, + provider_config: Arc, +) -> Box { match queue_params { - QueueParams::AWSSQS(aws_sqs_params) => Box::new(SqsQueue::new_with_params(aws_sqs_params.clone())), + QueueValidatedArgs::AWSSQS(aws_sqs_params) => { + let aws_config = provider_config.get_aws_client_or_panic(); + Box::new(SqsQueue::new_with_args(aws_sqs_params.clone(), aws_config)) + } } } -pub async fn build_database_client(database_params: &DatabaseParams) -> Box { +pub async fn build_database_client(database_params: &DatabaseValidatedArgs) -> Box { match database_params { - DatabaseParams::MongoDB(mongodb_params) => Box::new(MongoDb::new_with_params(mongodb_params).await), + DatabaseValidatedArgs::MongoDB(mongodb_params) => Box::new(MongoDb::new_with_args(mongodb_params).await), } } diff --git a/crates/orchestrator/src/cron/event_bridge.rs b/crates/orchestrator/src/cron/event_bridge.rs index 9e4c8d35..b9019e5c 100644 --- a/crates/orchestrator/src/cron/event_bridge.rs +++ b/crates/orchestrator/src/cron/event_bridge.rs @@ -1,11 +1,13 @@ use std::time::Duration; use async_trait::async_trait; +use aws_config::SdkConfig; use aws_sdk_eventbridge::types::{InputTransformer, RuleState, Target}; +use aws_sdk_eventbridge::Client as EventBridgeClient; use aws_sdk_sqs::types::QueueAttributeName; +use aws_sdk_sqs::Client as SqsClient; use crate::cron::Cron; -use crate::setup::SetupConfig; #[derive(Clone, Debug)] pub struct AWSEventBridgeValidatedArgs { @@ -14,29 +16,25 @@ pub struct AWSEventBridgeValidatedArgs { pub trigger_rule_name: String, } -pub struct AWSEventBridge {} +pub struct AWSEventBridge { + client: EventBridgeClient, + queue_client: SqsClient, +} impl AWSEventBridge { - pub fn new_with_params(_params: &AWSEventBridgeValidatedArgs) -> Self { - Self {} + pub fn new_with_args(_params: &AWSEventBridgeValidatedArgs, aws_config: &SdkConfig) -> Self { + Self { + client: aws_sdk_eventbridge::Client::new(aws_config), + queue_client: aws_sdk_sqs::Client::new(aws_config), + } } } #[async_trait] #[allow(unreachable_patterns)] impl Cron for AWSEventBridge { - async fn create_cron( - &self, - config: &SetupConfig, - cron_time: Duration, - trigger_rule_name: String, - ) -> color_eyre::Result<()> { - let config = match config { - SetupConfig::AWS(config) => config, - _ => panic!("Unsupported Event Bridge configuration"), - }; - let event_bridge_client = aws_sdk_eventbridge::Client::new(config); - event_bridge_client + async fn create_cron(&self, cron_time: Duration, trigger_rule_name: String) -> color_eyre::Result<()> { + self.client .put_rule() .name(&trigger_rule_name) .schedule_expression(duration_to_rate_string(cron_time)) @@ -48,20 +46,14 @@ impl Cron for AWSEventBridge { } async fn add_cron_target_queue( &self, - config: &SetupConfig, target_queue_name: String, message: String, trigger_rule_name: String, ) -> color_eyre::Result<()> { - let config = match config { - SetupConfig::AWS(config) => config, - _ => panic!("Unsupported Event Bridge configuration"), - }; - let event_bridge_client = aws_sdk_eventbridge::Client::new(config); - let sqs_client = aws_sdk_sqs::Client::new(config); - let queue_url = sqs_client.get_queue_url().queue_name(target_queue_name).send().await?; - - let queue_attributes = sqs_client + let queue_url = self.queue_client.get_queue_url().queue_name(target_queue_name).send().await?; + + let queue_attributes = self + .queue_client .get_queue_attributes() .queue_url(queue_url.queue_url.unwrap()) .attribute_names(QueueAttributeName::QueueArn) @@ -73,7 +65,7 @@ impl Cron for AWSEventBridge { let input_transformer = InputTransformer::builder().input_paths_map("$.time", "time").input_template(message).build()?; - event_bridge_client + self.client .put_targets() .rule(trigger_rule_name) .targets( diff --git a/crates/orchestrator/src/cron/mod.rs b/crates/orchestrator/src/cron/mod.rs index 251dc0fa..c8a4c4ed 100644 --- a/crates/orchestrator/src/cron/mod.rs +++ b/crates/orchestrator/src/cron/mod.rs @@ -5,13 +5,12 @@ use event_bridge::AWSEventBridgeValidatedArgs; use lazy_static::lazy_static; use crate::queue::job_queue::{WorkerTriggerMessage, WorkerTriggerType}; -use crate::setup::SetupConfig; pub mod event_bridge; #[derive(Clone, Debug)] -pub enum CronParams { - EventBridge(AWSEventBridgeValidatedArgs), +pub enum CronValidatedArgs { + AWSEventBridge(AWSEventBridgeValidatedArgs), } lazy_static! { @@ -29,24 +28,17 @@ lazy_static! { #[async_trait] pub trait Cron { - async fn create_cron( - &self, - config: &SetupConfig, - cron_time: Duration, - trigger_rule_name: String, - ) -> color_eyre::Result<()>; + async fn create_cron(&self, cron_time: Duration, trigger_rule_name: String) -> color_eyre::Result<()>; async fn add_cron_target_queue( &self, - config: &SetupConfig, target_queue_name: String, message: String, trigger_rule_name: String, ) -> color_eyre::Result<()>; - async fn setup(&self, config: SetupConfig) -> color_eyre::Result<()> { - self.create_cron(&config, *CRON_DURATION, WORKER_TRIGGER_RULE_NAME.clone()).await?; + async fn setup(&self) -> color_eyre::Result<()> { + self.create_cron(*CRON_DURATION, WORKER_TRIGGER_RULE_NAME.clone()).await?; for triggers in WORKER_TRIGGERS.iter() { self.add_cron_target_queue( - &config, TARGET_QUEUE_NAME.clone(), get_worker_trigger_message(triggers.clone())?, WORKER_TRIGGER_RULE_NAME.clone(), diff --git a/crates/orchestrator/src/data_storage/aws_s3/mod.rs b/crates/orchestrator/src/data_storage/aws_s3/mod.rs index d07c5c0e..0ca6a3f9 100644 --- a/crates/orchestrator/src/data_storage/aws_s3/mod.rs +++ b/crates/orchestrator/src/data_storage/aws_s3/mod.rs @@ -1,12 +1,10 @@ -use std::sync::Arc; - use async_trait::async_trait; +use aws_config::SdkConfig; use aws_sdk_s3::primitives::ByteStream; use aws_sdk_s3::Client; use bytes::Bytes; use color_eyre::Result; -use crate::config::ProviderConfig; use crate::data_storage::DataStorage; pub const S3_SETTINGS_NAME: &str = "s3"; @@ -27,8 +25,7 @@ pub struct AWSS3 { /// - initializing a new AWS S3 client impl AWSS3 { /// To init the struct with main settings - pub async fn new_with_params(s3_config: &AWSS3ValidatedArgs, provider_config: Arc) -> Self { - let aws_config = provider_config.get_aws_client_or_panic(); + pub async fn new_with_args(s3_config: &AWSS3ValidatedArgs, aws_config: &SdkConfig) -> Self { // Building AWS S3 config let mut s3_config_builder = aws_sdk_s3::config::Builder::from(aws_config); // this is necessary for it to work with localstack in test cases diff --git a/crates/orchestrator/src/data_storage/mod.rs b/crates/orchestrator/src/data_storage/mod.rs index eb55c916..2e0e8626 100644 --- a/crates/orchestrator/src/data_storage/mod.rs +++ b/crates/orchestrator/src/data_storage/mod.rs @@ -6,7 +6,7 @@ use bytes::Bytes; use color_eyre::Result; use mockall::automock; -use crate::cli::storage::StorageParams; +use crate::cli::storage::StorageValidatedArgs; /// Data Storage Trait /// @@ -23,9 +23,9 @@ pub trait DataStorage: Send + Sync { async fn get_data(&self, key: &str) -> Result; async fn put_data(&self, data: Bytes, key: &str) -> Result<()>; async fn create_bucket(&self, bucket_name: &str) -> Result<()>; - async fn setup(&self, storage_params: &StorageParams) -> Result<()> { + async fn setup(&self, storage_params: &StorageValidatedArgs) -> Result<()> { match storage_params { - StorageParams::AWSS3(aws_s3_params) => self.create_bucket(&aws_s3_params.bucket_name).await, + StorageValidatedArgs::AWSS3(aws_s3_params) => self.create_bucket(&aws_s3_params.bucket_name).await, } } } diff --git a/crates/orchestrator/src/database/mongodb/mod.rs b/crates/orchestrator/src/database/mongodb/mod.rs index 5fbcf380..da644111 100644 --- a/crates/orchestrator/src/database/mongodb/mod.rs +++ b/crates/orchestrator/src/database/mongodb/mod.rs @@ -31,7 +31,7 @@ pub struct MongoDb { } impl MongoDb { - pub async fn new_with_params(mongodb_params: &MongoDBValidatedArgs) -> Self { + pub async fn new_with_args(mongodb_params: &MongoDBValidatedArgs) -> Self { let mut client_options = ClientOptions::parse(mongodb_params.connection_url.clone()).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 diff --git a/crates/orchestrator/src/queue/mod.rs b/crates/orchestrator/src/queue/mod.rs index 8db89562..3d8c7499 100644 --- a/crates/orchestrator/src/queue/mod.rs +++ b/crates/orchestrator/src/queue/mod.rs @@ -13,7 +13,6 @@ use strum_macros::Display; use crate::config::Config; use crate::jobs::JobError; -use crate::setup::SetupConfig; #[derive(Display, Debug, Clone, PartialEq, Eq)] pub enum QueueType { @@ -136,11 +135,11 @@ pub trait QueueProvider: Send + Sync { async fn send_message_to_queue(&self, queue: QueueType, payload: String, delay: Option) -> EyreResult<()>; async fn consume_message_from_queue(&self, queue: QueueType) -> std::result::Result; - async fn create_queue(&self, queue_config: &QueueConfig, config: &SetupConfig) -> EyreResult<()>; - async fn setup(&self, config: SetupConfig) -> EyreResult<()> { + async fn create_queue(&self, queue_config: &QueueConfig) -> EyreResult<()>; + async fn setup(&self) -> EyreResult<()> { // Creating the queues : for queue in QUEUES.iter() { - self.create_queue(queue, &config).await?; + self.create_queue(queue).await?; } Ok(()) } diff --git a/crates/orchestrator/src/queue/sqs/mod.rs b/crates/orchestrator/src/queue/sqs/mod.rs index bffa8b8b..54a18e16 100644 --- a/crates/orchestrator/src/queue/sqs/mod.rs +++ b/crates/orchestrator/src/queue/sqs/mod.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::time::Duration; use async_trait::async_trait; +use aws_config::SdkConfig; use aws_sdk_sqs::types::QueueAttributeName; use aws_sdk_sqs::Client; use color_eyre::eyre::eyre; @@ -12,7 +13,6 @@ use serde::Serialize; use super::QueueType; use crate::queue::{QueueConfig, QueueProvider}; -use crate::setup::SetupConfig; #[derive(Debug, Clone, Serialize)] pub struct AWSSQSValidatedArgs { @@ -21,7 +21,25 @@ pub struct AWSSQSValidatedArgs { pub sqs_suffix: String, } -impl AWSSQSValidatedArgs { +pub struct SqsQueue { + client: Client, + queue_base_url: String, + sqs_prefix: String, + sqs_suffix: String, +} + +impl SqsQueue { + pub fn new_with_args(params: AWSSQSValidatedArgs, aws_config: &SdkConfig) -> Self { + let sqs_config_builder = aws_sdk_sqs::config::Builder::from(aws_config); + let client = Client::from_conf(sqs_config_builder.build()); + Self { + client, + queue_base_url: params.queue_base_url, + sqs_prefix: params.sqs_prefix, + sqs_suffix: params.sqs_suffix, + } + } + pub fn get_queue_url(&self, queue_type: QueueType) -> String { let name = format!("{}/{}", self.queue_base_url, self.get_queue_name(queue_type)); name @@ -32,21 +50,11 @@ impl AWSSQSValidatedArgs { } } -pub struct SqsQueue { - pub params: AWSSQSValidatedArgs, -} - -impl SqsQueue { - pub fn new_with_params(params: AWSSQSValidatedArgs) -> Self { - Self { params } - } -} - #[allow(unreachable_patterns)] #[async_trait] impl QueueProvider for SqsQueue { async fn send_message_to_queue(&self, queue: QueueType, payload: String, delay: Option) -> Result<()> { - let queue_url = self.params.get_queue_url(queue); + let queue_url = self.get_queue_url(queue); let producer = get_producer(queue_url).await?; match delay { @@ -58,19 +66,13 @@ impl QueueProvider for SqsQueue { } async fn consume_message_from_queue(&self, queue: QueueType) -> std::result::Result { - let queue_url = self.params.get_queue_url(queue); + let queue_url = self.get_queue_url(queue); let mut consumer = get_consumer(queue_url).await?; consumer.receive().await } - async fn create_queue(&self, queue_config: &QueueConfig, config: &SetupConfig) -> Result<()> { - let config = match config { - SetupConfig::AWS(config) => config, - _ => panic!("Unsupported SQS configuration"), - }; - let sqs_client = Client::new(config); - let res = - sqs_client.create_queue().queue_name(self.params.get_queue_name(queue_config.name.clone())).send().await?; + async fn create_queue(&self, queue_config: &QueueConfig) -> Result<()> { + let res = self.client.create_queue().queue_name(self.get_queue_name(queue_config.name.clone())).send().await?; let queue_url = res.queue_url().ok_or_else(|| eyre!("Not able to get queue url from result"))?; let mut attributes = HashMap::new(); @@ -78,11 +80,11 @@ impl QueueProvider for SqsQueue { if let Some(dlq_config) = &queue_config.dlq_config { let dlq_url = Self::get_queue_url_from_client( - self.params.get_queue_name(dlq_config.dlq_name.clone()).as_str(), - &sqs_client, + self.get_queue_name(dlq_config.dlq_name.clone()).as_str(), + &self.client, ) .await?; - let dlq_arn = Self::get_queue_arn(&sqs_client, &dlq_url).await?; + let dlq_arn = Self::get_queue_arn(&self.client, &dlq_url).await?; let policy = format!( r#"{{"deadLetterTargetArn":"{}","maxReceiveCount":"{}"}}"#, dlq_arn, &dlq_config.max_receive_count @@ -90,7 +92,7 @@ impl QueueProvider for SqsQueue { attributes.insert(QueueAttributeName::RedrivePolicy, policy); } - sqs_client.set_queue_attributes().queue_url(queue_url).set_attributes(Some(attributes)).send().await?; + self.client.set_queue_attributes().queue_url(queue_url).set_attributes(Some(attributes)).send().await?; Ok(()) } diff --git a/crates/orchestrator/src/setup/mod.rs b/crates/orchestrator/src/setup/mod.rs index 5ad754eb..46322b25 100644 --- a/crates/orchestrator/src/setup/mod.rs +++ b/crates/orchestrator/src/setup/mod.rs @@ -1,20 +1,16 @@ use std::process::Command; -use std::sync::Arc; -use aws_config::environment::EnvironmentVariableCredentialsProvider; -use aws_config::{from_env, Region, SdkConfig}; -use aws_credential_types::provider::ProvideCredentials; +use aws_config::SdkConfig; use crate::alerts::aws_sns::AWSSNS; use crate::alerts::Alerts; -use crate::cli::alert::AlertParams; -use crate::cli::aws_config::AWSConfigParams; -use crate::cli::queue::QueueParams; -use crate::cli::storage::StorageParams; +use crate::cli::alert::AlertValidatedArgs; +use crate::cli::queue::QueueValidatedArgs; +use crate::cli::storage::StorageValidatedArgs; use crate::cli::RunCmd; -use crate::config::{get_aws_config, ProviderConfig}; +use crate::config::build_provider_config; use crate::cron::event_bridge::AWSEventBridge; -use crate::cron::{Cron, CronParams}; +use crate::cron::{Cron, CronValidatedArgs}; use crate::data_storage::aws_s3::AWSS3; use crate::data_storage::DataStorage; use crate::queue::sqs::SqsQueue; @@ -25,33 +21,20 @@ pub enum SetupConfig { AWS(SdkConfig), } -pub enum ConfigType { - AWS(AWSConfigParams), -} - -async fn setup_config_from_params(client_type: ConfigType) -> SetupConfig { - match client_type { - ConfigType::AWS(aws_config) => { - let region_provider = Region::new(aws_config.aws_region); - let creds = EnvironmentVariableCredentialsProvider::new().provide_credentials().await.unwrap(); - SetupConfig::AWS(from_env().region(region_provider).credentials_provider(creds).load().await) - } - } -} - // TODO : move this to main.rs after moving to clap. pub async fn setup_cloud(run_cmd: &RunCmd) -> color_eyre::Result<()> { println!("Setting up cloud."); - let aws_config = run_cmd.validate_aws_config_params().expect("Failed to validate AWS config params"); - let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(&aws_config).await))); + let provider_params = run_cmd.validate_provider_params().expect("Failed to validate provider params"); + let provider_config = build_provider_config(&provider_params).await; println!("Setting up data storage."); let data_storage_params = run_cmd.validate_storage_params().expect("Failed to validate storage params"); + let aws_config = provider_config.get_aws_client_or_panic(); match data_storage_params { - StorageParams::AWSS3(aws_s3_params) => { - let s3 = Box::new(AWSS3::new_with_params(&aws_s3_params, provider_config.clone()).await); - s3.setup(&StorageParams::AWSS3(aws_s3_params.clone())).await? + StorageValidatedArgs::AWSS3(aws_s3_params) => { + let s3 = Box::new(AWSS3::new_with_args(&aws_s3_params, aws_config).await); + s3.setup(&StorageValidatedArgs::AWSS3(aws_s3_params.clone())).await? } } println!("Data storage setup completed ✅"); @@ -59,10 +42,9 @@ pub async fn setup_cloud(run_cmd: &RunCmd) -> color_eyre::Result<()> { println!("Setting up queues"); let queue_params = run_cmd.validate_queue_params().expect("Failed to validate queue params"); match queue_params { - QueueParams::AWSSQS(aws_sqs_params) => { - let config = setup_config_from_params(ConfigType::AWS(aws_config.clone())).await; - let sqs = Box::new(SqsQueue::new_with_params(aws_sqs_params)); - sqs.setup(config).await? + QueueValidatedArgs::AWSSQS(aws_sqs_params) => { + let sqs = Box::new(SqsQueue::new_with_args(aws_sqs_params, aws_config)); + sqs.setup().await? } } println!("Queues setup completed ✅"); @@ -70,10 +52,10 @@ pub async fn setup_cloud(run_cmd: &RunCmd) -> color_eyre::Result<()> { println!("Setting up cron"); let cron_params = run_cmd.validate_cron_params().expect("Failed to validate cron params"); match cron_params { - CronParams::EventBridge(aws_event_bridge_params) => { - let config = setup_config_from_params(ConfigType::AWS(aws_config)).await; - let event_bridge = Box::new(AWSEventBridge::new_with_params(&aws_event_bridge_params)); - event_bridge.setup(config).await? + CronValidatedArgs::AWSEventBridge(aws_event_bridge_params) => { + let aws_config = provider_config.get_aws_client_or_panic(); + let event_bridge = Box::new(AWSEventBridge::new_with_args(&aws_event_bridge_params, aws_config)); + event_bridge.setup().await? } } println!("Cron setup completed ✅"); @@ -81,9 +63,10 @@ pub async fn setup_cloud(run_cmd: &RunCmd) -> color_eyre::Result<()> { println!("Setting up alerts."); let alert_params = run_cmd.validate_alert_params().expect("Failed to validate alert params"); match alert_params { - AlertParams::AWSSNS(aws_sns_params) => { - let sns = Box::new(AWSSNS::new_with_params(&aws_sns_params, provider_config).await); - sns.setup(AlertParams::AWSSNS(aws_sns_params.clone())).await? + AlertValidatedArgs::AWSSNS(aws_sns_params) => { + let aws_config = provider_config.get_aws_client_or_panic(); + let sns = Box::new(AWSSNS::new_with_args(&aws_sns_params, aws_config).await); + sns.setup().await? } } println!("Alerts setup completed ✅"); diff --git a/crates/orchestrator/src/tests/common/mod.rs b/crates/orchestrator/src/tests/common/mod.rs index f07da191..5c1a9703 100644 --- a/crates/orchestrator/src/tests/common/mod.rs +++ b/crates/orchestrator/src/tests/common/mod.rs @@ -12,9 +12,9 @@ use mongodb::Client; use rstest::*; use serde::Deserialize; -use crate::cli::alert::AlertParams; -use crate::cli::database::DatabaseParams; -use crate::cli::queue::QueueParams; +use crate::cli::alert::AlertValidatedArgs; +use crate::cli::database::DatabaseValidatedArgs; +use crate::cli::queue::QueueValidatedArgs; use crate::config::ProviderConfig; use crate::data_storage::aws_s3::{AWSS3ValidatedArgs, AWSS3}; use crate::data_storage::DataStorage; @@ -49,11 +49,11 @@ pub fn custom_job_item(default_job_item: JobItem, #[default(String::from("0"))] pub async fn create_sns_arn( provider_config: Arc, - alert_params: &AlertParams, + alert_params: &AlertValidatedArgs, ) -> Result<(), SdkError> { - let AlertParams::AWSSNS(aws_sns_params) = alert_params; + let AlertValidatedArgs::AWSSNS(aws_sns_params) = alert_params; let sns_client = get_sns_client(provider_config.get_aws_client_or_panic()).await; - sns_client.create_topic().name(aws_sns_params.get_topic_name()).send().await?; + sns_client.create_topic().name(aws_sns_params.topic_arn.clone()).send().await?; Ok(()) } @@ -61,10 +61,10 @@ pub async fn get_sns_client(aws_config: &SdkConfig) -> aws_sdk_sns::client::Clie aws_sdk_sns::Client::new(aws_config) } -pub async fn drop_database(database_params: &DatabaseParams) -> color_eyre::Result<()> { +pub async fn drop_database(database_params: &DatabaseValidatedArgs) -> color_eyre::Result<()> { match database_params { - DatabaseParams::MongoDB(mongodb_params) => { - let db_client: Client = MongoDb::new_with_params(mongodb_params).await.client(); + DatabaseValidatedArgs::MongoDB(mongodb_params) => { + let db_client: Client = MongoDb::new_with_args(mongodb_params).await.client(); // dropping all the collection. // use .collection::("") // if only particular collection is to be dropped @@ -76,9 +76,12 @@ pub async fn drop_database(database_params: &DatabaseParams) -> color_eyre::Resu // SQS structs & functions -pub async fn create_queues(provider_config: Arc, queue_params: &QueueParams) -> color_eyre::Result<()> { +pub async fn create_queues( + provider_config: Arc, + queue_params: &QueueValidatedArgs, +) -> color_eyre::Result<()> { match queue_params { - QueueParams::AWSSQS(aws_sqs_params) => { + QueueValidatedArgs::AWSSQS(aws_sqs_params) => { let sqs_client = get_sqs_client(provider_config).await; // Dropping sqs queues @@ -93,7 +96,7 @@ pub async fn create_queues(provider_config: Arc, queue_params: & } for queue_type in QueueType::iter() { - let queue_name = aws_sqs_params.get_queue_name(queue_type); + let queue_name = format!("{}_{}_{}", aws_sqs_params.sqs_prefix, queue_type, aws_sqs_params.sqs_suffix); sqs_client.create_queue().queue_name(queue_name).send().await?; } } @@ -116,5 +119,6 @@ pub async fn get_storage_client( storage_cfg: &AWSS3ValidatedArgs, provider_config: Arc, ) -> Box { - Box::new(AWSS3::new_with_params(storage_cfg, provider_config).await) + let aws_config = provider_config.get_aws_client_or_panic(); + Box::new(AWSS3::new_with_args(storage_cfg, aws_config).await) } diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 786c45ca..9a677897 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -18,15 +18,15 @@ use utils::env_utils::{get_env_var_optional, get_env_var_or_default, get_env_var use crate::alerts::aws_sns::AWSSNSValidatedArgs; use crate::alerts::Alerts; -use crate::cli::alert::AlertParams; -use crate::cli::aws_config::AWSConfigParams; -use crate::cli::da::DaParams; -use crate::cli::database::DatabaseParams; -use crate::cli::prover::ProverParams; -use crate::cli::queue::QueueParams; -use crate::cli::settlement::SettlementParams; +use crate::cli::alert::AlertValidatedArgs; +use crate::cli::da::DaValidatedArgs; +use crate::cli::database::DatabaseValidatedArgs; +use crate::cli::prover::ProverValidatedArgs; +use crate::cli::provider::aws::AWSConfigValidatedArgs; +use crate::cli::queue::QueueValidatedArgs; +use crate::cli::settlement::SettlementValidatedArgs; use crate::cli::snos::SNOSParams; -use crate::cli::storage::StorageParams; +use crate::cli::storage::StorageValidatedArgs; use crate::config::{get_aws_config, Config, OrchestratorParams, ProviderConfig, ServiceParams}; use crate::data_storage::aws_s3::AWSS3ValidatedArgs; use crate::data_storage::{DataStorage, MockDataStorage}; @@ -235,7 +235,8 @@ impl TestConfigBuilder { let database = implement_client::init_database(database_type, ¶ms.db_params).await; - let queue = implement_client::init_queue_client(queue_type, params.queue_params.clone()).await; + let queue = + implement_client::init_queue_client(queue_type, params.queue_params.clone(), provider_config.clone()).await; // Deleting and Creating the queues in sqs. create_queues(provider_config.clone(), ¶ms.queue_params) @@ -302,13 +303,13 @@ pub mod implement_client { use super::{ConfigType, MockType}; use crate::alerts::{Alerts, MockAlerts}; - use crate::cli::alert::AlertParams; - use crate::cli::da::DaParams; - use crate::cli::database::DatabaseParams; - use crate::cli::prover::ProverParams; - use crate::cli::queue::QueueParams; - use crate::cli::settlement::SettlementParams; - use crate::cli::storage::StorageParams; + use crate::cli::alert::AlertValidatedArgs; + use crate::cli::da::DaValidatedArgs; + use crate::cli::database::DatabaseValidatedArgs; + use crate::cli::prover::ProverValidatedArgs; + use crate::cli::queue::QueueValidatedArgs; + use crate::cli::settlement::SettlementValidatedArgs; + use crate::cli::storage::StorageValidatedArgs; use crate::config::{ build_alert_client, build_da_client, build_database_client, build_prover_service, build_queue_client, build_settlement_client, ProviderConfig, @@ -340,7 +341,7 @@ pub mod implement_client { implement_mock_client_conversion!(SettlementClient, SettlementClient); implement_mock_client_conversion!(DaClient, DaClient); - pub(crate) async fn init_da_client(service: ConfigType, da_params: &DaParams) -> Box { + pub(crate) async fn init_da_client(service: ConfigType, da_params: &DaValidatedArgs) -> Box { match service { ConfigType::Mock(client) => client.into(), ConfigType::Actual => build_da_client(da_params).await, @@ -350,7 +351,7 @@ pub mod implement_client { pub(crate) async fn init_settlement_client( service: ConfigType, - settlement_cfg: &SettlementParams, + settlement_cfg: &SettlementValidatedArgs, ) -> Box { match service { ConfigType::Mock(client) => client.into(), @@ -361,7 +362,10 @@ pub mod implement_client { } } - pub(crate) async fn init_prover_client(service: ConfigType, prover_params: &ProverParams) -> Box { + pub(crate) async fn init_prover_client( + service: ConfigType, + prover_params: &ProverValidatedArgs, + ) -> Box { match service { ConfigType::Mock(client) => client.into(), ConfigType::Actual => build_prover_service(prover_params), @@ -371,7 +375,7 @@ pub mod implement_client { pub(crate) async fn init_alerts( service: ConfigType, - alert_params: &AlertParams, + alert_params: &AlertValidatedArgs, provider_config: Arc, ) -> Box { match service { @@ -383,13 +387,13 @@ pub mod implement_client { pub(crate) async fn init_storage_client( service: ConfigType, - storage_cfg: &StorageParams, + storage_cfg: &StorageValidatedArgs, provider_config: Arc, ) -> Box { match service { ConfigType::Mock(client) => client.into(), ConfigType::Actual => match storage_cfg { - StorageParams::AWSS3(aws_s3_params) => { + StorageValidatedArgs::AWSS3(aws_s3_params) => { let storage = get_storage_client(aws_s3_params, provider_config).await; storage.as_ref().create_bucket(&aws_s3_params.bucket_name).await.unwrap(); storage @@ -399,15 +403,22 @@ pub mod implement_client { } } - pub(crate) async fn init_queue_client(service: ConfigType, queue_params: QueueParams) -> Box { + pub(crate) async fn init_queue_client( + service: ConfigType, + queue_params: QueueValidatedArgs, + provider_config: Arc, + ) -> Box { match service { ConfigType::Mock(client) => client.into(), - ConfigType::Actual => build_queue_client(&queue_params), + ConfigType::Actual => build_queue_client(&queue_params, provider_config).await, ConfigType::Dummy => Box::new(MockQueueProvider::new()), } } - pub(crate) async fn init_database(service: ConfigType, database_params: &DatabaseParams) -> Box { + pub(crate) async fn init_database( + service: ConfigType, + database_params: &DatabaseValidatedArgs, + ) -> Box { match service { ConfigType::Mock(client) => client.into(), ConfigType::Actual => build_database_client(database_params).await, @@ -457,53 +468,51 @@ pub mod implement_client { } struct EnvParams { - aws_params: AWSConfigParams, - alert_params: AlertParams, - queue_params: QueueParams, - storage_params: StorageParams, - db_params: DatabaseParams, - da_params: DaParams, - settlement_params: SettlementParams, - prover_params: ProverParams, + aws_params: AWSConfigValidatedArgs, + alert_params: AlertValidatedArgs, + queue_params: QueueValidatedArgs, + storage_params: StorageValidatedArgs, + db_params: DatabaseValidatedArgs, + da_params: DaValidatedArgs, + settlement_params: SettlementValidatedArgs, + prover_params: ProverValidatedArgs, orchestrator_params: OrchestratorParams, #[allow(dead_code)] instrumentation_params: InstrumentationParams, } fn get_env_params() -> EnvParams { - let db_params = DatabaseParams::MongoDB(MongoDBValidatedArgs { + let db_params = DatabaseValidatedArgs::MongoDB(MongoDBValidatedArgs { connection_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL"), database_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_DATABASE_NAME"), }); - let storage_params = StorageParams::AWSS3(AWSS3ValidatedArgs { + let storage_params = StorageValidatedArgs::AWSS3(AWSS3ValidatedArgs { bucket_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME"), }); - let queue_params = QueueParams::AWSSQS(AWSSQSValidatedArgs { + let queue_params = QueueValidatedArgs::AWSSQS(AWSSQSValidatedArgs { queue_base_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL"), sqs_prefix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_PREFIX"), sqs_suffix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_SUFFIX"), }); - let aws_params = AWSConfigParams { + let aws_params = AWSConfigValidatedArgs { aws_access_key_id: get_env_var_or_panic("AWS_ACCESS_KEY_ID"), aws_secret_access_key: get_env_var_or_panic("AWS_SECRET_ACCESS_KEY"), aws_region: get_env_var_or_panic("AWS_REGION"), - aws_endpoint_url: Url::parse(&get_env_var_or_panic("AWS_ENDPOINT_URL")) - .expect("Failed to parse AWS_ENDPOINT_URL"), - aws_default_region: get_env_var_or_panic("AWS_DEFAULT_REGION"), }; - let da_params = DaParams::Ethereum(EthereumDaValidatedArgs { + let da_params = DaValidatedArgs::Ethereum(EthereumDaValidatedArgs { ethereum_da_rpc_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_DA_RPC_URL")) .expect("Failed to parse MADARA_ORCHESTRATOR_ETHEREUM_RPC_URL"), }); - let alert_params = - AlertParams::AWSSNS(AWSSNSValidatedArgs { sns_arn: get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_SNS_ARN") }); + let alert_params = AlertValidatedArgs::AWSSNS(AWSSNSValidatedArgs { + topic_arn: get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_SNS_ARN"), + }); - let settlement_params = SettlementParams::Ethereum(EthereumSettlementValidatedArgs { + let settlement_params = SettlementValidatedArgs::Ethereum(EthereumSettlementValidatedArgs { ethereum_rpc_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL")) .expect("Failed to parse MADARA_ORCHESTRATOR_ETHEREUM_RPC_URL"), ethereum_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), @@ -547,7 +556,7 @@ fn get_env_params() -> EnvParams { log_level: Level::from_str(&get_env_var_or_default("RUST_LOG", "info")).expect("Failed to parse RUST_LOG"), }; - let prover_params = ProverParams::Sharp(SharpValidatedArgs { + let prover_params = ProverValidatedArgs::Sharp(SharpValidatedArgs { sharp_customer_id: get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID"), sharp_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_URL")) .expect("Failed to parse MADARA_ORCHESTRATOR_SHARP_URL"), diff --git a/crates/prover-services/sharp-service/src/client.rs b/crates/prover-services/sharp-service/src/client.rs index 9a0dd62a..25c1b068 100644 --- a/crates/prover-services/sharp-service/src/client.rs +++ b/crates/prover-services/sharp-service/src/client.rs @@ -28,7 +28,7 @@ impl SharpClient { /// and then copy it and paste it into .env file : /// /// `cat | base64` - pub fn new_with_params(url: Url, sharp_params: &SharpValidatedArgs) -> Self { + pub fn new_with_args(url: Url, sharp_params: &SharpValidatedArgs) -> Self { // Getting the cert files from the .env and then decoding it from base64 let cert = general_purpose::STANDARD diff --git a/crates/prover-services/sharp-service/src/lib.rs b/crates/prover-services/sharp-service/src/lib.rs index f5dc1207..783d4324 100644 --- a/crates/prover-services/sharp-service/src/lib.rs +++ b/crates/prover-services/sharp-service/src/lib.rs @@ -145,8 +145,8 @@ impl SharpProverService { Self { sharp_client, fact_checker } } - pub fn new_with_params(sharp_params: &SharpValidatedArgs) -> Self { - let sharp_client = SharpClient::new_with_params(sharp_params.sharp_url.clone(), sharp_params); + pub fn new_with_args(sharp_params: &SharpValidatedArgs) -> Self { + let sharp_client = SharpClient::new_with_args(sharp_params.sharp_url.clone(), sharp_params); let fact_checker = FactChecker::new( sharp_params.sharp_rpc_node_url.clone(), sharp_params.gps_verifier_contract_address.clone(), @@ -155,7 +155,7 @@ impl SharpProverService { } pub fn with_test_params(port: u16, sharp_params: &SharpValidatedArgs) -> Self { - let sharp_client = SharpClient::new_with_params( + let sharp_client = SharpClient::new_with_args( format!("http://127.0.0.1:{}", port).parse().expect("Failed to create sharp client with the given params"), sharp_params, ); diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index 888441ba..4c32da4c 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -82,7 +82,7 @@ pub struct EthereumSettlementClient { } impl EthereumSettlementClient { - pub fn new_with_params(settlement_cfg: &EthereumSettlementValidatedArgs) -> Self { + pub fn new_with_args(settlement_cfg: &EthereumSettlementValidatedArgs) -> Self { let private_key = settlement_cfg.ethereum_private_key.clone(); let signer: PrivateKeySigner = private_key.parse().expect("Failed to parse private key"); let wallet_address = signer.address(); diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 7b1bb010..2b2bd676 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -59,7 +59,7 @@ pub struct StarknetSettlementValidatedArgs { // https://github.com/keep-starknet-strange/piltover impl StarknetSettlementClient { - pub async fn new_with_params(settlement_cfg: &StarknetSettlementValidatedArgs) -> Self { + pub async fn new_with_args(settlement_cfg: &StarknetSettlementValidatedArgs) -> Self { let provider: Arc> = Arc::new(JsonRpcClient::new(HttpTransport::new(settlement_cfg.starknet_rpc_url.clone()))); diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index fa4c2d22..2bbd0a59 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -170,7 +170,7 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) let is_success = wait_for_tx(&account, deploy_tx_hash, Duration::from_secs(2)).await; assert!(is_success, "Deploy trasaction failed"); - let settlement_client = StarknetSettlementClient::new_with_params(&starknet_settlement_params).await; + let settlement_client = StarknetSettlementClient::new_with_args(&starknet_settlement_params).await; let onchain_data_hash = [1; 32]; let mut program_output = Vec::with_capacity(32); program_output.fill(onchain_data_hash); diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index c1404091..097ab312 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -12,7 +12,7 @@ use e2e_tests::starknet_client::StarknetClient; use e2e_tests::utils::{get_mongo_db_client, read_state_update_from_file, vec_u8_to_hex_string}; use e2e_tests::{MongoDbServer, Orchestrator}; use mongodb::bson::doc; -use orchestrator::cli::database::DatabaseParams; +use orchestrator::cli::database::DatabaseValidatedArgs; use orchestrator::data_storage::DataStorage; use orchestrator::database::mongodb::MongoDBValidatedArgs; use orchestrator::jobs::constants::{JOB_METADATA_SNOS_BLOCK, JOB_METADATA_STATE_UPDATE_BLOCKS_TO_SETTLE_KEY}; @@ -50,12 +50,12 @@ struct Setup { impl Setup { /// Initialise a new setup pub async fn new(l2_block_number: String) -> Self { - let db_params = DatabaseParams::MongoDB(MongoDBValidatedArgs { + let db_params = DatabaseValidatedArgs::MongoDB(MongoDBValidatedArgs { connection_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL"), database_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_DATABASE_NAME"), }); - let DatabaseParams::MongoDB(mongodb_params) = db_params; + let DatabaseValidatedArgs::MongoDB(mongodb_params) = db_params; let mongo_db_instance = MongoDbServer::run(mongodb_params); println!("✅ Mongo DB setup completed"); @@ -290,7 +290,17 @@ pub async fn put_job_data_in_db_snos(mongo_db: &MongoDbServer, l2_block_number: /// as soon as it is picked up by orchestrator pub async fn put_snos_job_in_processing_queue(id: Uuid, queue_params: AWSSQSValidatedArgs) -> color_eyre::Result<()> { let message = JobQueueMessage { id }; - put_message_in_queue(message, queue_params.get_queue_url(QueueType::SnosJobProcessing)).await?; + put_message_in_queue( + message, + format!( + "{}/{}_{}_{}", + queue_params.queue_base_url, + queue_params.sqs_prefix, + QueueType::SnosJobProcessing, + queue_params.sqs_suffix + ), + ) + .await?; Ok(()) } From a79aaeb1d6abaa48314102a5abba98e6e32af9ae Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 13 Nov 2024 14:37:35 +0530 Subject: [PATCH 52/63] update: ProviderValidatedArgs --- crates/orchestrator/src/cli/cron/mod.rs | 7 ++++--- crates/orchestrator/src/cli/mod.rs | 6 +++--- crates/orchestrator/src/cli/provider/aws.rs | 7 ------- crates/orchestrator/src/cli/provider/mod.rs | 8 +++++++- crates/orchestrator/src/config.rs | 3 +-- crates/orchestrator/src/cron/mod.rs | 5 ----- crates/orchestrator/src/setup/mod.rs | 3 ++- crates/orchestrator/src/tests/config.rs | 2 +- 8 files changed, 18 insertions(+), 23 deletions(-) diff --git a/crates/orchestrator/src/cli/cron/mod.rs b/crates/orchestrator/src/cli/cron/mod.rs index f1b9e35a..2b40c5ae 100644 --- a/crates/orchestrator/src/cli/cron/mod.rs +++ b/crates/orchestrator/src/cli/cron/mod.rs @@ -1,8 +1,9 @@ -use crate::alerts::aws_sns::AWSSNSValidatedArgs; +use crate::cron::event_bridge::AWSEventBridgeValidatedArgs; + pub mod event_bridge; #[derive(Clone, Debug)] pub enum CronValidatedArgs { - AWSSNS(AWSSNSValidatedArgs), -} + AWSEventBridge(AWSEventBridgeValidatedArgs), +} \ No newline at end of file diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index a5b42a5a..2a68552d 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -3,13 +3,14 @@ use std::time::Duration; use alert::AlertValidatedArgs; use clap::{ArgGroup, Parser}; use cron::event_bridge::AWSEventBridgeCliArgs; +use cron::CronValidatedArgs; use da::DaValidatedArgs; use database::DatabaseValidatedArgs; use ethereum_da_client::EthereumDaValidatedArgs; use ethereum_settlement_client::EthereumSettlementValidatedArgs; use prover::ProverValidatedArgs; -use provider::aws::{AWSConfigCliArgs, AWSConfigValidatedArgs}; -use provider::ProviderValidatedArgs; +use provider::aws::AWSConfigCliArgs; +use provider::{AWSConfigValidatedArgs, ProviderValidatedArgs}; use queue::QueueValidatedArgs; use settlement::SettlementValidatedArgs; use sharp_service::SharpValidatedArgs; @@ -21,7 +22,6 @@ use url::Url; use crate::alerts::aws_sns::AWSSNSValidatedArgs; use crate::config::ServiceParams; use crate::cron::event_bridge::AWSEventBridgeValidatedArgs; -use crate::cron::CronValidatedArgs; use crate::data_storage::aws_s3::AWSS3ValidatedArgs; use crate::database::mongodb::MongoDBValidatedArgs; use crate::queue::sqs::AWSSQSValidatedArgs; diff --git a/crates/orchestrator/src/cli/provider/aws.rs b/crates/orchestrator/src/cli/provider/aws.rs index b7f00b9a..a3bb6ac6 100644 --- a/crates/orchestrator/src/cli/provider/aws.rs +++ b/crates/orchestrator/src/cli/provider/aws.rs @@ -21,10 +21,3 @@ pub struct AWSConfigCliArgs { #[arg(env = "AWS_REGION", long)] pub aws_region: String, } - -#[derive(Debug, Clone)] -pub struct AWSConfigValidatedArgs { - pub aws_access_key_id: String, - pub aws_secret_access_key: String, - pub aws_region: String, -} diff --git a/crates/orchestrator/src/cli/provider/mod.rs b/crates/orchestrator/src/cli/provider/mod.rs index e4080548..ae8d93f5 100644 --- a/crates/orchestrator/src/cli/provider/mod.rs +++ b/crates/orchestrator/src/cli/provider/mod.rs @@ -1,8 +1,14 @@ pub mod aws; -use aws::AWSConfigValidatedArgs; #[derive(Debug, Clone)] pub enum ProviderValidatedArgs { AWS(AWSConfigValidatedArgs), } + +#[derive(Debug, Clone)] +pub struct AWSConfigValidatedArgs { + pub aws_access_key_id: String, + pub aws_secret_access_key: String, + pub aws_region: String, +} diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 67788398..5475d805 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -27,8 +27,7 @@ use crate::cli::alert::AlertValidatedArgs; use crate::cli::da::DaValidatedArgs; use crate::cli::database::DatabaseValidatedArgs; use crate::cli::prover::ProverValidatedArgs; -use crate::cli::provider::aws::AWSConfigValidatedArgs; -use crate::cli::provider::ProviderValidatedArgs; +use crate::cli::provider::{AWSConfigValidatedArgs, ProviderValidatedArgs}; use crate::cli::queue::QueueValidatedArgs; use crate::cli::settlement::SettlementValidatedArgs; use crate::cli::snos::SNOSParams; diff --git a/crates/orchestrator/src/cron/mod.rs b/crates/orchestrator/src/cron/mod.rs index c8a4c4ed..d3ad7a4c 100644 --- a/crates/orchestrator/src/cron/mod.rs +++ b/crates/orchestrator/src/cron/mod.rs @@ -1,17 +1,12 @@ use std::time::Duration; use async_trait::async_trait; -use event_bridge::AWSEventBridgeValidatedArgs; use lazy_static::lazy_static; use crate::queue::job_queue::{WorkerTriggerMessage, WorkerTriggerType}; pub mod event_bridge; -#[derive(Clone, Debug)] -pub enum CronValidatedArgs { - AWSEventBridge(AWSEventBridgeValidatedArgs), -} lazy_static! { pub static ref CRON_DURATION: Duration = Duration::from_mins(1); diff --git a/crates/orchestrator/src/setup/mod.rs b/crates/orchestrator/src/setup/mod.rs index 46322b25..42e2d51b 100644 --- a/crates/orchestrator/src/setup/mod.rs +++ b/crates/orchestrator/src/setup/mod.rs @@ -5,12 +5,13 @@ use aws_config::SdkConfig; use crate::alerts::aws_sns::AWSSNS; use crate::alerts::Alerts; use crate::cli::alert::AlertValidatedArgs; +use crate::cli::cron::CronValidatedArgs; use crate::cli::queue::QueueValidatedArgs; use crate::cli::storage::StorageValidatedArgs; use crate::cli::RunCmd; use crate::config::build_provider_config; use crate::cron::event_bridge::AWSEventBridge; -use crate::cron::{Cron, CronValidatedArgs}; +use crate::cron::Cron; use crate::data_storage::aws_s3::AWSS3; use crate::data_storage::DataStorage; use crate::queue::sqs::SqsQueue; diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 9a677897..20bd1d06 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -22,7 +22,7 @@ use crate::cli::alert::AlertValidatedArgs; use crate::cli::da::DaValidatedArgs; use crate::cli::database::DatabaseValidatedArgs; use crate::cli::prover::ProverValidatedArgs; -use crate::cli::provider::aws::AWSConfigValidatedArgs; +use crate::cli::provider::AWSConfigValidatedArgs; use crate::cli::queue::QueueValidatedArgs; use crate::cli::settlement::SettlementValidatedArgs; use crate::cli::snos::SNOSParams; From 1a60dc2a5143af23b96ee27ce7ad4cdacee3b596 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 13 Nov 2024 15:46:15 +0530 Subject: [PATCH 53/63] update: reworked commands run and setup --- crates/orchestrator/src/cli/cron/mod.rs | 3 +- crates/orchestrator/src/cli/mod.rs | 555 ++++++++++++-------- crates/orchestrator/src/cli/provider/mod.rs | 1 - crates/orchestrator/src/cron/mod.rs | 1 - crates/orchestrator/src/main.rs | 27 +- crates/orchestrator/src/setup/mod.rs | 9 +- 6 files changed, 357 insertions(+), 239 deletions(-) diff --git a/crates/orchestrator/src/cli/cron/mod.rs b/crates/orchestrator/src/cli/cron/mod.rs index 2b40c5ae..19e8a5cf 100644 --- a/crates/orchestrator/src/cli/cron/mod.rs +++ b/crates/orchestrator/src/cli/cron/mod.rs @@ -1,9 +1,8 @@ use crate::cron::event_bridge::AWSEventBridgeValidatedArgs; - pub mod event_bridge; #[derive(Clone, Debug)] pub enum CronValidatedArgs { AWSEventBridge(AWSEventBridgeValidatedArgs), -} \ No newline at end of file +} diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index 2a68552d..edef75e0 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -1,7 +1,7 @@ use std::time::Duration; use alert::AlertValidatedArgs; -use clap::{ArgGroup, Parser}; +use clap::{ArgGroup, Parser, Subcommand}; use cron::event_bridge::AWSEventBridgeCliArgs; use cron::CronValidatedArgs; use da::DaValidatedArgs; @@ -42,16 +42,29 @@ pub mod settlement; pub mod snos; pub mod storage; +#[derive(Parser, Debug)] +pub struct Cli { + #[command(subcommand)] + pub command: Commands, +} + +#[derive(Subcommand, Debug)] +pub enum Commands { + /// Run the orchestrator + Run { + #[command(flatten)] + run_command: Box, + }, + /// Setup the orchestrator + Setup { + #[command(flatten)] + setup_command: Box, + }, +} + #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] #[clap( - group( - ArgGroup::new("mode") - .args(&["run", "setup"]) - .required(true) - .multiple(false) - ), - group( ArgGroup::new("provider") .args(&["aws"]) @@ -69,18 +82,21 @@ pub mod storage; .args(&["aws_s3"]) .required(true) .multiple(false) + .requires("provider") ), group( ArgGroup::new("queue") .args(&["aws_sqs"]) .required(true) .multiple(false) + .requires("provider") ), group( ArgGroup::new("alert") .args(&["aws_sns"]) .required(true) .multiple(false) + .requires("provider") ), group( ArgGroup::new("prover") @@ -94,21 +110,8 @@ pub mod storage; .required(true) .multiple(false) ), - group( - ArgGroup::new("cron") - .args(&["aws_event_bridge"]) - .required(true) - .multiple(false) - ), )] pub struct RunCmd { - // Run mode - #[arg(long)] - pub run: bool, - - #[arg(long)] - pub setup: bool, - // AWS Config #[clap(flatten)] pub aws_config_args: AWSConfigCliArgs, @@ -148,10 +151,6 @@ pub struct RunCmd { #[clap(flatten)] pub sharp_args: prover::sharp::SharpCliArgs, - // Cron - #[clap(flatten)] - pub aws_event_bridge_args: AWSEventBridgeCliArgs, - // SNOS #[clap(flatten)] pub snos_args: snos::SNOSCliArgs, @@ -334,33 +333,6 @@ impl RunCmd { } } - pub fn validate_cron_params(&self) -> Result { - if self.aws_event_bridge_args.aws_event_bridge { - Ok(CronValidatedArgs::AWSEventBridge(AWSEventBridgeValidatedArgs { - target_queue_name: self - .aws_event_bridge_args - .target_queue_name - .clone() - .expect("Target queue name is required"), - cron_time: Duration::from_secs( - self.aws_event_bridge_args - .cron_time - .clone() - .expect("Cron time is required") - .parse::() - .expect("Failed to parse cron time"), - ), - trigger_rule_name: self - .aws_event_bridge_args - .trigger_rule_name - .clone() - .expect("Trigger rule name is required"), - })) - } else { - Err("Only AWS Event Bridge is supported as of now".to_string()) - } - } - pub fn validate_instrumentation_params(&self) -> Result { Ok(InstrumentationParams { otel_service_name: self @@ -394,192 +366,323 @@ impl RunCmd { } } -#[cfg(test)] -pub mod test { - - use rstest::{fixture, rstest}; - use tracing::Level; - use url::Url; - - use super::alert::aws_sns::AWSSNSCliArgs; - use super::cron::event_bridge::AWSEventBridgeCliArgs; - use super::da::ethereum::EthereumDaCliArgs; - use super::database::mongodb::MongoDBCliArgs; - use super::instrumentation::InstrumentationCliArgs; - use super::prover::sharp::SharpCliArgs; - use super::provider::aws::AWSConfigCliArgs; - use super::queue::aws_sqs::AWSSQSCliArgs; - use super::server::ServerCliArgs; - use super::service::ServiceCliArgs; - use super::settlement::ethereum::EthereumSettlementCliArgs; - use super::settlement::starknet::StarknetSettlementCliArgs; - use super::snos::SNOSCliArgs; - use super::storage::aws_s3::AWSS3CliArgs; - use crate::cli::RunCmd; - - // create a fixture for the CLI - #[fixture] - pub fn setup_cmd() -> RunCmd { - RunCmd { - run: true, - setup: false, - aws_config_args: AWSConfigCliArgs { - aws: true, - aws_access_key_id: "".to_string(), - aws_secret_access_key: "".to_string(), - aws_region: "".to_string(), - }, - aws_event_bridge_args: AWSEventBridgeCliArgs { - aws_event_bridge: true, - target_queue_name: Some("".to_string()), - cron_time: Some("12".to_string()), - trigger_rule_name: Some("".to_string()), - }, - aws_s3_args: AWSS3CliArgs { aws_s3: true, bucket_name: Some("".to_string()) }, - aws_sqs_args: AWSSQSCliArgs { - aws_sqs: true, - queue_base_url: Some("".to_string()), - sqs_prefix: Some("".to_string()), - sqs_suffix: Some("".to_string()), - }, - server_args: ServerCliArgs { host: "".to_string(), port: 0 }, - aws_sns_args: AWSSNSCliArgs { aws_sns: true, sns_arn: Some("".to_string()) }, - - instrumentation_args: InstrumentationCliArgs { - otel_service_name: Some("".to_string()), - otel_collector_endpoint: None, - log_level: Level::INFO, - }, - - mongodb_args: MongoDBCliArgs { - mongodb: true, - mongodb_connection_url: Some("".to_string()), - mongodb_database_name: Some("".to_string()), - }, - - madara_rpc_url: Url::parse("http://localhost:8545").unwrap(), - - sharp_args: SharpCliArgs { - sharp: true, - sharp_customer_id: Some("".to_string()), - sharp_url: Some(Url::parse("http://localhost:8545").unwrap()), - sharp_user_crt: Some("".to_string()), - sharp_user_key: Some("".to_string()), - sharp_rpc_node_url: Some(Url::parse("http://localhost:8545").unwrap()), - sharp_proof_layout: Some("".to_string()), - gps_verifier_contract_address: Some("".to_string()), - sharp_server_crt: Some("".to_string()), - }, - - starknet_args: StarknetSettlementCliArgs { - starknet_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), - starknet_private_key: Some("".to_string()), - starknet_account_address: Some("".to_string()), - starknet_cairo_core_contract_address: Some("".to_string()), - starknet_finality_retry_wait_in_secs: Some(0), - starknet_madara_binary_path: Some("".to_string()), - settle_on_starknet: false, - }, - - ethereum_args: EthereumSettlementCliArgs { - ethereum_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), - ethereum_private_key: Some("".to_string()), - l1_core_contract_address: Some("".to_string()), - starknet_operator_address: Some("".to_string()), - settle_on_ethereum: true, - }, - - ethereum_da_args: EthereumDaCliArgs { - da_on_ethereum: true, - ethereum_da_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), - }, - - snos_args: SNOSCliArgs { rpc_for_snos: Url::parse("http://localhost:8545").unwrap() }, - - service_args: ServiceCliArgs { - max_block_to_process: Some("".to_string()), - min_block_to_process: Some("".to_string()), - }, - } - } - - // Let's create a test for the CLI each validator - - #[rstest] - fn test_validate_provider_params(setup_cmd: RunCmd) { - let provider_params = setup_cmd.validate_provider_params(); - assert!(provider_params.is_ok()); - } - - #[rstest] - fn test_validate_alert_params(setup_cmd: RunCmd) { - let alert_params = setup_cmd.validate_alert_params(); - assert!(alert_params.is_ok()); - } - - #[rstest] - fn test_validate_queue_params(setup_cmd: RunCmd) { - let queue_params = setup_cmd.validate_queue_params(); - assert!(queue_params.is_ok()); - } - - #[rstest] - fn test_validate_storage_params(setup_cmd: RunCmd) { - let storage_params = setup_cmd.validate_storage_params(); - assert!(storage_params.is_ok()); - } +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +#[clap( + group( + ArgGroup::new("provider") + .args(&["aws"]) + .required(true) + .multiple(false) + ), + group( + ArgGroup::new("storage") + .args(&["aws_s3"]) + .required(true) + .multiple(false) + .requires("provider") + ), + group( + ArgGroup::new("queue") + .args(&["aws_sqs"]) + .required(true) + .multiple(false) + .requires("provider") + ), + group( + ArgGroup::new("alert") + .args(&["aws_sns"]) + .required(true) + .multiple(false) + .requires("provider") + ), + group( + ArgGroup::new("cron") + .args(&["aws_event_bridge"]) + .required(true) + .multiple(false) + .requires("provider") + ), +)] +pub struct SetupCmd { + // AWS Config + #[clap(flatten)] + pub aws_config_args: AWSConfigCliArgs, - #[rstest] - fn test_validate_database_params(setup_cmd: RunCmd) { - let database_params = setup_cmd.validate_database_params(); - assert!(database_params.is_ok()); - } + // Storage + #[clap(flatten)] + pub aws_s3_args: storage::aws_s3::AWSS3CliArgs, - #[rstest] - fn test_validate_da_params(setup_cmd: RunCmd) { - let da_params = setup_cmd.validate_da_params(); - assert!(da_params.is_ok()); - } + // Queue + #[clap(flatten)] + pub aws_sqs_args: queue::aws_sqs::AWSSQSCliArgs, - #[rstest] - fn test_validate_settlement_params(setup_cmd: RunCmd) { - let settlement_params = setup_cmd.validate_settlement_params(); - assert!(settlement_params.is_ok()); - } + // Alert + #[clap(flatten)] + pub aws_sns_args: alert::aws_sns::AWSSNSCliArgs, - #[rstest] - fn test_validate_prover_params(setup_cmd: RunCmd) { - let prover_params = setup_cmd.validate_prover_params(); - assert!(prover_params.is_ok()); - } + // Cron + #[clap(flatten)] + pub aws_event_bridge_args: AWSEventBridgeCliArgs, +} - #[rstest] - fn test_validate_cron_params(setup_cmd: RunCmd) { - let cron_params = setup_cmd.validate_cron_params(); - assert!(cron_params.is_ok()); +impl SetupCmd { + pub fn validate_provider_params(&self) -> Result { + if self.aws_config_args.aws { + Ok(ProviderValidatedArgs::AWS(AWSConfigValidatedArgs { + aws_access_key_id: self.aws_config_args.aws_access_key_id.clone(), + aws_secret_access_key: self.aws_config_args.aws_secret_access_key.clone(), + aws_region: self.aws_config_args.aws_region.clone(), + })) + } else { + Err("Only AWS is supported as of now".to_string()) + } } - #[rstest] - fn test_validate_instrumentation_params(setup_cmd: RunCmd) { - let instrumentation_params = setup_cmd.validate_instrumentation_params(); - assert!(instrumentation_params.is_ok()); + pub fn validate_alert_params(&self) -> Result { + if self.aws_sns_args.aws_sns { + Ok(AlertValidatedArgs::AWSSNS(AWSSNSValidatedArgs { + topic_arn: self.aws_sns_args.sns_arn.clone().expect("SNS ARN is required"), + })) + } else { + Err("Only AWS SNS is supported as of now".to_string()) + } } - #[rstest] - fn test_validate_server_params(setup_cmd: RunCmd) { - let server_params = setup_cmd.validate_server_params(); - assert!(server_params.is_ok()); + pub fn validate_queue_params(&self) -> Result { + if self.aws_sqs_args.aws_sqs { + Ok(QueueValidatedArgs::AWSSQS(AWSSQSValidatedArgs { + queue_base_url: self.aws_sqs_args.queue_base_url.clone().expect("Queue base URL is required"), + sqs_prefix: self.aws_sqs_args.sqs_prefix.clone().expect("SQS prefix is required"), + sqs_suffix: self.aws_sqs_args.sqs_suffix.clone().expect("SQS suffix is required"), + })) + } else { + Err("Only AWS SQS is supported as of now".to_string()) + } } - #[rstest] - fn test_validate_snos_params(setup_cmd: RunCmd) { - let snos_params = setup_cmd.validate_snos_params(); - assert!(snos_params.is_ok()); + pub fn validate_storage_params(&self) -> Result { + if self.aws_s3_args.aws_s3 { + Ok(StorageValidatedArgs::AWSS3(AWSS3ValidatedArgs { + bucket_name: self.aws_s3_args.bucket_name.clone().expect("Bucket name is required"), + })) + } else { + Err("Only AWS S3 is supported as of now".to_string()) + } } - #[rstest] - fn test_validate_service_params(setup_cmd: RunCmd) { - let service_params = setup_cmd.validate_service_params(); - assert!(service_params.is_ok()); + pub fn validate_cron_params(&self) -> Result { + if self.aws_event_bridge_args.aws_event_bridge { + Ok(CronValidatedArgs::AWSEventBridge(AWSEventBridgeValidatedArgs { + target_queue_name: self + .aws_event_bridge_args + .target_queue_name + .clone() + .expect("Target queue name is required"), + cron_time: Duration::from_secs( + self.aws_event_bridge_args + .cron_time + .clone() + .expect("Cron time is required") + .parse::() + .expect("Failed to parse cron time"), + ), + trigger_rule_name: self + .aws_event_bridge_args + .trigger_rule_name + .clone() + .expect("Trigger rule name is required"), + })) + } else { + Err("Only AWS Event Bridge is supported as of now".to_string()) + } } } + +// #[cfg(test)] +// pub mod test { + +// use rstest::{fixture, rstest}; +// use tracing::Level; +// use url::Url; + +// use super::alert::aws_sns::AWSSNSCliArgs; +// use super::cron::event_bridge::AWSEventBridgeCliArgs; +// use super::da::ethereum::EthereumDaCliArgs; +// use super::database::mongodb::MongoDBCliArgs; +// use super::instrumentation::InstrumentationCliArgs; +// use super::prover::sharp::SharpCliArgs; +// use super::provider::aws::AWSConfigCliArgs; +// use super::queue::aws_sqs::AWSSQSCliArgs; +// use super::server::ServerCliArgs; +// use super::service::ServiceCliArgs; +// use super::settlement::ethereum::EthereumSettlementCliArgs; +// use super::settlement::starknet::StarknetSettlementCliArgs; +// use super::snos::SNOSCliArgs; +// use super::storage::aws_s3::AWSS3CliArgs; +// use crate::cli::RunCmd; + +// // create a fixture for the CLI +// #[fixture] +// pub fn setup_cmd() -> RunCmd { +// RunCmd { +// aws_config_args: AWSConfigCliArgs { +// aws: true, +// aws_access_key_id: "".to_string(), +// aws_secret_access_key: "".to_string(), +// aws_region: "".to_string(), +// }, +// aws_event_bridge_args: AWSEventBridgeCliArgs { +// aws_event_bridge: true, +// target_queue_name: Some("".to_string()), +// cron_time: Some("12".to_string()), +// trigger_rule_name: Some("".to_string()), +// }, +// aws_s3_args: AWSS3CliArgs { aws_s3: true, bucket_name: Some("".to_string()) }, +// aws_sqs_args: AWSSQSCliArgs { +// aws_sqs: true, +// queue_base_url: Some("".to_string()), +// sqs_prefix: Some("".to_string()), +// sqs_suffix: Some("".to_string()), +// }, +// server_args: ServerCliArgs { host: "".to_string(), port: 0 }, +// aws_sns_args: AWSSNSCliArgs { aws_sns: true, sns_arn: Some("".to_string()) }, + +// instrumentation_args: InstrumentationCliArgs { +// otel_service_name: Some("".to_string()), +// otel_collector_endpoint: None, +// log_level: Level::INFO, +// }, + +// mongodb_args: MongoDBCliArgs { +// mongodb: true, +// mongodb_connection_url: Some("".to_string()), +// mongodb_database_name: Some("".to_string()), +// }, + +// madara_rpc_url: Url::parse("http://localhost:8545").unwrap(), + +// sharp_args: SharpCliArgs { +// sharp: true, +// sharp_customer_id: Some("".to_string()), +// sharp_url: Some(Url::parse("http://localhost:8545").unwrap()), +// sharp_user_crt: Some("".to_string()), +// sharp_user_key: Some("".to_string()), +// sharp_rpc_node_url: Some(Url::parse("http://localhost:8545").unwrap()), +// sharp_proof_layout: Some("".to_string()), +// gps_verifier_contract_address: Some("".to_string()), +// sharp_server_crt: Some("".to_string()), +// }, + +// starknet_args: StarknetSettlementCliArgs { +// starknet_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), +// starknet_private_key: Some("".to_string()), +// starknet_account_address: Some("".to_string()), +// starknet_cairo_core_contract_address: Some("".to_string()), +// starknet_finality_retry_wait_in_secs: Some(0), +// starknet_madara_binary_path: Some("".to_string()), +// settle_on_starknet: false, +// }, + +// ethereum_args: EthereumSettlementCliArgs { +// ethereum_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), +// ethereum_private_key: Some("".to_string()), +// l1_core_contract_address: Some("".to_string()), +// starknet_operator_address: Some("".to_string()), +// settle_on_ethereum: true, +// }, + +// ethereum_da_args: EthereumDaCliArgs { +// da_on_ethereum: true, +// ethereum_da_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), +// }, + +// snos_args: SNOSCliArgs { rpc_for_snos: Url::parse("http://localhost:8545").unwrap() }, + +// service_args: ServiceCliArgs { +// max_block_to_process: Some("".to_string()), +// min_block_to_process: Some("".to_string()), +// }, +// } +// } + +// // Let's create a test for the CLI each validator + +// #[rstest] +// fn test_validate_provider_params(setup_cmd: RunCmd) { +// let provider_params = setup_cmd.validate_provider_params(); +// assert!(provider_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_alert_params(setup_cmd: RunCmd) { +// let alert_params = setup_cmd.validate_alert_params(); +// assert!(alert_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_queue_params(setup_cmd: RunCmd) { +// let queue_params = setup_cmd.validate_queue_params(); +// assert!(queue_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_storage_params(setup_cmd: RunCmd) { +// let storage_params = setup_cmd.validate_storage_params(); +// assert!(storage_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_database_params(setup_cmd: RunCmd) { +// let database_params = setup_cmd.validate_database_params(); +// assert!(database_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_da_params(setup_cmd: RunCmd) { +// let da_params = setup_cmd.validate_da_params(); +// assert!(da_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_settlement_params(setup_cmd: RunCmd) { +// let settlement_params = setup_cmd.validate_settlement_params(); +// assert!(settlement_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_prover_params(setup_cmd: RunCmd) { +// let prover_params = setup_cmd.validate_prover_params(); +// assert!(prover_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_cron_params(setup_cmd: RunCmd) { +// let cron_params = setup_cmd.validate_cron_params(); +// assert!(cron_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_instrumentation_params(setup_cmd: RunCmd) { +// let instrumentation_params = setup_cmd.validate_instrumentation_params(); +// assert!(instrumentation_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_server_params(setup_cmd: RunCmd) { +// let server_params = setup_cmd.validate_server_params(); +// assert!(server_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_snos_params(setup_cmd: RunCmd) { +// let snos_params = setup_cmd.validate_snos_params(); +// assert!(snos_params.is_ok()); +// } + +// #[rstest] +// fn test_validate_service_params(setup_cmd: RunCmd) { +// let service_params = setup_cmd.validate_service_params(); +// assert!(service_params.is_ok()); +// } +// } diff --git a/crates/orchestrator/src/cli/provider/mod.rs b/crates/orchestrator/src/cli/provider/mod.rs index ae8d93f5..7f51fe33 100644 --- a/crates/orchestrator/src/cli/provider/mod.rs +++ b/crates/orchestrator/src/cli/provider/mod.rs @@ -1,6 +1,5 @@ pub mod aws; - #[derive(Debug, Clone)] pub enum ProviderValidatedArgs { AWS(AWSConfigValidatedArgs), diff --git a/crates/orchestrator/src/cron/mod.rs b/crates/orchestrator/src/cron/mod.rs index d3ad7a4c..ec1804b0 100644 --- a/crates/orchestrator/src/cron/mod.rs +++ b/crates/orchestrator/src/cron/mod.rs @@ -7,7 +7,6 @@ use crate::queue::job_queue::{WorkerTriggerMessage, WorkerTriggerType}; pub mod event_bridge; - lazy_static! { pub static ref CRON_DURATION: Duration = Duration::from_mins(1); // TODO : we can take this from clap. diff --git a/crates/orchestrator/src/main.rs b/crates/orchestrator/src/main.rs index d63087b3..90461de6 100644 --- a/crates/orchestrator/src/main.rs +++ b/crates/orchestrator/src/main.rs @@ -1,6 +1,6 @@ use clap::Parser as _; use dotenvy::dotenv; -use orchestrator::cli::RunCmd; +use orchestrator::cli::{Cli, Commands, RunCmd, SetupCmd}; use orchestrator::config::init_config; use orchestrator::queue::init_consumers; use orchestrator::routes::setup_server; @@ -14,14 +14,20 @@ use orchestrator::telemetry::{setup_analytics, shutdown_analytics}; #[allow(clippy::needless_return)] async fn main() { dotenv().ok(); - // TODO: could this be an ARC ? - let run_cmd: RunCmd = RunCmd::parse(); - if run_cmd.setup { - setup_cloud(&run_cmd).await.expect("Failed to setup cloud"); - return; + let cli = Cli::parse(); + + match &cli.command { + Commands::Run { run_command } => { + run_orchestrator(run_command).await.expect("Failed to run orchestrator"); + } + Commands::Setup { setup_command } => { + setup_orchestrator(setup_command).await.expect("Failed to setup orchestrator"); + } } +} +async fn run_orchestrator(run_cmd: &RunCmd) -> color_eyre::Result<()> { // Analytics Setup let instrumentation_params = run_cmd.validate_instrumentation_params().expect("Invalid instrumentation params"); let meter_provider = setup_analytics(&instrumentation_params); @@ -30,7 +36,7 @@ async fn main() { color_eyre::install().expect("Unable to install color_eyre"); // initial config setup - let config = init_config(&run_cmd).await.expect("Config instantiation failed"); + let config = init_config(run_cmd).await.expect("Config instantiation failed"); tracing::debug!(service = "orchestrator", "Configuration initialized"); // initialize the server @@ -52,4 +58,11 @@ async fn main() { // Analytics Shutdown shutdown_analytics(meter_provider, &instrumentation_params); tracing::info!(service = "orchestrator", "Orchestrator service shutting down"); + + Ok(()) +} + +async fn setup_orchestrator(setup_cmd: &SetupCmd) -> color_eyre::Result<()> { + setup_cloud(setup_cmd).await.expect("Failed to setup cloud"); + Ok(()) } diff --git a/crates/orchestrator/src/setup/mod.rs b/crates/orchestrator/src/setup/mod.rs index 42e2d51b..3957816f 100644 --- a/crates/orchestrator/src/setup/mod.rs +++ b/crates/orchestrator/src/setup/mod.rs @@ -8,7 +8,7 @@ use crate::cli::alert::AlertValidatedArgs; use crate::cli::cron::CronValidatedArgs; use crate::cli::queue::QueueValidatedArgs; use crate::cli::storage::StorageValidatedArgs; -use crate::cli::RunCmd; +use crate::cli::SetupCmd; use crate::config::build_provider_config; use crate::cron::event_bridge::AWSEventBridge; use crate::cron::Cron; @@ -23,11 +23,13 @@ pub enum SetupConfig { } // TODO : move this to main.rs after moving to clap. -pub async fn setup_cloud(run_cmd: &RunCmd) -> color_eyre::Result<()> { +pub async fn setup_cloud(run_cmd: &SetupCmd) -> color_eyre::Result<()> { println!("Setting up cloud."); + // AWS let provider_params = run_cmd.validate_provider_params().expect("Failed to validate provider params"); let provider_config = build_provider_config(&provider_params).await; + // Data Storage println!("Setting up data storage."); let data_storage_params = run_cmd.validate_storage_params().expect("Failed to validate storage params"); let aws_config = provider_config.get_aws_client_or_panic(); @@ -40,6 +42,7 @@ pub async fn setup_cloud(run_cmd: &RunCmd) -> color_eyre::Result<()> { } println!("Data storage setup completed ✅"); + // Queues println!("Setting up queues"); let queue_params = run_cmd.validate_queue_params().expect("Failed to validate queue params"); match queue_params { @@ -50,6 +53,7 @@ pub async fn setup_cloud(run_cmd: &RunCmd) -> color_eyre::Result<()> { } println!("Queues setup completed ✅"); + // Cron println!("Setting up cron"); let cron_params = run_cmd.validate_cron_params().expect("Failed to validate cron params"); match cron_params { @@ -61,6 +65,7 @@ pub async fn setup_cloud(run_cmd: &RunCmd) -> color_eyre::Result<()> { } println!("Cron setup completed ✅"); + // Alerts println!("Setting up alerts."); let alert_params = run_cmd.validate_alert_params().expect("Failed to validate alert params"); match alert_params { From 3c3f83df394dd1f3788bdad8742a5e8ecb758a62 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 13 Nov 2024 18:07:07 +0530 Subject: [PATCH 54/63] update: optimised fixes --- Cargo.lock | 3 +- Cargo.toml | 2 + crates/orchestrator/Cargo.toml | 4 +- .../orchestrator/src/cli/cron/event_bridge.rs | 7 +- crates/orchestrator/src/cli/mod.rs | 140 ++++++++--------- .../src/cli/settlement/starknet.rs | 4 - crates/orchestrator/src/cron/event_bridge.rs | 25 +-- crates/orchestrator/src/cron/mod.rs | 24 +-- .../orchestrator/src/database/mongodb/mod.rs | 3 +- crates/orchestrator/src/queue/mod.rs | 25 +-- crates/orchestrator/src/queue/sqs/mod.rs | 5 +- crates/orchestrator/src/tests/common/mod.rs | 1 + crates/orchestrator/src/tests/config.rs | 17 ++- crates/orchestrator/src/workers/snos.rs | 11 +- crates/settlement-clients/ethereum/Cargo.toml | 1 - crates/settlement-clients/ethereum/src/lib.rs | 13 +- crates/settlement-clients/starknet/Cargo.toml | 2 + crates/settlement-clients/starknet/src/lib.rs | 15 +- .../starknet/src/tests/test.rs | 29 ++-- crates/utils/Cargo.toml | 1 - e2e-tests/Cargo.toml | 4 +- e2e-tests/src/mongodb.rs | 4 +- e2e-tests/src/node.rs | 144 ++++++++---------- e2e-tests/tests.rs | 14 +- 24 files changed, 224 insertions(+), 274 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2b9c25ae..e895e6d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9679,6 +9679,8 @@ dependencies = [ name = "starknet-settlement-client" version = "0.1.0" dependencies = [ + "alloy 0.2.1", + "alloy-primitives 0.7.7", "appchain-core-contract-client", "async-std", "async-trait", @@ -10875,7 +10877,6 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" name = "utils" version = "0.1.0" dependencies = [ - "clap", "color-eyre", "opentelemetry", "opentelemetry-appender-tracing", diff --git a/Cargo.toml b/Cargo.toml index 9f44c13b..ab790150 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,6 +60,8 @@ rstest = "0.22.0" serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.114" starknet = "0.11.0" +strum = "0.26.0" +strum_macros = "0.26.0" tempfile = "3.12.0" thiserror = "1.0.57" tokio = { version = "1.37.0" } diff --git a/crates/orchestrator/Cargo.toml b/crates/orchestrator/Cargo.toml index 0994416c..fb15e1a1 100644 --- a/crates/orchestrator/Cargo.toml +++ b/crates/orchestrator/Cargo.toml @@ -63,8 +63,8 @@ starknet = { workspace = true } starknet-core = "0.9.0" starknet-os = { workspace = true } starknet-settlement-client = { workspace = true } -strum = "0.26.0" -strum_macros = "0.26.0" +strum = { workspace = true } +strum_macros = { workspace = true } tempfile = { workspace = true } thiserror = { workspace = true } tokio = { workspace = true, features = ["sync", "macros", "rt-multi-thread"] } diff --git a/crates/orchestrator/src/cli/cron/event_bridge.rs b/crates/orchestrator/src/cli/cron/event_bridge.rs index 8719a597..321eab9b 100644 --- a/crates/orchestrator/src/cli/cron/event_bridge.rs +++ b/crates/orchestrator/src/cli/cron/event_bridge.rs @@ -9,14 +9,13 @@ pub struct AWSEventBridgeCliArgs { pub aws_event_bridge: bool, /// The name of the S3 bucket. - #[arg(env = "MADARA_ORCHESTRATOR_EVENT_BRIDGE_TARGET_QUEUE_NAME", long, default_value = Some("madara-orchestrator-event-bridge-target-queue-name"))] + #[arg(env = "MADARA_ORCHESTRATOR_EVENT_BRIDGE_TARGET_QUEUE_NAME", long, default_value = Some("madara-orchestrator-event-bridge-target-queue-name"), help = "The name of the SNS queue to send messages to from the event bridge.")] pub target_queue_name: Option, - /// The cron time for the event bridge trigger rule. - #[arg(env = "MADARA_ORCHESTRATOR_EVENT_BRIDGE_CRON_TIME", long, default_value = Some("10"))] + #[arg(env = "MADARA_ORCHESTRATOR_EVENT_BRIDGE_CRON_TIME", long, default_value = Some("10"), help = "The cron time for the event bridge trigger rule. Defaults to 10 seconds.")] pub cron_time: Option, /// The name of the event bridge trigger rule. - #[arg(env = "MADARA_ORCHESTRATOR_EVENT_BRIDGE_TRIGGER_RULE_NAME", long, default_value = Some("madara-orchestrator-event-bridge-trigger-rule-name"))] + #[arg(env = "MADARA_ORCHESTRATOR_EVENT_BRIDGE_TRIGGER_RULE_NAME", long, default_value = Some("madara-orchestrator-event-bridge-trigger-rule-name"), help = "The name of the event bridge trigger rule.")] pub trigger_rule_name: Option, } diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index edef75e0..886738c3 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -1,6 +1,8 @@ +use std::str::FromStr as _; use std::time::Duration; use alert::AlertValidatedArgs; +use alloy::primitives::Address; use clap::{ArgGroup, Parser, Subcommand}; use cron::event_bridge::AWSEventBridgeCliArgs; use cron::CronValidatedArgs; @@ -179,7 +181,7 @@ impl RunCmd { } pub fn validate_alert_params(&self) -> Result { - if self.aws_sns_args.aws_sns { + if self.aws_sns_args.aws_sns && self.aws_config_args.aws { Ok(AlertValidatedArgs::AWSSNS(AWSSNSValidatedArgs { topic_arn: self.aws_sns_args.sns_arn.clone().expect("SNS ARN is required"), })) @@ -189,9 +191,12 @@ impl RunCmd { } pub fn validate_queue_params(&self) -> Result { - if self.aws_sqs_args.aws_sqs { + if self.aws_sqs_args.aws_sqs && self.aws_config_args.aws { Ok(QueueValidatedArgs::AWSSQS(AWSSQSValidatedArgs { - queue_base_url: self.aws_sqs_args.queue_base_url.clone().expect("Queue base URL is required"), + queue_base_url: Url::parse( + &self.aws_sqs_args.queue_base_url.clone().expect("Queue base URL is required"), + ) + .expect("Invalid queue base URL"), sqs_prefix: self.aws_sqs_args.sqs_prefix.clone().expect("SQS prefix is required"), sqs_suffix: self.aws_sqs_args.sqs_suffix.clone().expect("SQS suffix is required"), })) @@ -201,7 +206,7 @@ impl RunCmd { } pub fn validate_storage_params(&self) -> Result { - if self.aws_s3_args.aws_s3 { + if self.aws_s3_args.aws_s3 && self.aws_config_args.aws { Ok(StorageValidatedArgs::AWSS3(AWSS3ValidatedArgs { bucket_name: self.aws_s3_args.bucket_name.clone().expect("Bucket name is required"), })) @@ -213,11 +218,10 @@ impl RunCmd { pub fn validate_database_params(&self) -> Result { if self.mongodb_args.mongodb { Ok(DatabaseValidatedArgs::MongoDB(MongoDBValidatedArgs { - connection_url: self - .mongodb_args - .mongodb_connection_url - .clone() - .expect("MongoDB connection URL is required"), + connection_url: Url::parse( + &self.mongodb_args.mongodb_connection_url.clone().expect("MongoDB connection URL is required"), + ) + .expect("Invalid MongoDB connection URL"), database_name: self .mongodb_args .mongodb_database_name @@ -244,67 +248,55 @@ impl RunCmd { } pub fn validate_settlement_params(&self) -> Result { - match (self.ethereum_args.settle_on_ethereum, self.starknet_args.settle_on_starknet) { - (true, false) => { - let ethereum_params = EthereumSettlementValidatedArgs { - ethereum_rpc_url: self - .ethereum_args - .ethereum_rpc_url - .clone() - .expect("Ethereum RPC URL is required"), - ethereum_private_key: self - .ethereum_args - .ethereum_private_key - .clone() - .expect("Ethereum private key is required"), - l1_core_contract_address: self - .ethereum_args - .l1_core_contract_address - .clone() - .expect("L1 core contract address is required"), - starknet_operator_address: self - .ethereum_args - .starknet_operator_address - .clone() - .expect("Starknet operator address is required"), - }; - Ok(SettlementValidatedArgs::Ethereum(ethereum_params)) - } - (false, true) => { - let starknet_params = StarknetSettlementValidatedArgs { - starknet_rpc_url: self - .starknet_args - .starknet_rpc_url - .clone() - .expect("Starknet RPC URL is required"), - starknet_private_key: self - .starknet_args - .starknet_private_key - .clone() - .expect("Starknet private key is required"), - starknet_account_address: self - .starknet_args - .starknet_account_address - .clone() - .expect("Starknet account address is required"), - starknet_cairo_core_contract_address: self + if self.ethereum_args.settle_on_ethereum { + let l1_core_contract_address = Address::from_str( + &self.ethereum_args.l1_core_contract_address.clone().expect("L1 core contract address is required"), + ) + .expect("Invalid L1 core contract address"); + let starknet_operator_address = Address::from_str( + &self.ethereum_args.starknet_operator_address.clone().expect("Starknet operator address is required"), + ) + .expect("Invalid Starknet operator address"); + + let ethereum_params = EthereumSettlementValidatedArgs { + ethereum_rpc_url: self.ethereum_args.ethereum_rpc_url.clone().expect("Ethereum RPC URL is required"), + ethereum_private_key: self + .ethereum_args + .ethereum_private_key + .clone() + .expect("Ethereum private key is required"), + l1_core_contract_address, + starknet_operator_address, + }; + Ok(SettlementValidatedArgs::Ethereum(ethereum_params)) + } else if self.starknet_args.settle_on_starknet { + let starknet_params = StarknetSettlementValidatedArgs { + starknet_rpc_url: self.starknet_args.starknet_rpc_url.clone().expect("Starknet RPC URL is required"), + starknet_private_key: self + .starknet_args + .starknet_private_key + .clone() + .expect("Starknet private key is required"), + starknet_account_address: Address::from_str( + &self.starknet_args.starknet_account_address.clone().expect("Starknet account address is required"), + ) + .expect("Invalid Starknet account address"), + starknet_cairo_core_contract_address: Address::from_str( + &self .starknet_args .starknet_cairo_core_contract_address .clone() .expect("Starknet Cairo core contract address is required"), - starknet_finality_retry_wait_in_secs: self - .starknet_args - .starknet_finality_retry_wait_in_secs - .expect("Starknet finality retry wait in seconds is required"), - madara_binary_path: self - .starknet_args - .starknet_madara_binary_path - .clone() - .expect("Starknet Madara binary path is required"), - }; - Ok(SettlementValidatedArgs::Starknet(starknet_params)) - } - (true, true) | (false, false) => Err("Exactly one settlement layer must be selected".to_string()), + ) + .expect("Invalid Starknet Cairo core contract address"), + starknet_finality_retry_wait_in_secs: self + .starknet_args + .starknet_finality_retry_wait_in_secs + .expect("Starknet finality retry wait in seconds is required"), + }; + Ok(SettlementValidatedArgs::Starknet(starknet_params)) + } else { + Err("Settlement layer is required".to_string()) } } @@ -339,7 +331,7 @@ impl RunCmd { .instrumentation_args .otel_service_name .clone() - .expect("OTel service name is required"), + .expect("Otel service name is required"), otel_collector_endpoint: self.instrumentation_args.otel_collector_endpoint.clone(), log_level: self.instrumentation_args.log_level, }) @@ -440,7 +432,7 @@ impl SetupCmd { } pub fn validate_alert_params(&self) -> Result { - if self.aws_sns_args.aws_sns { + if self.aws_sns_args.aws_sns && self.aws_config_args.aws { Ok(AlertValidatedArgs::AWSSNS(AWSSNSValidatedArgs { topic_arn: self.aws_sns_args.sns_arn.clone().expect("SNS ARN is required"), })) @@ -450,9 +442,12 @@ impl SetupCmd { } pub fn validate_queue_params(&self) -> Result { - if self.aws_sqs_args.aws_sqs { + if self.aws_sqs_args.aws_sqs && self.aws_config_args.aws { Ok(QueueValidatedArgs::AWSSQS(AWSSQSValidatedArgs { - queue_base_url: self.aws_sqs_args.queue_base_url.clone().expect("Queue base URL is required"), + queue_base_url: Url::parse( + &self.aws_sqs_args.queue_base_url.clone().expect("Queue base URL is required"), + ) + .expect("Invalid queue base URL"), sqs_prefix: self.aws_sqs_args.sqs_prefix.clone().expect("SQS prefix is required"), sqs_suffix: self.aws_sqs_args.sqs_suffix.clone().expect("SQS suffix is required"), })) @@ -462,7 +457,7 @@ impl SetupCmd { } pub fn validate_storage_params(&self) -> Result { - if self.aws_s3_args.aws_s3 { + if self.aws_s3_args.aws_s3 && self.aws_config_args.aws { Ok(StorageValidatedArgs::AWSS3(AWSS3ValidatedArgs { bucket_name: self.aws_s3_args.bucket_name.clone().expect("Bucket name is required"), })) @@ -472,7 +467,7 @@ impl SetupCmd { } pub fn validate_cron_params(&self) -> Result { - if self.aws_event_bridge_args.aws_event_bridge { + if self.aws_event_bridge_args.aws_event_bridge && self.aws_config_args.aws { Ok(CronValidatedArgs::AWSEventBridge(AWSEventBridgeValidatedArgs { target_queue_name: self .aws_event_bridge_args @@ -580,7 +575,6 @@ impl SetupCmd { // starknet_account_address: Some("".to_string()), // starknet_cairo_core_contract_address: Some("".to_string()), // starknet_finality_retry_wait_in_secs: Some(0), -// starknet_madara_binary_path: Some("".to_string()), // settle_on_starknet: false, // }, diff --git a/crates/orchestrator/src/cli/settlement/starknet.rs b/crates/orchestrator/src/cli/settlement/starknet.rs index 0d74ec82..9a171b22 100644 --- a/crates/orchestrator/src/cli/settlement/starknet.rs +++ b/crates/orchestrator/src/cli/settlement/starknet.rs @@ -27,8 +27,4 @@ pub struct StarknetSettlementCliArgs { /// The number of seconds to wait for finality. #[arg(env = "MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS", long)] pub starknet_finality_retry_wait_in_secs: Option, - - /// The path to the Madara binary. - #[arg(env = "MADARA_ORCHESTRATOR_MADARA_BINARY_PATH", long)] - pub starknet_madara_binary_path: Option, } diff --git a/crates/orchestrator/src/cron/event_bridge.rs b/crates/orchestrator/src/cron/event_bridge.rs index b9019e5c..b8b5c6e3 100644 --- a/crates/orchestrator/src/cron/event_bridge.rs +++ b/crates/orchestrator/src/cron/event_bridge.rs @@ -17,13 +17,19 @@ pub struct AWSEventBridgeValidatedArgs { } pub struct AWSEventBridge { + target_queue_name: String, + cron_time: Duration, + trigger_rule_name: String, client: EventBridgeClient, queue_client: SqsClient, } impl AWSEventBridge { - pub fn new_with_args(_params: &AWSEventBridgeValidatedArgs, aws_config: &SdkConfig) -> Self { + pub fn new_with_args(params: &AWSEventBridgeValidatedArgs, aws_config: &SdkConfig) -> Self { Self { + target_queue_name: params.target_queue_name.clone(), + cron_time: params.cron_time, + trigger_rule_name: params.trigger_rule_name.clone(), client: aws_sdk_eventbridge::Client::new(aws_config), queue_client: aws_sdk_sqs::Client::new(aws_config), } @@ -33,24 +39,19 @@ impl AWSEventBridge { #[async_trait] #[allow(unreachable_patterns)] impl Cron for AWSEventBridge { - async fn create_cron(&self, cron_time: Duration, trigger_rule_name: String) -> color_eyre::Result<()> { + async fn create_cron(&self) -> color_eyre::Result<()> { self.client .put_rule() - .name(&trigger_rule_name) - .schedule_expression(duration_to_rate_string(cron_time)) + .name(&self.trigger_rule_name) + .schedule_expression(duration_to_rate_string(self.cron_time)) .state(RuleState::Enabled) .send() .await?; Ok(()) } - async fn add_cron_target_queue( - &self, - target_queue_name: String, - message: String, - trigger_rule_name: String, - ) -> color_eyre::Result<()> { - let queue_url = self.queue_client.get_queue_url().queue_name(target_queue_name).send().await?; + async fn add_cron_target_queue(&self, message: String) -> color_eyre::Result<()> { + let queue_url = self.queue_client.get_queue_url().queue_name(&self.target_queue_name).send().await?; let queue_attributes = self .queue_client @@ -67,7 +68,7 @@ impl Cron for AWSEventBridge { self.client .put_targets() - .rule(trigger_rule_name) + .rule(&self.trigger_rule_name) .targets( Target::builder() .id(uuid::Uuid::new_v4().to_string()) diff --git a/crates/orchestrator/src/cron/mod.rs b/crates/orchestrator/src/cron/mod.rs index ec1804b0..5f1ed51a 100644 --- a/crates/orchestrator/src/cron/mod.rs +++ b/crates/orchestrator/src/cron/mod.rs @@ -1,5 +1,3 @@ -use std::time::Duration; - use async_trait::async_trait; use lazy_static::lazy_static; @@ -8,36 +6,22 @@ use crate::queue::job_queue::{WorkerTriggerMessage, WorkerTriggerType}; pub mod event_bridge; lazy_static! { - pub static ref CRON_DURATION: Duration = Duration::from_mins(1); - // TODO : we can take this from clap. - pub static ref TARGET_QUEUE_NAME: String = String::from("madara_orchestrator_worker_trigger_queue"); pub static ref WORKER_TRIGGERS: Vec = vec![ WorkerTriggerType::Snos, WorkerTriggerType::Proving, WorkerTriggerType::DataSubmission, WorkerTriggerType::UpdateState ]; - pub static ref WORKER_TRIGGER_RULE_NAME: String = String::from("worker_trigger_scheduled"); } #[async_trait] pub trait Cron { - async fn create_cron(&self, cron_time: Duration, trigger_rule_name: String) -> color_eyre::Result<()>; - async fn add_cron_target_queue( - &self, - target_queue_name: String, - message: String, - trigger_rule_name: String, - ) -> color_eyre::Result<()>; + async fn create_cron(&self) -> color_eyre::Result<()>; + async fn add_cron_target_queue(&self, message: String) -> color_eyre::Result<()>; async fn setup(&self) -> color_eyre::Result<()> { - self.create_cron(*CRON_DURATION, WORKER_TRIGGER_RULE_NAME.clone()).await?; + self.create_cron().await?; for triggers in WORKER_TRIGGERS.iter() { - self.add_cron_target_queue( - TARGET_QUEUE_NAME.clone(), - get_worker_trigger_message(triggers.clone())?, - WORKER_TRIGGER_RULE_NAME.clone(), - ) - .await?; + self.add_cron_target_queue(get_worker_trigger_message(triggers.clone())?).await?; } Ok(()) } diff --git a/crates/orchestrator/src/database/mongodb/mod.rs b/crates/orchestrator/src/database/mongodb/mod.rs index da644111..4f18eae8 100644 --- a/crates/orchestrator/src/database/mongodb/mod.rs +++ b/crates/orchestrator/src/database/mongodb/mod.rs @@ -10,6 +10,7 @@ use mongodb::options::{ UpdateOptions, }; use mongodb::{bson, Client, Collection}; +use url::Url; use utils::ToDocument; use uuid::Uuid; @@ -21,7 +22,7 @@ mod utils; #[derive(Debug, Clone)] pub struct MongoDBValidatedArgs { - pub connection_url: String, + pub connection_url: Url, pub database_name: String, } diff --git a/crates/orchestrator/src/queue/mod.rs b/crates/orchestrator/src/queue/mod.rs index 3d8c7499..57fa8f83 100644 --- a/crates/orchestrator/src/queue/mod.rs +++ b/crates/orchestrator/src/queue/mod.rs @@ -9,12 +9,12 @@ use color_eyre::Result as EyreResult; use lazy_static::lazy_static; use mockall::automock; use omniqueue::{Delivery, QueueError}; -use strum_macros::Display; +use strum_macros::{Display, EnumIter}; use crate::config::Config; use crate::jobs::JobError; -#[derive(Display, Debug, Clone, PartialEq, Eq)] +#[derive(Display, Debug, Clone, PartialEq, Eq, EnumIter)] pub enum QueueType { #[strum(serialize = "snos_job_processing")] SnosJobProcessing, @@ -42,27 +42,6 @@ pub enum QueueType { WorkerTrigger, } -impl QueueType { - pub fn iter() -> impl Iterator { - [ - QueueType::SnosJobProcessing, - QueueType::SnosJobVerification, - QueueType::ProvingJobProcessing, - QueueType::ProvingJobVerification, - QueueType::ProofRegistrationJobProcessing, - QueueType::ProofRegistrationJobVerification, - QueueType::DataSubmissionJobProcessing, - QueueType::DataSubmissionJobVerification, - QueueType::UpdateStateJobProcessing, - QueueType::UpdateStateJobVerification, - QueueType::JobHandleFailure, - QueueType::WorkerTrigger, - ] - .iter() - .cloned() - } -} - #[derive(Clone)] pub struct DlqConfig { pub max_receive_count: i32, diff --git a/crates/orchestrator/src/queue/sqs/mod.rs b/crates/orchestrator/src/queue/sqs/mod.rs index 54a18e16..dbb167c5 100644 --- a/crates/orchestrator/src/queue/sqs/mod.rs +++ b/crates/orchestrator/src/queue/sqs/mod.rs @@ -10,20 +10,21 @@ use color_eyre::Result; use omniqueue::backends::{SqsBackend, SqsConfig, SqsConsumer, SqsProducer}; use omniqueue::{Delivery, QueueError}; use serde::Serialize; +use url::Url; use super::QueueType; use crate::queue::{QueueConfig, QueueProvider}; #[derive(Debug, Clone, Serialize)] pub struct AWSSQSValidatedArgs { - pub queue_base_url: String, + pub queue_base_url: Url, pub sqs_prefix: String, pub sqs_suffix: String, } pub struct SqsQueue { client: Client, - queue_base_url: String, + queue_base_url: Url, sqs_prefix: String, sqs_suffix: String, } diff --git a/crates/orchestrator/src/tests/common/mod.rs b/crates/orchestrator/src/tests/common/mod.rs index 5c1a9703..54c43511 100644 --- a/crates/orchestrator/src/tests/common/mod.rs +++ b/crates/orchestrator/src/tests/common/mod.rs @@ -11,6 +11,7 @@ use chrono::{SubsecRound, Utc}; use mongodb::Client; use rstest::*; use serde::Deserialize; +use strum::IntoEnumIterator as _; use crate::cli::alert::AlertValidatedArgs; use crate::cli::database::DatabaseValidatedArgs; diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 20bd1d06..811e5ec2 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -2,6 +2,7 @@ use std::net::SocketAddr; use std::str::FromStr as _; use std::sync::Arc; +use alloy::primitives::Address; use axum::Router; use da_client_interface::{DaClient, MockDaClient}; use ethereum_da_client::EthereumDaValidatedArgs; @@ -483,7 +484,8 @@ struct EnvParams { fn get_env_params() -> EnvParams { let db_params = DatabaseValidatedArgs::MongoDB(MongoDBValidatedArgs { - connection_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL"), + connection_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL")) + .expect("Invalid MongoDB connection URL"), database_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_DATABASE_NAME"), }); @@ -492,7 +494,8 @@ fn get_env_params() -> EnvParams { }); let queue_params = QueueValidatedArgs::AWSSQS(AWSSQSValidatedArgs { - queue_base_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL"), + queue_base_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL")) + .expect("Invalid queue base URL"), sqs_prefix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_PREFIX"), sqs_suffix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_SUFFIX"), }); @@ -516,8 +519,14 @@ fn get_env_params() -> EnvParams { ethereum_rpc_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL")) .expect("Failed to parse MADARA_ORCHESTRATOR_ETHEREUM_RPC_URL"), ethereum_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), - l1_core_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"), - starknet_operator_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"), + l1_core_contract_address: Address::from_str(&get_env_var_or_panic( + "MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS", + )) + .expect("Invalid L1 core contract address"), + starknet_operator_address: Address::from_str(&get_env_var_or_panic( + "MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS", + )) + .expect("Invalid Starknet operator address"), }); let snos_config = SNOSParams { diff --git a/crates/orchestrator/src/workers/snos.rs b/crates/orchestrator/src/workers/snos.rs index d7900b21..d5364516 100644 --- a/crates/orchestrator/src/workers/snos.rs +++ b/crates/orchestrator/src/workers/snos.rs @@ -1,3 +1,4 @@ +use std::cmp::{max, min}; use std::collections::HashMap; use std::sync::Arc; @@ -23,7 +24,7 @@ impl Worker for SnosWorker { let block_number_provider = provider.block_number().await?; let latest_block_number = if let Some(max_block_to_process) = config.service_config().max_block_to_process { - max_block_to_process + min(max_block_to_process, block_number_provider) } else { block_number_provider }; @@ -33,15 +34,15 @@ impl Worker for SnosWorker { let latest_job_in_db = config.database().get_latest_job_by_type(JobType::SnosRun).await?; let latest_job_id = match latest_job_in_db { - Some(job) => job.internal_id, - None => "0".to_string(), + Some(job) => job.internal_id.parse::().unwrap(), + None => "0".to_string().parse::().unwrap(), }; // To be used when testing in specific block range let block_start = if let Some(min_block_to_process) = config.service_config().min_block_to_process { - min_block_to_process + max(min_block_to_process, latest_job_id) } else { - latest_job_id.parse::().unwrap() + latest_job_id }; for block_num in block_start..latest_block_number + 1 { diff --git a/crates/settlement-clients/ethereum/Cargo.toml b/crates/settlement-clients/ethereum/Cargo.toml index a458bb1d..987672f7 100644 --- a/crates/settlement-clients/ethereum/Cargo.toml +++ b/crates/settlement-clients/ethereum/Cargo.toml @@ -5,7 +5,6 @@ edition.workspace = true [dependencies] alloy-primitives = { version = "0.7.7", default-features = false } - alloy = { workspace = true, features = ["full", "node-bindings"] } async-trait = { workspace = true } bytes = "1.7.2" diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index 4c32da4c..55cc3fe9 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -67,9 +67,9 @@ pub struct EthereumSettlementValidatedArgs { pub ethereum_private_key: String, - pub l1_core_contract_address: String, + pub l1_core_contract_address: Address, - pub starknet_operator_address: String, + pub starknet_operator_address: Address, } #[allow(dead_code)] @@ -99,13 +99,8 @@ impl EthereumSettlementClient { .on_http(settlement_cfg.ethereum_rpc_url.clone()), ); - let core_contract_client = StarknetValidityContractClient::new( - Address::from_str(&settlement_cfg.l1_core_contract_address) - .expect("Failed to convert the validity contract address.") - .0 - .into(), - filler_provider, - ); + let core_contract_client = + StarknetValidityContractClient::new(settlement_cfg.l1_core_contract_address, filler_provider); EthereumSettlementClient { provider, core_contract_client, wallet, wallet_address, impersonate_account: None } } diff --git a/crates/settlement-clients/starknet/Cargo.toml b/crates/settlement-clients/starknet/Cargo.toml index 861df735..42be56a9 100644 --- a/crates/settlement-clients/starknet/Cargo.toml +++ b/crates/settlement-clients/starknet/Cargo.toml @@ -4,6 +4,8 @@ version.workspace = true edition.workspace = true [dependencies] +alloy-primitives = { version = "0.7.7", default-features = false } +alloy = { workspace = true, features = ["full", "node-bindings"] } appchain-core-contract-client = { workspace = true } async-trait = { workspace = true } c-kzg = { workspace = true } diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 2b2bd676..00d8245c 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -5,6 +5,7 @@ pub mod tests; use std::sync::Arc; +use alloy_primitives::Address; use appchain_core_contract_client::clients::StarknetCoreContractClient; use appchain_core_contract_client::interfaces::core_contract::CoreContract; use async_trait::async_trait; @@ -43,16 +44,10 @@ use url::Url; #[derive(Clone, Debug)] pub struct StarknetSettlementValidatedArgs { pub starknet_rpc_url: Url, - pub starknet_private_key: String, - - pub starknet_account_address: String, - - pub starknet_cairo_core_contract_address: String, - + pub starknet_account_address: Address, + pub starknet_cairo_core_contract_address: Address, pub starknet_finality_retry_wait_in_secs: u64, - - pub madara_binary_path: String, } // Assumed the contract called for settlement looks like: @@ -63,7 +58,7 @@ impl StarknetSettlementClient { let provider: Arc> = Arc::new(JsonRpcClient::new(HttpTransport::new(settlement_cfg.starknet_rpc_url.clone()))); - let public_key = settlement_cfg.starknet_account_address.clone(); + let public_key = settlement_cfg.starknet_account_address.clone().to_string(); let signer_address = Felt::from_hex(&public_key).expect("invalid signer address"); // TODO: Very insecure way of building the signer. Needs to be adjusted. @@ -71,7 +66,7 @@ impl StarknetSettlementClient { let signer = Felt::from_hex(&private_key).expect("Invalid private key"); let signer = LocalWallet::from(SigningKey::from_secret_scalar(signer)); - let core_contract_address = Felt::from_hex(&settlement_cfg.starknet_cairo_core_contract_address) + let core_contract_address = Felt::from_hex(&settlement_cfg.starknet_cairo_core_contract_address.to_string()) .expect("Invalid core contract address"); let account: Arc>, LocalWallet>> = diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 2bbd0a59..cd0a6c85 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -1,8 +1,10 @@ use std::env; use std::path::Path; +use std::str::FromStr as _; use std::sync::Arc; use std::time::Duration; +use alloy_primitives::Address; use color_eyre::eyre::eyre; use rstest::{fixture, rstest}; use settlement_client_interface::SettlementClient; @@ -82,16 +84,19 @@ async fn setup(#[future] spin_up_madara: MadaraCmd) -> (LocalWalletSignerMiddlew let starknet_settlement_params: StarknetSettlementValidatedArgs = StarknetSettlementValidatedArgs { starknet_rpc_url: Url::parse(madara_process.rpc_url.as_ref()).unwrap(), starknet_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY"), - starknet_account_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS"), - starknet_cairo_core_contract_address: get_env_var_or_panic( + starknet_account_address: Address::from_str(&get_env_var_or_panic( + "MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS", + )) + .unwrap(), + starknet_cairo_core_contract_address: Address::from_str(&get_env_var_or_panic( "MADARA_ORCHESTRATOR_STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", - ), + )) + .unwrap(), starknet_finality_retry_wait_in_secs: get_env_var_or_panic( "MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS", ) .parse::() .unwrap(), - madara_binary_path: get_env_var_or_panic("MADARA_ORCHESTRATOR_MADARA_BINARY_PATH"), }; let rpc_url = Url::parse(starknet_settlement_params.starknet_rpc_url.as_ref()).unwrap(); @@ -100,7 +105,7 @@ async fn setup(#[future] spin_up_madara: MadaraCmd) -> (LocalWalletSignerMiddlew let signer = LocalWallet::from(SigningKey::from_secret_scalar( Felt::from_hex(&starknet_settlement_params.starknet_private_key).expect("Invalid private key"), )); - let address = Felt::from_hex(&starknet_settlement_params.starknet_account_address).unwrap(); + let address = Felt::from_hex(&starknet_settlement_params.starknet_account_address.to_string()).unwrap(); let chain_id = provider.chain_id().await.unwrap(); let mut account = SingleOwnerAccount::new(provider, signer, address, chain_id, ExecutionEncoding::New); @@ -121,16 +126,19 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) let mut starknet_settlement_params: StarknetSettlementValidatedArgs = StarknetSettlementValidatedArgs { starknet_rpc_url: madara_process.rpc_url.clone(), starknet_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY"), - starknet_account_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS"), - starknet_cairo_core_contract_address: get_env_var_or_panic( + starknet_account_address: Address::from_str(&get_env_var_or_panic( + "MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS", + )) + .unwrap(), + starknet_cairo_core_contract_address: Address::from_str(&get_env_var_or_panic( "MADARA_ORCHESTRATOR_STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", - ), + )) + .unwrap(), starknet_finality_retry_wait_in_secs: get_env_var_or_panic( "MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS", ) .parse::() .unwrap(), - madara_binary_path: get_env_var_or_panic("MADARA_ORCHESTRATOR_MADARA_BINARY_PATH"), }; let project_root = Path::new(env!("CARGO_MANIFEST_DIR")).ancestors().nth(3).unwrap(); @@ -162,7 +170,8 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) let deployed_address = deploy_v1.deployed_address(); // env::set_var("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", deployed_address.to_hex_string()); - starknet_settlement_params.starknet_cairo_core_contract_address = deployed_address.to_hex_string(); + starknet_settlement_params.starknet_cairo_core_contract_address = + Address::from_str(&deployed_address.to_hex_string()).unwrap(); let InvokeTransactionResult { transaction_hash: deploy_tx_hash } = deploy_v1.send().await.expect("Unable to deploy contract"); diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml index 537df164..ab351dee 100644 --- a/crates/utils/Cargo.toml +++ b/crates/utils/Cargo.toml @@ -6,7 +6,6 @@ edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = { version = "4.4", features = ["derive", "env"] } color-eyre = { workspace = true } serde.workspace = true serde_json = { workspace = true } diff --git a/e2e-tests/Cargo.toml b/e2e-tests/Cargo.toml index dfb042d6..547301a1 100644 --- a/e2e-tests/Cargo.toml +++ b/e2e-tests/Cargo.toml @@ -26,8 +26,8 @@ rstest.workspace = true serde.workspace = true serde_json.workspace = true starknet.workspace = true -strum = "0.26.0" -strum_macros = "0.26.0" +strum = { workspace = true } +strum_macros = { workspace = true } testcontainers.workspace = true tokio = { workspace = true, features = ["full"] } tokio-stream.workspace = true diff --git a/e2e-tests/src/mongodb.rs b/e2e-tests/src/mongodb.rs index cc9a28a0..3f29c1cd 100644 --- a/e2e-tests/src/mongodb.rs +++ b/e2e-tests/src/mongodb.rs @@ -1,5 +1,3 @@ -use std::str::FromStr; - use orchestrator::database::mongodb::MongoDBValidatedArgs; use url::Url; #[allow(dead_code)] @@ -9,7 +7,7 @@ pub struct MongoDbServer { impl MongoDbServer { pub fn run(mongodb_params: MongoDBValidatedArgs) -> Self { - Self { endpoint: Url::from_str(&mongodb_params.connection_url).unwrap() } + Self { endpoint: mongodb_params.connection_url } } pub fn endpoint(&self) -> Url { diff --git a/e2e-tests/src/node.rs b/e2e-tests/src/node.rs index 030e3a09..bef74615 100644 --- a/e2e-tests/src/node.rs +++ b/e2e-tests/src/node.rs @@ -36,15 +36,22 @@ pub enum OrchestratorMode { } impl Orchestrator { - pub fn setup(envs: Vec<(String, String)>) { - let port = get_free_port(); + pub fn new(mode: OrchestratorMode, mut envs: Vec<(String, String)>) -> Option { let repository_root = &get_repository_root(); - let port_str = format!("{}", port); - std::env::set_current_dir(repository_root).expect("Failed to change working directory"); - let envs = [envs, vec![("MADARA_ORCHESTRATOR_PORT".to_string(), port_str)]].concat(); - println!("Running orchestrator in Setup mode"); + let (mode_str, is_run_mode) = match mode { + OrchestratorMode::Setup => { + println!("Running orchestrator in Setup mode"); + (OrchestratorMode::Setup.to_string(), false) + } + OrchestratorMode::Run => { + println!("Running orchestrator in Run mode"); + (OrchestratorMode::Run.to_string(), true) + } + }; + + // Configure common command arguments let mut command = Command::new("cargo"); command .arg("run") @@ -53,100 +60,71 @@ impl Orchestrator { .arg("orchestrator") .arg("--features") .arg("testing") + .arg(mode_str) .arg("--") - // if mode::Run then --run else if mode::Setup then --setup - .arg("--setup") + .arg("--aws") .arg("--settle-on-ethereum") .arg("--aws-s3") .arg("--aws-sqs") .arg("--aws-sns") .arg("--mongodb") .arg("--sharp") - .arg("--da-on-ethereum") - .arg("--aws-event-bridge") - .current_dir(repository_root) - .envs(envs) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()); - - let mut process = command.spawn().expect("Failed to start process"); + .arg("--da-on-ethereum"); - // Wait for the process to complete and get its exit status - let status = process.wait().expect("Failed to wait for process"); - - // You can check if the process succeeded - if status.success() { - println!("Setup Orchestrator completed successfully"); - } else { - // Get the exit code if available - if let Some(code) = status.code() { - println!("Setup Orchestrator failed with exit code: {}", code); - } else { - println!("Setup Orchestrator terminated by signal"); - } + // Add event bridge arg only for setup mode + if !is_run_mode { + command.arg("--aws-event-bridge"); } - } - - pub fn run(envs: Vec<(String, String)>) -> Self { - let port = get_free_port(); - let address = format!("127.0.0.1:{}", port); - let repository_root = &get_repository_root(); - - std::env::set_current_dir(repository_root).expect("Failed to change working directory"); - let port_str = format!("{}", port); - let envs = [envs, vec![("MADARA_ORCHESTRATOR_PORT".to_string(), port_str)]].concat(); + // Configure run-specific settings + let address = if is_run_mode { + let port = get_free_port(); + let addr = format!("127.0.0.1:{}", port); + envs.push(("MADARA_ORCHESTRATOR_PORT".to_string(), port.to_string())); + addr + } else { + String::new() + }; - println!("Running orchestrator in Run mode"); - let mut command = Command::new("cargo"); - command - .arg("run") - .arg("--release") - .arg("--bin") - .arg("orchestrator") - .arg("--features") - .arg("testing") - .arg("--") - // if mode::Run then --run else if mode::Setup then --setup - .arg("--run") - .arg("--settle-on-ethereum") - .arg("--aws-s3") - .arg("--aws-sqs") - .arg("--aws-sns") - .arg("--mongodb") - .arg("--sharp") - .arg("--da-on-ethereum") - .arg("--aws-event-bridge") - .current_dir(repository_root) - .envs(envs) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()); + command.current_dir(repository_root).envs(envs).stdout(Stdio::piped()).stderr(Stdio::piped()); let mut process = command.spawn().expect("Failed to start process"); - // Capture and print stdout - let stdout = process.stdout.take().expect("Failed to capture stdout"); - thread::spawn(move || { - let reader = BufReader::new(stdout); - reader.lines().for_each(|line| { - if let Ok(line) = line { - println!("STDOUT: {}", line); - } + if is_run_mode { + // Set up stdout and stderr handling for run mode + let stdout = process.stdout.take().expect("Failed to capture stdout"); + thread::spawn(move || { + let reader = BufReader::new(stdout); + reader.lines().for_each(|line| { + if let Ok(line) = line { + println!("STDOUT: {}", line); + } + }); }); - }); - - // Capture and print stderr - let stderr = process.stderr.take().expect("Failed to capture stderr"); - thread::spawn(move || { - let reader = BufReader::new(stderr); - reader.lines().for_each(|line| { - if let Ok(line) = line { - eprintln!("STDERR: {}", line); - } + + let stderr = process.stderr.take().expect("Failed to capture stderr"); + thread::spawn(move || { + let reader = BufReader::new(stderr); + reader.lines().for_each(|line| { + if let Ok(line) = line { + eprintln!("STDERR: {}", line); + } + }); }); - }); - Self { process, address } + Some(Self { process, address }) + } else { + // Handle setup mode + let status = process.wait().expect("Failed to wait for process"); + if status.success() { + println!("Setup Orchestrator completed successfully"); + } else if let Some(code) = status.code() { + println!("Setup Orchestrator failed with exit code: {}", code); + } else { + println!("Setup Orchestrator terminated by signal"); + } + None + } } pub fn endpoint(&self) -> Url { diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index 097ab312..2cd91a59 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -24,6 +24,7 @@ use rstest::rstest; use serde::{Deserialize, Serialize}; use serde_json::json; use starknet::core::types::{Felt, MaybePendingStateUpdate}; +use url::Url; use utils::env_utils::get_env_var_or_panic; use uuid::Uuid; @@ -51,7 +52,8 @@ impl Setup { /// Initialise a new setup pub async fn new(l2_block_number: String) -> Self { let db_params = DatabaseValidatedArgs::MongoDB(MongoDBValidatedArgs { - connection_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL"), + connection_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL")) + .expect("Invalid MongoDB connection URL"), database_name: get_env_var_or_panic("MADARA_ORCHESTRATOR_DATABASE_NAME"), }); @@ -126,10 +128,13 @@ impl Setup { async fn test_orchestrator_workflow(#[case] l2_block_number: String) { // Fetching the env vars from the test env file as these will be used in // setting up of the test and during orchestrator run too. + + use e2e_tests::node::OrchestratorMode; dotenvy::from_filename(".env.test").expect("Failed to load the .env file"); let queue_params = AWSSQSValidatedArgs { - queue_base_url: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL"), + queue_base_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL")) + .expect("Invalid queue base URL"), sqs_prefix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_PREFIX"), sqs_suffix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_SUFFIX"), }; @@ -137,7 +142,7 @@ async fn test_orchestrator_workflow(#[case] l2_block_number: String) { let mut setup_config = Setup::new(l2_block_number.clone()).await; // Setup Cloud // Setup orchestrator cloud - Orchestrator::setup(setup_config.envs()); + Orchestrator::new(OrchestratorMode::Setup, setup_config.envs()); println!("✅ Orchestrator cloud setup completed"); // Step 1 : SNOS job runs ========================================= @@ -160,7 +165,8 @@ async fn test_orchestrator_workflow(#[case] l2_block_number: String) { println!("✅ Orchestrator setup completed."); // Run orchestrator - let mut orchestrator = Orchestrator::run(setup_config.envs()); + let mut orchestrator = + Orchestrator::new(OrchestratorMode::Run, setup_config.envs()).expect("Failed to start orchestrator"); orchestrator.wait_till_started().await; println!("✅ Orchestrator started"); From 414d62484d727b9d55d94306ac922f65d589eb98 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 13 Nov 2024 18:22:36 +0530 Subject: [PATCH 55/63] update: added e2e corrections --- crates/orchestrator/src/config.rs | 8 +-- .../ethereum/src/tests/mod.rs | 36 +++++++--- e2e-tests/src/node.rs | 65 +++++++------------ 3 files changed, 52 insertions(+), 57 deletions(-) diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 5475d805..dc0fd408 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -1,9 +1,5 @@ -#[cfg(feature = "testing")] -use std::str::FromStr; use std::sync::Arc; -#[cfg(feature = "testing")] -use alloy::primitives::Address; #[cfg(feature = "testing")] use alloy::providers::RootProvider; use aws_config::meta::region::RegionProviderChain; @@ -295,9 +291,9 @@ pub async fn build_settlement_client( { Ok(Box::new(EthereumSettlementClient::with_test_params( RootProvider::new_http(ethereum_settlement_params.ethereum_rpc_url.clone()), - Address::from_str(ðereum_settlement_params.l1_core_contract_address)?, + ethereum_settlement_params.l1_core_contract_address, ethereum_settlement_params.ethereum_rpc_url.clone(), - Some(Address::from_str(ðereum_settlement_params.starknet_operator_address)?), + Some(ethereum_settlement_params.starknet_operator_address), ))) } } diff --git a/crates/settlement-clients/ethereum/src/tests/mod.rs b/crates/settlement-clients/ethereum/src/tests/mod.rs index 6389f1fb..bbd4a8e5 100644 --- a/crates/settlement-clients/ethereum/src/tests/mod.rs +++ b/crates/settlement-clients/ethereum/src/tests/mod.rs @@ -161,8 +161,14 @@ mod settlement_client_tests { let ethereum_settlement_params = EthereumSettlementValidatedArgs { ethereum_rpc_url: setup.rpc_url, ethereum_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), - l1_core_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"), - starknet_operator_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"), + l1_core_contract_address: Address::from_str(&get_env_var_or_panic( + "MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS", + )) + .expect("Invalid L1 core contract address"), + starknet_operator_address: Address::from_str(&get_env_var_or_panic( + "MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS", + )) + .expect("Invalid Starknet operator address"), }; // Deploying a dummy contract @@ -233,15 +239,21 @@ mod settlement_client_tests { let ethereum_settlement_params = EthereumSettlementValidatedArgs { ethereum_rpc_url: setup.rpc_url, ethereum_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), - l1_core_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"), - starknet_operator_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"), + l1_core_contract_address: Address::from_str(&get_env_var_or_panic( + "MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS", + )) + .expect("Invalid L1 core contract address"), + starknet_operator_address: Address::from_str(&get_env_var_or_panic( + "MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS", + )) + .expect("Invalid Starknet operator address"), }; let ethereum_settlement_client = EthereumSettlementClient::with_test_params( setup.provider.clone(), - Address::from_str(ðereum_settlement_params.l1_core_contract_address).unwrap(), + ethereum_settlement_params.l1_core_contract_address, ethereum_settlement_params.ethereum_rpc_url, - Some(Address::from_str(ðereum_settlement_params.starknet_operator_address).unwrap()), + Some(ethereum_settlement_params.starknet_operator_address), ); // let nonce = ethereum_settlement_client.get_nonce().await.expect("Unable to fetch nonce"); @@ -299,13 +311,19 @@ mod settlement_client_tests { let ethereum_settlement_params = EthereumSettlementValidatedArgs { ethereum_rpc_url: setup.rpc_url, ethereum_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), - l1_core_contract_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"), - starknet_operator_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"), + l1_core_contract_address: Address::from_str(&get_env_var_or_panic( + "MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS", + )) + .expect("Invalid L1 core contract address"), + starknet_operator_address: Address::from_str(&get_env_var_or_panic( + "MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS", + )) + .expect("Invalid Starknet operator address"), }; let ethereum_settlement_client = EthereumSettlementClient::with_test_params( setup.provider.clone(), - Address::from_str(ðereum_settlement_params.l1_core_contract_address).unwrap(), + ethereum_settlement_params.l1_core_contract_address, ethereum_settlement_params.ethereum_rpc_url, None, ); diff --git a/e2e-tests/src/node.rs b/e2e-tests/src/node.rs index bef74615..f491efd3 100644 --- a/e2e-tests/src/node.rs +++ b/e2e-tests/src/node.rs @@ -40,16 +40,10 @@ impl Orchestrator { let repository_root = &get_repository_root(); std::env::set_current_dir(repository_root).expect("Failed to change working directory"); - let (mode_str, is_run_mode) = match mode { - OrchestratorMode::Setup => { - println!("Running orchestrator in Setup mode"); - (OrchestratorMode::Setup.to_string(), false) - } - OrchestratorMode::Run => { - println!("Running orchestrator in Run mode"); - (OrchestratorMode::Run.to_string(), true) - } - }; + let is_run_mode = mode == OrchestratorMode::Run; + let mode_str = mode.to_string(); + + println!("Running orchestrator in {} mode", mode_str); // Configure common command arguments let mut command = Command::new("cargo"); @@ -90,41 +84,28 @@ impl Orchestrator { let mut process = command.spawn().expect("Failed to start process"); - if is_run_mode { - // Set up stdout and stderr handling for run mode - let stdout = process.stdout.take().expect("Failed to capture stdout"); - thread::spawn(move || { - let reader = BufReader::new(stdout); - reader.lines().for_each(|line| { - if let Ok(line) = line { - println!("STDOUT: {}", line); - } - }); + // Set up stdout and stderr handling for run mode + let stdout = process.stdout.take().expect("Failed to capture stdout"); + thread::spawn(move || { + let reader = BufReader::new(stdout); + reader.lines().for_each(|line| { + if let Ok(line) = line { + println!("STDOUT: {}", line); + } }); - - let stderr = process.stderr.take().expect("Failed to capture stderr"); - thread::spawn(move || { - let reader = BufReader::new(stderr); - reader.lines().for_each(|line| { - if let Ok(line) = line { - eprintln!("STDERR: {}", line); - } - }); + }); + + let stderr = process.stderr.take().expect("Failed to capture stderr"); + thread::spawn(move || { + let reader = BufReader::new(stderr); + reader.lines().for_each(|line| { + if let Ok(line) = line { + eprintln!("STDERR: {}", line); + } }); + }); - Some(Self { process, address }) - } else { - // Handle setup mode - let status = process.wait().expect("Failed to wait for process"); - if status.success() { - println!("Setup Orchestrator completed successfully"); - } else if let Some(code) = status.code() { - println!("Setup Orchestrator failed with exit code: {}", code); - } else { - println!("Setup Orchestrator terminated by signal"); - } - None - } + if is_run_mode { Some(Self { process, address }) } else { None } } pub fn endpoint(&self) -> Url { From 02618d145acff4d7cd3b90d362c2c4161718e7d6 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Wed, 13 Nov 2024 23:42:29 +0530 Subject: [PATCH 56/63] update: e2e fixed --- .../orchestrator/src/cli/cron/event_bridge.rs | 4 +- crates/orchestrator/src/cli/mod.rs | 2 +- crates/orchestrator/src/queue/mod.rs | 2 +- crates/orchestrator/src/setup/mod.rs | 10 +-- e2e-tests/src/node.rs | 82 ++++++++++++------- e2e-tests/tests.rs | 4 +- 6 files changed, 64 insertions(+), 40 deletions(-) diff --git a/crates/orchestrator/src/cli/cron/event_bridge.rs b/crates/orchestrator/src/cli/cron/event_bridge.rs index 321eab9b..db32a091 100644 --- a/crates/orchestrator/src/cli/cron/event_bridge.rs +++ b/crates/orchestrator/src/cli/cron/event_bridge.rs @@ -9,10 +9,10 @@ pub struct AWSEventBridgeCliArgs { pub aws_event_bridge: bool, /// The name of the S3 bucket. - #[arg(env = "MADARA_ORCHESTRATOR_EVENT_BRIDGE_TARGET_QUEUE_NAME", long, default_value = Some("madara-orchestrator-event-bridge-target-queue-name"), help = "The name of the SNS queue to send messages to from the event bridge.")] + #[arg(env = "MADARA_ORCHESTRATOR_EVENT_BRIDGE_TARGET_QUEUE_NAME", long, default_value = Some("madara_orchestrator_worker_trigger_queue"), help = "The name of the SNS queue to send messages to from the event bridge.")] pub target_queue_name: Option, /// The cron time for the event bridge trigger rule. - #[arg(env = "MADARA_ORCHESTRATOR_EVENT_BRIDGE_CRON_TIME", long, default_value = Some("10"), help = "The cron time for the event bridge trigger rule. Defaults to 10 seconds.")] + #[arg(env = "MADARA_ORCHESTRATOR_EVENT_BRIDGE_CRON_TIME", long, default_value = Some("300"), help = "The cron time for the event bridge trigger rule. Defaults to 10 seconds.")] pub cron_time: Option, /// The name of the event bridge trigger rule. diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index 886738c3..e8320fa3 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -114,7 +114,7 @@ pub enum Commands { ), )] pub struct RunCmd { - // AWS Config + // Provider Config #[clap(flatten)] pub aws_config_args: AWSConfigCliArgs, diff --git a/crates/orchestrator/src/queue/mod.rs b/crates/orchestrator/src/queue/mod.rs index 57fa8f83..cf9d9ece 100644 --- a/crates/orchestrator/src/queue/mod.rs +++ b/crates/orchestrator/src/queue/mod.rs @@ -58,6 +58,7 @@ pub struct QueueConfig { // TODO: use QueueType::iter() or format! lazy_static! { pub static ref QUEUES: Vec = vec![ + QueueConfig { name: QueueType::JobHandleFailure, visibility_timeout: 300, dlq_config: None }, QueueConfig { name: QueueType::SnosJobProcessing, visibility_timeout: 300, @@ -98,7 +99,6 @@ lazy_static! { visibility_timeout: 300, dlq_config: Some(DlqConfig { max_receive_count: 5, dlq_name: QueueType::JobHandleFailure }) }, - QueueConfig { name: QueueType::JobHandleFailure, visibility_timeout: 300, dlq_config: None }, QueueConfig { name: QueueType::WorkerTrigger, visibility_timeout: 300, dlq_config: None }, ]; } diff --git a/crates/orchestrator/src/setup/mod.rs b/crates/orchestrator/src/setup/mod.rs index 3957816f..10c4e8b0 100644 --- a/crates/orchestrator/src/setup/mod.rs +++ b/crates/orchestrator/src/setup/mod.rs @@ -24,13 +24,13 @@ pub enum SetupConfig { // TODO : move this to main.rs after moving to clap. pub async fn setup_cloud(run_cmd: &SetupCmd) -> color_eyre::Result<()> { - println!("Setting up cloud."); + println!("Setting up cloud. ⏳"); // AWS let provider_params = run_cmd.validate_provider_params().expect("Failed to validate provider params"); let provider_config = build_provider_config(&provider_params).await; // Data Storage - println!("Setting up data storage."); + println!("Setting up data storage. ⏳"); let data_storage_params = run_cmd.validate_storage_params().expect("Failed to validate storage params"); let aws_config = provider_config.get_aws_client_or_panic(); @@ -43,7 +43,7 @@ pub async fn setup_cloud(run_cmd: &SetupCmd) -> color_eyre::Result<()> { println!("Data storage setup completed ✅"); // Queues - println!("Setting up queues"); + println!("Setting up queues. ⏳"); let queue_params = run_cmd.validate_queue_params().expect("Failed to validate queue params"); match queue_params { QueueValidatedArgs::AWSSQS(aws_sqs_params) => { @@ -54,7 +54,7 @@ pub async fn setup_cloud(run_cmd: &SetupCmd) -> color_eyre::Result<()> { println!("Queues setup completed ✅"); // Cron - println!("Setting up cron"); + println!("Setting up cron. ⏳"); let cron_params = run_cmd.validate_cron_params().expect("Failed to validate cron params"); match cron_params { CronValidatedArgs::AWSEventBridge(aws_event_bridge_params) => { @@ -66,7 +66,7 @@ pub async fn setup_cloud(run_cmd: &SetupCmd) -> color_eyre::Result<()> { println!("Cron setup completed ✅"); // Alerts - println!("Setting up alerts."); + println!("Setting up alerts. ⏳"); let alert_params = run_cmd.validate_alert_params().expect("Failed to validate alert params"); match alert_params { AlertValidatedArgs::AWSSNS(aws_sns_params) => { diff --git a/e2e-tests/src/node.rs b/e2e-tests/src/node.rs index f491efd3..58c50a45 100644 --- a/e2e-tests/src/node.rs +++ b/e2e-tests/src/node.rs @@ -34,7 +34,6 @@ pub enum OrchestratorMode { #[strum(serialize = "setup")] Setup, } - impl Orchestrator { pub fn new(mode: OrchestratorMode, mut envs: Vec<(String, String)>) -> Option { let repository_root = &get_repository_root(); @@ -55,18 +54,19 @@ impl Orchestrator { .arg("--features") .arg("testing") .arg(mode_str) - .arg("--") .arg("--aws") - .arg("--settle-on-ethereum") .arg("--aws-s3") .arg("--aws-sqs") - .arg("--aws-sns") - .arg("--mongodb") - .arg("--sharp") - .arg("--da-on-ethereum"); + .arg("--aws-sns"); // Add event bridge arg only for setup mode - if !is_run_mode { + if is_run_mode { + command.arg("--settle-on-ethereum"); + command.arg("--da-on-ethereum"); + command.arg("--sharp"); + command.arg("--mongodb"); + + } else { command.arg("--aws-event-bridge"); } @@ -80,34 +80,58 @@ impl Orchestrator { String::new() }; - command.current_dir(repository_root).envs(envs).stdout(Stdio::piped()).stderr(Stdio::piped()); + command.current_dir(repository_root).envs(envs); + + // Handle stdout/stderr differently based on mode + if is_run_mode { + command.stdout(Stdio::piped()).stderr(Stdio::piped()); + } else { + // For setup mode, inherit the stdio to show output directly + command.stdout(Stdio::inherit()).stderr(Stdio::inherit()); + } let mut process = command.spawn().expect("Failed to start process"); - // Set up stdout and stderr handling for run mode - let stdout = process.stdout.take().expect("Failed to capture stdout"); - thread::spawn(move || { - let reader = BufReader::new(stdout); - reader.lines().for_each(|line| { - if let Ok(line) = line { - println!("STDOUT: {}", line); - } + // Set up stdout and stderr handling only for run mode + if is_run_mode { + let stdout = process.stdout.take().expect("Failed to capture stdout"); + thread::spawn(move || { + let reader = BufReader::new(stdout); + reader.lines().for_each(|line| { + if let Ok(line) = line { + println!("STDOUT: {}", line); + } + }); }); - }); - - let stderr = process.stderr.take().expect("Failed to capture stderr"); - thread::spawn(move || { - let reader = BufReader::new(stderr); - reader.lines().for_each(|line| { - if let Ok(line) = line { - eprintln!("STDERR: {}", line); - } + + let stderr = process.stderr.take().expect("Failed to capture stderr"); + thread::spawn(move || { + let reader = BufReader::new(stderr); + reader.lines().for_each(|line| { + if let Ok(line) = line { + eprintln!("STDERR: {}", line); + } + }); }); - }); + } - if is_run_mode { Some(Self { process, address }) } else { None } + if is_run_mode { Some(Self { process, address }) } else { + // Wait for the process to complete and get its exit status + let status = process.wait().expect("Failed to wait for process"); + if status.success() { + println!("Orchestrator cloud setup completed ✅"); + } else { + // Get the exit code if available + if let Some(code) = status.code() { + println!("Orchestrator cloud setup failed with exit code: {}", code); + } else { + println!("Orchestrator cloud setup terminated by signal"); + } + } + None + } } - + pub fn endpoint(&self) -> Url { Url::parse(&format!("http://{}", self.address)).unwrap() } diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index 2cd91a59..8ff2900f 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -317,14 +317,14 @@ pub async fn put_message_in_queue(message: JobQueueMessage, queue_url: String) - let rsp = client.send_message().queue_url(queue_url).message_body(serde_json::to_string(&message)?).send().await?; - println!("Successfully sent message with ID: {:?}", rsp.message_id()); + println!("✅ Successfully sent message with ID: {:?}", rsp.message_id()); Ok(()) } /// Mocks the endpoint for sharp client pub async fn mock_proving_job_endpoint_output(sharp_client: &mut SharpClient) { - // Add job response + // Add job response, let add_job_response = json!( { "code" : "JOB_RECEIVED_SUCCESSFULLY" From ad0c7541cb0216d4cfb44239128d5cedb2c11a43 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Thu, 14 Nov 2024 00:37:40 +0530 Subject: [PATCH 57/63] update: fixed coverage --- .env.test | 2 ++ crates/orchestrator/src/tests/config.rs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.env.test b/.env.test index a4ad346a..9a93b801 100644 --- a/.env.test +++ b/.env.test @@ -13,8 +13,10 @@ AWS_DEFAULT_REGION=localhost #### ALERTS #### +MADARA_ORCHESTRATOR_AWS_SNS_ARN_NAME=madara-orchestrator-arn MADARA_ORCHESTRATOR_AWS_SNS_ARN=arn:aws:sns:us-east-1:000000000000:madara-orchestrator-arn + #### DATA AVAILABILITY #### ## ETHEREUM ## diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 811e5ec2..22da06b7 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -512,7 +512,7 @@ fn get_env_params() -> EnvParams { }); let alert_params = AlertValidatedArgs::AWSSNS(AWSSNSValidatedArgs { - topic_arn: get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_SNS_ARN"), + topic_arn: get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_SNS_ARN_NAME"), }); let settlement_params = SettlementValidatedArgs::Ethereum(EthereumSettlementValidatedArgs { From ec4ad856384077a2bc23dfce9dbcf3c0ef03ca4d Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Thu, 14 Nov 2024 00:55:29 +0530 Subject: [PATCH 58/63] update: MADARA_ORCHESTRATOR_EVENT_BRIDGE_CRON_TIME to 60 seconds --- crates/orchestrator/src/cli/cron/event_bridge.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/orchestrator/src/cli/cron/event_bridge.rs b/crates/orchestrator/src/cli/cron/event_bridge.rs index db32a091..a7dba45d 100644 --- a/crates/orchestrator/src/cli/cron/event_bridge.rs +++ b/crates/orchestrator/src/cli/cron/event_bridge.rs @@ -12,7 +12,7 @@ pub struct AWSEventBridgeCliArgs { #[arg(env = "MADARA_ORCHESTRATOR_EVENT_BRIDGE_TARGET_QUEUE_NAME", long, default_value = Some("madara_orchestrator_worker_trigger_queue"), help = "The name of the SNS queue to send messages to from the event bridge.")] pub target_queue_name: Option, /// The cron time for the event bridge trigger rule. - #[arg(env = "MADARA_ORCHESTRATOR_EVENT_BRIDGE_CRON_TIME", long, default_value = Some("300"), help = "The cron time for the event bridge trigger rule. Defaults to 10 seconds.")] + #[arg(env = "MADARA_ORCHESTRATOR_EVENT_BRIDGE_CRON_TIME", long, default_value = Some("60"), help = "The cron time for the event bridge trigger rule. Defaults to 10 seconds.")] pub cron_time: Option, /// The name of the event bridge trigger rule. From 982aed98dfafe96f5012acceea45198e051d2b77 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Thu, 14 Nov 2024 16:03:12 +0530 Subject: [PATCH 59/63] update: testcase fixes --- .env.test | 1 - crates/orchestrator/src/cli/alert/aws_sns.rs | 2 +- crates/orchestrator/src/cli/mod.rs | 888 ++++++++++-------- crates/orchestrator/src/setup/mod.rs | 12 +- crates/orchestrator/src/tests/common/mod.rs | 3 +- crates/orchestrator/src/tests/config.rs | 2 +- crates/settlement-clients/ethereum/Cargo.toml | 2 +- crates/settlement-clients/starknet/Cargo.toml | 2 +- crates/settlement-clients/starknet/src/lib.rs | 5 +- .../starknet/src/tests/test.rs | 25 +- e2e-tests/src/node.rs | 30 +- e2e-tests/tests.rs | 148 +-- 12 files changed, 559 insertions(+), 561 deletions(-) diff --git a/.env.test b/.env.test index 9a93b801..c1bc7ea8 100644 --- a/.env.test +++ b/.env.test @@ -13,7 +13,6 @@ AWS_DEFAULT_REGION=localhost #### ALERTS #### -MADARA_ORCHESTRATOR_AWS_SNS_ARN_NAME=madara-orchestrator-arn MADARA_ORCHESTRATOR_AWS_SNS_ARN=arn:aws:sns:us-east-1:000000000000:madara-orchestrator-arn diff --git a/crates/orchestrator/src/cli/alert/aws_sns.rs b/crates/orchestrator/src/cli/alert/aws_sns.rs index c335cee0..93355374 100644 --- a/crates/orchestrator/src/cli/alert/aws_sns.rs +++ b/crates/orchestrator/src/cli/alert/aws_sns.rs @@ -9,6 +9,6 @@ pub struct AWSSNSCliArgs { pub aws_sns: bool, /// The name of the S3 bucket. - #[arg(env = "MADARA_ORCHESTRATOR_AWS_SNS_ARN", long, default_value = Some("madara-orchestrator-arn"))] + #[arg(env = "MADARA_ORCHESTRATOR_AWS_SNS_ARN", long, default_value = Some("arn:aws:sns:us-east-1:000000000000:madara-orchestrator-arn"))] pub sns_arn: Option, } diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index e8320fa3..c067b7db 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -1,32 +1,18 @@ -use std::str::FromStr as _; -use std::time::Duration; - use alert::AlertValidatedArgs; -use alloy::primitives::Address; use clap::{ArgGroup, Parser, Subcommand}; use cron::event_bridge::AWSEventBridgeCliArgs; use cron::CronValidatedArgs; use da::DaValidatedArgs; use database::DatabaseValidatedArgs; -use ethereum_da_client::EthereumDaValidatedArgs; -use ethereum_settlement_client::EthereumSettlementValidatedArgs; use prover::ProverValidatedArgs; use provider::aws::AWSConfigCliArgs; -use provider::{AWSConfigValidatedArgs, ProviderValidatedArgs}; +use provider::ProviderValidatedArgs; use queue::QueueValidatedArgs; -use settlement::SettlementValidatedArgs; -use sharp_service::SharpValidatedArgs; use snos::SNOSParams; -use starknet_settlement_client::StarknetSettlementValidatedArgs; use storage::StorageValidatedArgs; use url::Url; -use crate::alerts::aws_sns::AWSSNSValidatedArgs; use crate::config::ServiceParams; -use crate::cron::event_bridge::AWSEventBridgeValidatedArgs; -use crate::data_storage::aws_s3::AWSS3ValidatedArgs; -use crate::database::mongodb::MongoDBValidatedArgs; -use crate::queue::sqs::AWSSQSValidatedArgs; use crate::routes::ServerParams; use crate::telemetry::InstrumentationParams; @@ -169,192 +155,51 @@ pub struct RunCmd { impl RunCmd { pub fn validate_provider_params(&self) -> Result { - if self.aws_config_args.aws { - Ok(ProviderValidatedArgs::AWS(AWSConfigValidatedArgs { - aws_access_key_id: self.aws_config_args.aws_access_key_id.clone(), - aws_secret_access_key: self.aws_config_args.aws_secret_access_key.clone(), - aws_region: self.aws_config_args.aws_region.clone(), - })) - } else { - Err("Only AWS is supported as of now".to_string()) - } + validate_params::validate_provider_params(&self.aws_config_args) } pub fn validate_alert_params(&self) -> Result { - if self.aws_sns_args.aws_sns && self.aws_config_args.aws { - Ok(AlertValidatedArgs::AWSSNS(AWSSNSValidatedArgs { - topic_arn: self.aws_sns_args.sns_arn.clone().expect("SNS ARN is required"), - })) - } else { - Err("Only AWS SNS is supported as of now".to_string()) - } + validate_params::validate_alert_params(&self.aws_sns_args, &self.aws_config_args) } pub fn validate_queue_params(&self) -> Result { - if self.aws_sqs_args.aws_sqs && self.aws_config_args.aws { - Ok(QueueValidatedArgs::AWSSQS(AWSSQSValidatedArgs { - queue_base_url: Url::parse( - &self.aws_sqs_args.queue_base_url.clone().expect("Queue base URL is required"), - ) - .expect("Invalid queue base URL"), - sqs_prefix: self.aws_sqs_args.sqs_prefix.clone().expect("SQS prefix is required"), - sqs_suffix: self.aws_sqs_args.sqs_suffix.clone().expect("SQS suffix is required"), - })) - } else { - Err("Only AWS SQS is supported as of now".to_string()) - } + validate_params::validate_queue_params(&self.aws_sqs_args, &self.aws_config_args) } pub fn validate_storage_params(&self) -> Result { - if self.aws_s3_args.aws_s3 && self.aws_config_args.aws { - Ok(StorageValidatedArgs::AWSS3(AWSS3ValidatedArgs { - bucket_name: self.aws_s3_args.bucket_name.clone().expect("Bucket name is required"), - })) - } else { - Err("Only AWS S3 is supported as of now".to_string()) - } + validate_params::validate_storage_params(&self.aws_s3_args, &self.aws_config_args) } pub fn validate_database_params(&self) -> Result { - if self.mongodb_args.mongodb { - Ok(DatabaseValidatedArgs::MongoDB(MongoDBValidatedArgs { - connection_url: Url::parse( - &self.mongodb_args.mongodb_connection_url.clone().expect("MongoDB connection URL is required"), - ) - .expect("Invalid MongoDB connection URL"), - database_name: self - .mongodb_args - .mongodb_database_name - .clone() - .expect("MongoDB database name is required"), - })) - } else { - Err("Only MongoDB is supported as of now".to_string()) - } + validate_params::validate_database_params(&self.mongodb_args) } pub fn validate_da_params(&self) -> Result { - if self.ethereum_da_args.da_on_ethereum { - Ok(DaValidatedArgs::Ethereum(EthereumDaValidatedArgs { - ethereum_da_rpc_url: self - .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()) - } + validate_params::validate_da_params(&self.ethereum_da_args) } pub fn validate_settlement_params(&self) -> Result { - if self.ethereum_args.settle_on_ethereum { - let l1_core_contract_address = Address::from_str( - &self.ethereum_args.l1_core_contract_address.clone().expect("L1 core contract address is required"), - ) - .expect("Invalid L1 core contract address"); - let starknet_operator_address = Address::from_str( - &self.ethereum_args.starknet_operator_address.clone().expect("Starknet operator address is required"), - ) - .expect("Invalid Starknet operator address"); - - let ethereum_params = EthereumSettlementValidatedArgs { - ethereum_rpc_url: self.ethereum_args.ethereum_rpc_url.clone().expect("Ethereum RPC URL is required"), - ethereum_private_key: self - .ethereum_args - .ethereum_private_key - .clone() - .expect("Ethereum private key is required"), - l1_core_contract_address, - starknet_operator_address, - }; - Ok(SettlementValidatedArgs::Ethereum(ethereum_params)) - } else if self.starknet_args.settle_on_starknet { - let starknet_params = StarknetSettlementValidatedArgs { - starknet_rpc_url: self.starknet_args.starknet_rpc_url.clone().expect("Starknet RPC URL is required"), - starknet_private_key: self - .starknet_args - .starknet_private_key - .clone() - .expect("Starknet private key is required"), - starknet_account_address: Address::from_str( - &self.starknet_args.starknet_account_address.clone().expect("Starknet account address is required"), - ) - .expect("Invalid Starknet account address"), - starknet_cairo_core_contract_address: Address::from_str( - &self - .starknet_args - .starknet_cairo_core_contract_address - .clone() - .expect("Starknet Cairo core contract address is required"), - ) - .expect("Invalid Starknet Cairo core contract address"), - starknet_finality_retry_wait_in_secs: self - .starknet_args - .starknet_finality_retry_wait_in_secs - .expect("Starknet finality retry wait in seconds is required"), - }; - Ok(SettlementValidatedArgs::Starknet(starknet_params)) - } else { - Err("Settlement layer is required".to_string()) - } + validate_params::validate_settlement_params(&self.ethereum_args, &self.starknet_args) } pub fn validate_prover_params(&self) -> Result { - if self.sharp_args.sharp { - Ok(ProverValidatedArgs::Sharp(SharpValidatedArgs { - sharp_customer_id: self.sharp_args.sharp_customer_id.clone().expect("Sharp customer ID is required"), - sharp_url: self.sharp_args.sharp_url.clone().expect("Sharp URL is required"), - sharp_user_crt: self.sharp_args.sharp_user_crt.clone().expect("Sharp user certificate is required"), - sharp_user_key: self.sharp_args.sharp_user_key.clone().expect("Sharp user key is required"), - sharp_rpc_node_url: self.sharp_args.sharp_rpc_node_url.clone().expect("Sharp RPC node URL is required"), - sharp_proof_layout: self.sharp_args.sharp_proof_layout.clone().expect("Sharp proof layout is required"), - gps_verifier_contract_address: self - .sharp_args - .gps_verifier_contract_address - .clone() - .expect("GPS verifier contract address is required"), - sharp_server_crt: self - .sharp_args - .sharp_server_crt - .clone() - .expect("Sharp server certificate is required"), - })) - } else { - Err("Only Sharp is supported as of now".to_string()) - } + validate_params::validate_prover_params(&self.sharp_args) } pub fn validate_instrumentation_params(&self) -> Result { - Ok(InstrumentationParams { - otel_service_name: self - .instrumentation_args - .otel_service_name - .clone() - .expect("Otel service name is required"), - otel_collector_endpoint: self.instrumentation_args.otel_collector_endpoint.clone(), - log_level: self.instrumentation_args.log_level, - }) + validate_params::validate_instrumentation_params(&self.instrumentation_args) } pub fn validate_server_params(&self) -> Result { - Ok(ServerParams { host: self.server_args.host.clone(), port: self.server_args.port }) + validate_params::validate_server_params(&self.server_args) } pub fn validate_service_params(&self) -> Result { - Ok(ServiceParams { - // return None if the value is empty string - max_block_to_process: self.service_args.max_block_to_process.clone().and_then(|s| { - if s.is_empty() { None } else { Some(s.parse::().expect("Failed to parse max block to process")) } - }), - min_block_to_process: self.service_args.min_block_to_process.clone().and_then(|s| { - if s.is_empty() { None } else { Some(s.parse::().expect("Failed to parse min block to process")) } - }), - }) + validate_params::validate_service_params(&self.service_args) } pub fn validate_snos_params(&self) -> Result { - Ok(SNOSParams { rpc_for_snos: self.snos_args.rpc_for_snos.clone() }) + validate_params::validate_snos_params(&self.snos_args) } } @@ -420,70 +265,144 @@ pub struct SetupCmd { impl SetupCmd { pub fn validate_provider_params(&self) -> Result { - if self.aws_config_args.aws { + validate_params::validate_provider_params(&self.aws_config_args) + } + + pub fn validate_storage_params(&self) -> Result { + validate_params::validate_storage_params(&self.aws_s3_args, &self.aws_config_args) + } + + pub fn validate_queue_params(&self) -> Result { + validate_params::validate_queue_params(&self.aws_sqs_args, &self.aws_config_args) + } + + pub fn validate_alert_params(&self) -> Result { + validate_params::validate_alert_params(&self.aws_sns_args, &self.aws_config_args) + } + + pub fn validate_cron_params(&self) -> Result { + validate_params::validate_cron_params(&self.aws_event_bridge_args, &self.aws_config_args) + } +} + +pub mod validate_params { + use std::str::FromStr as _; + use std::time::Duration; + + use alloy::primitives::Address; + use ethereum_da_client::EthereumDaValidatedArgs; + use ethereum_settlement_client::EthereumSettlementValidatedArgs; + use sharp_service::SharpValidatedArgs; + use starknet_settlement_client::StarknetSettlementValidatedArgs; + use url::Url; + + use super::alert::aws_sns::AWSSNSCliArgs; + use super::alert::AlertValidatedArgs; + use super::cron::event_bridge::AWSEventBridgeCliArgs; + use super::cron::CronValidatedArgs; + use super::da::ethereum::EthereumDaCliArgs; + use super::da::DaValidatedArgs; + use super::database::mongodb::MongoDBCliArgs; + use super::database::DatabaseValidatedArgs; + use super::instrumentation::InstrumentationCliArgs; + use super::prover::sharp::SharpCliArgs; + use super::prover::ProverValidatedArgs; + use super::provider::aws::AWSConfigCliArgs; + use super::provider::{AWSConfigValidatedArgs, ProviderValidatedArgs}; + use super::queue::aws_sqs::AWSSQSCliArgs; + use super::queue::QueueValidatedArgs; + use super::server::ServerCliArgs; + use super::service::ServiceCliArgs; + use super::settlement::ethereum::EthereumSettlementCliArgs; + use super::settlement::starknet::StarknetSettlementCliArgs; + use super::settlement::SettlementValidatedArgs; + use super::snos::{SNOSCliArgs, SNOSParams}; + use super::storage::aws_s3::AWSS3CliArgs; + use super::storage::StorageValidatedArgs; + use crate::alerts::aws_sns::AWSSNSValidatedArgs; + use crate::config::ServiceParams; + use crate::cron::event_bridge::AWSEventBridgeValidatedArgs; + use crate::data_storage::aws_s3::AWSS3ValidatedArgs; + use crate::database::mongodb::MongoDBValidatedArgs; + use crate::queue::sqs::AWSSQSValidatedArgs; + use crate::routes::ServerParams; + use crate::telemetry::InstrumentationParams; + + pub(crate) fn validate_provider_params( + aws_config_args: &AWSConfigCliArgs, + ) -> Result { + if aws_config_args.aws { Ok(ProviderValidatedArgs::AWS(AWSConfigValidatedArgs { - aws_access_key_id: self.aws_config_args.aws_access_key_id.clone(), - aws_secret_access_key: self.aws_config_args.aws_secret_access_key.clone(), - aws_region: self.aws_config_args.aws_region.clone(), + aws_access_key_id: aws_config_args.aws_access_key_id.clone(), + aws_secret_access_key: aws_config_args.aws_secret_access_key.clone(), + aws_region: aws_config_args.aws_region.clone(), })) } else { Err("Only AWS is supported as of now".to_string()) } } - pub fn validate_alert_params(&self) -> Result { - if self.aws_sns_args.aws_sns && self.aws_config_args.aws { + pub(crate) fn validate_alert_params( + aws_sns_args: &AWSSNSCliArgs, + aws_config_args: &AWSConfigCliArgs, + ) -> Result { + if aws_sns_args.aws_sns && aws_config_args.aws { Ok(AlertValidatedArgs::AWSSNS(AWSSNSValidatedArgs { - topic_arn: self.aws_sns_args.sns_arn.clone().expect("SNS ARN is required"), + topic_arn: aws_sns_args.sns_arn.clone().expect("SNS ARN is required"), })) } else { Err("Only AWS SNS is supported as of now".to_string()) } } - pub fn validate_queue_params(&self) -> Result { - if self.aws_sqs_args.aws_sqs && self.aws_config_args.aws { + pub(crate) fn validate_queue_params( + aws_sqs_args: &AWSSQSCliArgs, + aws_config_args: &AWSConfigCliArgs, + ) -> Result { + if aws_sqs_args.aws_sqs && aws_config_args.aws { Ok(QueueValidatedArgs::AWSSQS(AWSSQSValidatedArgs { - queue_base_url: Url::parse( - &self.aws_sqs_args.queue_base_url.clone().expect("Queue base URL is required"), - ) - .expect("Invalid queue base URL"), - sqs_prefix: self.aws_sqs_args.sqs_prefix.clone().expect("SQS prefix is required"), - sqs_suffix: self.aws_sqs_args.sqs_suffix.clone().expect("SQS suffix is required"), + queue_base_url: Url::parse(&aws_sqs_args.queue_base_url.clone().expect("Queue base URL is required")) + .expect("Invalid queue base URL"), + sqs_prefix: aws_sqs_args.sqs_prefix.clone().expect("SQS prefix is required"), + sqs_suffix: aws_sqs_args.sqs_suffix.clone().expect("SQS suffix is required"), })) } else { Err("Only AWS SQS is supported as of now".to_string()) } } - pub fn validate_storage_params(&self) -> Result { - if self.aws_s3_args.aws_s3 && self.aws_config_args.aws { + pub(crate) fn validate_storage_params( + aws_s3_args: &AWSS3CliArgs, + aws_config_args: &AWSConfigCliArgs, + ) -> Result { + if aws_s3_args.aws_s3 && aws_config_args.aws { Ok(StorageValidatedArgs::AWSS3(AWSS3ValidatedArgs { - bucket_name: self.aws_s3_args.bucket_name.clone().expect("Bucket name is required"), + bucket_name: aws_s3_args.bucket_name.clone().expect("Bucket name is required"), })) } else { Err("Only AWS S3 is supported as of now".to_string()) } } - pub fn validate_cron_params(&self) -> Result { - if self.aws_event_bridge_args.aws_event_bridge && self.aws_config_args.aws { + pub(crate) fn validate_cron_params( + aws_event_bridge_args: &AWSEventBridgeCliArgs, + aws_config_args: &AWSConfigCliArgs, + ) -> Result { + if aws_event_bridge_args.aws_event_bridge && aws_config_args.aws { Ok(CronValidatedArgs::AWSEventBridge(AWSEventBridgeValidatedArgs { - target_queue_name: self - .aws_event_bridge_args + target_queue_name: aws_event_bridge_args .target_queue_name .clone() .expect("Target queue name is required"), cron_time: Duration::from_secs( - self.aws_event_bridge_args + aws_event_bridge_args .cron_time .clone() .expect("Cron time is required") .parse::() .expect("Failed to parse cron time"), ), - trigger_rule_name: self - .aws_event_bridge_args + trigger_rule_name: aws_event_bridge_args .trigger_rule_name .clone() .expect("Trigger rule name is required"), @@ -492,191 +411,400 @@ impl SetupCmd { Err("Only AWS Event Bridge is supported as of now".to_string()) } } -} -// #[cfg(test)] -// pub mod test { - -// use rstest::{fixture, rstest}; -// use tracing::Level; -// use url::Url; - -// use super::alert::aws_sns::AWSSNSCliArgs; -// use super::cron::event_bridge::AWSEventBridgeCliArgs; -// use super::da::ethereum::EthereumDaCliArgs; -// use super::database::mongodb::MongoDBCliArgs; -// use super::instrumentation::InstrumentationCliArgs; -// use super::prover::sharp::SharpCliArgs; -// use super::provider::aws::AWSConfigCliArgs; -// use super::queue::aws_sqs::AWSSQSCliArgs; -// use super::server::ServerCliArgs; -// use super::service::ServiceCliArgs; -// use super::settlement::ethereum::EthereumSettlementCliArgs; -// use super::settlement::starknet::StarknetSettlementCliArgs; -// use super::snos::SNOSCliArgs; -// use super::storage::aws_s3::AWSS3CliArgs; -// use crate::cli::RunCmd; - -// // create a fixture for the CLI -// #[fixture] -// pub fn setup_cmd() -> RunCmd { -// RunCmd { -// aws_config_args: AWSConfigCliArgs { -// aws: true, -// aws_access_key_id: "".to_string(), -// aws_secret_access_key: "".to_string(), -// aws_region: "".to_string(), -// }, -// aws_event_bridge_args: AWSEventBridgeCliArgs { -// aws_event_bridge: true, -// target_queue_name: Some("".to_string()), -// cron_time: Some("12".to_string()), -// trigger_rule_name: Some("".to_string()), -// }, -// aws_s3_args: AWSS3CliArgs { aws_s3: true, bucket_name: Some("".to_string()) }, -// aws_sqs_args: AWSSQSCliArgs { -// aws_sqs: true, -// queue_base_url: Some("".to_string()), -// sqs_prefix: Some("".to_string()), -// sqs_suffix: Some("".to_string()), -// }, -// server_args: ServerCliArgs { host: "".to_string(), port: 0 }, -// aws_sns_args: AWSSNSCliArgs { aws_sns: true, sns_arn: Some("".to_string()) }, - -// instrumentation_args: InstrumentationCliArgs { -// otel_service_name: Some("".to_string()), -// otel_collector_endpoint: None, -// log_level: Level::INFO, -// }, - -// mongodb_args: MongoDBCliArgs { -// mongodb: true, -// mongodb_connection_url: Some("".to_string()), -// mongodb_database_name: Some("".to_string()), -// }, - -// madara_rpc_url: Url::parse("http://localhost:8545").unwrap(), - -// sharp_args: SharpCliArgs { -// sharp: true, -// sharp_customer_id: Some("".to_string()), -// sharp_url: Some(Url::parse("http://localhost:8545").unwrap()), -// sharp_user_crt: Some("".to_string()), -// sharp_user_key: Some("".to_string()), -// sharp_rpc_node_url: Some(Url::parse("http://localhost:8545").unwrap()), -// sharp_proof_layout: Some("".to_string()), -// gps_verifier_contract_address: Some("".to_string()), -// sharp_server_crt: Some("".to_string()), -// }, - -// starknet_args: StarknetSettlementCliArgs { -// starknet_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), -// starknet_private_key: Some("".to_string()), -// starknet_account_address: Some("".to_string()), -// starknet_cairo_core_contract_address: Some("".to_string()), -// starknet_finality_retry_wait_in_secs: Some(0), -// settle_on_starknet: false, -// }, - -// ethereum_args: EthereumSettlementCliArgs { -// ethereum_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), -// ethereum_private_key: Some("".to_string()), -// l1_core_contract_address: Some("".to_string()), -// starknet_operator_address: Some("".to_string()), -// settle_on_ethereum: true, -// }, - -// ethereum_da_args: EthereumDaCliArgs { -// da_on_ethereum: true, -// ethereum_da_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), -// }, - -// snos_args: SNOSCliArgs { rpc_for_snos: Url::parse("http://localhost:8545").unwrap() }, - -// service_args: ServiceCliArgs { -// max_block_to_process: Some("".to_string()), -// min_block_to_process: Some("".to_string()), -// }, -// } -// } - -// // Let's create a test for the CLI each validator - -// #[rstest] -// fn test_validate_provider_params(setup_cmd: RunCmd) { -// let provider_params = setup_cmd.validate_provider_params(); -// assert!(provider_params.is_ok()); -// } - -// #[rstest] -// fn test_validate_alert_params(setup_cmd: RunCmd) { -// let alert_params = setup_cmd.validate_alert_params(); -// assert!(alert_params.is_ok()); -// } - -// #[rstest] -// fn test_validate_queue_params(setup_cmd: RunCmd) { -// let queue_params = setup_cmd.validate_queue_params(); -// assert!(queue_params.is_ok()); -// } - -// #[rstest] -// fn test_validate_storage_params(setup_cmd: RunCmd) { -// let storage_params = setup_cmd.validate_storage_params(); -// assert!(storage_params.is_ok()); -// } - -// #[rstest] -// fn test_validate_database_params(setup_cmd: RunCmd) { -// let database_params = setup_cmd.validate_database_params(); -// assert!(database_params.is_ok()); -// } - -// #[rstest] -// fn test_validate_da_params(setup_cmd: RunCmd) { -// let da_params = setup_cmd.validate_da_params(); -// assert!(da_params.is_ok()); -// } - -// #[rstest] -// fn test_validate_settlement_params(setup_cmd: RunCmd) { -// let settlement_params = setup_cmd.validate_settlement_params(); -// assert!(settlement_params.is_ok()); -// } - -// #[rstest] -// fn test_validate_prover_params(setup_cmd: RunCmd) { -// let prover_params = setup_cmd.validate_prover_params(); -// assert!(prover_params.is_ok()); -// } - -// #[rstest] -// fn test_validate_cron_params(setup_cmd: RunCmd) { -// let cron_params = setup_cmd.validate_cron_params(); -// assert!(cron_params.is_ok()); -// } - -// #[rstest] -// fn test_validate_instrumentation_params(setup_cmd: RunCmd) { -// let instrumentation_params = setup_cmd.validate_instrumentation_params(); -// assert!(instrumentation_params.is_ok()); -// } - -// #[rstest] -// fn test_validate_server_params(setup_cmd: RunCmd) { -// let server_params = setup_cmd.validate_server_params(); -// assert!(server_params.is_ok()); -// } - -// #[rstest] -// fn test_validate_snos_params(setup_cmd: RunCmd) { -// let snos_params = setup_cmd.validate_snos_params(); -// assert!(snos_params.is_ok()); -// } - -// #[rstest] -// fn test_validate_service_params(setup_cmd: RunCmd) { -// let service_params = setup_cmd.validate_service_params(); -// assert!(service_params.is_ok()); -// } -// } + pub(crate) fn validate_database_params(mongodb_args: &MongoDBCliArgs) -> Result { + if mongodb_args.mongodb { + Ok(DatabaseValidatedArgs::MongoDB(MongoDBValidatedArgs { + connection_url: Url::parse( + &mongodb_args.mongodb_connection_url.clone().expect("MongoDB connection URL is required"), + ) + .expect("Invalid MongoDB connection URL"), + database_name: mongodb_args.mongodb_database_name.clone().expect("MongoDB database name is required"), + })) + } else { + Err("Only MongoDB is supported as of now".to_string()) + } + } + + pub(crate) fn validate_da_params(ethereum_da_args: &EthereumDaCliArgs) -> Result { + if ethereum_da_args.da_on_ethereum { + 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()) + } + } + + pub(crate) fn validate_settlement_params( + ethereum_args: &EthereumSettlementCliArgs, + starknet_args: &StarknetSettlementCliArgs, + ) -> Result { + if ethereum_args.settle_on_ethereum { + if starknet_args.settle_on_starknet { + return Err("Cannot settle on both Ethereum and Starknet".to_string()); + } + let l1_core_contract_address = Address::from_str( + ðereum_args.l1_core_contract_address.clone().expect("L1 core contract address is required"), + ) + .expect("Invalid L1 core contract address"); + let starknet_operator_address = Address::from_str( + ðereum_args.starknet_operator_address.clone().expect("Starknet operator address is required"), + ) + .expect("Invalid Starknet operator address"); + + let ethereum_params = EthereumSettlementValidatedArgs { + ethereum_rpc_url: ethereum_args.ethereum_rpc_url.clone().expect("Ethereum RPC URL is required"), + ethereum_private_key: ethereum_args + .ethereum_private_key + .clone() + .expect("Ethereum private key is required"), + l1_core_contract_address, + starknet_operator_address, + }; + Ok(SettlementValidatedArgs::Ethereum(ethereum_params)) + } else if starknet_args.settle_on_starknet { + if ethereum_args.settle_on_ethereum { + return Err("Cannot settle on both Starknet and Ethereum".to_string()); + } + let starknet_params = StarknetSettlementValidatedArgs { + starknet_rpc_url: starknet_args.starknet_rpc_url.clone().expect("Starknet RPC URL is required"), + starknet_private_key: starknet_args + .starknet_private_key + .clone() + .expect("Starknet private key is required"), + starknet_account_address: starknet_args + .starknet_account_address + .clone() + .expect("Starknet account address is required"), + starknet_cairo_core_contract_address: starknet_args + .starknet_cairo_core_contract_address + .clone() + .expect("Starknet Cairo core contract address is required"), + starknet_finality_retry_wait_in_secs: starknet_args + .starknet_finality_retry_wait_in_secs + .expect("Starknet finality retry wait in seconds is required"), + }; + Ok(SettlementValidatedArgs::Starknet(starknet_params)) + } else { + Err("Settlement layer is required".to_string()) + } + } + + pub(crate) fn validate_prover_params(sharp_args: &SharpCliArgs) -> Result { + if sharp_args.sharp { + Ok(ProverValidatedArgs::Sharp(SharpValidatedArgs { + sharp_customer_id: sharp_args.sharp_customer_id.clone().expect("Sharp customer ID is required"), + sharp_url: sharp_args.sharp_url.clone().expect("Sharp URL is required"), + sharp_user_crt: sharp_args.sharp_user_crt.clone().expect("Sharp user certificate is required"), + sharp_user_key: sharp_args.sharp_user_key.clone().expect("Sharp user key is required"), + sharp_rpc_node_url: sharp_args.sharp_rpc_node_url.clone().expect("Sharp RPC node URL is required"), + sharp_proof_layout: sharp_args.sharp_proof_layout.clone().expect("Sharp proof layout is required"), + gps_verifier_contract_address: sharp_args + .gps_verifier_contract_address + .clone() + .expect("GPS verifier contract address is required"), + sharp_server_crt: sharp_args.sharp_server_crt.clone().expect("Sharp server certificate is required"), + })) + } else { + Err("Only Sharp is supported as of now".to_string()) + } + } + + pub(crate) fn validate_instrumentation_params( + instrumentation_args: &InstrumentationCliArgs, + ) -> Result { + Ok(InstrumentationParams { + otel_service_name: instrumentation_args.otel_service_name.clone().expect("Otel service name is required"), + otel_collector_endpoint: instrumentation_args.otel_collector_endpoint.clone(), + log_level: instrumentation_args.log_level, + }) + } + + pub(crate) fn validate_server_params(server_args: &ServerCliArgs) -> Result { + Ok(ServerParams { host: server_args.host.clone(), port: server_args.port }) + } + + pub(crate) fn validate_service_params(service_args: &ServiceCliArgs) -> Result { + Ok(ServiceParams { + // return None if the value is empty string + max_block_to_process: service_args.max_block_to_process.clone().and_then(|s| { + if s.is_empty() { None } else { Some(s.parse::().expect("Failed to parse max block to process")) } + }), + min_block_to_process: service_args.min_block_to_process.clone().and_then(|s| { + if s.is_empty() { None } else { Some(s.parse::().expect("Failed to parse min block to process")) } + }), + }) + } + + pub(crate) fn validate_snos_params(snos_args: &SNOSCliArgs) -> Result { + Ok(SNOSParams { rpc_for_snos: snos_args.rpc_for_snos.clone() }) + } + + #[cfg(test)] + pub mod test { + + use rstest::rstest; + use tracing::Level; + use url::Url; + + use crate::cli::alert::aws_sns::AWSSNSCliArgs; + use crate::cli::cron::event_bridge::AWSEventBridgeCliArgs; + use crate::cli::da::ethereum::EthereumDaCliArgs; + use crate::cli::database::mongodb::MongoDBCliArgs; + use crate::cli::instrumentation::InstrumentationCliArgs; + use crate::cli::prover::sharp::SharpCliArgs; + use crate::cli::provider::aws::AWSConfigCliArgs; + use crate::cli::queue::aws_sqs::AWSSQSCliArgs; + use crate::cli::server::ServerCliArgs; + use crate::cli::service::ServiceCliArgs; + use crate::cli::settlement::ethereum::EthereumSettlementCliArgs; + use crate::cli::settlement::starknet::StarknetSettlementCliArgs; + use crate::cli::snos::SNOSCliArgs; + use crate::cli::storage::aws_s3::AWSS3CliArgs; + use crate::cli::validate_params::{ + validate_alert_params, validate_cron_params, validate_da_params, validate_database_params, + validate_instrumentation_params, validate_prover_params, validate_provider_params, validate_queue_params, + validate_server_params, validate_service_params, validate_settlement_params, validate_snos_params, + validate_storage_params, + }; + + #[rstest] + #[case(true)] + #[case(false)] + fn test_validate_provider_params(#[case] is_aws: bool) { + let aws_config_args: AWSConfigCliArgs = AWSConfigCliArgs { + aws: is_aws, + aws_access_key_id: "".to_string(), + aws_secret_access_key: "".to_string(), + aws_region: "".to_string(), + }; + + let provider_params = validate_provider_params(&aws_config_args); + if is_aws { + assert!(provider_params.is_ok()); + } else { + assert!(provider_params.is_err()); + } + } + + #[rstest] + #[case(true, true)] + #[case(true, false)] + #[case(false, true)] + #[case(false, false)] + fn test_validate_alert_params(#[case] is_aws: bool, #[case] is_sns: bool) { + let aws_config_args: AWSConfigCliArgs = AWSConfigCliArgs { + aws: is_aws, + aws_access_key_id: "".to_string(), + aws_secret_access_key: "".to_string(), + aws_region: "".to_string(), + }; + let aws_sns_args: AWSSNSCliArgs = AWSSNSCliArgs { aws_sns: is_sns, sns_arn: Some("".to_string()) }; + + let alert_params = validate_alert_params(&aws_sns_args, &aws_config_args); + if is_aws && is_sns { + assert!(alert_params.is_ok()); + } else { + assert!(alert_params.is_err()); + } + } + + #[rstest] + #[case(true, true)] + #[case(true, false)] + #[case(false, true)] + #[case(false, false)] + fn test_validate_queue_params(#[case] is_aws: bool, #[case] is_sqs: bool) { + let aws_config_args: AWSConfigCliArgs = AWSConfigCliArgs { + aws: is_aws, + aws_access_key_id: "".to_string(), + aws_secret_access_key: "".to_string(), + aws_region: "".to_string(), + }; + let aws_sqs_args: AWSSQSCliArgs = AWSSQSCliArgs { + aws_sqs: is_sqs, + queue_base_url: Some("http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000".to_string()), + sqs_prefix: Some("".to_string()), + sqs_suffix: Some("".to_string()), + }; + let queue_params = validate_queue_params(&aws_sqs_args, &aws_config_args); + if is_aws && is_sqs { + assert!(queue_params.is_ok()); + } else { + assert!(queue_params.is_err()); + } + } + + #[rstest] + #[case(true, true)] + #[case(true, false)] + #[case(false, true)] + #[case(false, false)] + fn test_validate_storage_params(#[case] is_aws: bool, #[case] is_s3: bool) { + let aws_s3_args: AWSS3CliArgs = AWSS3CliArgs { aws_s3: is_s3, bucket_name: Some("".to_string()) }; + let aws_config_args: AWSConfigCliArgs = AWSConfigCliArgs { + aws: is_aws, + aws_access_key_id: "".to_string(), + aws_secret_access_key: "".to_string(), + aws_region: "".to_string(), + }; + let storage_params = validate_storage_params(&aws_s3_args, &aws_config_args); + if is_aws && is_s3 { + assert!(storage_params.is_ok()); + } else { + assert!(storage_params.is_err()); + } + } + + #[rstest] + #[case(true)] + #[case(false)] + fn test_validate_database_params(#[case] is_mongodb: bool) { + let mongodb_args: MongoDBCliArgs = MongoDBCliArgs { + mongodb: is_mongodb, + mongodb_connection_url: Some("mongodb://localhost:27017".to_string()), + mongodb_database_name: Some("orchestrator".to_string()), + }; + let database_params = validate_database_params(&mongodb_args); + if is_mongodb { + assert!(database_params.is_ok()); + } else { + assert!(database_params.is_err()); + } + } + + #[rstest] + #[case(true)] + #[case(false)] + fn test_validate_da_params(#[case] is_ethereum: 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(ðereum_da_args); + if is_ethereum { + assert!(da_params.is_ok()); + } else { + assert!(da_params.is_err()); + } + } + + #[rstest] + #[case(true, false)] + #[case(false, true)] + #[case(false, false)] + #[case(true, true)] + fn test_validate_settlement_params(#[case] is_ethereum: bool, #[case] is_starknet: bool) { + let ethereum_args: EthereumSettlementCliArgs = EthereumSettlementCliArgs { + ethereum_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), + ethereum_private_key: Some("".to_string()), + l1_core_contract_address: Some("0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057".to_string()), + starknet_operator_address: Some("0x5b98B836969A60FEC50Fa925905Dd1D382a7db43".to_string()), + settle_on_ethereum: is_ethereum, + }; + let starknet_args: StarknetSettlementCliArgs = StarknetSettlementCliArgs { + starknet_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()), + starknet_private_key: Some("".to_string()), + starknet_account_address: Some("".to_string()), + starknet_cairo_core_contract_address: Some("".to_string()), + starknet_finality_retry_wait_in_secs: Some(0), + settle_on_starknet: is_starknet, + }; + let settlement_params = validate_settlement_params(ðereum_args, &starknet_args); + if is_ethereum ^ is_starknet { + assert!(settlement_params.is_ok()); + } else { + assert!(settlement_params.is_err()); + } + } + + #[rstest] + #[case(true)] + #[case(false)] + fn test_validate_prover_params(#[case] is_sharp: bool) { + let sharp_args: SharpCliArgs = SharpCliArgs { + sharp: is_sharp, + sharp_customer_id: Some("".to_string()), + sharp_url: Some(Url::parse("http://localhost:8545").unwrap()), + sharp_user_crt: Some("".to_string()), + sharp_user_key: Some("".to_string()), + sharp_rpc_node_url: Some(Url::parse("http://localhost:8545").unwrap()), + sharp_proof_layout: Some("".to_string()), + gps_verifier_contract_address: Some("".to_string()), + sharp_server_crt: Some("".to_string()), + }; + let prover_params = validate_prover_params(&sharp_args); + if is_sharp { + assert!(prover_params.is_ok()); + } else { + assert!(prover_params.is_err()); + } + } + + #[rstest] + #[case(true)] + #[case(false)] + fn test_validate_cron_params(#[case] is_aws: bool) { + let aws_event_bridge_args: AWSEventBridgeCliArgs = AWSEventBridgeCliArgs { + aws_event_bridge: is_aws, + target_queue_name: Some(String::from("test")), + cron_time: Some(String::from("12")), + trigger_rule_name: Some(String::from("test")), + }; + let aws_config_args: AWSConfigCliArgs = AWSConfigCliArgs { + aws: is_aws, + aws_access_key_id: "".to_string(), + aws_secret_access_key: "".to_string(), + aws_region: "".to_string(), + }; + let cron_params = validate_cron_params(&aws_event_bridge_args, &aws_config_args); + if is_aws { + assert!(cron_params.is_ok()); + } else { + assert!(cron_params.is_err()); + } + } + + #[rstest] + fn test_validate_instrumentation_params() { + let instrumentation_args: InstrumentationCliArgs = InstrumentationCliArgs { + otel_service_name: Some("".to_string()), + otel_collector_endpoint: None, + log_level: Level::INFO, + }; + let instrumentation_params = validate_instrumentation_params(&instrumentation_args); + assert!(instrumentation_params.is_ok()); + } + + #[rstest] + fn test_validate_server_params() { + let server_args: ServerCliArgs = ServerCliArgs { host: "".to_string(), port: 0 }; + let server_params = validate_server_params(&server_args); + assert!(server_params.is_ok()); + } + + #[rstest] + fn test_validate_snos_params() { + let snos_args: SNOSCliArgs = SNOSCliArgs { rpc_for_snos: Url::parse("http://localhost:8545").unwrap() }; + let snos_params = validate_snos_params(&snos_args); + assert!(snos_params.is_ok()); + } + + #[rstest] + fn test_validate_service_params() { + let service_args: ServiceCliArgs = ServiceCliArgs { + max_block_to_process: Some("66645".to_string()), + min_block_to_process: Some("100".to_string()), + }; + let service_params = validate_service_params(&service_args); + assert!(service_params.is_ok()); + let service_params = service_params.unwrap(); + assert_eq!(service_params.max_block_to_process, Some(66645)); + assert_eq!(service_params.min_block_to_process, Some(100)); + } + } +} diff --git a/crates/orchestrator/src/setup/mod.rs b/crates/orchestrator/src/setup/mod.rs index 10c4e8b0..e917de3d 100644 --- a/crates/orchestrator/src/setup/mod.rs +++ b/crates/orchestrator/src/setup/mod.rs @@ -23,15 +23,15 @@ pub enum SetupConfig { } // TODO : move this to main.rs after moving to clap. -pub async fn setup_cloud(run_cmd: &SetupCmd) -> color_eyre::Result<()> { +pub async fn setup_cloud(setup_cmd: &SetupCmd) -> color_eyre::Result<()> { println!("Setting up cloud. ⏳"); // AWS - let provider_params = run_cmd.validate_provider_params().expect("Failed to validate provider params"); + let provider_params = setup_cmd.validate_provider_params().expect("Failed to validate provider params"); let provider_config = build_provider_config(&provider_params).await; // Data Storage println!("Setting up data storage. ⏳"); - let data_storage_params = run_cmd.validate_storage_params().expect("Failed to validate storage params"); + let data_storage_params = setup_cmd.validate_storage_params().expect("Failed to validate storage params"); let aws_config = provider_config.get_aws_client_or_panic(); match data_storage_params { @@ -44,7 +44,7 @@ pub async fn setup_cloud(run_cmd: &SetupCmd) -> color_eyre::Result<()> { // Queues println!("Setting up queues. ⏳"); - let queue_params = run_cmd.validate_queue_params().expect("Failed to validate queue params"); + let queue_params = setup_cmd.validate_queue_params().expect("Failed to validate queue params"); match queue_params { QueueValidatedArgs::AWSSQS(aws_sqs_params) => { let sqs = Box::new(SqsQueue::new_with_args(aws_sqs_params, aws_config)); @@ -55,7 +55,7 @@ pub async fn setup_cloud(run_cmd: &SetupCmd) -> color_eyre::Result<()> { // Cron println!("Setting up cron. ⏳"); - let cron_params = run_cmd.validate_cron_params().expect("Failed to validate cron params"); + let cron_params = setup_cmd.validate_cron_params().expect("Failed to validate cron params"); match cron_params { CronValidatedArgs::AWSEventBridge(aws_event_bridge_params) => { let aws_config = provider_config.get_aws_client_or_panic(); @@ -67,7 +67,7 @@ pub async fn setup_cloud(run_cmd: &SetupCmd) -> color_eyre::Result<()> { // Alerts println!("Setting up alerts. ⏳"); - let alert_params = run_cmd.validate_alert_params().expect("Failed to validate alert params"); + let alert_params = setup_cmd.validate_alert_params().expect("Failed to validate alert params"); match alert_params { AlertValidatedArgs::AWSSNS(aws_sns_params) => { let aws_config = provider_config.get_aws_client_or_panic(); diff --git a/crates/orchestrator/src/tests/common/mod.rs b/crates/orchestrator/src/tests/common/mod.rs index 54c43511..7e5f7c9e 100644 --- a/crates/orchestrator/src/tests/common/mod.rs +++ b/crates/orchestrator/src/tests/common/mod.rs @@ -53,8 +53,9 @@ pub async fn create_sns_arn( alert_params: &AlertValidatedArgs, ) -> Result<(), SdkError> { let AlertValidatedArgs::AWSSNS(aws_sns_params) = alert_params; + let topic_name = aws_sns_params.topic_arn.split(":").last().unwrap(); let sns_client = get_sns_client(provider_config.get_aws_client_or_panic()).await; - sns_client.create_topic().name(aws_sns_params.topic_arn.clone()).send().await?; + sns_client.create_topic().name(topic_name).send().await?; Ok(()) } diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 22da06b7..811e5ec2 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -512,7 +512,7 @@ fn get_env_params() -> EnvParams { }); let alert_params = AlertValidatedArgs::AWSSNS(AWSSNSValidatedArgs { - topic_arn: get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_SNS_ARN_NAME"), + topic_arn: get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_SNS_ARN"), }); let settlement_params = SettlementValidatedArgs::Ethereum(EthereumSettlementValidatedArgs { diff --git a/crates/settlement-clients/ethereum/Cargo.toml b/crates/settlement-clients/ethereum/Cargo.toml index 987672f7..c0c56f92 100644 --- a/crates/settlement-clients/ethereum/Cargo.toml +++ b/crates/settlement-clients/ethereum/Cargo.toml @@ -4,8 +4,8 @@ version.workspace = true edition.workspace = true [dependencies] -alloy-primitives = { version = "0.7.7", default-features = false } alloy = { workspace = true, features = ["full", "node-bindings"] } +alloy-primitives = { version = "0.7.7", default-features = false } async-trait = { workspace = true } bytes = "1.7.2" c-kzg = { workspace = true } diff --git a/crates/settlement-clients/starknet/Cargo.toml b/crates/settlement-clients/starknet/Cargo.toml index 42be56a9..06154407 100644 --- a/crates/settlement-clients/starknet/Cargo.toml +++ b/crates/settlement-clients/starknet/Cargo.toml @@ -4,8 +4,8 @@ version.workspace = true edition.workspace = true [dependencies] -alloy-primitives = { version = "0.7.7", default-features = false } alloy = { workspace = true, features = ["full", "node-bindings"] } +alloy-primitives = { version = "0.7.7", default-features = false } appchain-core-contract-client = { workspace = true } async-trait = { workspace = true } c-kzg = { workspace = true } diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 00d8245c..ade0d17b 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -5,7 +5,6 @@ pub mod tests; use std::sync::Arc; -use alloy_primitives::Address; use appchain_core_contract_client::clients::StarknetCoreContractClient; use appchain_core_contract_client::interfaces::core_contract::CoreContract; use async_trait::async_trait; @@ -45,8 +44,8 @@ use url::Url; pub struct StarknetSettlementValidatedArgs { pub starknet_rpc_url: Url, pub starknet_private_key: String, - pub starknet_account_address: Address, - pub starknet_cairo_core_contract_address: Address, + pub starknet_account_address: String, + pub starknet_cairo_core_contract_address: String, pub starknet_finality_retry_wait_in_secs: u64, } diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index cd0a6c85..d4860e40 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -1,10 +1,8 @@ use std::env; use std::path::Path; -use std::str::FromStr as _; use std::sync::Arc; use std::time::Duration; -use alloy_primitives::Address; use color_eyre::eyre::eyre; use rstest::{fixture, rstest}; use settlement_client_interface::SettlementClient; @@ -84,14 +82,10 @@ async fn setup(#[future] spin_up_madara: MadaraCmd) -> (LocalWalletSignerMiddlew let starknet_settlement_params: StarknetSettlementValidatedArgs = StarknetSettlementValidatedArgs { starknet_rpc_url: Url::parse(madara_process.rpc_url.as_ref()).unwrap(), starknet_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY"), - starknet_account_address: Address::from_str(&get_env_var_or_panic( - "MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS", - )) - .unwrap(), - starknet_cairo_core_contract_address: Address::from_str(&get_env_var_or_panic( + starknet_account_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS"), + starknet_cairo_core_contract_address: get_env_var_or_panic( "MADARA_ORCHESTRATOR_STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", - )) - .unwrap(), + ), starknet_finality_retry_wait_in_secs: get_env_var_or_panic( "MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS", ) @@ -126,14 +120,10 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) let mut starknet_settlement_params: StarknetSettlementValidatedArgs = StarknetSettlementValidatedArgs { starknet_rpc_url: madara_process.rpc_url.clone(), starknet_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY"), - starknet_account_address: Address::from_str(&get_env_var_or_panic( - "MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS", - )) - .unwrap(), - starknet_cairo_core_contract_address: Address::from_str(&get_env_var_or_panic( + starknet_account_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS"), + starknet_cairo_core_contract_address: get_env_var_or_panic( "MADARA_ORCHESTRATOR_STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", - )) - .unwrap(), + ), starknet_finality_retry_wait_in_secs: get_env_var_or_panic( "MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS", ) @@ -170,8 +160,7 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) let deployed_address = deploy_v1.deployed_address(); // env::set_var("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", deployed_address.to_hex_string()); - starknet_settlement_params.starknet_cairo_core_contract_address = - Address::from_str(&deployed_address.to_hex_string()).unwrap(); + starknet_settlement_params.starknet_cairo_core_contract_address = deployed_address.to_hex_string(); let InvokeTransactionResult { transaction_hash: deploy_tx_hash } = deploy_v1.send().await.expect("Unable to deploy contract"); diff --git a/e2e-tests/src/node.rs b/e2e-tests/src/node.rs index 58c50a45..0603cb40 100644 --- a/e2e-tests/src/node.rs +++ b/e2e-tests/src/node.rs @@ -37,6 +37,7 @@ pub enum OrchestratorMode { impl Orchestrator { pub fn new(mode: OrchestratorMode, mut envs: Vec<(String, String)>) -> Option { let repository_root = &get_repository_root(); + let mut address = String::new(); std::env::set_current_dir(repository_root).expect("Failed to change working directory"); let is_run_mode = mode == OrchestratorMode::Run; @@ -65,34 +66,24 @@ impl Orchestrator { command.arg("--da-on-ethereum"); command.arg("--sharp"); command.arg("--mongodb"); - - } else { - command.arg("--aws-event-bridge"); - } - // Configure run-specific settings - let address = if is_run_mode { let port = get_free_port(); let addr = format!("127.0.0.1:{}", port); envs.push(("MADARA_ORCHESTRATOR_PORT".to_string(), port.to_string())); - addr - } else { - String::new() - }; + address = addr; - command.current_dir(repository_root).envs(envs); - - // Handle stdout/stderr differently based on mode - if is_run_mode { command.stdout(Stdio::piped()).stderr(Stdio::piped()); } else { + command.arg("--aws-event-bridge"); + // For setup mode, inherit the stdio to show output directly command.stdout(Stdio::inherit()).stderr(Stdio::inherit()); } + command.current_dir(repository_root).envs(envs); + let mut process = command.spawn().expect("Failed to start process"); - // Set up stdout and stderr handling only for run mode if is_run_mode { let stdout = process.stdout.take().expect("Failed to capture stdout"); thread::spawn(move || { @@ -113,9 +104,8 @@ impl Orchestrator { } }); }); - } - - if is_run_mode { Some(Self { process, address }) } else { + Some(Self { process, address }) + } else { // Wait for the process to complete and get its exit status let status = process.wait().expect("Failed to wait for process"); if status.success() { @@ -129,9 +119,9 @@ impl Orchestrator { } } None - } + } } - + pub fn endpoint(&self) -> Url { Url::parse(&format!("http://{}", self.address)).unwrap() } diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index 8ff2900f..89a63ee4 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -45,7 +45,7 @@ struct Setup { mongo_db_instance: MongoDbServer, starknet_client: StarknetClient, sharp_client: SharpClient, - env_vector: Vec<(String, String)>, + env_vector: HashMap, } impl Setup { @@ -72,34 +72,38 @@ impl Setup { let (starknet_core_contract_address, verifier_contract_address) = anvil_setup.deploy_contracts().await; println!("✅ Anvil setup completed"); - let mut env_vec: Vec<(String, String)> = - vec![("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL".to_string(), mongo_db_instance.endpoint().to_string())]; + let mut env_vec: HashMap = HashMap::new(); + + let env_vars = dotenvy::vars(); + for (key, value) in env_vars { + env_vec.insert(key, value); + } + + env_vec + .insert("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL".to_string(), mongo_db_instance.endpoint().to_string()); // Adding other values to the environment variables vector - env_vec.push(("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL".to_string(), anvil_setup.rpc_url.to_string())); - env_vec.push(("MADARA_ORCHESTRATOR_SHARP_URL".to_string(), sharp_client.url())); + env_vec.insert("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL".to_string(), anvil_setup.rpc_url.to_string()); + env_vec.insert("MADARA_ORCHESTRATOR_SHARP_URL".to_string(), sharp_client.url()); // Adding impersonation for operator as our own address here. // As we are using test contracts thus we don't need any impersonation. // But that logic is being used in integration tests so to keep that. We // add this address here. // Anvil.addresses[0] - env_vec.push(( + env_vec.insert( "MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS".to_string(), "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266".to_string(), - )); - env_vec.push(( + ); + env_vec.insert( "MADARA_ORCHESTRATOR_GPS_VERIFIER_CONTRACT_ADDRESS".to_string(), verifier_contract_address.to_string(), - )); - env_vec.push(( + ); + env_vec.insert( "MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS".to_string(), starknet_core_contract_address.to_string(), - )); - env_vec.push(("MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS".to_string(), l2_block_number)); - - let env_vec_2: Vec<(String, String)> = set_env_vars(); - env_vec.extend(env_vec_2); + ); + env_vec.insert("MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS".to_string(), l2_block_number); Self { mongo_db_instance, starknet_client, sharp_client, env_vector: env_vec } } @@ -118,7 +122,7 @@ impl Setup { } pub fn envs(&self) -> Vec<(String, String)> { - self.env_vector.clone() + self.env_vector.iter().map(|(k, v)| (k.clone(), v.clone())).collect() } } @@ -477,115 +481,3 @@ pub async fn setup_s3(s3_client: &Box) -> color_e s3_client.create_bucket(&get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME")).await.unwrap(); Ok(()) } - -fn set_env_vars() -> Vec<(String, String)> { - let env_vec: Vec<(String, String)> = vec![ - // AWS Config - ("AWS_ACCESS_KEY_ID".to_string(), get_env_var_or_panic("AWS_ACCESS_KEY_ID")), - ("AWS_SECRET_ACCESS_KEY".to_string(), get_env_var_or_panic("AWS_SECRET_ACCESS_KEY")), - ("AWS_REGION".to_string(), get_env_var_or_panic("AWS_REGION")), - ("AWS_ENDPOINT_URL".to_string(), get_env_var_or_panic("AWS_ENDPOINT_URL")), - ("AWS_DEFAULT_REGION".to_string(), get_env_var_or_panic("AWS_DEFAULT_REGION")), - // Alerts - ("MADARA_ORCHESTRATOR_AWS_SNS_ARN".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_SNS_ARN")), - // Data Availability - ( - "MADARA_ORCHESTRATOR_ETHEREUM_DA_RPC_URL".to_string(), - get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_DA_RPC_URL"), - ), - // Database - // ("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL".to_string(), - // get_env_var_or_panic("MADARA_ORCHESTRATOR_MONGODB_CONNECTION_URL")), - ("MADARA_ORCHESTRATOR_DATABASE_NAME".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_DATABASE_NAME")), - // Prover - ( - "MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID".to_string(), - get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID"), - ), - // ("MADARA_ORCHESTRATOR_SHARP_URL".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_URL")), - ("MADARA_ORCHESTRATOR_SHARP_USER_CRT".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_USER_CRT")), - ("MADARA_ORCHESTRATOR_SHARP_USER_KEY".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_USER_KEY")), - ( - "MADARA_ORCHESTRATOR_SHARP_SERVER_CRT".to_string(), - get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_SERVER_CRT"), - ), - ( - "MADARA_ORCHESTRATOR_SHARP_RPC_NODE_URL".to_string(), - get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_RPC_NODE_URL"), - ), - ( - "MADARA_ORCHESTRATOR_SHARP_PROOF_LAYOUT".to_string(), - get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_PROOF_LAYOUT"), - ), - // ("MADARA_ORCHESTRATOR_GPS_VERIFIER_CONTRACT_ADDRESS".to_string(), - // get_env_var_or_panic("MADARA_ORCHESTRATOR_GPS_VERIFIER_CONTRACT_ADDRESS")), - - // Queue - ("MADARA_ORCHESTRATOR_SQS_PREFIX".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_PREFIX")), - ("MADARA_ORCHESTRATOR_SQS_SUFFIX".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_SUFFIX")), - ( - "MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL".to_string(), - get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_BASE_QUEUE_URL"), - ), - // Settlement - Ethereum - // ("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL".to_string(), - // get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL")), - ( - "MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY".to_string(), - get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_PRIVATE_KEY"), - ), - // ("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS".to_string(), - // get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS")), - // ("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS".to_string(), - // get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS")), - - // Settlement - Starknet - ( - "MADARA_ORCHESTRATOR_STARKNET_SETTLEMENT_RPC_URL".to_string(), - get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_SETTLEMENT_RPC_URL"), - ), - ( - "MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY".to_string(), - get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY"), - ), - ( - "MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS".to_string(), - get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS"), - ), - ( - "MADARA_ORCHESTRATOR_STARKNET_CAIRO_CORE_CONTRACT_ADDRESS".to_string(), - get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_CAIRO_CORE_CONTRACT_ADDRESS"), - ), - ( - "MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS".to_string(), - get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS"), - ), - // ( - // "MADARA_ORCHESTRATOR_MADARA_BINARY_PATH".to_string(), - // get_env_var_or_panic("MADARA_ORCHESTRATOR_MADARA_BINARY_PATH"), - // ), - // Storage - ( - "MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME".to_string(), - get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_S3_BUCKET_NAME"), - ), - // Instrumentation - ( - "MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME".to_string(), - get_env_var_or_panic("MADARA_ORCHESTRATOR_OTEL_SERVICE_NAME"), - ), - // Server - ("MADARA_ORCHESTRATOR_HOST".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_HOST")), - ("MADARA_ORCHESTRATOR_PORT".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_PORT")), - // Service - // ("MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS".to_string(), - // get_env_var_or_panic("MADARA_ORCHESTRATOR_MAX_BLOCK_NO_TO_PROCESS")), - // ( - // "MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS".to_string(), - // get_env_var_or_panic("MADARA_ORCHESTRATOR_MIN_BLOCK_NO_TO_PROCESS"), - // ), - // SNOS - ("MADARA_ORCHESTRATOR_RPC_FOR_SNOS".to_string(), get_env_var_or_panic("MADARA_ORCHESTRATOR_RPC_FOR_SNOS")), - ]; - env_vec -} From a7e5947fd726e14972baace398f9ce2dd7a05f0f Mon Sep 17 00:00:00 2001 From: mohiiit Date: Tue, 19 Nov 2024 19:38:39 +0530 Subject: [PATCH 60/63] resolved: comments --- Cargo.toml | 1 + crates/da-clients/ethereum/src/lib.rs | 2 - crates/orchestrator/src/alerts/aws_sns/mod.rs | 2 +- crates/orchestrator/src/cli/alert/aws_sns.rs | 2 +- .../orchestrator/src/cli/cron/event_bridge.rs | 4 +- crates/orchestrator/src/cli/mod.rs | 89 +++++++++---------- crates/orchestrator/src/cli/queue/aws_sqs.rs | 2 +- crates/orchestrator/src/cli/storage/aws_s3.rs | 2 +- crates/orchestrator/src/queue/job_queue.rs | 2 +- crates/orchestrator/src/setup/mod.rs | 18 ++-- crates/orchestrator/src/telemetry.rs | 14 +-- crates/orchestrator/src/workers/snos.rs | 4 +- .../gps-fact-checker/src/lib.rs | 8 +- crates/settlement-clients/ethereum/Cargo.toml | 2 +- crates/settlement-clients/starknet/Cargo.toml | 2 +- madara-bootstrapper | 2 +- 16 files changed, 77 insertions(+), 79 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ab790150..ed7c1a7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ alloy = { version = "0.2.1", features = [ "json-rpc", "rpc-client", ] } +alloy-primitives = { version = "0.7.7", default-features = false } aws-config = { version = "1.1.7", features = ["behavior-version-latest"] } aws-sdk-s3 = { version = "1.38.0", features = ["behavior-version-latest"] } aws-sdk-eventbridge = { version = "1.41.0", features = [ diff --git a/crates/da-clients/ethereum/src/lib.rs b/crates/da-clients/ethereum/src/lib.rs index e9b4aefa..ee156c91 100644 --- a/crates/da-clients/ethereum/src/lib.rs +++ b/crates/da-clients/ethereum/src/lib.rs @@ -21,8 +21,6 @@ pub struct EthereumDaValidatedArgs { pub ethereum_da_rpc_url: Url, } -pub const DA_SETTINGS_NAME: &str = "ethereum"; - pub struct EthereumDaClient { #[allow(dead_code)] provider: RootProvider>, diff --git a/crates/orchestrator/src/alerts/aws_sns/mod.rs b/crates/orchestrator/src/alerts/aws_sns/mod.rs index e7416d6e..cc0a608c 100644 --- a/crates/orchestrator/src/alerts/aws_sns/mod.rs +++ b/crates/orchestrator/src/alerts/aws_sns/mod.rs @@ -37,6 +37,6 @@ impl Alerts for AWSSNS { } async fn get_topic_name(&self) -> String { - self.topic_arn.split(":").last().unwrap().to_string() + self.topic_arn.split(":").last().expect("Failed to get last part of topic ARN").to_string() } } diff --git a/crates/orchestrator/src/cli/alert/aws_sns.rs b/crates/orchestrator/src/cli/alert/aws_sns.rs index 93355374..2e9e9860 100644 --- a/crates/orchestrator/src/cli/alert/aws_sns.rs +++ b/crates/orchestrator/src/cli/alert/aws_sns.rs @@ -8,7 +8,7 @@ pub struct AWSSNSCliArgs { #[arg(long)] pub aws_sns: bool, - /// The name of the S3 bucket. + /// The ARN of the SNS topic. #[arg(env = "MADARA_ORCHESTRATOR_AWS_SNS_ARN", long, default_value = Some("arn:aws:sns:us-east-1:000000000000:madara-orchestrator-arn"))] pub sns_arn: Option, } diff --git a/crates/orchestrator/src/cli/cron/event_bridge.rs b/crates/orchestrator/src/cli/cron/event_bridge.rs index a7dba45d..923d3736 100644 --- a/crates/orchestrator/src/cli/cron/event_bridge.rs +++ b/crates/orchestrator/src/cli/cron/event_bridge.rs @@ -1,6 +1,6 @@ use clap::Args; -/// Parameters used to config AWS SNS. +/// CLI arguments for the aws event bridge. #[derive(Debug, Clone, Args)] #[group()] pub struct AWSEventBridgeCliArgs { @@ -8,7 +8,7 @@ pub struct AWSEventBridgeCliArgs { #[arg(long)] pub aws_event_bridge: bool, - /// The name of the S3 bucket. + /// The name of the queue for the event bridge #[arg(env = "MADARA_ORCHESTRATOR_EVENT_BRIDGE_TARGET_QUEUE_NAME", long, default_value = Some("madara_orchestrator_worker_trigger_queue"), help = "The name of the SNS queue to send messages to from the event bridge.")] pub target_queue_name: Option, /// The cron time for the event bridge trigger rule. diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index c067b7db..43359276 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -443,54 +443,51 @@ pub mod validate_params { ethereum_args: &EthereumSettlementCliArgs, starknet_args: &StarknetSettlementCliArgs, ) -> Result { - if ethereum_args.settle_on_ethereum { - if starknet_args.settle_on_starknet { - return Err("Cannot settle on both Ethereum and Starknet".to_string()); + match (ethereum_args.settle_on_ethereum, starknet_args.settle_on_starknet) { + (true, true) => Err("Cannot settle on both Ethereum and Starknet".to_string()), + (true, false) => { + let l1_core_contract_address = Address::from_str( + ðereum_args.l1_core_contract_address.clone().expect("L1 core contract address is required"), + ) + .expect("Invalid L1 core contract address"); + let starknet_operator_address = Address::from_str( + ðereum_args.starknet_operator_address.clone().expect("Starknet operator address is required"), + ) + .expect("Invalid Starknet operator address"); + + let ethereum_params = EthereumSettlementValidatedArgs { + ethereum_rpc_url: ethereum_args.ethereum_rpc_url.clone().expect("Ethereum RPC URL is required"), + ethereum_private_key: ethereum_args + .ethereum_private_key + .clone() + .expect("Ethereum private key is required"), + l1_core_contract_address, + starknet_operator_address, + }; + Ok(SettlementValidatedArgs::Ethereum(ethereum_params)) } - let l1_core_contract_address = Address::from_str( - ðereum_args.l1_core_contract_address.clone().expect("L1 core contract address is required"), - ) - .expect("Invalid L1 core contract address"); - let starknet_operator_address = Address::from_str( - ðereum_args.starknet_operator_address.clone().expect("Starknet operator address is required"), - ) - .expect("Invalid Starknet operator address"); - - let ethereum_params = EthereumSettlementValidatedArgs { - ethereum_rpc_url: ethereum_args.ethereum_rpc_url.clone().expect("Ethereum RPC URL is required"), - ethereum_private_key: ethereum_args - .ethereum_private_key - .clone() - .expect("Ethereum private key is required"), - l1_core_contract_address, - starknet_operator_address, - }; - Ok(SettlementValidatedArgs::Ethereum(ethereum_params)) - } else if starknet_args.settle_on_starknet { - if ethereum_args.settle_on_ethereum { - return Err("Cannot settle on both Starknet and Ethereum".to_string()); + (false, true) => { + let starknet_params = StarknetSettlementValidatedArgs { + starknet_rpc_url: starknet_args.starknet_rpc_url.clone().expect("Starknet RPC URL is required"), + starknet_private_key: starknet_args + .starknet_private_key + .clone() + .expect("Starknet private key is required"), + starknet_account_address: starknet_args + .starknet_account_address + .clone() + .expect("Starknet account address is required"), + starknet_cairo_core_contract_address: starknet_args + .starknet_cairo_core_contract_address + .clone() + .expect("Starknet Cairo core contract address is required"), + starknet_finality_retry_wait_in_secs: starknet_args + .starknet_finality_retry_wait_in_secs + .expect("Starknet finality retry wait in seconds is required"), + }; + Ok(SettlementValidatedArgs::Starknet(starknet_params)) } - let starknet_params = StarknetSettlementValidatedArgs { - starknet_rpc_url: starknet_args.starknet_rpc_url.clone().expect("Starknet RPC URL is required"), - starknet_private_key: starknet_args - .starknet_private_key - .clone() - .expect("Starknet private key is required"), - starknet_account_address: starknet_args - .starknet_account_address - .clone() - .expect("Starknet account address is required"), - starknet_cairo_core_contract_address: starknet_args - .starknet_cairo_core_contract_address - .clone() - .expect("Starknet Cairo core contract address is required"), - starknet_finality_retry_wait_in_secs: starknet_args - .starknet_finality_retry_wait_in_secs - .expect("Starknet finality retry wait in seconds is required"), - }; - Ok(SettlementValidatedArgs::Starknet(starknet_params)) - } else { - Err("Settlement layer is required".to_string()) + (false, false) => Err("Settlement layer is required".to_string()), } } diff --git a/crates/orchestrator/src/cli/queue/aws_sqs.rs b/crates/orchestrator/src/cli/queue/aws_sqs.rs index 0a71d29f..39ee0874 100644 --- a/crates/orchestrator/src/cli/queue/aws_sqs.rs +++ b/crates/orchestrator/src/cli/queue/aws_sqs.rs @@ -8,7 +8,7 @@ pub struct AWSSQSCliArgs { #[arg(long)] pub aws_sqs: bool, - /// The name of the S3 bucket. + /// The prefix of the queue. #[arg(env = "MADARA_ORCHESTRATOR_SQS_PREFIX", long, default_value = Some("madara_orchestrator"))] pub sqs_prefix: Option, diff --git a/crates/orchestrator/src/cli/storage/aws_s3.rs b/crates/orchestrator/src/cli/storage/aws_s3.rs index d678f452..3b801261 100644 --- a/crates/orchestrator/src/cli/storage/aws_s3.rs +++ b/crates/orchestrator/src/cli/storage/aws_s3.rs @@ -2,7 +2,7 @@ use clap::Args; /// Parameters used to config AWS S3. #[derive(Debug, Clone, Args)] -#[group()] +#[group(requires_all = ["bucket_name"])] pub struct AWSS3CliArgs { /// Use the AWS s3 client #[arg(long)] diff --git a/crates/orchestrator/src/queue/job_queue.rs b/crates/orchestrator/src/queue/job_queue.rs index d9f1f153..16b5eedd 100644 --- a/crates/orchestrator/src/queue/job_queue.rs +++ b/crates/orchestrator/src/queue/job_queue.rs @@ -193,7 +193,7 @@ where Fut: Future> + Send, { tracing::debug!("Consuming from queue {:?}", queue); - let delivery = get_delivery_from_queue(queue.clone(), config.clone()).await?; + let delivery = get_delivery_from_queue(queue, Arc::clone(&config)).await?; let message = match delivery { DeliveryReturnType::Message(message) => message, diff --git a/crates/orchestrator/src/setup/mod.rs b/crates/orchestrator/src/setup/mod.rs index e917de3d..eb35d99a 100644 --- a/crates/orchestrator/src/setup/mod.rs +++ b/crates/orchestrator/src/setup/mod.rs @@ -24,13 +24,13 @@ pub enum SetupConfig { // TODO : move this to main.rs after moving to clap. pub async fn setup_cloud(setup_cmd: &SetupCmd) -> color_eyre::Result<()> { - println!("Setting up cloud. ⏳"); + tracing::info!("Setting up cloud. ⏳"); // AWS let provider_params = setup_cmd.validate_provider_params().expect("Failed to validate provider params"); let provider_config = build_provider_config(&provider_params).await; // Data Storage - println!("Setting up data storage. ⏳"); + tracing::info!("Setting up data storage. ⏳"); let data_storage_params = setup_cmd.validate_storage_params().expect("Failed to validate storage params"); let aws_config = provider_config.get_aws_client_or_panic(); @@ -40,10 +40,10 @@ pub async fn setup_cloud(setup_cmd: &SetupCmd) -> color_eyre::Result<()> { s3.setup(&StorageValidatedArgs::AWSS3(aws_s3_params.clone())).await? } } - println!("Data storage setup completed ✅"); + tracing::info!("Data storage setup completed ✅"); // Queues - println!("Setting up queues. ⏳"); + tracing::info!("Setting up queues. ⏳"); let queue_params = setup_cmd.validate_queue_params().expect("Failed to validate queue params"); match queue_params { QueueValidatedArgs::AWSSQS(aws_sqs_params) => { @@ -51,10 +51,10 @@ pub async fn setup_cloud(setup_cmd: &SetupCmd) -> color_eyre::Result<()> { sqs.setup().await? } } - println!("Queues setup completed ✅"); + tracing::info!("Queues setup completed ✅"); // Cron - println!("Setting up cron. ⏳"); + tracing::info!("Setting up cron. ⏳"); let cron_params = setup_cmd.validate_cron_params().expect("Failed to validate cron params"); match cron_params { CronValidatedArgs::AWSEventBridge(aws_event_bridge_params) => { @@ -63,10 +63,10 @@ pub async fn setup_cloud(setup_cmd: &SetupCmd) -> color_eyre::Result<()> { event_bridge.setup().await? } } - println!("Cron setup completed ✅"); + tracing::info!("Cron setup completed ✅"); // Alerts - println!("Setting up alerts. ⏳"); + tracing::info!("Setting up alerts. ⏳"); let alert_params = setup_cmd.validate_alert_params().expect("Failed to validate alert params"); match alert_params { AlertValidatedArgs::AWSSNS(aws_sns_params) => { @@ -75,7 +75,7 @@ pub async fn setup_cloud(setup_cmd: &SetupCmd) -> color_eyre::Result<()> { sns.setup().await? } } - println!("Alerts setup completed ✅"); + tracing::info!("Alerts setup completed ✅"); Ok(()) } diff --git a/crates/orchestrator/src/telemetry.rs b/crates/orchestrator/src/telemetry.rs index 7e29e51d..80315360 100644 --- a/crates/orchestrator/src/telemetry.rs +++ b/crates/orchestrator/src/telemetry.rs @@ -21,6 +21,13 @@ pub struct OTELConfig { service_name: String, } +#[derive(Debug, Clone)] +pub struct InstrumentationParams { + pub otel_service_name: String, + pub otel_collector_endpoint: Option, + pub log_level: Level, +} + pub fn setup_analytics(instrumentation: &InstrumentationParams) -> Option { let otel_config = get_otel_config(instrumentation); let level = instrumentation.log_level; @@ -220,10 +227,3 @@ mod tests { register_metric!(ORCHESTRATOR_METRICS, OrchestratorMetrics); } } - -#[derive(Debug, Clone)] -pub struct InstrumentationParams { - pub otel_service_name: String, - pub otel_collector_endpoint: Option, - pub log_level: Level, -} diff --git a/crates/orchestrator/src/workers/snos.rs b/crates/orchestrator/src/workers/snos.rs index d5364516..a346dd37 100644 --- a/crates/orchestrator/src/workers/snos.rs +++ b/crates/orchestrator/src/workers/snos.rs @@ -34,8 +34,8 @@ impl Worker for SnosWorker { let latest_job_in_db = config.database().get_latest_job_by_type(JobType::SnosRun).await?; let latest_job_id = match latest_job_in_db { - Some(job) => job.internal_id.parse::().unwrap(), - None => "0".to_string().parse::().unwrap(), + Some(job) => job.internal_id.parse::().expect("Failed to parse job internal ID to u64"), + None => "0".to_string().parse::().expect("Failed to parse '0' to u64"), }; // To be used when testing in specific block range diff --git a/crates/prover-services/gps-fact-checker/src/lib.rs b/crates/prover-services/gps-fact-checker/src/lib.rs index 5dccce21..8189e653 100644 --- a/crates/prover-services/gps-fact-checker/src/lib.rs +++ b/crates/prover-services/gps-fact-checker/src/lib.rs @@ -28,9 +28,11 @@ type ProviderT = RootProvider; impl FactChecker { pub fn new(sharp_rpc_node_url: Url, gps_verifier_contract_address: String) -> Self { - let provider = ProviderBuilder::new().on_http(sharp_rpc_node_url.clone()); - let fact_registry = - FactRegistry::new(Address::from_str(gps_verifier_contract_address.as_str()).unwrap(), provider); + let provider = ProviderBuilder::new().on_http(sharp_rpc_node_url); + let fact_registry = FactRegistry::new( + Address::from_str(gps_verifier_contract_address.as_str()).expect("Invalid GPS verifier contract address"), + provider, + ); Self { fact_registry } } diff --git a/crates/settlement-clients/ethereum/Cargo.toml b/crates/settlement-clients/ethereum/Cargo.toml index c0c56f92..9dc43b69 100644 --- a/crates/settlement-clients/ethereum/Cargo.toml +++ b/crates/settlement-clients/ethereum/Cargo.toml @@ -5,7 +5,7 @@ edition.workspace = true [dependencies] alloy = { workspace = true, features = ["full", "node-bindings"] } -alloy-primitives = { version = "0.7.7", default-features = false } +alloy-primitives = { workspace = true, default-features = false } async-trait = { workspace = true } bytes = "1.7.2" c-kzg = { workspace = true } diff --git a/crates/settlement-clients/starknet/Cargo.toml b/crates/settlement-clients/starknet/Cargo.toml index 06154407..bfd9d5a4 100644 --- a/crates/settlement-clients/starknet/Cargo.toml +++ b/crates/settlement-clients/starknet/Cargo.toml @@ -5,7 +5,7 @@ edition.workspace = true [dependencies] alloy = { workspace = true, features = ["full", "node-bindings"] } -alloy-primitives = { version = "0.7.7", default-features = false } +alloy-primitives = { workspace = true, default-features = false } appchain-core-contract-client = { workspace = true } async-trait = { workspace = true } c-kzg = { workspace = true } diff --git a/madara-bootstrapper b/madara-bootstrapper index b0b64750..f717bf17 160000 --- a/madara-bootstrapper +++ b/madara-bootstrapper @@ -1 +1 @@ -Subproject commit b0b647500c2ae3e3b0d99e345fa652989bca4726 +Subproject commit f717bf179581da53d68fee03b50ef78e0628ee20 From 712b6ed9ccbaa2c02fc6f52428ee08e4654af37a Mon Sep 17 00:00:00 2001 From: mohiiit Date: Tue, 19 Nov 2024 23:37:12 +0530 Subject: [PATCH 61/63] resolve: removed bucket name from require_all --- crates/orchestrator/src/cli/storage/aws_s3.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/orchestrator/src/cli/storage/aws_s3.rs b/crates/orchestrator/src/cli/storage/aws_s3.rs index 3b801261..d678f452 100644 --- a/crates/orchestrator/src/cli/storage/aws_s3.rs +++ b/crates/orchestrator/src/cli/storage/aws_s3.rs @@ -2,7 +2,7 @@ use clap::Args; /// Parameters used to config AWS S3. #[derive(Debug, Clone, Args)] -#[group(requires_all = ["bucket_name"])] +#[group()] pub struct AWSS3CliArgs { /// Use the AWS s3 client #[arg(long)] From 81491c3a47196b3d9874fb4ff1c3088a8b7b5bb7 Mon Sep 17 00:00:00 2001 From: mohiiit Date: Wed, 20 Nov 2024 09:39:35 +0530 Subject: [PATCH 62/63] chore: comments added for the decisions taken --- crates/orchestrator/src/cli/storage/aws_s3.rs | 2 +- crates/orchestrator/src/setup/mod.rs | 24 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/crates/orchestrator/src/cli/storage/aws_s3.rs b/crates/orchestrator/src/cli/storage/aws_s3.rs index d678f452..d8da0692 100644 --- a/crates/orchestrator/src/cli/storage/aws_s3.rs +++ b/crates/orchestrator/src/cli/storage/aws_s3.rs @@ -2,7 +2,7 @@ use clap::Args; /// Parameters used to config AWS S3. #[derive(Debug, Clone, Args)] -#[group()] +#[group()] // Note: we are not using bucket_name in requires_all because it has a default value. pub struct AWSS3CliArgs { /// Use the AWS s3 client #[arg(long)] diff --git a/crates/orchestrator/src/setup/mod.rs b/crates/orchestrator/src/setup/mod.rs index eb35d99a..2b440f3b 100644 --- a/crates/orchestrator/src/setup/mod.rs +++ b/crates/orchestrator/src/setup/mod.rs @@ -23,14 +23,16 @@ pub enum SetupConfig { } // TODO : move this to main.rs after moving to clap. +// Note: we are using println! instead of tracing::info! because telemetry is not yet initialized +// and it get initialized during the run_orchestrator function. pub async fn setup_cloud(setup_cmd: &SetupCmd) -> color_eyre::Result<()> { - tracing::info!("Setting up cloud. ⏳"); + println!("Setting up cloud. ⏳"); // AWS let provider_params = setup_cmd.validate_provider_params().expect("Failed to validate provider params"); let provider_config = build_provider_config(&provider_params).await; // Data Storage - tracing::info!("Setting up data storage. ⏳"); + println!("Setting up data storage. ⏳"); let data_storage_params = setup_cmd.validate_storage_params().expect("Failed to validate storage params"); let aws_config = provider_config.get_aws_client_or_panic(); @@ -40,10 +42,10 @@ pub async fn setup_cloud(setup_cmd: &SetupCmd) -> color_eyre::Result<()> { s3.setup(&StorageValidatedArgs::AWSS3(aws_s3_params.clone())).await? } } - tracing::info!("Data storage setup completed ✅"); + println!("Data storage setup completed ✅"); // Queues - tracing::info!("Setting up queues. ⏳"); + println!("Setting up queues. ⏳"); let queue_params = setup_cmd.validate_queue_params().expect("Failed to validate queue params"); match queue_params { QueueValidatedArgs::AWSSQS(aws_sqs_params) => { @@ -51,10 +53,10 @@ pub async fn setup_cloud(setup_cmd: &SetupCmd) -> color_eyre::Result<()> { sqs.setup().await? } } - tracing::info!("Queues setup completed ✅"); + println!("Queues setup completed ✅"); // Cron - tracing::info!("Setting up cron. ⏳"); + println!("Setting up cron. ⏳"); let cron_params = setup_cmd.validate_cron_params().expect("Failed to validate cron params"); match cron_params { CronValidatedArgs::AWSEventBridge(aws_event_bridge_params) => { @@ -63,10 +65,10 @@ pub async fn setup_cloud(setup_cmd: &SetupCmd) -> color_eyre::Result<()> { event_bridge.setup().await? } } - tracing::info!("Cron setup completed ✅"); + println!("Cron setup completed ✅"); // Alerts - tracing::info!("Setting up alerts. ⏳"); + println!("Setting up alerts. ⏳"); let alert_params = setup_cmd.validate_alert_params().expect("Failed to validate alert params"); match alert_params { AlertValidatedArgs::AWSSNS(aws_sns_params) => { @@ -75,18 +77,18 @@ pub async fn setup_cloud(setup_cmd: &SetupCmd) -> color_eyre::Result<()> { sns.setup().await? } } - tracing::info!("Alerts setup completed ✅"); + println!("Alerts setup completed ✅"); Ok(()) } pub async fn setup_db() -> color_eyre::Result<()> { // We run the js script in the folder root: - tracing::info!("Setting up database."); + println!("Setting up database."); Command::new("node").arg("migrate-mongo-config.js").output()?; - tracing::info!("Database setup completed ✅"); + println!("Database setup completed ✅"); Ok(()) } From 58b6dda61a9e0e52c0fc5db21c02daa886e9dda3 Mon Sep 17 00:00:00 2001 From: mohiiit Date: Wed, 20 Nov 2024 10:13:11 +0530 Subject: [PATCH 63/63] chore: setup cloud todo removed, plan dropped to move it to main.rs --- crates/orchestrator/src/setup/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/orchestrator/src/setup/mod.rs b/crates/orchestrator/src/setup/mod.rs index 2b440f3b..6e1a3f0a 100644 --- a/crates/orchestrator/src/setup/mod.rs +++ b/crates/orchestrator/src/setup/mod.rs @@ -22,7 +22,6 @@ pub enum SetupConfig { AWS(SdkConfig), } -// TODO : move this to main.rs after moving to clap. // Note: we are using println! instead of tracing::info! because telemetry is not yet initialized // and it get initialized during the run_orchestrator function. pub async fn setup_cloud(setup_cmd: &SetupCmd) -> color_eyre::Result<()> {